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
17package com.replica.replicaisland;
18
19public class GenericAnimationComponent extends GameComponent {
20    private SpriteComponent mSprite;
21
22    public GenericAnimationComponent() {
23        super();
24        setPhase(ComponentPhases.ANIMATION.ordinal());
25        reset();
26    }
27
28    @Override
29    public void reset() {
30        mSprite = null;
31    }
32
33    @Override
34    public void update(float timeDelta, BaseObject parent) {
35        if (mSprite != null) {
36            GameObject parentObject = (GameObject) parent;
37            if (parentObject.facingDirection.x != 0.0f && parentObject.getVelocity().x != 0.0f) {
38                parentObject.facingDirection.x = Utils.sign(parentObject.getVelocity().x);
39            }
40            switch(parentObject.getCurrentAction()) {
41
42                case IDLE:
43                    mSprite.playAnimation(Animation.IDLE);
44                    break;
45                case MOVE:
46                    mSprite.playAnimation(Animation.MOVE);
47                    break;
48                case ATTACK:
49                    mSprite.playAnimation(Animation.ATTACK);
50                    break;
51                case HIT_REACT:
52                    mSprite.playAnimation(Animation.HIT_REACT);
53                    break;
54                case DEATH:
55                    mSprite.playAnimation(Animation.DEATH);
56                    break;
57                case HIDE:
58                    mSprite.playAnimation(Animation.HIDE);
59                    break;
60                case FROZEN:
61                    mSprite.playAnimation(Animation.FROZEN);
62                    break;
63                case INVALID:
64                default:
65                    mSprite.playAnimation(-1);
66                    break;
67            }
68        }
69    }
70
71    public void setSprite(SpriteComponent sprite) {
72        mSprite = sprite;
73    }
74
75
76    public static final class Animation {
77        public static final int IDLE = 0;
78        public static final int MOVE = 1;
79        public static final int ATTACK = 2;
80        public static final int HIT_REACT = 3;
81        public static final int DEATH = 4;
82        public static final int HIDE = 5;
83        public static final int FROZEN = 6;
84    }
85}
86