Skip to content

Commit

Permalink
removing features to meet 13kb limit
Browse files Browse the repository at this point in the history
  • Loading branch information
gtanczyk committed Aug 25, 2024
1 parent 0147d51 commit 5c5d66c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
26 changes: 14 additions & 12 deletions js13k2024/game/src/game-states/intro/intro.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { GamePreview } from './game-preview';
// Game preview is removed for now
// import { GamePreview } from './game-preview';
import { createElement, createDiv, createButton, appendChildren } from '../../utils/dom';

export class Intro {
private onStart: () => void;
private onInstructions: () => void;
// private onInstructions: () => void;

constructor(onStart: () => void, onInstructions: () => void) {
constructor(onStart: () => void /*, onInstructions: () => void*/) {
this.onStart = onStart;
this.onInstructions = onInstructions;
// this.onInstructions = onInstructions;
}

render(): HTMLElement {
Expand All @@ -19,30 +20,31 @@ export class Intro {

const introResponsive = createDiv('game-intro-responsive');

const previewContainer = createDiv('game-preview-container');
const gamePreview = new GamePreview();
previewContainer.appendChild(gamePreview.render());
// const previewContainer = createDiv('game-preview-container');
// const gamePreview = new GamePreview();
// previewContainer.appendChild(gamePreview.render());

const introColumn = createDiv('game-intro-column');

const buttonContainer = createDiv('intro-buttons');
const startButton = createButton('Start Game', this.onStart);
const instructionsButton = createButton('Instructions', this.onInstructions);
appendChildren(buttonContainer, [startButton, instructionsButton]);
// const instructionsButton = createButton('Instructions', this.onInstructions);
appendChildren(buttonContainer, [startButton /*, instructionsButton*/]);

const tip = createElement('p');
tip.className = 'intro-tip';
tip.textContent = 'Press right arrow to start';

appendChildren(introColumn, [buttonContainer, tip]);
appendChildren(introResponsive, [previewContainer, introColumn]);
appendChildren(introResponsive, [/*previewContainer, */ introColumn]);

const authorInfo = createElement('p');
authorInfo.className = 'author-name';
authorInfo.innerHTML = 'Created by <a href="https://x.com/gtanczyk">Grzegorz Tańczyk</a> | <a href="https://github.com/gamedevpl/www.gamedev.pl/tree/master/js13k2024">Source code (GitHub)</a>';
authorInfo.innerHTML =
'Created by <a href="https://x.com/gtanczyk">Grzegorz Tańczyk</a> | <a href="https://github.com/gamedevpl/www.gamedev.pl/tree/js13k2024-monster-steps-version/js13k2024">Source code (GitHub)</a>';

appendChildren(container, [title, introResponsive, authorInfo]);

return container;
}
}
}
62 changes: 28 additions & 34 deletions js13k2024/game/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Intro } from './game-states/intro/intro';
import { Instructions } from './game-states/instructions/instructions';
// Instructions are removed from the UI for now
// import { Instructions } from './game-states/instructions/instructions';
import { Gameplay } from './game-states/gameplay/gameplay';
import { GameOver } from './game-states/game-over/game-over';
import { LevelComplete } from './game-states/level-complete/level-complete';
Expand All @@ -10,12 +11,12 @@ import './global-styles.css';

enum GameState {
Intro,
Instructions,
// Instructions,
LevelStory,
Gameplay,
GameOver,
LevelComplete,
GameComplete
GameComplete,
}

export class MonsterStepsApp {
Expand Down Expand Up @@ -59,7 +60,7 @@ export class MonsterStepsApp {
}
} else if (e.key === 'Escape') {
if (
this.gameState === GameState.Instructions ||
// this.gameState === GameState.Instructions ||
this.gameState === GameState.GameOver ||
this.gameState === GameState.GameComplete
) {
Expand All @@ -75,16 +76,13 @@ export class MonsterStepsApp {

switch (this.gameState) {
case GameState.Intro:
this.currentScreen = new Intro(this.startGame.bind(this), this.showInstructions.bind(this));
break;
case GameState.Instructions:
this.currentScreen = new Instructions(this.quitGame.bind(this));
this.currentScreen = new Intro(this.startGame.bind(this) /*, this.showInstructions.bind(this)*/);
break;
// case GameState.Instructions:
// this.currentScreen = new Instructions(this.quitGame.bind(this));
// break;
case GameState.LevelStory:
this.currentScreen = new LevelStory(
this.level,
this.startGameplay.bind(this)
);
this.currentScreen = new LevelStory(this.level, this.startGameplay.bind(this));
break;
case GameState.Gameplay:
this.currentScreen = new Gameplay(
Expand All @@ -94,30 +92,26 @@ export class MonsterStepsApp {
this.levelComplete.bind(this),
this.gameComplete.bind(this),
this.updateScore.bind(this),
this.updateSteps.bind(this)
this.updateSteps.bind(this),
);
break;
case GameState.GameOver:
this.currentScreen = new GameOver(
this.score,
this.steps,
this.restartLevel.bind(this),
this.quitGame.bind(this)
this.quitGame.bind(this),
);
break;
case GameState.LevelComplete:
this.currentScreen = new LevelComplete(
this.level,
this.nextLevel.bind(this),
this.quitGame.bind(this)
);
this.currentScreen = new LevelComplete(this.level, this.nextLevel.bind(this), this.quitGame.bind(this));
break;
case GameState.GameComplete:
this.currentScreen = new GameComplete(
this.score,
this.steps,
this.restartGame.bind(this),
this.quitGame.bind(this)
this.quitGame.bind(this),
);
break;
}
Expand All @@ -136,10 +130,10 @@ export class MonsterStepsApp {
this.renderCurrentState();
}

private showInstructions() {
this.gameState = GameState.Instructions;
this.renderCurrentState();
}
// private showInstructions() {
// this.gameState = GameState.Instructions;
// this.renderCurrentState();
// }

private restartGame() {
this.level = 1;
Expand Down Expand Up @@ -205,43 +199,43 @@ class GameComplete {

render(): HTMLElement {
const container = createDiv('game-complete intro');

const title = document.createElement('h1');
title.className = 'game-title';
title.textContent = 'Monster Steps';

const subtitle = document.createElement('h2');
subtitle.className = 'game-complete-subtitle';
subtitle.textContent = 'Congratulations!';

const stats = createDiv('game-complete-stats');
stats.innerHTML = `
<p>Final Score: ${this.score}</p>
<p>Total Steps: ${this.steps}</p>
`;

const buttons = createDiv('intro-buttons');
const playAgainButton = document.createElement('button');
playAgainButton.textContent = 'Play Again';
playAgainButton.onclick = this.onPlayAgain;

const quitButton = document.createElement('button');
quitButton.textContent = 'Quit';
quitButton.onclick = this.onQuit;

buttons.appendChild(playAgainButton);
buttons.appendChild(quitButton);

const tip = document.createElement('p');
tip.className = 'intro-tip';
tip.textContent = 'Press right arrow to play again';

container.appendChild(title);
container.appendChild(subtitle);
container.appendChild(stats);
container.appendChild(buttons);
container.appendChild(tip);

return container;
}
}
}

0 comments on commit 5c5d66c

Please sign in to comment.