Rob Colbert
2 years ago
4 changed files with 90 additions and 23 deletions
@ -1,10 +1,10 @@ |
|||
// cyberegg2077.js
|
|||
// game-app.js
|
|||
// Copyright (C) 2022 Rob Colbert @[email protected]
|
|||
// License: Apache-2.0
|
|||
|
|||
'use strict'; |
|||
|
|||
const DTP_COMPONENT_NAME = 'nice-game'; |
|||
const DTP_COMPONENT_NAME = 'game-app'; |
|||
|
|||
import { NiceGame } from '/dtp-nice-game/nice-game.js'; |
|||
|
|||
@ -13,7 +13,7 @@ import GameEggSimulator from './lib/game-egg-simulator.js'; |
|||
import GamePlayer from './lib/game-player.js'; |
|||
import GameEnemies from './lib/game-enemies.js'; |
|||
|
|||
class CyberEgg2077 extends NiceGame { |
|||
export default class GameApp extends NiceGame { |
|||
|
|||
constructor ( ) { |
|||
super(DTP_COMPONENT_NAME); |
|||
@ -27,7 +27,10 @@ class CyberEgg2077 extends NiceGame { |
|||
} |
|||
|
|||
async run ( ) { |
|||
await this.startGameEngine(this.onUpdateDisplay.bind(this)); |
|||
await this.startGameEngine( |
|||
this.onGameUpdate.bind(this), |
|||
this.onGameRender.bind(this), |
|||
); |
|||
|
|||
this.input.addKey('moveLeft', 'ArrowLeft'); |
|||
this.input.addKey('moveRight', 'ArrowRight'); |
|||
@ -69,23 +72,36 @@ class CyberEgg2077 extends NiceGame { |
|||
this.nextSpawnTime = NOW.valueOf() + this.nextSpawnInterval; |
|||
} |
|||
|
|||
onUpdateDisplay (ctx) { |
|||
onGameUpdate ( ) { |
|||
switch (this.mode) { |
|||
case 'loading': |
|||
break; |
|||
case 'menu': |
|||
return this.updateMenu(ctx); |
|||
return this.updateMenu( ); |
|||
case 'game': |
|||
return this.updateGame(ctx); |
|||
return this.updateGame( ); |
|||
} |
|||
} |
|||
|
|||
updateMenu (ctx) { |
|||
onGameRender (ctx) { |
|||
switch (this.mode) { |
|||
case 'loading': |
|||
break; |
|||
case 'menu': |
|||
return this.renderMenu(ctx); |
|||
case 'game': |
|||
return this.renderGame(ctx); |
|||
} |
|||
} |
|||
|
|||
updateMenu ( ) { } |
|||
|
|||
renderMenu (ctx) { |
|||
this.background.draw(ctx, 0, 0); |
|||
this.tex.render(ctx); |
|||
} |
|||
|
|||
updateGame (ctx) { |
|||
updateGame ( ) { |
|||
const NOW = new Date(); |
|||
|
|||
this.background.update(); |
|||
@ -113,16 +129,10 @@ class CyberEgg2077 extends NiceGame { |
|||
} |
|||
this.eggs.update(); |
|||
|
|||
/* |
|||
* See if any eggs have hit any enemies |
|||
*/ |
|||
} |
|||
|
|||
/* |
|||
* Render "back to front" (painter's algorithm) |
|||
*/ |
|||
|
|||
renderGame (ctx) { |
|||
this.background.draw(ctx, 0, 0); |
|||
|
|||
this.enemies.render(ctx); |
|||
this.eggs.render(ctx); |
|||
this.tex.render(ctx); |
|||
@ -181,6 +191,6 @@ class CyberEgg2077 extends NiceGame { |
|||
} |
|||
|
|||
window.addEventListener('load', async ( ) => { |
|||
window.game = new CyberEgg2077(); |
|||
window.game = new GameApp(); |
|||
window.game.run(); |
|||
}); |
Loading…
Reference in new issue