forked from GiorgiaC9/hci-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspike.pde
54 lines (48 loc) · 1.11 KB
/
spike.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
int SPIKE_WIDTH = 245;
int SPIKE_HEIGHT = 95;
class Spike extends Obstacle
{
float h; // rect height
float w; // rect width
PImage icon;
Spike() {
super(BOTTOM - SPIKE_HEIGHT/2);
h=SPIKE_HEIGHT;
w=SPIKE_WIDTH;
switch(mode){
case CITY:
icon = getCity();
break;
case WEST:
break;
case MEDIEVAL:
break;
case FUTURE:
break;
}
}
void display() {
imageMode(CENTER);
image(icon, x, y);
}
void effect() {
if (shield>0)
score+=3;
else
p.die();
}
PImage getCity(){
int choice = int(random(4));
switch (choice){
case 0: return loadImage("City/Trash/Trash-01.png");
case 1: return loadImage("City/Trash/Trash-02.png");
case 2: return loadImage("City/Trash/Trash-03.png");
default: return loadImage("City/Trash/Trash-04.png");
}
}
boolean detectCollision() {
if (p.x+(p.w/2) > x-(w/2) && p.x-(p.w/2) < x+(w/2) && p.y+(p.h/2) > y-(h/2) && p.y-(p.h/2) < y+(h/2))
return true;
return false;
}
}