Skip to content

Commit

Permalink
feat(scenes): add tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 26, 2025
1 parent 92b742f commit f5a9748
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/constants/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export enum Scene {
Lose = 'Lose',
Preload = 'Preload',
Title = 'Title',
Tutorial = 'Tutorial',
}
1 change: 1 addition & 0 deletions src/scenes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './game'
import './lose'
import './preload'
import './title'
import './tutorial'

import { Scene } from '../constants'

Expand Down
21 changes: 17 additions & 4 deletions src/scenes/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { addButton } from '../gameobjects'

scene(Scene.Title, () => {
const { x, y } = center()
const margin = 100
const buttonHeight = 80

const textbox = add([
rect(400, 100),
pos(x, y - margin),
pos(x, y - buttonHeight * 2),
anchor('center'),
color(255, 255, 255),
])
Expand All @@ -20,14 +20,27 @@ scene(Scene.Title, () => {

addButton({
width: 220,
height: 80,
height: buttonHeight,
radius: 8,
x,
y: y + margin,
y: y + buttonHeight,
text: 'Play',
onClick() {
play(Sound.Hit)
go(Scene.Game)
},
})

addButton({
width: 220,
height: buttonHeight,
radius: 8,
x,
y: y + buttonHeight * 2 + 20,
text: 'Tutorial',
onClick() {
play(Sound.Hit)
go(Scene.Tutorial)
},
})
})
35 changes: 35 additions & 0 deletions src/scenes/tutorial.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Scene, Sound } from '../constants'
import { addPlayer } from '../gameobjects'
import { addButton } from '../gameobjects'

scene(Scene.Tutorial, () => {
const { x } = center()

const textbox = add([
rect(600, 100),
pos(x, 80),
anchor('center'),
color(255, 255, 255),
])

textbox.add([
text('WASD or arrow keys to move\nLeft click to shoot'),
anchor('center'),
color(0, 0, 0),
])

addPlayer()

addButton({
width: 220,
height: 80,
radius: 8,
x,
y: height() - 80,
text: 'Play',
onClick() {
play(Sound.Hit)
go(Scene.Game)
},
})
})

0 comments on commit f5a9748

Please sign in to comment.