-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTile.java
More file actions
120 lines (107 loc) · 3.35 KB
/
Copy pathTile.java
File metadata and controls
120 lines (107 loc) · 3.35 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Tiles have different images and "passability" (whether or not user can move through).
*
* @author Angela Wang
* @version June 4 2025
*/
public class Tile extends Scroller
{
protected GreenfootImage image;
protected GreenfootSound sound;
public static final int SIZE = 64;
private char type;
protected boolean isPassable = true;
private boolean isMouseHeld;
public Tile(String imageName, char type){
image = new GreenfootImage(imageName);
setImage(image);
this.type = type;
if (type == 'u' || type == 'b'){
isPassable = false;
}
}
//omds i need to change sm
public Tile(char type){
setType(type); // use setType instead of manual code
}
public void act(){
super.act();
// if this tile is in a RoomEditor (NOT in a game world), user can edit type
if (getWorld() instanceof RoomEditor){
RoomEditor room = (RoomEditor) getWorld();
// if user is dragging mouse + touches this tile, set tile to new type based on RoomEditor
if (room.getIsMousePressed() && intersects(room.getCursor())){
setType(room.getNewType()); // use setType() here too
}
}
}
/**
* Return type of this tile
* @return char e.g. f for floor, w for wall...
*/
public char getType(){
return type;
}
/**
* Return whether or not characters can go through this tile
* @return boolean True if characters can pass through
*/
public boolean getIsPassable(){
return isPassable;
}
/**
* Safely sets the type and updates the image together
* @param newType The new type of the tile
*/
public void setType(char newType){
this.type = newType;
String imageName = "";
switch (newType){
case 'f':
imageName = "tile_floor.png";
break;
case 'w':
imageName = "tile_water.png";
break;
case 'u':
imageName = "tile_wall.png";
break;
case 'b':
imageName = "tile_barrel.png";
break;
case 'l':
imageName = "tile_lava.png";
break;
case 's':
imageName = "tile_spike0.png";
break;
case 'e':
imageName = "tile_blank.png";
break;
case 'g':
imageName = "tile_gate0.png";
break;
case 'q':
imageName = "tile_gate0.png";
break;
case 'p':
imageName = "tile_floor.png";
isPassable = true;
break;
default:
imageName = "tile_floor.png";
}
image = new GreenfootImage(imageName);
setImage(image);
}
public void setIsPassable(boolean bool){
isPassable = bool;
}
protected boolean isInTopHalfOfBoard() {
MyWorld world = (MyWorld) getWorld();
Board board = world.getObjects(Board.class).get(0);
int row = board.getTileRow(this);
return row != -1 && row < board.getTileRowCount() / 2;
}
}