Skip to content

Commit

Permalink
Wire into level data
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Nov 25, 2023
1 parent 978dcc2 commit 1f08365
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/levels/level-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Resources } from '../resources';

export interface LevelData {
name: string;
displayName: string;
nextLevel: string;
width: number;
height: number;
Expand Down Expand Up @@ -100,6 +101,7 @@ export class LevelBase extends ex.Scene {

override onDeactivate(): void {
// TODO deactivate event handlers on types that have them!!
Resources.LevelMusic2.instances.forEach(i => i.stop());
Resources.LevelMusic2.stop();
}

Expand Down
16 changes: 9 additions & 7 deletions src/levels/start-screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ export class StartScreen extends ex.Scene {
title!: ex.Actor;
instructions!: ex.Actor;
override onInitialize(engine: ex.Engine): void {
engine.input.pointers.primary.once('down', () => {
engine.goToScene('tutorial');
});
engine.input.keyboard.once('press', () => {
engine.goToScene('tutorial');
});

this.engine = engine;
this.add(new Cloud(ex.vec(800, 0)));
this.add(new Cloud(ex.vec(400, 300)));
this.add(new Cloud(ex.vec(700, 700)));
Expand Down Expand Up @@ -67,6 +61,14 @@ export class StartScreen extends ex.Scene {
Resources.TitleMusic.loop = true;
Resources.TitleMusic.volume = .05;
Resources.TitleMusic.play();

this.engine.input.pointers.primary.once('down', () => {
this.engine.goToScene('tutorial');
});
this.engine.input.keyboard.once('press', () => {
this.engine.goToScene('tutorial');
});

}
onDeactivate(): void {
Resources.TitleMusic.stop();
Expand Down
15 changes: 9 additions & 6 deletions src/levels/tutorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { UnitMenu } from '../ui-components/unit-menu';
import { HumanPlayer } from '../human-player';

export const TutorialData: LevelData = {
name: 'Gentle Plains',
name: 'tutorial',
displayName: 'Gentle Plains',
nextLevel: 'level',
width: 6,
height: 3,
Expand Down Expand Up @@ -42,11 +43,7 @@ export class Tutorial extends LevelBase {
this.engine.add(this.focus);
}

engine.input.keyboard.once('press', evt => {
if (evt.key === ex.Keys.Esc) {
this.engine.goToScene('level1');
}
})

}

async moveToUnit1() {
Expand Down Expand Up @@ -126,6 +123,12 @@ export class Tutorial extends LevelBase {
}

async onActivate() {
this.engine.input.keyboard.once('press', evt => {
if (evt.key === ex.Keys.Esc) {
this.engine.goToScene('level1');
}
})

Resources.LevelMusic2.loop = true;
Resources.LevelMusic2.volume = .05;
Resources.LevelMusic2.play();
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ game.addScene(tutorial.name, tutorial);


const Level1Data: LevelData = {
name: 'Gentle Plains',
displayName: 'Gentle Plains',
name: 'level1',
nextLevel: 'level2',
width: 6,
height: 3,
Expand All @@ -40,7 +41,8 @@ const level1 = new LevelBase(Level1Data, 'level1')
game.addScene(level1.name, level1);

export const Level2Data: LevelData = {
name: 'Gentle Plains 2',
displayName: 'Gentle Plains 2',
name: 'level2',
nextLevel: 'start',
width: 6,
height: 6,
Expand Down
4 changes: 1 addition & 3 deletions src/turn-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,14 @@ export class TurnManager {
if (this.currentPlayer instanceof HumanPlayer) {
await this.showGameOver();
this.engine.input.pointers.once('down', () => {
// TODO go to current level name
Resources.LevelMusic2.stop();
this.engine.goToScene('level1');
this.engine.goToScene(this.level.levelData.name);
});
return;
}
if (this.currentPlayer instanceof ComputerPlayer) {
await this.showVictory();
this.engine.input.pointers.once('down', () => {
// TODO next level!
this.engine.goToScene(this.level.levelData.nextLevel);
});
return;
Expand Down
1 change: 1 addition & 0 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [ ] Skip tutorial option
* [ ] Show the name of the stage "Gentle Plains"
* [ ] Show the players name when they should move
* [ ] Range viz, support mobile
* [x] Win condition
* [x] Tutorial (what is the point of the game)
* [x] Only show valid actions
Expand Down

0 comments on commit 1f08365

Please sign in to comment.