Browse code

Add stone animation

Pierre Marijon authored on 18/05/2015 18:04:18
Showing 1 changed files
... ...
@@ -23,6 +23,9 @@ package org.geekygoblin.nedetlesmaki.core.components.gamesystems;
23 23
 
24 24
 import com.artemis.Entity;
25 25
 import im.bci.jnuit.animation.IAnimationCollection;
26
+import im.bci.jnuit.animation.PlayMode;
27
+import im.bci.jnuit.artemis.sprite.Sprite;
28
+import im.bci.jnuit.artemis.sprite.SpritePuppetControls;
26 29
 import org.geekygoblin.nedetlesmaki.core.IAssets;
27 30
 import org.geekygoblin.nedetlesmaki.core.backend.LevelIndex;
28 31
 import org.geekygoblin.nedetlesmaki.core.backend.Position;
... ...
@@ -54,25 +57,25 @@ public class Stone extends GameObject {
54 57
     public void setColorType(ColorType c) {
55 58
         this.color = c;
56 59
     }
57
-    
60
+
58 61
     public boolean isPushed() {
59 62
         return this.pushed;
60 63
     }
61 64
 
62 65
     public void setState(boolean new_state) {
63
-        if(new_state == this.pushed) {
66
+        if (new_state == this.pushed) {
64 67
             return;
65 68
         }
66
-        
69
+
67 70
         this.pushed = new_state;
68
-        
69
-        if(this.pushed) {
71
+
72
+        if (this.pushed) {
70 73
             this.run_animations(MoveType.PUSH);
71 74
         } else {
72 75
             this.run_animations(MoveType.OUT);
73 76
         }
74 77
     }
75
-    
78
+
76 79
     @Override
77 80
     public Position moveTo(Position diff, float wait_time) {
78 81
         return this.pos;
... ...
@@ -81,8 +84,31 @@ public class Stone extends GameObject {
81 84
     @Override
82 85
     public void undo() {
83 86
     }
84
-    
87
+
85 88
     private void run_animations(MoveType type) {
86
-    
89
+        Sprite sprite = this.entity.getComponent(Sprite.class);
90
+        SpritePuppetControls updatable = this.entity.getComponent(SpritePuppetControls.class);
91
+
92
+        if (updatable == null) {
93
+            updatable = new SpritePuppetControls(sprite);
94
+        }
95
+
96
+        if (type == MoveType.OUT) {
97
+            if (color == ColorType.green) {
98
+                updatable.startAnimation(this.animation.getAnimationByName("stele_green_out"), PlayMode.ONCE);
99
+            } else if (color == ColorType.orange) {
100
+                updatable.startAnimation(this.animation.getAnimationByName("stele_orange_out"), PlayMode.ONCE);
101
+            } else {
102
+                updatable.startAnimation(this.animation.getAnimationByName("stele_blue_out"), PlayMode.ONCE);
103
+            }
104
+        } else if (type == MoveType.PUSH) {
105
+            if (color == ColorType.green) {
106
+                updatable.startAnimation(this.animation.getAnimationByName("stele_green_pushed"), PlayMode.ONCE);
107
+            } else if (color == ColorType.orange) {
108
+                updatable.startAnimation(this.animation.getAnimationByName("stele_orange_pushed"), PlayMode.ONCE);
109
+            } else {
110
+                updatable.startAnimation(this.animation.getAnimationByName("stele_blue_pushed"), PlayMode.ONCE);
111
+            }
112
+        }
87 113
     }
88 114
 }