-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatePlay.js
More file actions
121 lines (107 loc) · 2.95 KB
/
Copy pathstatePlay.js
File metadata and controls
121 lines (107 loc) · 2.95 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function playGame() {
pHealth = health;
////unicorn
u.update();
for (var i = 0; i < platforms.length; ++i) {
u.collisionSide = rectangleCollisions(u, platforms[i]);
if (u.collisionSide != "none" && platforms[i].typeof == "death") {
health -= 0.1; //lower health when on the bad platform
}
//change the uni color when on the ground
if (pHealth > health) {
u.c = color(255, 0, 0);
} else {
u.c = color(255);
}
u.checkPlatforms();
}
////enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
if (rectangleCollisionPvE(u, enemies[i]) && !enemies[i].dead) {
enemies[i].deathJump();
health -= 20;
enemiesDispatched++;
// playSFX(sfxDead, true);
sfxDead.play();
}
}
////bullets
if (space) {
if (firingTimer.complete()) {
// playSFX(sfxShoot, false);
sfxShoot.play();
bullets[nextBullet].fire(u.x, u.y, u.w, u.facingRight);
nextBullet = (nextBullet + 1) % bullets.length;
firingTimer.start();
}
}
for (var i = 0; i < bullets.length; ++i) {
bullets[i].update();
for (var j = 0; j < enemies.length; j++) {
if (rectangleCollisionBvE(bullets[i], enemies[j]) && !enemies[j].dead) {
enemies[j].deathJump();
bullets[i].reset();
health += 20;
score++;
enemiesDispatched++;
// playSFX(sfxDing, true);
sfxDing.play();
}
}
}
//Move the camera
camera.x = floor(u.x + (u.halfWidth) - (camera.w / 2));
camera.y = floor(u.y + (u.halfHeight) - (camera.h / 2));
//Keep the camera inside the gameWorld boundaries
if (camera.x < gameWorld.x) {
camera.x = gameWorld.x;
}
if (camera.y < gameWorld.y) {
camera.y = gameWorld.y;
}
if (camera.x + camera.w > gameWorld.x + gameWorld.w) {
camera.x = gameWorld.x + gameWorld.w - camera.w;
}
if (camera.y + camera.h > gameWorld.h) {
camera.y = gameWorld.h - camera.h;
}
push();
translate(-camera.x, -camera.y + 100); //downward shift is for UI elements
backImage.display();
u.display();
for (var i = 0; i < platforms.length; ++i) {
platforms[i].display();
}
for (var i = 0; i < enemies.length; i++) {
enemies[i].display();
}
for (var i = 0; i < bullets.length; ++i) {
if (bullets[i].inMotion){
bullets[i].display();
}
}
pop();
displayUI();
//danger overlay
//strobe BG overlay if touching ground
if (u.y >= platforms[0].y - u.h) {
// fill(255, 0, 0, a/10);
fill('rgba(255,0,0,0.5)')
rect(0, 100, camera.w, camera.h);
//TODO:figure out strobing fill
// a = ((a + 1) % 50)/50;
}
//check for win
//cannot use score because enemies die with collisions and shooting
if (enemiesDispatched == enemies.length){
gameState = "WIN";
musicPlayer(winMusic, playMusic);
}
//check for lose
if (health <= 0) {
//chage game state when implemented
gameState = "LOSE";
musicPlayer(loseMusic, playMusic);
}
}