forked from IlanOu/Jetpack_POO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.js
105 lines (91 loc) · 2.02 KB
/
player.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
let player = {
position: {
x: 200,
y: 200
},
size: {
w: 20,
h: 20
},
velocity: {
x: 0,
y: 0
},
speed: {
up: 5,
down: -3,
right: 5,
left: 5
},
colliding: {
top: false,
bottom: false,
right: false,
left: false
},
isAlive: true
};
let jetpack = {
position: {
x: 0,
y: 0
},
size: {
w: 10,
h: 20
},
colour: {
r: 100,
g: 100,
b: 100
}
}
let fire = {
position: {
x: 0,
y: 0
},
size: {
w: 10,
h: 10
},
colour: {
r: 200,
g: 10,
b: 10
}
}
function drawPlayer() {
// ----- Draw player
// --- Jetpack
jetpack.position.x = player.position.x - player.size.w / 2
jetpack.position.y = player.position.y
fire.position.x = jetpack.position.x
fire.position.y = jetpack.position.y + jetpack.size.h
// Jetpack texture
fill(jetpack.colour.r, jetpack.colour.g, jetpack.colour.b)
rect(jetpack.position.x, jetpack.position.y, jetpack.size.w, jetpack.size.h);
// Fire texture
if (keys.ArrowUp) {
stroke(fire.colour.r, fire.colour.g, fire.colour.b)
fill(fire.colour.r, fire.colour.g, fire.colour.b)
rect(fire.position.x, fire.position.y, fire.size.w, fire.size.h);
stroke(0, 0, 0)
}
if (keys.ArrowDown) {
stroke(fire.colour.r, fire.colour.g, fire.colour.b)
fill(fire.colour.r, fire.colour.g, fire.colour.b)
rect(fire.position.x, fire.position.y, fire.size.w, fire.size.h/2);
stroke(0, 0, 0)
}
// --- Player
fill(255, 255, 255)
square(player.position.x, player.position.y, player.size.w);
}
function playerCollideMap(){
// Add colliders
player = processColliders(player, limitTop)
player = processColliders(player, limitBottom)
player = processColliders(player, limitRight)
player = processColliders(player, limitLeft)
}