Browse code

Ned make run good animations when use revert.

Pierre Marijon authored on 04/05/2015 19:06:44
Showing 1 changed files
... ...
@@ -55,36 +55,43 @@ public class Ned extends GameObject {
55 55
 
56 56
         if (n_obj == null) {
57 57
             this.pos.setPosition(n_pos);
58
-            this.run_animation(diff, MoveType.WALK, 0.0f);
58
+            this.run_animation(diff, MoveType.WALK, 0.0f, false);
59 59
             this.save(new Memento(diff, MoveType.WALK, null));
60 60
             return this.pos;
61 61
         } else {
62 62
             Position n_move_to = n_obj.moveTo(diff, 0.0f);
63 63
             if (!n_move_to.equals(n_pos)) {
64
+                
64 65
                 if (n_obj instanceof GreenMaki || n_obj instanceof Box || n_obj instanceof RootBox) { //PushGreen Maki, Box or RootedBox
66
+                
65 67
                     this.pos.setPosition(n_pos);
66
-                    this.run_animation(diff, MoveType.PUSH, 0.0f);
68
+                    this.run_animation(diff, MoveType.PUSH, 0.0f, false);
67 69
                     this.save(new Memento(diff, MoveType.PUSH, n_obj));
68 70
                     return this.pos;
71
+                
69 72
                 } else if (n_obj instanceof OrangeMaki) { //Push OrangeMaki
73
+                
70 74
                     Position fly_final_pos = Position.deduction(n_move_to, diff);
75
+                    
71 76
                     if (Position.deduction(fly_final_pos, this.pos).equals(diff)) {
72
-                        this.run_animation(diff, MoveType.PUSH, 0.0f);
77
+                        this.run_animation(diff, MoveType.PUSH, 0.0f, false);
73 78
                     } else {
74
-                        this.run_animation(Position.deduction(fly_final_pos, this.pos), MoveType.FLY, 0.0f);
79
+                        this.run_animation(Position.deduction(fly_final_pos, this.pos), MoveType.FLY, 0.0f, false);
75 80
                     }
81
+                    
76 82
                     this.pos.setPosition(fly_final_pos);
77 83
                     this.save(new Memento(Position.sum(Position.deduction(fly_final_pos, n_pos), diff), MoveType.FLY, n_obj));
84
+                   
78 85
                     return this.pos;
79 86
                 } else if (n_obj instanceof BlueMaki) { //Push BlueMaki
80
-                    this.run_animation(diff, MoveType.WAIT, 0.0f);
87
+                    this.run_animation(diff, MoveType.WAIT, 0.0f, false);
81 88
                     this.save(new Memento(Position.getVoid(), MoveType.NO, n_obj));
82 89
                     return this.pos;
83 90
                 }
84 91
             } else if (n_obj instanceof Stairs && ((Stairs) n_obj).isOpen()) { // Walk on stairs
85 92
                 Stairs s = (Stairs) n_obj;
86 93
                 if (diff.equals(Position.multiplication(s.getDir(), -1))) {
87
-                    this.run_animation(diff, MoveType.MOUNT, 0.0f);
94
+                    this.run_animation(diff, MoveType.MOUNT, 0.0f, false);
88 95
                     this.end = true;
89 96
                 }
90 97
 
... ...
@@ -105,14 +112,14 @@ public class Ned extends GameObject {
105 112
 
106 113
         Position n_pos = Position.sum(this.pos, Position.multiplication(m.getDiff(), -1));
107 114
         this.pos.setPosition(n_pos);
108
-        this.run_animation(Position.multiplication(m.getDiff(), -1), m.getType(), 0.0f);
115
+        this.run_animation(Position.multiplication(m.getDiff(), -1), m.getType(), 0.0f, true);
109 116
 
110 117
         if (m.getNext() != null) {
111 118
             m.getNext().undo();
112 119
         }
113 120
     }
114 121
 
115
-    private void run_animation(Position diff, MoveType type, float wait_time) {
122
+    private void run_animation(Position diff, MoveType type, float wait_time, boolean undo) {
116 123
         Sprite sprite = this.entity.getComponent(Sprite.class);
117 124
         SpritePuppetControls updatable = this.entity.getComponent(SpritePuppetControls.class);
118 125
 
... ...
@@ -135,7 +142,19 @@ public class Ned extends GameObject {
135 142
                         .moveToRelative(new Vector3(diff.getY(), diff.getX(), 0), AnimationTime.base);
136 143
             }
137 144
         } else if (type == MoveType.PUSH) { // Push animation
138
-            if (diff.equals(Position.getUp())) {
145
+            if (diff.equals(Position.getUp()) && undo) {
146
+                updatable.startAnimation(this.animation.getAnimationByName("push_down"), PlayMode.ONCE)
147
+                        .moveToRelative(new Vector3(diff.getY(), diff.getX(), 0), AnimationTime.base);
148
+            } else if (diff.equals(Position.getDown()) && undo) {
149
+                updatable.startAnimation(this.animation.getAnimationByName("push_up"), PlayMode.ONCE)
150
+                        .moveToRelative(new Vector3(diff.getY(), diff.getX(), 0), AnimationTime.base);
151
+            } else if (diff.equals(Position.getRight()) && undo) {
152
+                updatable.startAnimation(this.animation.getAnimationByName("push_left"), PlayMode.ONCE)
153
+                        .moveToRelative(new Vector3(diff.getY(), diff.getX(), 0), AnimationTime.base);
154
+            } else if (diff.equals(Position.getLeft()) && undo) {
155
+                updatable.startAnimation(this.animation.getAnimationByName("push_right"), PlayMode.ONCE)
156
+                        .moveToRelative(new Vector3(diff.getY(), diff.getX(), 0), AnimationTime.base);
157
+            } else if (diff.equals(Position.getUp())) {
139 158
                 updatable.startAnimation(this.animation.getAnimationByName("push_up"), PlayMode.ONCE)
140 159
                         .moveToRelative(new Vector3(diff.getY(), diff.getX(), 0), AnimationTime.base);
141 160
             } else if (diff.equals(Position.getDown())) {