forked from IlanOu/Jetpack_POO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rockets.js
90 lines (72 loc) · 1.62 KB
/
rockets.js
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
let rocket_laser = {
position: {
x: 400,
y: 200
},
size: {
w: 300,
h: 25
},
speed: {
up: 5,
down: -3,
right: 5,
left: 5
},
colour: {
r: 255,
g: 0,
b: 0,
}
};
let rocket = {
position: {
x: 400,
y: 200
},
size: {
w: 40,
h: 25
},
speed: {
up: 5,
down: -3,
right: 15,
left: 7
},
colour: {
r: 255,
g: 150,
b: 0,
}
};
function launchRocket(rocket) {
if (rocket.position.x + rocket.size.w > 0) {
rocket.position.x -= rocket.speed.left
} else {
rocket.position.x = width
rocket.position.y = randomRange(30, height - 30)
// rocket.position.speed += 1
points += 1
}
}
function drawRocket(rocket) {
fill(0, 0, 0)
stroke(0, 0, 0)
circle(rocket.position.x, rocket.position.y + rocket.size.h / 4, rocket.size.h / 2)
stroke(rocket.colour.r, rocket.colour.g, rocket.colour.b)
fill(rocket.colour.r, rocket.colour.g, rocket.colour.b)
rect(rocket.position.x, rocket.position.y, rocket.size.w, rocket.size.h / 2);
stroke(0, 0, 0)
}
function processKillPlayer(player, rocket){
rocketCollider = JSON.parse(JSON.stringify(rocket));
// rocketCollider.size.w *= 1.5;
rocketCollider.size.h *= 2;
// rocketCollider.position.x -= rocketCollider.size.w/3;
rocketCollider.position.y -= rocketCollider.size.h/4;
if (rectIsInRect(player, rocketCollider)){
player.isAlive = false
}
return player
}