Cut out tombstones, make settings depend on the game, fix default settings values, fix game crashing with no setting cookies, add multiple enemies into pumpkin roll

This commit is contained in:
csd4ni3l
2025-11-02 16:50:43 +01:00
parent dbaecc846c
commit f056977548
4 changed files with 65 additions and 43 deletions

View File

@@ -1,22 +1,23 @@
function spawn_tombstone() {
const tombstone_width = 150;
const tombstone_height = 150;
const tombstone_sprite = add([
sprite("tombstone"),
pos(1280 - tombstone_width, 720 - tombstone_height),
function spawn_enemy() {
let enemy_type = "tombstone";
const enemy_width = 140;
const enemy_height = 120;
const enemy_sprite = add([
sprite(enemy_type),
pos(1280 - enemy_width, 720 - enemy_height),
scale(0.05),
area(),
"tombstone"
"enemy"
]);
tombstone_sprite.onUpdate(() => {
tombstone_sprite.pos.x -= 300 * dt();
enemy_sprite.onUpdate(() => {
enemy_sprite.pos.x -= 1000 * dt();
if (tombstone_sprite.pos.x <= -tombstone_width) {
destroy(tombstone_sprite);
if (enemy_sprite.pos.x <= -enemy_width) {
destroy(enemy_sprite);
}
})
return tombstone_sprite;
return enemy_sprite;
}
function setup_game() {
@@ -24,30 +25,30 @@ function setup_game() {
loadSprite("tombstone", "/static/graphics/tombstone.png");
const SETTINGS = {
"Graphics": {
"Anti-Aliasing": {"type": "bool", "default": true},
"Anti-Aliasing": {"type": "bool", "default": "true"},
"Texture Filtering": {"type": "option", "options": ["Nearest", "Linear"], "default": "Linear"},
"FPS Limit": {"type": "slider", "min": 0, "max": 480, "default": 60},
},
"Sound": {
"Music": {"type": "bool", "default": true},
"SFX": {"type": "bool", "default": true},
"Music": {"type": "bool", "default": "true"},
"SFX": {"type": "bool", "default": "true"},
"Music Volume": {"type": "slider", "min": 0, "max": 100, "default": 50},
"SFX Volume": {"type": "slider", "min": 0, "max": 100, "default": 50},
},
"Input": {
"Controller Enabled": {"type": "bool", "default": true}
"Controller Enabled": {"type": "bool", "default": "true"}
}
};
const GRAVITY = 1500;
const JUMP_VELOCITY = -1300;
const GRAVITY = 2500;
const JUMP_VELOCITY = -1200;
const GROUND_Y = 670;
scene("play", () => {
let score = 0;
let high_score = localStorage.getItem("pumpkin_roll_highscore");
let game_over = false;
let tombstones = [];
let last_tombstone_spawn = performance.now();
let enemys = [];
let last_enemy_spawn = performance.now();
const score_label = create_label(480, 10, `Score: ${score} High Score: ${high_score}`);
@@ -68,17 +69,26 @@ function setup_game() {
create_button(5, 5, 150, 75, "Back", color(127, 127, 127), color(0, 0, 0, 0), scene_lambda("main_menu"))
onCollide("pumpkin", "tombstone", () => {
onCollide("pumpkin", "enemy", () => {
if (game_over) return;
game_over = true;
for (let tombstone of tombstones) {
destroy(tombstone);
for (let enemy of enemys) {
destroy(enemy);
}
create_label(520, 320, `Game Over!\nScore: ${Math.floor(score)}\nHigh Score: ${high_score}`, 48);
})
enemy_spawn_with_check = () => {
if (game_over) {
return
}
enemys.push(spawn_enemy())
}
spawn_enemy();
pumpkin_sprite.onUpdate(() => {
if (game_over) return;
score += 60 * dt();
@@ -90,9 +100,21 @@ function setup_game() {
score_label.text = `Score: ${Math.floor(score)} High Score: ${high_score}`;
if ((performance.now() - last_tombstone_spawn) >= 2000) {
last_tombstone_spawn = performance.now();
tombstones.push(spawn_tombstone());
if ((performance.now() - last_enemy_spawn) >= 1000) {
last_enemy_spawn = performance.now();
const random = Math.random();
if (random < 0.2) {
enemys.push(spawn_enemy());
setTimeout(enemy_spawn_with_check, 150);
setTimeout(enemy_spawn_with_check, 300);
}
else if (random < 0.5) {
enemys.push(spawn_enemy());
setTimeout(enemy_spawn_with_check, 150);
}
else {
enemys.push(spawn_enemy());
}
}
if (isKeyDown("space") && !pumpkin_sprite.isJumping) {