-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlock.pde
87 lines (82 loc) · 2.28 KB
/
Block.pde
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
class Block {
int x;
int y;
PVector loc;
PImage img;
PVector imgSize;
String type;
float timer;
boolean explode;
boolean exploding;
Block(int x, int y, String type) {
this.x = x;
this.y = y;
this.type = type;
updateLoc();
if (!"blank".equals(getType().name)) {
img = getImage(getType().img);
imgSize = imgToWorldCoords(img);
}
explode = false;
exploding = false;
}
public void updateLoc() {
loc = toWorldCoords(new PVector(x*TILESIZE,y*TILESIZE));
}
public BlockType getType() {
return blockTypes.get(type);
}
public void display() {
if (!"blank".equals(getType().name)) {
image(img,loc.x,loc.y,imgSize.x,imgSize.y);
}
}
public void update(float delta) {
if (explode) {
timer+=delta;
if (timer>(speed/2.5) && timer<(speed/1.9)) {
exploding = true;
img = getImage("block_explosion1");
}
else if (timer>=(speed/1.9) && timer<(speed/1.5)) {
img = getImage("block_explosion2");
}
else if (timer>=(speed/1.5)) {
board.setBlock(x,y,"blank");
score+=(combos-1);
}
}
}
}
public Block makeBlock(int x, int y, String type) {
return new Block(x,y,type);
}
HashMap<String,BlockType> blockTypes;
class BlockType {
String name;
String img;
BlockType(String name, String img) {
this.name = name;
this.img = img;
}
}
public void addBlockType(BlockType t) {
blockTypes.put(t.name, t);
}
public void generateBlocks() {
blockTypes = new HashMap<String,BlockType>();
addBlockType(new BlockType("blank",""));
addBlockType(new BlockType("blue","block_blue"));
addBlockType(new BlockType("purple","block_purple"));
addBlockType(new BlockType("green","block_green"));
addBlockType(new BlockType("yellow","block_yellow"));
addBlockType(new BlockType("red","block_red"));
// Destroy blocks of same color
addBlockType(new BlockType("star","block_star"));
// Nuke all blocks in surrounding area
addBlockType(new BlockType("n","block_n"));
// Destroy column of blocks
addBlockType(new BlockType("lightning","block_lightning"));
// Can only be destroyed by special blocks
addBlockType(new BlockType("stone","block_stone"));
}