Skip to content

Commit

Permalink
added 100 puzzles
Browse files Browse the repository at this point in the history
200 if u count mirrors
  • Loading branch information
Spentine committed Jun 20, 2024
1 parent f57a0ed commit 6300b0e
Show file tree
Hide file tree
Showing 5 changed files with 1,392 additions and 21 deletions.
11 changes: 9 additions & 2 deletions init.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,25 @@ <h1 class="ui" id="UI-homepageTitle"> Spentris </h1>
<div class="ui page" id="playMenu">
<button class="ui Button1" id="UI-gamemodes"> Game Modes </button>
<button class="ui Button1 unfinished" id="UI-learn"> Learn </button>
<button class="ui Button1 unfinished" id="UI-train"> Train </button>
<button class="ui Button1" id="UI-train"> Train </button>
<button class="ui Button1" id="UI-playMenu-back"> Back </button>
</div>

<div class="ui page" id="gamemodesMenu">
<button class="ui Button1" id="UI-marathon"> Marathon </button>
<button class="ui Button1" id="UI-fourtyLines"> 40 Lines </button>
<button class="ui Button1" id="UI-fortyLines"> 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>
</div>

<div class="ui page" id="trainMenu">
<button class="ui Button1" id="UI-trainMenu-easy"> Easy </button>
<button class="ui Button1 unfinished" id="UI-trainMenu-medium"> Medium </button>
<button class="ui Button1 unfinished" id="UI-trainMenu-hard"> Hard </button>
<button class="ui Button1" id="UI-trainMenu-back"> Back </button>
</div>

<div class="ui page" id="settingsMenu">
<button class="ui Button1 unfinished" id="UI-keybinds"> Keybinds </button>
<button class="ui Button1" id="UI-handling"> Handling </button>
Expand Down
69 changes: 59 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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"
import { gameModes } from "./modes.js"
import { gameModes, easyPuzzles } from "./modes.js"

var userSettings = {
"version": 1,
Expand Down Expand Up @@ -117,10 +117,29 @@ function DOMLoaded(event) {
renderer.updateScene(scene);
});

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

const UITrainElement = document.getElementById('UI-train');
UITrainElement.addEventListener("click", () => {
scene = "trainMenu";
renderer.updateScene(scene);
});

const UITrainEasyElement = document.getElementById('UI-trainMenu-easy');
UITrainEasyElement.addEventListener("click", () => {
scene = "game-puzzleEasy";
startGame("puzzleEasy");
renderer.updateScene(scene);
});

const UITrainMenuBackElement = document.getElementById('UI-trainMenu-back');
UITrainMenuBackElement.addEventListener("click", () => {
scene = "playMenu";
renderer.updateScene(scene);
});

Expand Down Expand Up @@ -182,6 +201,7 @@ function DOMLoaded(event) {

var lastFrame;
var lastInputs;
var currentPuzzle;

function startGame(mode) {

Expand All @@ -191,27 +211,43 @@ function startGame(mode) {
case "marathon":
playSettings = gameModes.marathon;
break;
case "fourtyLines":
playSettings = gameModes.fourtyLines;
case "fortyLines":
playSettings = gameModes.fortyLines;
break;
case "blitz":
playSettings = gameModes.blitz;
break;
case "puzzleEasy":
currentPuzzle = Math.floor(Math.random() * easyPuzzles.length);
playSettings = easyPuzzles[currentPuzzle].outputData();
break;
}

startGameSettings(playSettings);

/*
game = new Stacker(playSettings);
game.setUserSettings(userSettings);
lastFrame = Date.now();
lastInputs = inputHandler.getInputs();
*/
}

function startGameSettings(settings) {
game = new Stacker(settings);

game.setUserSettings(userSettings);

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

function tickFrameGame() {
const inputs = inputHandler.getInputs();
// console.log(inputs);
const gameEvents = game.tick(inputs, lastInputs, Date.now() - lastFrame)
const gameEvents = game.tick(inputs, lastInputs, Date.now() - lastFrame);

/*
if (JSON.stringify(gameEvents) !== '{"playing":true}') {
Expand All @@ -230,17 +266,30 @@ function tickFrameGame() {

lastFrame = Date.now();
lastInputs = structuredClone(inputs);

if (scene === "game-puzzleEasy") {
if (game.end){
if (game.end.ending === "noPieces") {
console.log("Failed Easy Puzzle " + currentPuzzle);
startGameSettings(easyPuzzles[currentPuzzle].outputData());
} else {
console.log("Passed Easy Puzzle " + currentPuzzle);
startGame("puzzleEasy");
}
}
}
}

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

function tickFrame() {

if (gameScenes.includes(scene)) {
//if (gameScenes.includes(scene)) {
if (scene.substring(0, 5) === "game-") {
tickFrameGame();
} else {
renderer.renderScreen({
Expand Down
Loading

0 comments on commit 6300b0e

Please sign in to comment.