Skip to content

Commit

Permalink
added new mode
Browse files Browse the repository at this point in the history
nice
  • Loading branch information
Spentine committed Jun 19, 2024
1 parent 1109e05 commit f57a0ed
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 63 deletions.
2 changes: 1 addition & 1 deletion init.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1 class="ui" id="UI-homepageTitle"> Spentris </h1>

<div class="ui page" id="gamemodesMenu">
<button class="ui Button1" id="UI-marathon"> Marathon </button>
<button class="ui Button1 unfinished" id="UI-fourtyLines"> 40 Lines </button>
<button class="ui Button1" id="UI-fourtyLines"> 40 Lines </button>
<button class="ui Button1 unfinished" id="UI-blitz"> Blitz </button>
<button class="ui Button1 unfinished" id="UI-zen"> Zen </button>
<button class="ui Button1" id="UI-gamemodesMenu-back"> Back </button>
Expand Down
95 changes: 34 additions & 61 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,7 @@ import { Position, Kick, Mino, Piece, RotationSystem, Stacker } from "./stacker/
import { SRS_mono, SRS_color } from "./stacker/rs.js"
import { GameRenderer } from "./render.js"
import { InputHandler } from "./input.js"

var settings = {
"version": 1, // settings version for backwards compatibility
"handling": { // handling is in ms

// "das": 100,
// "arr": 16,
"das": 83,
"arr": 0,

// "sdf": 30,
"sdf": Infinity,
"msg": 0.001,
"dcd": 0,
"are": 0,
"lca": 0, // line clear ARE
},
"dimensions": {
"width": 10,
"height": 40,
"visualHeight": 20,
"spawnHeight": 22, // from bottom
"renderHeight": 25, // from bottom
},
"gameSettings": {
// "seed": 0,
"seed": null,
"rotationSystem": SRS_color,
// "gravity": 0.0001, // minos fallen per ms
"gravity": 0,
"gravityIncrease": 0.000000007, // multiply by elapsed ms and add to gravity

"levelling": true, // overrides gravity
"level": 1,

// "lockDelay": 500, // ms until locks
"lockDelay": 500,
},
"gamePermissions": {
"allow180": true,
"hardDropAllowed": true,
"holdAllowed": true,
"infiniteMovement": false,
},
"userSettings": {
"next": 5,
"ghost": true,
},
};
// console.log(JSON.stringify(settings));
import { gameModes } from "./modes.js"

