-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevelR.java
More file actions
166 lines (116 loc) · 4.34 KB
/
Copy pathLevelR.java
File metadata and controls
166 lines (116 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.smiths;
import java.util.ArrayList;
import java.util.Map;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.color.Color;
import org.andengine.util.debug.Debug;
//level definition
public class LevelR
{
static int platforms = 20;
static int VerticalIncrement = 64;
static int HorizontalIncrement = 100;
int platformcount = 0;
int height = 10;
static Platform[] platformgroup;
VertexBufferObjectManager vbom;
ArrayList<Rectangle> horiz;
Color col;
Scene SCENE;
String LevelString = "";
public LevelR(VertexBufferObjectManager vBOM, Scene scene, ArrayList<Rectangle> horizontals, ArrayList<Rectangle> verticals, Color color )
{
SCENE = scene;
col = color;
vbom = vBOM;
horiz = horizontals;
platformgroup = new Platform[platforms];
verticals.add(new Rectangle(-1000,-1000,1000,1500,vBOM)); //left wall
verticals.add(new Rectangle(2000,-1000,850,1500,vBOM)); //right wall
horizontals.add(new Rectangle(-2000, 300, 6000, 512, vBOM)); //main floor
//horizontals.add(new Rectangle(150,150,150, 10, vBOM));
int VerticalRange = 10;
int HorizontalRange = 20;
int xpos;
int ypos;
int length;
int Xgridstart = 0;
int Ygridstart = -200;
int segments;
for(int r=0; r < platforms; r++)
{
xpos = ((int) (Math.random()*HorizontalRange)*HorizontalIncrement)+Xgridstart;
ypos = ((int) (Math.random()*VerticalRange)*VerticalIncrement)+Ygridstart;
segments = (int)(Math.random()*3);
length = HorizontalIncrement+(segments*HorizontalIncrement);
LevelString = LevelString+length+"|"+Integer.toString(xpos)+"|"+Integer.toString(ypos)+"|";
//horizontals.add(new Rectangle(xpos, ypos, length, height, vBOM));
}
Debug.d("LevelString = "+LevelString);
StringToLevel(LevelString, horizontals, scene, color);
for(int i=0; i<horizontals.size(); i++)
{
scene.attachChild(horizontals.get(i));
horizontals.get(i).setColor(color);
}
for(int i=0; i<verticals.size(); i++)
{
scene.attachChild(verticals.get(i));
verticals.get(i).setColor(color);
}
}
public void StringToLevel(String args, ArrayList<Rectangle> horizontals, Scene scene, Color color) {
//String str = "e|1000|-200|c|1100|120|c|1300|-72|a|100|56|c|1100|376|c|500|120|b|1100|-72|c|400|56|e|1600|-72|e|1500|-72|c|800|56|a|1600|120|c|400|-200|e|1500|-72|b|700|56|b|1200|-72|e|0|-200|b|300|120|b|0|-136|b|1500|-200|";
int threecount = 1;
int xpos=0;
int ypos=0;
int length=0;
for(int index = 0;index<platforms*3;index++){
String piece = str_piece(args, '|', index+1);
Debug.d("index ="+index+", piece = "+piece+", threecount = "+threecount+", parsed = "+Integer.parseInt(piece)+", platformcount = "+platformcount);
if(threecount == 1){
length = (int)Integer.parseInt(piece);
}
else if(threecount==2){
xpos = Integer.parseInt(piece);
}
else if(threecount == 3){
ypos = Integer.parseInt(piece);
}
threecount++;
if(threecount==4)
{
MakePlatform(platformcount,length, xpos,ypos, horizontals, scene, color);
threecount=1;
}
}
}
public void MakePlatform(int index, int l, int x, int y, ArrayList<Rectangle> horizontals, Scene scene, Color color){
platformgroup[platformcount]=new Platform((float)x, (float)y, (float)l, height, vbom);
horizontals.add(platformgroup[platformcount]);
platformgroup[platformcount].setColor(color);
platformgroup[platformcount].setVisible(true);
//scene.attachChild(platformgroup[platformcount]);
platformcount++;
}
private static String str_piece(String str, char separator, int index) {
String str_result = "";
int count = 0;
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) == separator) {
count++;
if(count == index) {
break;
}
}
else {
if(count == index-1) {
str_result += str.charAt(i);
}
}
}
return str_result;
}
}