Home | History | Annotate | Download | only in replicaisland
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.replica.replicaisland;
     18 
     19 import com.replica.replicaisland.SoundSystem.Sound;
     20 
     21 public class ButtonAnimationComponent extends GameComponent {
     22     public static final class Animation {
     23         // Animations
     24         public static final int UP = 0;
     25         public static final int DOWN = 1;
     26     }
     27     private ChannelSystem.Channel mChannel;
     28     private SpriteComponent mSprite;
     29     private ChannelSystem.ChannelFloatValue mLastPressedTime;
     30     private Sound mDepressSound;
     31 
     32     public ButtonAnimationComponent() {
     33         super();
     34         setPhase(ComponentPhases.ANIMATION.ordinal());
     35         mLastPressedTime = new ChannelSystem.ChannelFloatValue();
     36         reset();
     37     }
     38 
     39     @Override
     40     public void reset() {
     41         mSprite = null;
     42         mChannel = null;
     43         mLastPressedTime.value = 0.0f;
     44         mDepressSound = null;
     45     }
     46 
     47     @Override
     48     public void update(float timeDelta, BaseObject parent) {
     49         if (mSprite != null) {
     50             GameObject parentObject = (GameObject)parent;
     51 
     52             if (parentObject.getCurrentAction() == GameObject.ActionType.HIT_REACT &&
     53                     parentObject.lastReceivedHitType == CollisionParameters.HitType.DEPRESS) {
     54             	if (mSprite.getCurrentAnimation() == Animation.UP) {
     55             		SoundSystem sound = sSystemRegistry.soundSystem;
     56             		if (sound != null) {
     57             			sound.play(mDepressSound, false, SoundSystem.PRIORITY_NORMAL);
     58             		}
     59             	}
     60                 mSprite.playAnimation(Animation.DOWN);
     61                 parentObject.setCurrentAction(GameObject.ActionType.IDLE);
     62                 if (mChannel != null) {
     63                     TimeSystem time = sSystemRegistry.timeSystem;
     64                     mLastPressedTime.value = time.getGameTime();
     65                     mChannel.value = mLastPressedTime;
     66                 }
     67             } else {
     68                 mSprite.playAnimation(Animation.UP);
     69 
     70             }
     71         }
     72     }
     73 
     74     public void setSprite(SpriteComponent sprite) {
     75         mSprite = sprite;
     76     }
     77 
     78     public void setChannel(ChannelSystem.Channel channel) {
     79         mChannel = channel;
     80     }
     81 
     82 	public void setDepressSound(Sound sound) {
     83 		mDepressSound = sound;
     84 	}
     85 }
     86