var userSettings = {
"version": 1,
Expand Down Expand Up @@ -161,15 +112,21 @@ function DOMLoaded(event) {

const UIMarathonElement = document.getElementById('UI-marathon');
UIMarathonElement.addEventListener("click", () => {
scene = "game";
startGame();
scene = "game-marathon";
startGame("marathon");
renderer.updateScene(scene);
});

const UIFourtyLinesElement = document.getElementById('UI-fourtyLines');
UIFourtyLinesElement.addEventListener("click", () => {
scene = "game-fourtyLines";
startGame("fourtyLines");
renderer.updateScene(scene);
});

const UISettingsElement = document.getElementById('UI-settings');
UISettingsElement.addEventListener("click", () => {
scene = "settingsMenu";
startGame();
renderer.updateScene(scene);
});

Expand All @@ -182,7 +139,6 @@ function DOMLoaded(event) {
const UIKeybindsElement = document.getElementById('UI-keybinds');
UIKeybindsElement.addEventListener("click", () => {
scene = "keybindsMenu";
startGame();
renderer.updateKeybindButtons();
renderer.updateScene(scene);
});
Expand All @@ -196,7 +152,6 @@ function DOMLoaded(event) {
const UIHandlingElement = document.getElementById('UI-handling');
UIHandlingElement.addEventListener("click", () => {
scene = "handlingMenu";
startGame();
renderer.updateHandlingInputs();
renderer.updateScene(scene);
});
Expand Down Expand Up @@ -228,14 +183,26 @@ function DOMLoaded(event) {
var lastFrame;
var lastInputs;

function startGame() {
function startGame(mode) {

var playSettings = null;

switch (mode) {
case "marathon":
playSettings = gameModes.marathon;
break;
case "fourtyLines":
playSettings = gameModes.fourtyLines;
break;
case "blitz":
playSettings = gameModes.blitz;
break;
}

const playSettings = structuredClone(settings);

playSettings.handling = userSettings.inGame.handling;

game = new Stacker(playSettings);

game.setUserSettings(userSettings);

lastFrame = Date.now();
lastInputs = inputHandler.getInputs();

Expand Down Expand Up @@ -265,9 +232,15 @@ function tickFrameGame() {
lastInputs = structuredClone(inputs);
}

const gameScenes = [
"game-marathon",
"game-fourtyLines",
"game-blitz",
];

function tickFrame() {

if (scene === "game") {
if (gameScenes.includes(scene)) {
tickFrameGame();
} else {
renderer.renderScreen({
Expand Down
172 changes: 172 additions & 0 deletions modes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import { SRS_mono, SRS_color } from "./stacker/rs.js"

const template = {
"version": 1, // settings version for backwards compatibility

"handling": { // handling is in ms
"das": 100,
"arr": 16,
"sdf": 30,
"msg": 0.001,
"dcd": 0,
"are": 0,
"lca": 0, // line clear ARE
},

"dimensions": {
"width": 10,
"height": 40,
"visualHeight": 20,
"spawnHeight": 22, // from bottom
"renderHeight": 25, // from bottom
},

"gameSettings": {
// "seed": 0,
"seed": null,
"rotationSystem": SRS_color,
// "gravity": 0.0001, // minos fallen per ms
"gravity": 0,
"gravityIncrease": 0.000000007, // multiply by elapsed ms and add to gravity

"levelling": true, // overrides gravity
"level": 1,

// "lockDelay": 500, // ms until locks
"lockDelay": 500,

"startingBoard": null,
"startingQueue": null,
"customQueueType": null,
/*
if startingQueue is not null:
- "repeating": will repeat the queue forever
- null: will simply append 7bag afterwards
- "ending": will not generate any more pieces
*/
"endCondition": null,
// end condition for game
},

"gamePermissions": {
"allow180": true,
"hardDropAllowed": true,
"holdAllowed": true,
"infiniteMovement": false,
},

"userSettings": {
"next": 5,
},
};

const gameModes = {
"marathon": {
"version": 1, // settings version for backwards compatibility

"handling": { // handling is in ms
"das": 100,
"arr": 16,
"sdf": 30,
"msg": 0.001,
"dcd": 0,
"are": 0,
"lca": 0, // line clear ARE
},

"dimensions": {
"width": 10,
"height": 40,
"visualHeight": 20,
"spawnHeight": 22, // from bottom
"renderHeight": 25, // from bottom
},

"gameSettings": {
"seed": null,
"rotationSystem": SRS_color,
"gravity": 0,
"gravityIncrease": 0.000000007,

"levelling": true,
"level": 1,
"lockDelay": 500,

"startingBoard": null,
"startingQueue": null,
"customQueueType": null,
"endCondition": null,
},

"gamePermissions": {
"allow180": true,
"hardDropAllowed": true,
"holdAllowed": true,
"infiniteMovement": false,
},

"userSettings": {
"next": 5,
},
},
"fourtyLines": {
"version": 1, // settings version for backwards compatibility

"handling": { // handling is in ms
"das": 100,
"arr": 16,
"sdf": 30,
"msg": 0.001,
"dcd": 0,
"are": 0,
"lca": 0, // line clear ARE
},

"dimensions": {
"width": 10,
"height": 40,
"visualHeight": 20,
"spawnHeight": 22, // from bottom
"renderHeight": 25, // from bottom
},

"gameSettings": {
"seed": null,
"rotationSystem": SRS_color,
"gravity": 0.001,
"gravityIncrease": 0.000000007,

"levelling": false,
"level": 1,
"lockDelay": 500,

"startingBoard": null,
"startingQueue": null,
"customQueueType": null,
"endCondition": function () {
if (this.stats.linesCleared < 40) {
return false;
} else {
return {
"ending": "40l",
"timeStamp": Date.now(),
}
}
},
},

"gamePermissions": {
"allow180": true,
"hardDropAllowed": true,
"holdAllowed": true,
"infiniteMovement": false,
},

"userSettings": {
"next": 5,
},
}
}

export { gameModes };
Loading

0 comments on commit f57a0ed

Please sign in to comment.