forked from JanPauldeVoor/gauntlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel.java
More file actions
140 lines (107 loc) · 4.05 KB
/
Copy pathLevel.java
File metadata and controls
140 lines (107 loc) · 4.05 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
package com.example.gauntlet;
import android.content.Context;
import android.graphics.PointF;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
class Level {
// Keep track of specific types
public static final int BACKGROUND_INDEX = 0;
public static final int PLAYER_INDEX = 1;
public static final int FIRST_PLAYER_ARROW = 2;
public static final int LAST_PLAYER_ARROW = 4;
public static int mNextPlayerArrow;
public static final int FIRST_ALIEN = 5;
public static final int DOOR_INDEX = 1;
public static final int LAST_ALIEN = 5;
public static final int FIRST_ALIEN_ARROW = 6;
public static final int LAST_ALIEN_ARROW = 10;
public static int mNextAlienArrow;
public static int[][] mMapMatrix;
private static final int MAP_ROWS = 32;
private static final int MAP_COLS = 32;
// track all dungeon maps
Context appContext;
public static int currentDungeon = 1;
public static final int lastDungeon = 1;
// keep dungeonMaps[0] empty because dungeon levels start at 1
public static final String[] dungeonMaps = {
"",
"gauntlet_room_1_text_32.txt"
};
// This will hold all the instances of GameObject
private ArrayList<GameObject> objects;
public Level(Context context,
PointF mScreenSize,
GameEngine ge) {
appContext = context;
objects = new ArrayList<>();
GameObjectFactory factory = new GameObjectFactory(
context, mScreenSize, ge);
mMapMatrix = new int[MAP_ROWS][MAP_COLS];
buildGameObjects(factory);
loadMap();
}
ArrayList<GameObject> buildGameObjects(
GameObjectFactory factory) {
objects.clear();
objects.add(BACKGROUND_INDEX, factory
.create(new BackgroundSpec()));
objects.add(PLAYER_INDEX, factory
.create(new PlayerSpec()));
// Spawn the player's Arrows
for (int i = FIRST_PLAYER_ARROW;
i != LAST_PLAYER_ARROW + 1; i++) {
objects.add(i, factory
.create(new PlayerArrowSpec()));
}
mNextPlayerArrow = FIRST_PLAYER_ARROW;
// Create some aliens
objects.add(FIRST_ALIEN, factory
.create(new GhostChaseSpec()));
// Create some alien Arrows
for (int i = FIRST_ALIEN_ARROW; i != LAST_ALIEN_ARROW + 1; i++) {
objects.add(i, factory
.create(new GhostArrowSpec()));
}
mNextAlienArrow = FIRST_ALIEN_ARROW;
objects.add(DOOR_INDEX, factory
.create(new DoorSpec()));
return objects;
}
ArrayList<GameObject> getGameObjects() {
return objects;
}
void loadMap() {
int currentRow = 0;
String line;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
appContext.getAssets().open(
dungeonMaps[currentDungeon])));
while( (line = reader.readLine()) != null){
String[] stringArray = line.split(" ");
for( int i=0; i<stringArray.length; i++ ){
mMapMatrix[currentRow][i] = Integer.parseInt(stringArray[i]);
}
currentRow++;
Log.d("map-row", String.valueOf(currentRow));
for(int i=0; i<32; i++){
String temp = " Col: " + i + "\t Val: " +mMapMatrix[2][i] ;
Log.d("map-col", temp);
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
int getCurrentDungeon() { return currentDungeon; }
public void goToNextDungeon() {
if (currentDungeon != lastDungeon) {
currentDungeon++;
loadMap();
}
}
}