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 WIDTH = 1280;
|
||||||
const HEIGHT = 720;
|
const HEIGHT = 720;
|
||||||
|
|
||||||
function change_setting(category, setting, value) {
|
function change_setting(category, setting, value, GAME_TITLE) {
|
||||||
localStorage.setItem(setting, value);
|
localStorage.setItem(`${GAME_TITLE} ${setting}`, value);
|
||||||
go("settings", category);
|
go("settings", category);
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_settings(category, SETTINGS) {
|
function show_settings(category, GAME_TITLE, SETTINGS) {
|
||||||
const x = 400;
|
const x = 400;
|
||||||
const label_x = 50;
|
const label_x = 50;
|
||||||
const space_between = 100;
|
const space_between = 100;
|
||||||
@@ -26,10 +26,10 @@ function show_settings(category, SETTINGS) {
|
|||||||
|
|
||||||
create_label(label_x, y + 10, key, 32);
|
create_label(label_x, y + 10, key, 32);
|
||||||
|
|
||||||
let value = localStorage.getItem(key);
|
let value = localStorage.getItem(`${GAME_TITLE} ${key}`);
|
||||||
|
|
||||||
if (value == undefined) {
|
if (value == null) {
|
||||||
localStorage.setItem(key, settings_dict.default);
|
localStorage.setItem(`${GAME_TITLE} ${key}`, settings_dict.default);
|
||||||
value = settings_dict.default;
|
value = settings_dict.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,25 +39,25 @@ function show_settings(category, SETTINGS) {
|
|||||||
"ON",
|
"ON",
|
||||||
value === "true" ? color(255, 255, 255) : color(127, 127, 127),
|
value === "true" ? color(255, 255, 255) : color(127, 127, 127),
|
||||||
color(0, 0, 0, 0),
|
color(0, 0, 0, 0),
|
||||||
() => { change_setting(category, currentKey, true); }
|
() => { change_setting(category, currentKey, true, GAME_TITLE); }
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"OFF",
|
"OFF",
|
||||||
value === "false" ? color(255, 255, 255) : color(127, 127, 127),
|
value === "false" ? color(255, 255, 255) : color(127, 127, 127),
|
||||||
color(0, 0, 0, 0),
|
color(0, 0, 0, 0),
|
||||||
() => { change_setting(category, currentKey, false); }
|
() => { change_setting(category, currentKey, false, GAME_TITLE); }
|
||||||
]
|
]
|
||||||
], 100, 50, 20);
|
], 100, 50, 20);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (settings_dict.type == "option") {
|
else if (settings_dict.type == "option") {
|
||||||
create_dropdown(x, y, 300, 75, settings_dict.options, 0, (option) => {
|
create_dropdown(x, y, 300, 75, settings_dict.options, settings_dict.options.indexOf(value), (option) => {
|
||||||
localStorage.setItem(currentKey, option);
|
localStorage.setItem(`${GAME_TITLE} ${currentKey}`, option);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (settings_dict.type == "slider") {
|
else if (settings_dict.type == "slider") {
|
||||||
create_slider(x, y, 400, Number(settings_dict.min), Number(settings_dict.max), Number(value), (new_value) => {
|
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"),
|
canvas: document.getElementById("canvas"),
|
||||||
root: document.getElementById("game-container"),
|
root: document.getElementById("game-container"),
|
||||||
crisp: !localStorage.getItem("Anti-Alasing"),
|
crisp: !localStorage.getItem("Anti-Alasing"),
|
||||||
texFilter: localStorage.getItem("Texture Filtering").toLowerCase(),
|
texFilter: (localStorage.getItem("Texture Filtering") || "nearest").toLowerCase(),
|
||||||
maxFPS: Number(localStorage.getItem("FPS Limit")),
|
maxFPS: Number(localStorage.getItem("FPS Limit")),
|
||||||
font: "New Rocker",
|
font: "New Rocker",
|
||||||
background: "#e18888",
|
background: "#e18888",
|
||||||
@@ -99,10 +99,10 @@ function start_game() {
|
|||||||
horizontal_buttons(10, 10, generated_button_lists, 200, 75, 10);
|
horizontal_buttons(10, 10, generated_button_lists, 200, 75, 10);
|
||||||
|
|
||||||
if (setting_category != null) {
|
if (setting_category != null) {
|
||||||
show_settings(setting_category, SETTINGS);
|
show_settings(setting_category, GAME_TITLE, SETTINGS);
|
||||||
}
|
}
|
||||||
else {
|
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");
|
loadSprite("pumpkin", "/static/graphics/pumpkin.png");
|
||||||
const SETTINGS = {
|
const SETTINGS = {
|
||||||
"Graphics": {
|
"Graphics": {
|
||||||
"Anti-Aliasing": {"type": "bool", "default": true},
|
"Anti-Aliasing": {"type": "bool", "default": "true"},
|
||||||
"Texture Filtering": {"type": "option", "options": ["Nearest", "Linear"], "default": "Linear"},
|
"Texture Filtering": {"type": "option", "options": ["Nearest", "Linear"], "default": "Linear"},
|
||||||
"FPS Limit": {"type": "slider", "min": 0, "max": 480, "default": 60},
|
"FPS Limit": {"type": "slider", "min": 0, "max": 480, "default": 60},
|
||||||
},
|
},
|
||||||
"Sound": {
|
"Sound": {
|
||||||
"Music": {"type": "bool", "default": true},
|
"Music": {"type": "bool", "default": "true"},
|
||||||
"SFX": {"type": "bool", "default": true},
|
"SFX": {"type": "bool", "default": "true"},
|
||||||
"Music Volume": {"type": "slider", "min": 0, "max": 100, "default": 50},
|
"Music Volume": {"type": "slider", "min": 0, "max": 100, "default": 50},
|
||||||
"SFX 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() {
|
function spawn_enemy() {
|
||||||
const tombstone_width = 150;
|
let enemy_type = "tombstone";
|
||||||
const tombstone_height = 150;
|
const enemy_width = 140;
|
||||||
const tombstone_sprite = add([
|
const enemy_height = 120;
|
||||||
sprite("tombstone"),
|
const enemy_sprite = add([
|
||||||
pos(1280 - tombstone_width, 720 - tombstone_height),
|
sprite(enemy_type),
|
||||||
|
pos(1280 - enemy_width, 720 - enemy_height),
|
||||||
scale(0.05),
|
scale(0.05),
|
||||||
area(),
|
area(),
|
||||||
"tombstone"
|
"enemy"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
tombstone_sprite.onUpdate(() => {
|
enemy_sprite.onUpdate(() => {
|
||||||
tombstone_sprite.pos.x -= 300 * dt();
|
enemy_sprite.pos.x -= 1000 * dt();
|
||||||
|
|
||||||
if (tombstone_sprite.pos.x <= -tombstone_width) {
|
if (enemy_sprite.pos.x <= -enemy_width) {
|
||||||
destroy(tombstone_sprite);
|
destroy(enemy_sprite);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return tombstone_sprite;
|
return enemy_sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_game() {
|
function setup_game() {
|
||||||
@@ -24,30 +25,30 @@ function setup_game() {
|
|||||||
loadSprite("tombstone", "/static/graphics/tombstone.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"},
|
||||||
"Texture Filtering": {"type": "option", "options": ["Nearest", "Linear"], "default": "Linear"},
|
"Texture Filtering": {"type": "option", "options": ["Nearest", "Linear"], "default": "Linear"},
|
||||||
"FPS Limit": {"type": "slider", "min": 0, "max": 480, "default": 60},
|
"FPS Limit": {"type": "slider", "min": 0, "max": 480, "default": 60},
|
||||||
},
|
},
|
||||||
"Sound": {
|
"Sound": {
|
||||||
"Music": {"type": "bool", "default": true},
|
"Music": {"type": "bool", "default": "true"},
|
||||||
"SFX": {"type": "bool", "default": true},
|
"SFX": {"type": "bool", "default": "true"},
|
||||||
"Music Volume": {"type": "slider", "min": 0, "max": 100, "default": 50},
|
"Music Volume": {"type": "slider", "min": 0, "max": 100, "default": 50},
|
||||||
"SFX Volume": {"type": "slider", "min": 0, "max": 100, "default": 50},
|
"SFX Volume": {"type": "slider", "min": 0, "max": 100, "default": 50},
|
||||||
},
|
},
|
||||||
"Input": {
|
"Input": {
|
||||||
"Controller Enabled": {"type": "bool", "default": true}
|
"Controller Enabled": {"type": "bool", "default": "true"}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const GRAVITY = 1500;
|
const GRAVITY = 2500;
|
||||||
const JUMP_VELOCITY = -1300;
|
const JUMP_VELOCITY = -1200;
|
||||||
const GROUND_Y = 670;
|
const GROUND_Y = 670;
|
||||||
|
|
||||||
scene("play", () => {
|
scene("play", () => {
|
||||||
let score = 0;
|
let score = 0;
|
||||||
let high_score = localStorage.getItem("pumpkin_roll_highscore");
|
let high_score = localStorage.getItem("pumpkin_roll_highscore");
|
||||||
let game_over = false;
|
let game_over = false;
|
||||||
let tombstones = [];
|
let enemys = [];
|
||||||
let last_tombstone_spawn = performance.now();
|
let last_enemy_spawn = performance.now();
|
||||||
|
|
||||||
const score_label = create_label(480, 10, `Score: ${score} High Score: ${high_score}`);
|
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"))
|
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;
|
if (game_over) return;
|
||||||
game_over = true;
|
game_over = true;
|
||||||
|
|
||||||
for (let tombstone of tombstones) {
|
for (let enemy of enemys) {
|
||||||
destroy(tombstone);
|
destroy(enemy);
|
||||||
}
|
}
|
||||||
|
|
||||||
create_label(520, 320, `Game Over!\nScore: ${Math.floor(score)}\nHigh Score: ${high_score}`, 48);
|
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(() => {
|
pumpkin_sprite.onUpdate(() => {
|
||||||
if (game_over) return;
|
if (game_over) return;
|
||||||
score += 60 * dt();
|
score += 60 * dt();
|
||||||
@@ -90,9 +100,21 @@ function setup_game() {
|
|||||||
|
|
||||||
score_label.text = `Score: ${Math.floor(score)} High Score: ${high_score}`;
|
score_label.text = `Score: ${Math.floor(score)} High Score: ${high_score}`;
|
||||||
|
|
||||||
if ((performance.now() - last_tombstone_spawn) >= 2000) {
|
if ((performance.now() - last_enemy_spawn) >= 1000) {
|
||||||
last_tombstone_spawn = performance.now();
|
last_enemy_spawn = performance.now();
|
||||||
tombstones.push(spawn_tombstone());
|
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) {
|
if (isKeyDown("space") && !pumpkin_sprite.isJumping) {
|
||||||
|
|||||||
Reference in New Issue
Block a user