From cdff9ac9a2797b11929b5d4919d19b62d741533b Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 20 Jan 2025 23:07:11 -0500 Subject: [PATCH] refactor(constants): capitalize enums --- src/constants/scenes.ts | 4 ++-- src/constants/sprites.ts | 4 ++-- src/constants/tags.ts | 6 +++--- src/gameobjects/bullet.ts | 4 ++-- src/gameobjects/enemy.ts | 4 ++-- src/gameobjects/player.ts | 4 ++-- src/scenes/game.ts | 2 +- src/scenes/index.ts | 2 +- src/scenes/preload.ts | 8 ++++---- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/constants/scenes.ts b/src/constants/scenes.ts index 93ae260..136e82b 100644 --- a/src/constants/scenes.ts +++ b/src/constants/scenes.ts @@ -1,4 +1,4 @@ export enum Scene { - game = 'game', - preload = 'preload', + Game = 'Game', + Preload = 'Preload', } diff --git a/src/constants/sprites.ts b/src/constants/sprites.ts index c60dc0f..e599b04 100644 --- a/src/constants/sprites.ts +++ b/src/constants/sprites.ts @@ -1,4 +1,4 @@ export enum Sprite { - bean = 'bean', - ghosty = 'ghosty', + Bean = 'Bean', + Ghosty = 'Ghosty', } diff --git a/src/constants/tags.ts b/src/constants/tags.ts index d98d89f..952f1c1 100644 --- a/src/constants/tags.ts +++ b/src/constants/tags.ts @@ -1,5 +1,5 @@ export enum Tag { - 'bullet' = 'bullet', - 'enemy' = 'enemy', - 'player' = 'player', + 'Bullet' = 'Bullet', + 'Enemy' = 'Enemy', + 'Player' = 'Player', } diff --git a/src/gameobjects/bullet.ts b/src/gameobjects/bullet.ts index 83f9800..0cf4dd3 100644 --- a/src/gameobjects/bullet.ts +++ b/src/gameobjects/bullet.ts @@ -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) diff --git a/src/gameobjects/enemy.ts b/src/gameobjects/enemy.ts index 88b10b5..e5058d6 100644 --- a/src/gameobjects/enemy.ts +++ b/src/gameobjects/enemy.ts @@ -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(() => { diff --git a/src/gameobjects/player.ts b/src/gameobjects/player.ts index c837c40..9ed9ec2 100644 --- a/src/gameobjects/player.ts +++ b/src/gameobjects/player.ts @@ -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) diff --git a/src/scenes/game.ts b/src/scenes/game.ts index bbc6a84..9883e79 100644 --- a/src/scenes/game.ts +++ b/src/scenes/game.ts @@ -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)]) diff --git a/src/scenes/index.ts b/src/scenes/index.ts index bacd843..28d3c95 100644 --- a/src/scenes/index.ts +++ b/src/scenes/index.ts @@ -4,5 +4,5 @@ import './preload' import { Scene } from '../constants' export function start() { - go(Scene.preload) + go(Scene.Preload) } diff --git a/src/scenes/preload.ts b/src/scenes/preload.ts index 83c54dc..a5df15b 100644 --- a/src/scenes/preload.ts +++ b/src/scenes/preload.ts @@ -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) })