generated from n1md7/three-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af944ce
commit f54dd6c
Showing
11 changed files
with
278 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Screen } from '@/src/game-boy/components/Screen'; | ||
import { Game } from '@/src/game-boy/abstract/Game'; | ||
import { Digger } from '@/src/game-boy/games/Digger'; | ||
import { Group } from 'three'; | ||
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader'; | ||
|
||
export enum Cartridge { | ||
Digger = 'Digger', | ||
} | ||
|
||
type Games = Map<Cartridge, Game>; | ||
|
||
export class GameBoy { | ||
public readonly screen: Screen; | ||
public readonly games: Games; | ||
public readonly scene: Group; | ||
|
||
private currentGame?: Game; | ||
|
||
constructor(model: GLTF) { | ||
this.games = new Map(); | ||
this.scene = new Group(); | ||
this.screen = new Screen(320, 200); | ||
this.screen.position.set(0, 0.43, 0.2); | ||
|
||
this.scene.add(model.scene.clone(), this.screen); | ||
this.games.set(Cartridge.Digger, new Digger()); | ||
} | ||
|
||
getCurrentGame(): Game | undefined { | ||
return this.currentGame; | ||
} | ||
|
||
insertCartridge(gameName: Cartridge): Game { | ||
// Make sure we unsubscribe from the previous game. | ||
this.currentGame?.stop(); | ||
this.currentGame = this.games.get(gameName)!; | ||
// HDMI or TYPE-C both work.🙂 | ||
this.currentGame.connect(this.screen); | ||
|
||
return this.currentGame; | ||
} | ||
|
||
async runGame(): Promise<void> { | ||
await this.currentGame?.run(); | ||
} | ||
} |
Oops, something went wrong.