Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacurtiss committed Jun 8, 2024
1 parent 4662d43 commit 9f2f08f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const {
z,
} = k;

const CURRENT_PLAYER_TAG = 'current-player';

const levelConf: LevelOpt = {
tileWidth: 8,
tileHeight: 8,
Expand Down Expand Up @@ -192,8 +194,7 @@ export default function(options: Partial<GameSceneOpt>) {
const ENEMY_SPEED_INC = 3;
const enemyInitialSpeed = enemies[0].speed;
let lastEnemySpeedCheck=0;
onUpdate('player', p=>{
// TODO: I think this is looking at all players incorrectly. Check it's current player?
onUpdate(CURRENT_PLAYER_TAG, p=>{
const levelTime = Math.floor(p.levelTime);
if (levelTime-lastEnemySpeedCheck>=ENEMY_SPEED_CHECK_FREQUENCY) {
lastEnemySpeedCheck = levelTime;
Expand Down Expand Up @@ -221,28 +222,30 @@ export default function(options: Partial<GameSceneOpt>) {
// Player setup
opt.players.forEach(p=>{
p.freeze();
p.unuse(CURRENT_PLAYER_TAG);
p.pos = vec2(-20);
});
player.use(CURRENT_PLAYER_TAG);
player.level = levelNumber;
player.pos = vec2(128, 165);
player.setObjects({ floors, stairs, stairtops });
player.setAnim(vec2(0));
player.isAlive = true;
player.isFrozen = true;
on(ON_DIE, 'player', ()=>{
on(ON_DIE, CURRENT_PLAYER_TAG, ()=>{
enemies.forEach(enemy=>enemy.freeze());
wait(0.5, ()=>music.stop());
wait(5, ()=>goNextScene('die'));
});
on(ON_WIN, 'player', ()=>{
on(ON_WIN, CURRENT_PLAYER_TAG, ()=>{
music.stop();
enemies.forEach(enemy=>enemy.freeze());
wait(5, ()=>goNextScene('win'));
});

// Controls
onKeyPress(player.controls.keyboard.action, ()=>player.action());
onUpdate('player', p=>{
onUpdate(CURRENT_PLAYER_TAG, p=>{
if (p.isFrozen || !p.isAlive) return;
const { up, down, left, right } = p.controls.keyboard;
let dir = vec2(0);
Expand Down

0 comments on commit 9f2f08f

Please sign in to comment.