Skip to content

Commit

Permalink
added total mayhem randomiser, refactored randomisers to be more easi…
Browse files Browse the repository at this point in the history
…ly added
  • Loading branch information
TitanPlayz100 committed Oct 30, 2024
1 parent cc322f5 commit a7e9df0
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 116 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ <h1>Teti</h1>
<div class="settingRow"><p>Allspin's are mini</p> <input class="option check" type="checkbox" id="allspinminis" /></div>
<div class="settingRow"><p>Allow history (undo/redo)</p> <input class="option check" type="checkbox" id="history" /></div>
<div class="settingRow"><p>Stride (better queue)</p> <input class="option check" type="checkbox" id="stride" /></div>
<div class="settingRow"><p>Randomiser</p> <select class="option dropdown" id="randomiser"></select></div>
<div class="settingRow"><p>Sidebar Stats</p>
<select class="option dropdown statoption" id="statoption1"></select>
<select class="option dropdown statoption" id="statoption2"></select>
Expand Down
8 changes: 8 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Things that I am working on based on other changes
- ready set go start option
- arcade mode
- rotation centres
- bag seperators

- issue holding softdrop and left/right removes piece dropping cooldown

Expand Down Expand Up @@ -108,6 +109,12 @@ White (#ffffff)
***

## Updates
#### v1.3.6
- added total mayhem randomiser
- in the future it is very easy to add more randomisers
- thinking of adding all tetrio randomisers
- also figuring out tetrio's seed gen to mimic it for future additions (digging source code aaaaaa)

#### v1.3.5
- New board design inspired from [this reddit post](https://www.reddit.com/r/Tetris/comments/1g80adg/tetris_ui_concept/)
- added continue button in menu, and changed ingame buttons to use pixijs now
Expand Down Expand Up @@ -280,6 +287,7 @@ Future wants for game, kinda ordered by ease and desire for feature
- misdrop remover mode
- holdless and next queueless gamemode kinda like qp2 cards
- colourblind gamemode
- TEC Zone mode
- guide like progression using custom maps
- maybe like tetris tres bien
- achievements, progression tree
Expand Down
1 change: 1 addition & 0 deletions src/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const spinChecks = [
],
];

// when adding new gamemodes make sure to add variables
export const gameoverText = {
clearlines: "Cleared _ lines",
attack: "Sent _ damage",
Expand Down
1 change: 1 addition & 0 deletions src/data/defaultSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"competitiveMode": false,
"sidebar": ["time", "apm", "pps"],
"stride": false,
"randomiser": "7bag",
"requiredLines": 40,
"timeLimit": 120,
"requiredAttack": 40,
Expand Down
1 change: 0 additions & 1 deletion src/display/pixirender.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class PixiRender {
this.generateAllSprites("board", this.game.board.boardState, 39, [0, 0]);
this.generateAllSprites("hold", this.game.renderer.holdQueueGrid, 2, [0, 0]);
this.generateAllSprites("next", this.game.renderer.nextQueueGrid, 15, [0, 0]);
this.game.renderer.updateNext();
this.game.renderer.updateHold();

this.app.ticker.add(time => this.tick(time));
Expand Down
14 changes: 4 additions & 10 deletions src/display/renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Game } from "../game.js";
import pieces from "../data/pieces.json" with { type: "json" };
import { statDecimals, statsSecondary as statsSecondaries } from "../data/data.js";
import { getPiece } from "../mechanics/randomisers.js";

export class Renderer {
holdQueueGrid = [];
Expand All @@ -27,9 +27,8 @@ export class Renderer {
updateNext() {
this.nextQueueGrid = [...Array(15)].map(() => [...Array(4)].map(() => ""));

const next5 = this.game.bag.getFirstFive();
next5.forEach((name, idx) => {
const piece = this.getPiece(name);
const next5 = this.game.bag.getFirstN(this.game.settings.game.nextPieces);
next5.forEach((piece, idx) => {
let [dx, dy] = [0, 3 * (4 - idx)];
if (piece.name == "o") [dx, dy] = [dx + 1, dy + 1]; // shift o piece
const coords = this.board.pieceToCoords(piece.shape1);
Expand All @@ -39,11 +38,6 @@ export class Renderer {
this.game.pixi.render("next", this.nextQueueGrid);
}

getPiece(name) {
if (name == "G") return { colour: "gray" }
return pieces.filter(p => p.name == name)[0];
}

updateHold() {
this.holdQueueGrid = [...Array(3)].map(() => [...Array(4)].map(() => ""));
this.clearHold();
Expand Down Expand Up @@ -170,7 +164,7 @@ export class Renderer {
const elPieces = [...this.elementEditPieces.children];
elPieces.forEach(elpiece => {
const pieceid = elpiece.id.split("_")[0];
elpiece.style.backgroundColor = this.getPiece(pieceid).colour
elpiece.style.backgroundColor = getPiece(pieceid).colour
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/features/editboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class BoardEditor {

convertToMap() {
const board = this.game.board.boardState;
const next = this.game.bag.nextPieces;
const next = this.game.bag.getMapQueue();
const hold = this.game.hold.piece == null ? "" : this.game.hold.piece.name;
const currPiece = this.game.falling.piece.name;

Expand All @@ -71,7 +71,7 @@ export class BoardEditor {
return col;
})
}).join("")
return `${boardstring}?${currPiece},${next.flat()}?${hold}`
return `${boardstring}?${currPiece},${next}?${hold}`

}

Expand Down
11 changes: 6 additions & 5 deletions src/features/history.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Game } from "../game.js";
import { getPiece } from "../mechanics/randomisers.js";

export class History {
/**
Expand Down Expand Up @@ -150,7 +151,7 @@ export class History {

convertToMapCompressed() {
const board = this.game.board.boardState;
const next = this.game.bag.nextPieces;
const next = this.game.bag.getMapQueue();
const hold = this.game.hold.piece == null ? "" : this.game.hold.piece.name;
const currPiece = this.game.falling.piece == null ? "" : this.game.falling.piece.name;
let boardstring = board.toReversed().flatMap(row => {
Expand All @@ -164,7 +165,7 @@ export class History {
return col;
})
}).join("")
return `${this.compress(boardstring)}?${currPiece},${next.flat()}?${hold}`
return `${this.compress(boardstring)}?${currPiece},${next}?${hold}`

}

Expand All @@ -179,8 +180,8 @@ export class History {
});
})
this.game.board.boardState = board;
this.game.bag.nextPieces = [next.split(","), []];
this.game.hold.piece = this.game.renderer.getPiece(hold);
this.game.mechanics.spawnPiece(this.game.bag.randomiser());
this.game.bag.setQueue(next.split(","));
this.game.hold.piece = getPiece(hold);
this.game.mechanics.spawnPiece(this.game.bag.cycleNext());
}
}
9 changes: 4 additions & 5 deletions src/game.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bag } from "./mechanics/bag.js";
import { BagFactory } from "./mechanics/randomisers.js";
import { Board } from "./mechanics/board.js";
import { Controls } from "./movement/controls.js";
import { Hold } from "./mechanics/hold.js";
Expand Down Expand Up @@ -45,7 +45,6 @@ export class Game {
this.hold = new Hold(this);
this.sounds = new Sounds(this);
this.board = new Board(this);
this.bag = new Bag(this);
this.mechanics = new Mechanics(this);
this.menuactions = new MenuActions(this);
this.modals = new ModalActions(this);
Expand All @@ -57,7 +56,7 @@ export class Game {
this.history = new History(this);
this.modes = new Modes(this);
this.zenith = new Zenith(this);
this.grandmaster = new Grandmaster(this);;
this.grandmaster = new Grandmaster(this);
this.pixi = new PixiRender(this);
this.init();
}
Expand Down Expand Up @@ -86,7 +85,7 @@ export class Game {
this.modes.loadModes();
this.resetState();
this.renderer.renderStyles();
this.mechanics.spawnPiece(this.bag.randomiser(true), true);
this.mechanics.spawnPiece(this.bag.cycleNext(true), true);
this.history.save();
}

Expand Down Expand Up @@ -141,7 +140,7 @@ export class Game {
this.stopGameTimers();
this.pixi.resetActionTexts();

this.bag = new Bag(this);
this.bag = BagFactory(this);
this.mechanics = new Mechanics(this);
this.falling = new Falling(this);
this.hold = new Hold(this);
Expand Down
79 changes: 0 additions & 79 deletions src/mechanics/bag.js

This file was deleted.

8 changes: 2 additions & 6 deletions src/mechanics/hold.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Game } from "../game.js";
import pieces from "../data/pieces.json" with { type: "json" };
import { getPiece } from "./randomisers.js";


export class Hold {
Expand Down Expand Up @@ -30,14 +30,10 @@ export class Hold {

setNewHold(val) {
const validPiece = [val].filter(p => this.pieceNames.includes(p));
this.piece = this.getPiece(validPiece);
this.piece = getPiece(validPiece);
this.occured = false;
this.game.renderer.updateHold();
this.game.history.save();
}

getPiece(name) {
return pieces.filter(p => p.name == name)[0];
}

}
2 changes: 1 addition & 1 deletion src/mechanics/locking.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class LockPiece {

const delay = (cleared > 0) ? this.game.settings.game.clearDelay : 0;
const onClear = () => {
this.game.mechanics.spawnPiece(this.game.bag.randomiser());
this.game.mechanics.spawnPiece(this.game.bag.cycleNext());
this.game.history.save();
this.timings.clearDelay = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mechanics/mechanics.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Mechanics {

spawnOverlay() {
this.board.MinoToNone("NP");
const next = this.game.bag.nextPiece();
const next = this.game.bag.getFirstN(1)[0];
const x = next.name == "o" ? 4 : 3;
const y = next.name == "o" ? 21 : next.name == "i" ? 19 : 20;
this.board.pieceToCoords(next.shape1, [x, y]).forEach(([x, y]) => this.board.addValue([x, y], "NP"));
Expand Down Expand Up @@ -122,7 +122,7 @@ export class Mechanics {
this.game.stats.holds++;
if (this.game.hold.piece == null) {
this.game.hold.setHold();
this.spawnPiece(this.game.bag.randomiser());
this.spawnPiece(this.game.bag.cycleNext());
} else {
this.game.hold.swapHold();
this.spawnPiece(this.game.falling.piece);
Expand Down
Loading

0 comments on commit a7e9df0

Please sign in to comment.