mirror of
https://github.com/csd4ni3l/loginween.git
synced 2025-11-05 05:58:10 +01:00
Add starting Pumpkin roll game which i will improve, add score and high score counters to both games
This commit is contained in:
3
CREDITS
3
CREDITS
@@ -1,3 +1,6 @@
|
|||||||
|
Tombstone image from Scary PNGs by Vecteezy
|
||||||
|
https://www.vecteezy.com/free-png/scary
|
||||||
|
|
||||||
Huge Thanks to Python for being the programming language used in this app.
|
Huge Thanks to Python for being the programming language used in this app.
|
||||||
https://www.python.org/
|
https://www.python.org/
|
||||||
|
|
||||||
|
|||||||
BIN
static/graphics/tombstone.png
Normal file
BIN
static/graphics/tombstone.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 165 KiB |
@@ -67,15 +67,30 @@ function setup_game() {
|
|||||||
revealed = [];
|
revealed = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let best_time = Number(localStorage.getItem("pumpkin_memory_best_time")) || 99999;
|
||||||
|
let first_time = best_time == 99999;
|
||||||
|
|
||||||
|
const best_time_display = (best_time == 99999) ? "None" : `${best_time}s`;
|
||||||
const elapsed = performance.now() - start;
|
const elapsed = performance.now() - start;
|
||||||
const timer_label = create_label(520, 5, `Time spent: ${(elapsed / 1000).toFixed(1)} s`);
|
const timer_label = create_label(520, 5, `Time spent: ${(elapsed / 1000).toFixed(1)}s Best Time: ${best_time_display}`);
|
||||||
|
|
||||||
const timer_interval_id = setInterval(() => {
|
const timer_interval_id = setInterval(() => {
|
||||||
const elapsed = performance.now() - start;
|
const elapsed = performance.now() - start;
|
||||||
timer_label.text = `Time spent: ${(elapsed / 1000).toFixed(1)} s`
|
if (first_time) {
|
||||||
|
best_time = (elapsed / 1000).toFixed(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
timer_label.text = `Time spent: ${(elapsed / 1000).toFixed(1)}s Best Time: ${best_time}s`
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
if (pumpkin_pairs == found_pairs.length - 1) {
|
if (pumpkin_pairs == found_pairs.length - 1) {
|
||||||
create_label(520, 320, `You win!\nTime took: ${(elapsed / 1000).toFixed(1)} s`, 48);
|
const elapsed = performance.now() - start;
|
||||||
|
if ((elapsed / 1000).toFixed(1) < best_time) {
|
||||||
|
best_time = (elapsed / 1000).toFixed(1);
|
||||||
|
}
|
||||||
|
localStorage.setItem(`memory_best_${pumpkin_pairs}`, best_time);
|
||||||
|
|
||||||
|
create_label(520, 320, `You win!\nTime took: ${(elapsed / 1000).toFixed(1)} s Best Time: ${best_time_display}`, 48);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,27 @@
|
|||||||
|
function spawn_tombstone() {
|
||||||
|
const tombstone_width = 150;
|
||||||
|
const tombstone_height = 150;
|
||||||
|
const tombstone_sprite = add([
|
||||||
|
sprite("tombstone"),
|
||||||
|
pos(1280 - tombstone_width, 720 - tombstone_height),
|
||||||
|
scale(0.05),
|
||||||
|
area(),
|
||||||
|
"tombstone"
|
||||||
|
]);
|
||||||
|
|
||||||
|
tombstone_sprite.onUpdate(() => {
|
||||||
|
tombstone_sprite.pos.x -= 300 * dt();
|
||||||
|
|
||||||
|
if (tombstone_sprite.pos.x <= -tombstone_width) {
|
||||||
|
destroy(tombstone_sprite);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return tombstone_sprite;
|
||||||
|
}
|
||||||
|
|
||||||
function setup_game() {
|
function setup_game() {
|
||||||
loadSprite("pumpkin", "/static/graphics/pumpkin.png");
|
loadSprite("pumpkin", "/static/graphics/pumpkin.png");
|
||||||
loadSprite("gravestone", "/static/gravestone.png")
|
loadSprite("tombstone", "/static/graphics/tombstone.png");
|
||||||
const SETTINGS = {
|
const SETTINGS = {
|
||||||
"Graphics": {
|
"Graphics": {
|
||||||
"Anti-Aliasing": {"type": "bool", "default": true},
|
"Anti-Aliasing": {"type": "bool", "default": true},
|
||||||
@@ -17,22 +38,81 @@ function setup_game() {
|
|||||||
"Controller Enabled": {"type": "bool", "default": true}
|
"Controller Enabled": {"type": "bool", "default": true}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const GRAVITY = 1500;
|
||||||
|
const JUMP_VELOCITY = -1300;
|
||||||
|
const GROUND_Y = 670;
|
||||||
|
|
||||||
scene("play", () => {
|
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();
|
||||||
|
|
||||||
|
const score_label = create_label(480, 10, `Score: ${score} High Score: ${high_score}`);
|
||||||
|
|
||||||
|
if (high_score == null) {
|
||||||
|
high_score = 0;
|
||||||
|
}
|
||||||
|
|
||||||
let pumpkin_sprite = add([
|
let pumpkin_sprite = add([
|
||||||
sprite("pumpkin"),
|
sprite("pumpkin"),
|
||||||
pos(50, 670),
|
pos(50, 670),
|
||||||
anchor("center"),
|
anchor("center"),
|
||||||
rotate(0)
|
rotate(0),
|
||||||
|
area(),
|
||||||
|
"pumpkin"
|
||||||
])
|
])
|
||||||
|
|
||||||
setInterval(() => {
|
|
||||||
pumpkin_sprite.angle = (pumpkin_sprite.angle + dt() * 720) % 360;
|
|
||||||
}, 100)
|
|
||||||
|
|
||||||
onKeyPress("jump", () => {
|
pumpkin_sprite.isJumping = false;
|
||||||
|
|
||||||
|
create_button(5, 5, 150, 75, "Back", color(127, 127, 127), color(0, 0, 0, 0), scene_lambda("main_menu"))
|
||||||
|
|
||||||
|
onCollide("pumpkin", "tombstone", () => {
|
||||||
|
if (game_over) return;
|
||||||
|
game_over = true;
|
||||||
|
|
||||||
|
for (let tombstone of tombstones) {
|
||||||
|
destroy(tombstone);
|
||||||
|
}
|
||||||
|
|
||||||
|
create_label(520, 320, `Game Over!\nScore: ${Math.floor(score)}\nHigh Score: ${high_score}`, 48);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
pumpkin_sprite.onUpdate(() => {
|
||||||
|
if (game_over) return;
|
||||||
|
score += 60 * dt();
|
||||||
|
|
||||||
|
if (Math.floor(score) > high_score) {
|
||||||
|
high_score = Math.floor(score);
|
||||||
|
localStorage.setItem("pumpkin_roll_highscore", high_score);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (isKeyDown("space") && !pumpkin_sprite.isJumping) {
|
||||||
|
pumpkin_sprite.vy = JUMP_VELOCITY;
|
||||||
|
pumpkin_sprite.isJumping = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pumpkin_sprite.angle = (pumpkin_sprite.angle + dt() * 270) % 360;
|
||||||
|
|
||||||
|
if (!pumpkin_sprite.isJumping) return;
|
||||||
|
|
||||||
|
pumpkin_sprite.vy += GRAVITY * dt();
|
||||||
|
pumpkin_sprite.pos.y += pumpkin_sprite.vy * dt();
|
||||||
|
|
||||||
|
if (pumpkin_sprite.pos.y >= GROUND_Y) {
|
||||||
|
pumpkin_sprite.pos.y = GROUND_Y;
|
||||||
|
pumpkin_sprite.isJumping = false;
|
||||||
|
pumpkin_sprite.vy = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
return ["Pumpkin Roll", SETTINGS];
|
return ["Pumpkin Roll", SETTINGS];
|
||||||
|
|||||||
Reference in New Issue
Block a user