From ecf5dc689303dd6afcf9494baeff8857377ce413 Mon Sep 17 00:00:00 2001 From: Josh Curtiss Date: Fri, 7 Jun 2024 16:19:43 -0500 Subject: [PATCH] feat: Add cheat codes --- src/scenes/GameScene.ts | 48 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/scenes/GameScene.ts b/src/scenes/GameScene.ts index f17326e..0eacc79 100644 --- a/src/scenes/GameScene.ts +++ b/src/scenes/GameScene.ts @@ -1,4 +1,4 @@ -import { LevelOpt } from 'kaboom'; +import { LevelOpt, TimerController } from 'kaboom'; import { k, BURGERTIME_BLUE } from '../kaboom'; import { waitSpawnPowerup } from '../objects/Powerup'; import { addEnemy } from '../objects/Enemy'; @@ -15,6 +15,7 @@ const { anchor, area, color, + debug, fixed, go, isKeyDown, @@ -22,6 +23,7 @@ const { on, play, pos, + randi, rect, sprite, text, @@ -249,6 +251,50 @@ export default function(options: Partial) { p.setIntendedDir(dir); }); + // Cheat Codes + let keylog = ''; + let keylogTimer: TimerController; + function debugLog(msg: string) { + debug.showLog = true; + debug.log(msg); + } + onKeyPress(key=>{ + if (key.length>1) return; + if (keylogTimer) keylogTimer.cancel(); + keylog += key.toLowerCase(); + keylogTimer=wait(5, ()=>{ + keylog=''; + debug.showLog = debug.inspect; + }); + if (keylog.slice(-6)==='invuln') { + player.isInvulnerable = !player.isInvulnerable; + debugLog(`Invulnerability: ${player.isInvulnerable}`); + } else if (keylog.slice(-5)==='crazy') { + player.speed *= 2; + player.levelTime += ENEMY_SPEED_CHECK_FREQUENCY * 15; + debugLog(`It's gonna get crazy up in here!`); + } else if (keylog.slice(-4)==='gold') { + player.score += randi(75, 150) * 100; + debugLog(`Score: ${player.score}`); + } else if (keylog.slice(-4)==='gone') { + while (enemies.length) enemies.pop()?.destroy(); + debugLog(`Everybody's gone now...`); + } else if (keylog.slice(-4)==='life') { + player.lives+=1; + debugLog(`Lives: ${player.lives}`); + } else if (keylog.slice(-5)==='music') { + if (!music.paused) music.stop(); + else music.play(); + debugLog(`Music: ${music.paused ? 'paused' : 'playing'}`) + } else if (keylog.slice(-4)==='salt' || keylog.slice(-6)==='pepper') { + player.salt+=1; + debugLog(`Pepper: ${player.salt}`); + } else if (keylog.slice(-3)==='win') { + player.win(); + debugLog('Good job... NOT.'); + } + }); + // "Player Ready" message and music pause const dlg = add([ rect(k.width(), k.height()),