Browse code

Merge https://git.framasoft.org/ggp/ned-et-les-maki

devnewton authored on 05/07/2015 20:41:15
Showing 5 changed files
... ...
@@ -25,7 +25,7 @@
25 25
 55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,
26 26
 55,55,55,0,141,0,0,55,55,0,0,55,0,1,55,
27 27
 55,55,26,0,0,0,26,55,0,0,0,55,0,0,55,
28
-55,0,0,0,0,0,0,55,4,0,4,0,4,0,55,
28
+55,13,0,0,0,0,0,55,4,0,4,0,4,0,55,
29 29
 55,0,0,0,0,0,0,55,0,4,55,55,0,0,55,
30 30
 55,0,0,0,55,55,55,55,0,4,0,55,0,55,55,
31 31
 55,0,0,0,0,55,0,0,0,0,0,0,0,55,55,
... ...
@@ -35,8 +35,10 @@ import im.bci.tmxloader.TmxTileInstance;
35 35
 import im.bci.tmxloader.TmxTileInstanceEffect;
36 36
 import java.util.ArrayList;
37 37
 import java.util.EnumSet;
38
+import java.util.HashSet;
38 39
 import java.util.List;
39 40
 import java.util.Random;
41
+import java.util.Set;
40 42
 import org.geekygoblin.nedetlesmaki.core.components.LevelBackground;
41 43
 import org.geekygoblin.nedetlesmaki.core.components.gamesystems.Plate;
42 44
 import org.geekygoblin.nedetlesmaki.core.backend.Position;
... ...
@@ -212,9 +214,21 @@ public abstract class AbstractStartGameTrigger implements IStartGameTrigger {
212 214
         if ("dark_stairs_close_left".equals(type)) {
213 215
             return createStairs(tile, game, x, y, l, layer, Position.getLeft());
214 216
         }
217
+        if ("dark_stairs_close_right".equals(type)) {
218
+            return createStairs(tile, game, x, y, l, layer, Position.getRight());
219
+        }
215 220
         if ("low_stairs".equals(type)) {
216 221
             return createLowStairs(tile, game, x, y, l, layer);
217 222
         }
223
+        if ("green_stele_out".equals(type)) {
224
+            return createStone(tile, game, x, y, l, layer, ColorType.green, true);
225
+        }
226
+        if ("orange_stele_out".equals(type)) {
227
+            return createStone(tile, game, x, y, l, layer, ColorType.orange, true);
228
+        }
229
+        if ("blue_stele_out".equals(type)) {
230
+            return createStone(tile, game, x, y, l, layer, ColorType.blue, true);
231
+        }
218 232
         return createDecoration(tile, game, x, y, l, layer);
219 233
     }
220 234
 
... ...
@@ -402,6 +416,17 @@ public abstract class AbstractStartGameTrigger implements IStartGameTrigger {
402 416
         return this.createWall(tile, game, x, y, l, layer);
403 417
     }
404 418
 
419
+    protected Entity createStone(TmxTileInstance tile, NedGame game, int x, int y, int l, TmxLayer layer, ColorType c, boolean pushed) {
420
+        Entity stone = game.createEntity();
421
+        Stone obj = new Stone(new PositionIndexed(x, y, index), stone, index, assets);
422
+        obj.setColorType(c);
423
+        stone.addComponent(obj);
424
+        createSprite(x, y, l, tile, ApparitionEffect.FROM_ABOVE, stone);
425
+        game.addEntity(stone);
426
+        index.addStone(obj, new Position(x, y));
427
+        return stone;
428
+    }
429
+
405 430
     protected abstract void createProjector(NedGame game);
406 431
 
407 432
     @Override
... ...
@@ -29,6 +29,8 @@ import org.geekygoblin.nedetlesmaki.core.components.gamesystems.GameObject;
29 29
 import org.geekygoblin.nedetlesmaki.core.components.gamesystems.Plate;
30 30
 import org.geekygoblin.nedetlesmaki.core.components.gamesystems.Stairs;
