Skip to content

Commit 8ccdeb1

Browse files
committed
Polish In Progress
Pixi-Sound has been added Hurt sound effect Screen shake on hurt
1 parent 9ce6237 commit 8ccdeb1

File tree

5 files changed

+48
-21
lines changed

5 files changed

+48
-21
lines changed

games/GMTK Jam/app.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ PIXI.input.mouseContainer = app.view;
77

88
const diceImg = [null, PIXI.Texture.from("assets/one.png"), PIXI.Texture.from("assets/two.png"), PIXI.Texture.from("assets/three.png"), PIXI.Texture.from("assets/four.png"), PIXI.Texture.from("assets/five.png"), PIXI.Texture.from("assets/six.png")];
99

10+
const sound = {
11+
hurt: PIXI.sound.Sound.from("assets/hurt.mp3"),
12+
}
13+
1014
// const dangerTint = [0xffffff, 0xffff00, 0xffcc00, 0xff9900, 0xff6600, 0xff3300, 0xff0000];
1115
const dangerTint = [0xffffff, 0xff20ff, 0x8020ff, 0x2020ff, 0x2080ff, 0x20ffff, 0x20ff80];
1216

@@ -26,11 +30,15 @@ const rand = (min, max) => {
2630
const scene = new PIXI.Container();
2731
app.stage.addChild(scene);
2832

33+
const bloomContainer = new PIXI.ParticleContainer();
34+
bloomContainer.visible = false;
35+
app.stage.addChild(bloomContainer);
36+
2937
const allocationScreen = new PIXI.Container();
3038
app.stage.addChild(allocationScreen);
3139

32-
const menu = new PIXI.Container();
33-
app.stage.addChild(menu);
40+
const menuContainer = new PIXI.Container();
41+
app.stage.addChild(menuContainer);
3442

3543
const states = {
3644
start: false,
@@ -48,7 +56,8 @@ const states = {
4856
}
4957

5058
const phys = {
51-
bounce: 0.4
59+
bounce: 0.4,
60+
shake: 64
5261
}
5362

5463
const textStyle = new PIXI.TextStyle({
@@ -59,18 +68,21 @@ const textStyle = new PIXI.TextStyle({
5968
});
6069

6170
// Menu stuff
71+
const menu = {
72+
score: new PIXI.Text("", textStyle),
73+
info: new PIXI.Text(" [F] to enter fullscreen\n\n [A] is left, [D] is right\n[W] is jump, [S] is to drop\n\nGetting hit by an enemy die\n will lower your health by\n the shown number, jumping\n on top of it will restore\n your health by the number\n\n\n Press [E]", textStyle)
74+
}
6275

63-
const infoText = new PIXI.Text(" [F] to enter fullscreen\n\n [A] is left, [D] is right\n[W] is jump, [S] is to drop\n\nGetting hit by an enemy die\n will lower your health by\n the shown number, jumping\n on top of it will restore\n your health by the number\n\n\n Press [E]", textStyle);
64-
infoText.x = app.view.width * 0.5;
65-
infoText.y = app.view.height * 0.5;
66-
infoText.anchor = { x: 0.5, y: 0.5 };
67-
menu.addChild(infoText);
76+
menu.score = new PIXI.Text("", textStyle);
77+
menu.score.x = app.view.width * 0.5;
78+
menu.score.y = app.view.height * 0.05;
79+
menu.score.anchor = { x: 0.5, y: 0.5 };
80+
menuContainer.addChild(menu.score);
6881

69-
const menuScore = new PIXI.Text("", textStyle);
70-
menuScore.x = app.view.width * 0.5;
71-
menuScore.y = app.view.height * 0.05;
72-
menuScore.anchor = { x: 0.5, y: 0.5 };
73-
menu.addChild(menuScore);
82+
menu.info.x = app.view.width * 0.5;
83+
menu.info.y = app.view.height * 0.5;
84+
menu.info.anchor = { x: 0.5, y: 0.5 };
85+
menuContainer.addChild(menu.info);
7486

7587
// Allocation stuff
7688
const topMessage = new PIXI.Text("Lady Luck rolls again!", textStyle)
@@ -141,10 +153,6 @@ score.y = app.view.height * 0.05;
141153
score.anchor = { x: 0.5, y: 0.5 };
142154
scene.addChild(score);
143155

144-
menu.visible = false;
145-
scene.visible = true;
146-
allocationScreen.visible = false;
147-
148156
// PLAY GAME
149157

150158
app.ticker.add((deltaTime) => {
@@ -153,10 +161,10 @@ app.ticker.add((deltaTime) => {
153161
}
154162
if (!states.start || states.life <= 0) {
155163

156-
menu.visible = true;
164+
menuContainer.visible = true;
157165
scene.visible = false;
158166
allocationScreen.visible = false;
159-
menuScore.text = "Level " + states.level + " | " + states.score + " points";
167+
menu.score.text = "Level " + states.level + " | " + states.score + " points";
160168

161169
if (PIXI.input.getKeyFired("e")) {
162170
states.start = true;
@@ -179,7 +187,7 @@ app.ticker.add((deltaTime) => {
179187
}
180188
} else {
181189

182-
menu.visible = false;
190+
menuContainer.visible = false;
183191

184192
if (states.allocation) {
185193

@@ -254,13 +262,18 @@ app.ticker.add((deltaTime) => {
254262
scene.removeChild(danger);
255263
dangerSet.delete(danger);
256264
});
265+
scene.x = 0; // Reset screen shake
257266
}
258267
}
259268

260269
} else {
261270
allocationScreen.visible = false;
262271
scene.visible = true;
263272

273+
if (scene.x != 0) {
274+
scene.x += (0 - scene.x) * 1.875;
275+
}
276+
264277
let t = Math.max(states.life, 1);
265278
player.texture = diceImg[t];
266279
player.tint = lifeTint[t];
@@ -318,7 +331,7 @@ app.ticker.add((deltaTime) => {
318331
danger.vec.x *= -phys.bounce;
319332
}
320333
if (PIXI.collision.aabb(player, danger)) {
321-
if (player.y + player.height * 0.25 < danger.y) {
334+
if (player.y + player.height * 0.35 < danger.y) {
322335
// Jumped on top, score up AND heal AND bounce
323336
states.life = clamp(states.life + danger.facing, 1, 6)
324337
player.vec.y = -24 - states.jump * states.jumpMult;
@@ -327,6 +340,8 @@ app.ticker.add((deltaTime) => {
327340
} else {
328341
// Hit by danger, lose life
329342
states.life -= danger.facing;
343+
scene.x += phys.shake;
344+
sound.hurt.play();
330345
}
331346
scene.removeChild(danger);
332347
dangerSet.delete(danger);

games/GMTK Jam/assets/hurt.mp3

11.3 KB
Binary file not shown.

games/GMTK Jam/engine/pixi-sound.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

games/GMTK Jam/engine/pixi-sound.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

games/GMTK Jam/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<head>
55
<title>Take a Chance</title>
66
<script src="engine/pixi.min.js"></script>
7+
<script src="engine/pixi-sound.js"></script>
78
<script src="engine/zepyhr.js"></script>
89
<style>
910
* {

0 commit comments

Comments
 (0)