Skip to content

Commit 7d2be6a

Browse files
committed
good
1 parent 1b0d1f2 commit 7d2be6a

File tree

3 files changed

+88
-80
lines changed

3 files changed

+88
-80
lines changed

games/GMTK Jam/app.js

Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const diceImg = [null, PIXI.Texture.from("assets/one.png"), PIXI.Texture.from("a
99

1010
const img = {
1111
bg: PIXI.Texture.from("assets/background.png"),
12+
edgeLight: PIXI.Texture.from("assets/edgeLight.png"),
1213
}
1314

1415
const sound = {
@@ -28,29 +29,34 @@ const dangerTint = [
2829
];
2930

3031
const lifeTint = [
31-
0xff2211,
32-
0xff4433,
33-
0xff6655,
3432
0xff8877,
33+
0xff9988,
3534
0xffaa99,
35+
0xffbbaa,
3636
0xffccbb,
37+
0xffddcc,
3738
0xffeedd
3839
];
3940

4041
const bgTint = [
4142
0x100808,
42-
0x775533,
43-
0x557733,
44-
0x553377,
45-
0x335577,
46-
0x337755,
43+
0x34092D,
44+
0x340926,
45+
0x34091F,
46+
0x340917,
47+
0x340910,
48+
0x340909
4749
]
4850

4951
const ladyLuck = [
50-
"Ah, my favorite little die... WHAT?!? You don't want to work for me anymore? Let's see how lucky you are without me!",
51-
"Look at that, a die being on a hot streak. I play by my own rules though, so let's change yours!",
52-
"Enough chances, you keep on getting lucky breaks... Figures for a die.",
53-
"Will you quit it? A dice without luck is just a cube, come back and I'll decide your fate... What do you mean that sounds unfair?"
52+
"Lady Luck: Ah, my favorite little die... WHAT?!? You don't want to work for me anymore? Let's see how lucky you are without me!",
53+
"Lady Luck: Look at that, a die on a hot streak. I play by my own rules though, so let's change yours!",
54+
"Lady Luck: You keep on getting lucky breaks... Makes sense for a die.",
55+
"Lady Luck: I don't have time for these games of chance... What? What do you mean that's all I do?!",
56+
"Lady luck: Come back and I'll decide your fate... What do you mean that sounds unfair?",
57+
"Lady Luck: Alright, you've had your fun, give me a second chance?",
58+
"Lady Luck: Your luck's bound to run out soon, I'm not giving you any more!",
59+
"YOU'VE BEAT LADY LUCK!\n\nKeep playing to see how far you can push your luck!"
5460
]
5561

5662
// USEFUL FUNCTIONS
@@ -79,16 +85,9 @@ app.stage.addChild(allocationScreen);
7985
const menuContainer = new PIXI.Container();
8086
app.stage.addChild(menuContainer);
8187

82-
const particle = {
83-
tex: PIXI.Texture.from("assets/particle.png"),
84-
container: new PIXI.ParticleContainer(),
85-
set: new Set()
86-
}
87-
88-
app.stage.addChild(particle.container);
89-
9088
const states = {
9189
start: false,
90+
menu: true,
9291
requestAllocationRolls: false,
9392
allocation: false,
9493
life: 3,
@@ -130,9 +129,9 @@ const menu = {
130129
fillGradientType: 1,
131130
fontFamily: "Courier New",
132131
fontSize: 192,
133-
letterSpacing: -7,
132+
letterSpacing: -16,
134133
})),
135-
options: new PIXI.Text("[A] Start\t\t\t\t[S] Controls\t\t\t\t[D] About", textStyle),
134+
options: new PIXI.Text("Start [A]\t\t\t\tControls [S]\t\t\t\tAbout [D]", textStyle),
136135
info: new PIXI.Text("", textStyle)
137136
}
138137

@@ -210,14 +209,30 @@ allocation.ladyLuck.y = app.view.height * 0.65;
210209
allocation.ladyLuck.anchor = { x: 0.5, y: 0.5 };
211210
allocationScreen.addChild(allocation.ladyLuck);
212211

213-
const directions = new PIXI.Text("Press [W] try your luck in the next level...", textStyle)
212+
const directions = new PIXI.Text("Test your luck in the next round... [W]", textStyle)
214213
directions.x = app.view.width * 0.5;
215214
directions.y = app.view.height * 0.9;
216215
directions.anchor = { x: 0.5, y: 0.5 };
217216
directions.visible = false;
218217
allocationScreen.addChild(directions);
219218

220219
// Scene stuff
220+
const gameOver = new PIXI.Text("Looks like that's the end of your lucky break... [W]", new PIXI.TextStyle({
221+
align: "center",
222+
wordWrap: true,
223+
wordWrapWidth: 1200,
224+
fontFamily: "Courier New",
225+
fontSize: 32,
226+
fontWeight: 300,
227+
fill: ["#D92B2B"]
228+
}));
229+
230+
gameOver.x = app.view.width * 0.5;
231+
gameOver.y = app.view.height * 0.9;
232+
gameOver.anchor = { x: 0.5, y: 0.5 };
233+
gameOver.visible = false;
234+
scene.addChild(gameOver);
235+
221236
const player = PIXI.Sprite.from(diceImg[6]);
222237
player.x = app.view.width * 0.5;
223238
player.y = app.view.height;
@@ -230,50 +245,43 @@ scene.addChild(player);
230245
const objectSet = new Set();
231246
const dangerSet = new Set();
232247

233-
const pauseText = new PIXI.Text("Paused [Esc]", textStyle);
234-
pauseText.x = app.view.width * 0.5;
235-
pauseText.y = app.view.height * 0.5;
236-
pauseText.anchor = { x: 0.5, y: 0.5 };
237-
pauseText.visible = false;
238-
scene.addChild(pauseText);
239-
240248
const score = new PIXI.Text(0, textStyle)
241249
score.x = app.view.width * 0.5;
242250
score.y = app.view.height * 0.1;
243251
score.anchor = { x: 0.5, y: 0.5 };
244252
scene.addChild(score);
245253

254+
const edgeLight = PIXI.Sprite.from(img.edgeLight);
255+
edgeLight.anchor = { x: 0.5, y: 0 };
256+
edgeLight.x = 0.5 * app.view.width;
257+
edgeLight.y = 0;
258+
edgeLight.alpha = 0.25;
259+
app.stage.addChild(edgeLight);
260+
246261
// PLAY GAME
247262

248263
app.ticker.add((deltaTime) => {
249264

250-
if (PIXI.input.getKeyDown("f")) {
265+
if (PIXI.input.getKeyFired("f")) {
251266
PIXI.utils.openFullScreen(app.view);
252267
}
253268

254-
// Shake screen return
269+
// Shake screen and flare lights
255270
app.stage.x *= -0.75;
271+
edgeLight.alpha -= (edgeLight.alpha > 0.25) * 0.01;
256272

257-
// Particle decay
258-
particle.set.forEach((p) => {
259-
if (--p.life <= 0) {
260-
particle.container.removeChild(p);
261-
particle.set.delete(p);
262-
}
263-
});
264-
265-
if (!states.start || states.life <= 0) {
273+
if (!states.start || states.menu) {
266274
menuContainer.visible = true;
267275
scene.visible = false;
268276
allocationScreen.visible = false;
269-
particle.container.visible = false;
270277
menu.score.text = "Previous Run: " + states.level + " round" + (states.level == 1 ? "" : "s") + ", " + states.score + " points";
271278

272279
bg.tint = bgTint[0];
273280

274281
if (PIXI.input.getKeyFired("a")) {
275282
menu.info.text = "";
276283
states.start = true;
284+
states.menu = false;
277285
states.allocation = true;
278286
states.requestAllocationRolls = false;
279287
states.life = 3;
@@ -295,9 +303,9 @@ app.ticker.add((deltaTime) => {
295303
player.vec = { x: 0, y: 0 };
296304
player.allowJump = true;
297305
} else if (PIXI.input.getKeyFired("s")) {
298-
menu.info.text = "[F] Fullscreen\n\n[W] Jump\t[A] Left\t[S] Drop\t[D] Right\n\nDodge or destroy Lady Luck's falling dice. Getting hit by one will lower your health by the number shown, but jumping on top of it will destroy it and heal you by that same amount. Take a chance and roll the dice!";
306+
menu.info.text = "Fullscreen [F]\n\nJump [W]\tLeft [A]\tDrop [S]\tRight [D]\n\nDodge or destroy Lady Luck's falling dice. Getting hit by one will lower your health by the number shown, but jumping on top of it will heal you by that same amount, and net you some extra points based on the risk! Take a chance and roll the dice!";
299307
} else if (PIXI.input.getKeyFired("d")) {
300-
menu.info.text = 'This game was made for the GMTK Game Jam 2022, with the theme "Roll of the Dice". The role of artist, programmer, and game designer were all filled by Cooper Ott.\n\nYou are a die fed up with Lady Luck telling you what to do, but trying to break free is easier said than done';
308+
menu.info.text = 'You play as a die, fed up with Lady Luck telling you what to do, but trying to break away is easier said than done.\n\nThis game was made for the GMTK Game Jam 2022, with the theme "Roll of the Dice." The role of artist, programmer, and game designer were all filled by Cooper Ott.';
301309
}
302310
} else {
303311

@@ -307,9 +315,8 @@ app.ticker.add((deltaTime) => {
307315

308316
scene.visible = false;
309317
allocationScreen.visible = true;
310-
particle.container.visible = false;
311318

312-
allocation.ladyLuck.text = "Lady Luck: " + ladyLuck[clamp(states.level, 0, ladyLuck.length)];
319+
allocation.ladyLuck.text = ladyLuck[clamp(states.level, 0, ladyLuck.length - 1)];
313320

314321
bg.tint = bgTint[0];
315322

@@ -380,10 +387,11 @@ app.ticker.add((deltaTime) => {
380387
});
381388

382389
if (newRolls.length == 4) {
390+
directions.text = "Test your luck in round " + (states.level + 1) + "... [W]"
383391
directions.visible = true;
384392
if (PIXI.input.getKeyFired("w")) {
385393
states.level++;
386-
states.dangerCount = 15 + states.level * 5;
394+
states.dangerCount = states.level * 10 + 10;
387395
states.allocation = false;
388396
states.jump = newRolls[0];
389397
states.speed = newRolls[1];
@@ -399,7 +407,7 @@ app.ticker.add((deltaTime) => {
399407
newRolls = [];
400408
directions.visible = false;
401409

402-
bg.tint = dangerTint[rand(1, 6)];
410+
bg.tint = bgTint[rand(1, bgTint.length - 1)];
403411

404412
dangerSet.forEach((danger) => {
405413
scene.removeChild(danger);
@@ -411,24 +419,30 @@ app.ticker.add((deltaTime) => {
411419
} else {
412420
allocationScreen.visible = false;
413421
scene.visible = true;
414-
particle.container.visible = true;
415422

416-
let t = Math.max(states.life, 1);
417-
player.texture = diceImg[t];
418-
player.tint = lifeTint[t];
423+
player.texture = diceImg[clamp(states.life, 0, 6)];
424+
player.tint = lifeTint[clamp(states.life, 0, 6)];
419425

420426
score.text = "Round " + states.level + ", " + states.score + " points, " + states.dangerCount + " remaining";
421427

422-
// X velocity
423-
player.vec.x *= 1 - (0.2 * player.allowJump);
424-
player.vec.x += (states.speedMult * states.speed * player.allowJump * (PIXI.input.getKeyDown("d") - PIXI.input.getKeyDown("a")));
425-
player.vec.x = clamp(player.vec.x, (states.speed + 2) * -states.speedMult, (states.speed + 2) * states.speedMult);
426-
427-
// Y velocity
428-
player.vec.y += (1 + (player.vec.y > 0) + 2 * PIXI.input.getKeyDown("s"));
429-
if (player.allowJump && PIXI.input.getKeyFired("w")) {
430-
player.allowJump = false;
431-
player.vec.y = -14 - states.jump * states.jumpMult;
428+
if (states.life > 0) { // X velocity
429+
player.vec.x *= 1 - (0.2 * player.allowJump);
430+
player.vec.x += (states.speedMult * states.speed * player.allowJump * (PIXI.input.getKeyDown("d") - PIXI.input.getKeyDown("a")));
431+
player.vec.x = clamp(player.vec.x, (states.speed + 2) * -states.speedMult, (states.speed + 2) * states.speedMult);
432+
433+
// Y velocity
434+
player.vec.y += 2 * PIXI.input.getKeyDown("s");
435+
if (player.allowJump && PIXI.input.getKeyFired("w")) {
436+
sound.bounce[rand(1, 2)].play();
437+
player.allowJump = false;
438+
player.vec.y = -14 - states.jump * states.jumpMult;
439+
}
440+
} else {
441+
gameOver.visible = true;
442+
if (PIXI.input.getKeyFired("w")) {
443+
states.menu = true;
444+
gameOver.visible = false;
445+
}
432446
}
433447

434448
// Player X position
@@ -442,11 +456,12 @@ app.ticker.add((deltaTime) => {
442456
}
443457
player.x = (player.x + 0.5) ^ 0;
444458
// Player Y position
459+
player.vec.y += 1 + (player.vec.y > 0);
445460
player.y += player.vec.y * deltaTime;
446461
if (player.y >= app.view.height) {
462+
if (!player.allowJump) sound.bounce[rand(0, 2)].play();
447463
player.y = app.view.height;
448464
player.allowJump = true;
449-
player.vec.y *= -phys.bounce * 0.1;
450465
}
451466
player.y ^= 0;
452467

@@ -459,7 +474,7 @@ app.ticker.add((deltaTime) => {
459474
danger.vec.y *= -phys.bounce;
460475
danger.vec.x = danger.vec.x * phys.bounce + (Math.random() - 0.5) * danger.vec.y;
461476
if (danger.vec.y < -2) {
462-
states.score += danger.facing;
477+
states.score += danger.facing * (states.life > 0);
463478
danger.facing = rand(1, 6);
464479
danger.texture = diceImg[danger.facing];
465480
danger.tint = dangerTint[danger.facing];
@@ -474,37 +489,30 @@ app.ticker.add((deltaTime) => {
474489
danger.x = app.view.width - danger.width * 0.5;
475490
danger.vec.x *= -phys.bounce;
476491
}
477-
if (PIXI.collision.aabb(player, danger)) {
478-
if (player.y - player.vec.y * 0.5 < danger.y) {
492+
if (PIXI.collision.aabb(player, danger) && states.life > 0) {
493+
if (player.y + player.height * 0.5 < danger.y && player.vec.y != 0) {
479494
// Jumped on top, score up AND heal AND bounce
480495
states.life = clamp(states.life + danger.facing, 1, 6)
481496
player.y -= player.height;
482497
player.vec.y = -14 - states.jump * states.jumpMult;
483-
states.score += danger.facing * 4;
498+
states.score += danger.facing * 5;
484499
states.dangerCount--;
485500
scene.removeChild(danger);
486501
dangerSet.delete(danger);
502+
edgeLight.alpha = 0.65;
487503
} else {
488504
// Hit by danger, lose life
489505
states.life -= danger.facing;
490506
app.stage.x += phys.shake;
491507
danger.vec = { x: rand(-16, 16), y: -16 };
492508
danger.y -= player.height;
493509
}
494-
let i = 6;
495-
while (--i >= 0) {
496-
let p = PIXI.Sprite.from(particle.tex);
497-
p.x = player.x + rand(-64, 64);
498-
p.y = player.y + rand(-64, 64);
499-
p.life = rand(15, 30);
500-
p.tint = player.tint;
501-
particle.set.add(p);
502-
particle.container.addChild(p);
503-
}
504510
sound.hit[rand(0, 2)].play();
505511
} else if (Math.abs(danger.vec.y) < 0.25 && danger.y == app.view.height) {
506-
states.score += danger.facing;
507-
states.dangerCount--;
512+
if (states.life > 0) {
513+
states.score += danger.facing;
514+
states.dangerCount--;
515+
}
508516
scene.removeChild(danger);
509517
dangerSet.delete(danger);
510518
}
@@ -533,7 +541,7 @@ app.ticker.add((deltaTime) => {
533541
scene.addChild(newDanger);
534542
dangerSet.add(newDanger);
535543
} else {
536-
states.dangerSpawnBoost += 0.00004 * (states.danger + states.level * 2);
544+
states.dangerSpawnBoost += 0.00003 * (states.danger + states.level * 3);
537545
}
538546

539547
if (states.dangerCount <= 0) {
36.5 KB
Loading

games/GMTK Jam/assets/particle.png

-489 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)