-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDinosaur.pde
49 lines (43 loc) · 1.12 KB
/
Dinosaur.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
class Dinosaur extends Enemy {
// Requirement #4: Complete Dinosaur Class
final float TRIGGERED_SPEED_MULTIPLIER = 5;
float speed = 1f;
boolean is = false;
PImage img;
// HINT: Player Detection in update()
float currentSpeed = speed;
void display(){
if (x < 0 || x > width - w) {
currentSpeed *= -1 ;
}
int direction = ( currentSpeed > 0) ? RIGHT : LEFT;
pushMatrix();
translate(x, y);
if ( direction == RIGHT ) {
scale(1, 1);
image(img, 0, 0, w, h);
}
else {
scale(-1, 1);
image(img, -w, 0, w, h);
}
popMatrix();
//image(dinosaur, x, y);
}
void update(){
x += currentSpeed;
if( player.y == y && ((x+w < player.x && !is && currentSpeed>0) || (x > player.x && !is && currentSpeed<0))){
//println("aaaa\n");
currentSpeed *= TRIGGERED_SPEED_MULTIPLIER;
is = true;
}
else if( is ){
currentSpeed /= TRIGGERED_SPEED_MULTIPLIER;
is = false;
}
}
Dinosaur( float x, float y ){
super( x,y );
img = dinosaur;
}
}