Skip to content

Commit

Permalink
refactor(constants): capitalize enums
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 21, 2025
1 parent a28ed3f commit cdff9ac
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/constants/scenes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum Scene {
game = 'game',
preload = 'preload',
Game = 'Game',
Preload = 'Preload',
}
4 changes: 2 additions & 2 deletions src/constants/sprites.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum Sprite {
bean = 'bean',
ghosty = 'ghosty',
Bean = 'Bean',
Ghosty = 'Ghosty',
}
6 changes: 3 additions & 3 deletions src/constants/tags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export enum Tag {
'bullet' = 'bullet',
'enemy' = 'enemy',
'player' = 'player',
'Bullet' = 'Bullet',
'Enemy' = 'Enemy',
'Player' = 'Player',
}
4 changes: 2 additions & 2 deletions src/gameobjects/bullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export function addBullet(player: Player) {
offscreen({ destroy: true }),
anchor('center'),
color(0, 0, 255),
Tag.bullet,
Tag.Bullet,
])

bullet.onCollide(Tag.enemy, (enemy) => {
bullet.onCollide(Tag.Enemy, (enemy) => {
bullet.destroy()
const currentEnemy = enemy as Enemy
currentEnemy.hurt(BULLET_DAMAGE)
Expand Down
4 changes: 2 additions & 2 deletions src/gameobjects/enemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const ENEMY_SPEED = 200

export function addEnemy(x: number, y: number, player: Player) {
const enemy = add([
sprite(Sprite.ghosty),
sprite(Sprite.Ghosty),
pos(x, y),
anchor('center'),
health(100),
opacity(1),
area(),
Tag.enemy,
Tag.Enemy,
])

enemy.onUpdate(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/gameobjects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { addBullet } from './bullet'

export function addPlayer(x = center().x, y = center().y) {
const player = add([
sprite(Sprite.bean),
sprite(Sprite.Bean),
pos(x, y),
rotate(0),
anchor('center'),
area(),
Tag.player,
Tag.Player,
])

addCursorKeys(player)
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/game.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Scene } from '../constants'
import { addEnemy, addPlayer } from '../gameobjects'

scene(Scene.game, () => {
scene(Scene.Game, () => {
const player = addPlayer()

add([text('Press arrow keys', { width: width() / 2 }), pos(12, 12)])
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import './preload'
import { Scene } from '../constants'

export function start() {
go(Scene.preload)
go(Scene.Preload)
}
8 changes: 4 additions & 4 deletions src/scenes/preload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Scene, Sprite } from '../constants'

scene(Scene.preload, () => {
loadSprite(Sprite.bean, 'sprites/bean.png')
loadSprite(Sprite.ghosty, 'sprites/ghosty.png')
go(Scene.game)
scene(Scene.Preload, () => {
loadSprite(Sprite.Bean, 'sprites/bean.png')
loadSprite(Sprite.Ghosty, 'sprites/ghosty.png')
go(Scene.Game)
})

0 comments on commit cdff9ac

Please sign in to comment.