Browse code

Add base for Stone support, not enable yet.

Pierre Marijon authored on 18/05/2015 11:49:25
Showing 3 changed files
... ...
@@ -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,88 @@
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 org.geekygoblin.nedetlesmaki.core.IAssets;
27
+import org.geekygoblin.nedetlesmaki.core.backend.LevelIndex;
28
+import org.geekygoblin.nedetlesmaki.core.backend.Position;
29
+import org.geekygoblin.nedetlesmaki.core.backend.PositionIndexed;
30
+import org.geekygoblin.nedetlesmaki.core.components.gamesystems.GameObject;
31
+import org.geekygoblin.nedetlesmaki.core.constants.ColorType;
32
+
33
+/**
34
+ *
35
+ * @author pierre
36
+ */
37
+public class Stone extends GameObject {
38
+
39
+    private final IAnimationCollection animation;
40
+    private ColorType color;
41
+    private boolean pushed;
42
+
43
+    public Stone(PositionIndexed pos, Entity entity, LevelIndex index, IAssets assets) {
44
+        super(pos, entity, index);
45
+
46
+        this.animation = assets.getAnimations("animation/stones/steles.json");
47
+        this.pushed = false;
48
+    }
49
+
50
+    public ColorType getColorType() {
51
+        return color;
52
+    }
53
+
54
+    public void setColorType(ColorType c) {
55
+        this.color = c;
56
+    }
57
+    
58
+    public boolean isPushed() {
59
+        return this.pushed;
60
+    }
61
+
62
+    public void setState(boolean new_state) {
63
+        if(new_state == this.pushed) {
64
+            return;
65
+        }
66
+        
67
+        this.pushed = new_state;
68
+        
69
+        if(this.pushed) {
70
+            this.run_animations(MoveType.PUSH);
71
+        } else {
72
+            this.run_animations(MoveType.OUT);
73
+        }
74
+    }
75
+    
76
+    @Override
77
+    public Position moveTo(Position diff, float wait_time) {
78
+        return this.pos;
79
+    }
80
+
81
+    @Override
82
+    public void undo() {
83
+    }
84
+    
85
+    private void run_animations(MoveType type) {
86
+    
87
+    }
88
+}