-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScene.java
More file actions
93 lines (77 loc) · 1.76 KB
/
Copy pathScene.java
File metadata and controls
93 lines (77 loc) · 1.76 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
import java.util.ArrayList;
public class Scene {
private int rows;
private int cols;
private GameObject background;
private ArrayList<Block> blocks;
private ArrayList<Block> monsters;
private Player player;
private Exit exit;
public Scene(String[][] map) {
this.rows = map.length;
this.cols = map[0].length;
int width = cols * 32;
int height = rows * 32;
this.background = new GameObject(0, 0, width, height, "/Assets/background.png");
this.blocks = new ArrayList<Block>();
this.monsters = new ArrayList<Block>();
for (int y=0; y<rows; y++) {
for (int x = 0; x<cols; x++) {
String tile = map[y][x];
setTile( x, y, tile);
}
}
StdDraw.setCanvasSize (width, height);
StdDraw.setXscale(0.0, width);
StdDraw.setYscale(height, 0.0);
}
public void draw() {
background.draw();
for ( Block block : this.blocks) {
block.draw();
}
for ( Block spike : this.monsters) {
spike.draw();
}
exit.draw();
player.draw();
}
private void setTile(int x, int y, String tile) {
if (tile.equals("#") )
{
Block block = new Block(x, y);
this.blocks.add(block);
}
else if (tile.equals("@") ) {
this.player = new Player(x, y);
}
else if (tile.equals("A") ) {
FloorHazard spike = new FloorHazard(x,y);
this.monsters.add(spike);
}
else if (tile.equals("V") ) {
CeilingHazard spike = new CeilingHazard(x,y);
this.monsters.add(spike);
}
else if (tile.equals("!") ) {
this.exit = new Exit(x,y);
}
}
public void update() {
player.update(blocks);
}
public Player getPlayer() {
return this.player;
}
public boolean isPlayerDead() {
for (Block hazard : monsters) {
if (hazard.isTouching(player) ) {
return true;
}
}
return false;
}
public Exit getExit() {
return this.exit;
}
}