mirror of
https://github.com/csd4ni3l/loginween.git
synced 2025-11-05 05:58:10 +01:00
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:
Binary file not shown.
|
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 35 KiB |
@@ -1,12 +1,12 @@
|
||||
const WIDTH = 1280;
|
||||
const HEIGHT = 720;
|
||||
|
||||
function change_setting(category, setting, value) {
|
||||
localStorage.setItem(setting, value);
|
||||
function change_setting(category, setting, value, GAME_TITLE) {
|
||||
localStorage.setItem(`${GAME_TITLE} ${setting}`, value);
|
||||
go("settings", category);
|
||||
}
|
||||
|
||||
function show_settings(category, SETTINGS) {
|
||||
function show_settings(category, GAME_TITLE, SETTINGS) {
|
||||
const x = 400;
|
||||
const label_x = 50;
|
||||
const space_between = 100;
|
||||
@@ -26,10 +26,10 @@ function show_settings(category, SETTINGS) {
|
||||
|
||||
create_label(label_x, y + 10, key, 32);
|
||||
|
||||
let value = localStorage.getItem(key);
|
||||
let value = localStorage.getItem(`${GAME_TITLE} ${key}`);
|
||||
|
||||
if (value == undefined) {
|
||||
localStorage.setItem(key, settings_dict.default);
|
||||
if (value == null) {
|
||||
localStorage.setItem(`${GAME_TITLE} ${key}`, settings_dict.default);
|
||||
value = settings_dict.default;
|
||||
}
|
||||
|
||||
@@ -39,25 +39,25 @@ function show_settings(category, SETTINGS) {
|
||||
"ON",
|
||||
value === "true" ? color(255, 255, 255) : color(127, 127, 127),
|
||||
color(0, 0, 0, 0),
|
||||
() => { change_setting(category, currentKey, true); }
|
||||
() => { change_setting(category, currentKey, true, GAME_TITLE); }
|
||||
],
|
||||
[
|
||||
"OFF",
|
||||
value === "false" ? color(255, 255, 255) : color(127, 127, 127),
|
||||
color(0, 0, 0, 0),
|
||||
() => { change_setting(category, currentKey, false); }
|
||||
() => { change_setting(category, currentKey, false, GAME_TITLE); }
|
||||
]
|
||||
], 100, 50, 20);
|
||||
|
||||
}
|
||||
else if (settings_dict.type == "option") {
|
||||
create_dropdown(x, y, 300, 75, settings_dict.options, 0, (option) => {
|
||||
localStorage.setItem(currentKey, option);
|
||||
create_dropdown(x, y, 300, 75, settings_dict.options, settings_dict.options.indexOf(value), (option) => {
|
||||
localStorage.setItem(`${GAME_TITLE} ${currentKey}`, option);
|
||||
});
|
||||
}
|
||||
else if (settings_dict.type == "slider") {
|
||||
create_slider(x, y, 400, Number(settings_dict.min), Number(settings_dict.max), Number(value), (new_value) => {
|
||||
localStorage.setItem(currentKey, new_value);
|
||||
localStorage.setItem(`${GAME_TITLE} ${currentKey}`, new_value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ function start_game() {
|
||||
canvas: document.getElementById("canvas"),
|
||||
root: document.getElementById("game-container"),
|
||||
crisp: !localStorage.getItem("Anti-Alasing"),
|
||||
texFilter: localStorage.getItem("Texture Filtering").toLowerCase(),
|
||||
texFilter: (localStorage.getItem("Texture Filtering") || "nearest").toLowerCase(),
|
||||
maxFPS: Number(localStorage.getItem("FPS Limit")),
|
||||
font: "New Rocker",
|
||||
background: "#e18888",
|
||||
@@ -99,10 +99,10 @@ function start_game() {
|
||||
horizontal_buttons(10, 10, generated_button_lists, 200, 75, 10);
|
||||
|
||||
if (setting_category != null) {
|
||||
show_settings(setting_category, SETTINGS);
|
||||
show_settings(setting_category, GAME_TITLE, SETTINGS);
|
||||
}
|
||||
else {
|
||||
show_settings(Object.keys(SETTINGS)[0], SETTINGS);
|
||||
show_settings(Object.keys(SETTINGS)[0], GAME_TITLE, SETTINGS);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ function setup_game() {
|
||||
loadSprite("pumpkin", "/static/graphics/pumpkin.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},
|
||||
},
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user