Skip to content

Commit

Permalink
feat: game-boy fn component
Browse files Browse the repository at this point in the history
  • Loading branch information
monster-zero-sugar committed Jul 22, 2023
1 parent af944ce commit f54dd6c
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 113 deletions.
7 changes: 2 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
<base href="%GAME_BASE_URL%" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="/js-dos/js-dos.js"></script>
<link rel="stylesheet" href="/js-dos/js-dos.css" />
<script>
emulators.pathPrefix = './js-dos/';
</script>
<script src="node_modules/js-dos/dist/js-dos.js"></script>
<link rel="stylesheet" href="node_modules/js-dos/dist/js-dos.css" />
<title>Vite + ThreeJS + TS</title>
</head>
<body>
Expand Down
118 changes: 72 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"js-dos": "^7.1.11",
"emulators": "^0.73.8",
"emulators-ui": "^0.73.9",
"js-dos": "^7.5.0",
"lil-gui": "^0.18.2",
"stats.js": "^0.17.0",
"three": "^0.154.0"
Expand Down
Binary file added public/games/digger.jsdos
Binary file not shown.
47 changes: 47 additions & 0 deletions src/game-boy/GameBoy.ts
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();
}
}
Loading

0 comments on commit f54dd6c

Please sign in to comment.