31 31
 import org.geekygoblin.nedetlesmaki.core.components.gamesystems.Wall;
32
+import org.geekygoblin.nedetlesmaki.core.components.gamesystems.Stone;
33
+import org.geekygoblin.nedetlesmaki.core.constants.ColorType;
32 34
 
33 35
 /**
34 36
  *
... ...
@@ -42,12 +44,24 @@ public class LevelIndex {
42 44
     private Entity ned;
43 45
     private Stairs stairs;
44 46
     private final ArrayList<Plate> allPlate;
47
+    private final ArrayList<Plate> greenPlate;
48
+    private final ArrayList<Plate> orangePlate;
49
+    private final ArrayList<Plate> bluePlate;
50
+    private final ArrayList<Stone> greenStone;
51
+    private final ArrayList<Stone> orangeStone;
52
+    private final ArrayList<Stone> blueStone;
45 53
 
46 54
     @Inject
47 55
     public LevelIndex() {
48 56
         this.height = -1;
49 57
         this.width = -1;
50 58
         this.allPlate = new ArrayList<Plate>();
59
+        this.greenPlate = new ArrayList<Plate>();
60
+        this.orangePlate = new ArrayList<Plate>();
61
+        this.bluePlate = new ArrayList<Plate>();
62
+        this.greenStone = new ArrayList<Stone>();
63
+        this.orangeStone = new ArrayList<Stone>();
64
+        this.blueStone = new ArrayList<Stone>();
51 65
     }
52 66
 
53 67
     public void initialize(int height, int width) {
... ...
@@ -93,11 +107,30 @@ public class LevelIndex {
93 107
 
94 108
             this.index[p.getX()][p.getY()].setPlate(e);
95 109
             this.allPlate.add(e);
110
+
111
+            if (e.getColorType() == ColorType.green) {
112
+                this.greenPlate.add(e);
113
+            } else if (e.getColorType() == ColorType.orange) {
114
+                this.orangePlate.add(e);
115
+            } else {
116
+                this.bluePlate.add(e);
117
+            }
118
+        }
119
+    }
120
+
121
+    public void addStone(Stone e, Position p) {
122
+        this.added(e, p);
123
+        if (e.getColorType() == ColorType.green) {
124
+            this.greenStone.add(e);
125
+        } else if (e.getColorType() == ColorType.orange) {
126
+            this.orangeStone.add(e);
127
+        } else if (e.getColorType() == ColorType.blue) {
128
+            this.blueStone.add(e);
96 129
         }
97 130
     }
98 131
 
99 132
     public GameObject getGameObject(int x, int y) {
100
-        if(this.outOfBounds(x, y)) {
133
+        if (this.outOfBounds(x, y)) {
101 134
             return new Wall(new PositionIndexed(x, y, null), null, null);
102 135
         }
103 136
 
... ...
@@ -190,6 +223,10 @@ public class LevelIndex {
190 223
         if (p != null) {
191 224
             p.setMaki(b);
192 225
 
226
+            this.checkStone(this.greenPlate, this.greenStone);
227
+            this.checkStone(this.orangePlate, this.orangeStone);
228
+            this.checkStone(this.bluePlate, this.blueStone);
229
+
193 230
             if (this.checkEndLevel()) {
194 231
                 this.stairs.setOpen(true);
195 232
             } else if (this.stairs.isOpen()) {
... ...
@@ -199,8 +236,26 @@ public class LevelIndex {
199 236
     }
200 237
 
201 238
     private boolean checkEndLevel() {
202
-        for (int i = 0; i < this.allPlate.size(); i++) {
203
-            if (!this.allPlate.get(i).haveMaki()) {
239
+        return this.checkPlateGroup(this.allPlate);
240
+    }
241
+
242
+    private void checkStone(ArrayList<Plate> plate, ArrayList<Stone> stone) {
243
+        if (this.checkPlateGroup(plate)) {
244
+            for (Stone s : stone) {
245
+                s.setState(true);
246
+                this.deleted(s.getPos());
247
+            }
248
+        } else {
249
+            for (Stone s : stone) {
250
+                s.setState(false);
251
+                this.enabled(s, s.getPos());
252
+            }
253
+        }
254
+    }
255
+
256
+    private boolean checkPlateGroup(ArrayList<Plate> list_plate) {
257
+        for (int i = 0; i < list_plate.size(); i++) {
258
+            if (!list_plate.get(i).haveMaki()) {
204 259
                 return false;
205 260
             }
206 261
         }
... ...
@@ -47,14 +47,17 @@ public abstract class GameObject extends Component {
47 47
         UNDESTROY,
48 48
         //Ned
49 49
         WALK,
50
-        PUSH,
51 50
         FLY,
52 51
         MOUNT,
52
+        //Ned and Stone
53
+        PUSH,
53 54
         //Stairs
54 55
         OPEN,
55 56
         CLOSE,
56 57
         //Orange Maki and Ned
57 58
         WAIT,
59
+        //Stone
60
+        OUT,
58 61
     }
59 62
 
60 63
     protected Entity entity;
61 64
new file mode 100644
... ...
@@ -0,0 +1,117 @@
1
+/*
2
+ * Copyright © 2015S, Pierre Marijon <pierre@marijon.fr>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
8
+ * copies of the Software, and to permit persons to whom the Software is 
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in 
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * The Software is provided "as is", without warranty of any kind, express or 
15
+ * implied, including but not limited to the warranties of merchantability, 
16
+ * fitness for a particular purpose and noninfringement. In no event shall the 
17
+ * authors or copyright holders X be liable for any claim, damages or other 
18
+ * liability, whether in an action of contract, tort or otherwise, arising from,
19
+ * out of or in connection with the software or the use or other dealings in the
20
+ * Software.
21
+ */
22
+package org.geekygoblin.nedetlesmaki.core.components.gamesystems;
23
+
24
+import com.artemis.Entity;
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;
29
+import org.geekygoblin.nedetlesmaki.core.IAssets;
30
+import org.geekygoblin.nedetlesmaki.core.backend.LevelIndex;
31
+import org.geekygoblin.nedetlesmaki.core.backend.Position;
32
+import org.geekygoblin.nedetlesmaki.core.backend.PositionIndexed;
33
+import org.geekygoblin.nedetlesmaki.core.components.gamesystems.GameObject;
34
+import org.geekygoblin.nedetlesmaki.core.constants.ColorType;
35
+
36
+/**
37
+ *
38
+ * @author pierre
39
+ */
40
+public class Stone extends GameObject {
41
+
42
+    private final IAnimationCollection animation;
43
+    private ColorType color;
44
+    private boolean pushed;
45
+
46
+    public Stone(PositionIndexed pos, Entity entity, LevelIndex index, IAssets assets) {
47
+        super(pos, entity, index);
48
+
49
+        this.animation = assets.getAnimations("animation/steles/steles.json");
50
+        this.pushed = false;
51
+    }
52
+
53
+    public ColorType getColorType() {
54
+        return color;
55
+    }
56
+
57
+    public void setColorType(ColorType c) {
58
+        this.color = c;
59
+    }
60
+
61
+    public boolean isPushed() {
62
+        return this.pushed;
63
+    }
64
+
65
+    public void setState(boolean new_state) {
66
+        if (new_state == this.pushed) {
67
+            return;
68
+        }
69
+
70
+        this.pushed = new_state;
71
+
72
+        if (this.pushed) {
73
+            this.run_animations(MoveType.PUSH);
74
+        } else {
75
+            this.run_animations(MoveType.OUT);
76
+        }
77
+    }
78
+
79
+    @Override
80
+    public Position moveTo(Position diff, float wait_time) {
81
+        return this.pos;
82
+    }
83
+
84
+    @Override
85
+    public void undo() {
86
+    }
87
+
88
+    private void run_animations(MoveType type) {
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
+        }
113
+
114
+        this.entity.addComponent(updatable);
115
+        this.entity.changedInWorld();
116
+    }
117
+}