Skip to content

Commit

Permalink
Update configs, add maze collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
smburdick committed Mar 4, 2024
1 parent 0001a79 commit 01a460b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
runtime: nodejs20
handlers:
# Catch all handler to index.html
- url: /play
- url: /.*
static_files: www/*
upload: www/*

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "qGhast",
"scripts": {
"build": "esbuild --bundle src/main.js --outfile=www/main.js --minify",
"build": "esbuild --bundle www/main.js --outfile=www/main.js --minify --allow-overwrite --servedir=www",
"dev": "esbuild --bundle src/main.js --outfile=www/main.js --servedir=www",
"bundle": "npm run build && mkdir -p dist && zip -r dist/game.zip www -x \"**/.DS_Store\""
"bundle": "npm run build && mkdir -p dist && zip -r dist/game.zip www -x \"**/.DS_Store\"",
"start": "npm run build"
},
"dependencies": {
"kaboom": "^3000.1.17",
Expand Down
18 changes: 11 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ const STABILIZER_INSERTION_RATE = 0.05;
const WAIT_TIME = 2;
const BLOCK_DIMENSION = 32 * 1.75;
const SPRITE_SCALE = 0.25;
const PC_SCALE = 0.15;
const DMG_THRESHOLD = 5;

const player = add([
sprite("pc"),
scale(SPRITE_SCALE),
pos(width() / 4 + BLOCK_DIMENSION - 8, BLOCK_DIMENSION - 8),
scale(PC_SCALE),
pos(width() / 4 + BLOCK_DIMENSION +4, BLOCK_DIMENSION + 8), // place the player in top-right of the maze
area(),
body(), // collide with blocks
]);

player.xDamage = 0;
Expand All @@ -39,9 +42,13 @@ player.zDamage = 0;
let ticks = 0;

loop(1, () => {
if (!player.exists() || player.xDamage >= 3 || player.zDamage >= 3) {
if (!player.exists() || player.xDamage >= DMG_THRESHOLD || player.zDamage >= DMG_THRESHOLD) {
go("gameover", { score: 20 - player.xDamage + player.zDamage });
}
// update opacity and color of the player based on damage
player.color = rgb(255, 255 - player.zDamage * 50, 255 - player.zDamage * 50);
player.opacity = 1 - (player.xDamage + player.xDamage) * 0.1;
// Decide whether to spawn an error
const poll = ticks++ > WAIT_TIME ? round(random() * (1 / ERROR_RATE)) : 0;
if (poll === 2) {
const zError = add([
Expand Down Expand Up @@ -153,10 +160,6 @@ player.onCollide("z-stabilizer", (stabilizer) => {
destroy(stabilizer);
});

player.onCollide("block", () => {
// player.move(-SPEED, 0);
});

player.onCollide("measure", (measure) => {
go("You win!");
});
Expand Down Expand Up @@ -294,6 +297,7 @@ const mazeTileSettings = {
rect(BLOCK_DIMENSION, BLOCK_DIMENSION),
color(BLACK),
// solid(),
body({ isStatic: true }),
area(),
"block",
],
Expand Down

0 comments on commit 01a460b

Please sign in to comment.