SpikeWars WIP working towards initial render and loop function.
This commit is contained in:
parent
39b87ac1a5
commit
d618506653
@ -1,11 +1,19 @@
|
|||||||
|
// @flow
|
||||||
import type Board from './game-types';
|
import type Board from './game-types';
|
||||||
|
import type GameState from './game-types';
|
||||||
|
|
||||||
function render(state: GameState, g: CanvasRenderingContext2D) {
|
function render(state: GameState, g: CanvasRenderingContext2D): void {
|
||||||
|
var space = g.measureText(state.count + '');
|
||||||
|
g.clearRect(100, 100, space.width, 50);
|
||||||
|
g.fillText(state.count + '', 100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function update(board: Board) {
|
function update(state: GameState): GameState {
|
||||||
|
state.count++;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeyboardEvent(ke: KeyboardEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export {render, update};
|
export {render, update};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
export type Board = Array<number>;
|
export type Board = Array<number>;
|
||||||
export type GameState = {
|
export type GameState = {
|
||||||
board: Board
|
board: Board,
|
||||||
|
count: number
|
||||||
};
|
};
|
||||||
|
@ -5,6 +5,7 @@ import type Board from './game-types';
|
|||||||
import type GameState from './game-types';
|
import type GameState from './game-types';
|
||||||
|
|
||||||
type SpikeWarsOptions = {fps?: number};
|
type SpikeWarsOptions = {fps?: number};
|
||||||
|
|
||||||
export default class SpikeWars {
|
export default class SpikeWars {
|
||||||
ROWS: number; // How many rows does our board have?
|
ROWS: number; // How many rows does our board have?
|
||||||
COLS: number; // How many columns does our board have?
|
COLS: number; // How many columns does our board have?
|
||||||
@ -34,11 +35,14 @@ export default class SpikeWars {
|
|||||||
this.COLS = 20;
|
this.COLS = 20;
|
||||||
this.TILE_SIZE = 48;
|
this.TILE_SIZE = 48;
|
||||||
|
|
||||||
this.state = {board: this.newBoard()}; // create a new board
|
this.state = {board: this.newBoard(), count: 0}; // create a new board
|
||||||
|
|
||||||
// Find our canvas and ask for the reference to the drawing API.
|
// Find our canvas and ask for the reference to the drawing API.
|
||||||
this.canvas = window.document.getElementsByTagName('canvas')[0];
|
this.canvas = window.document.getElementsByTagName('canvas')[0];
|
||||||
this.canvas2d = this.canvas.getContext('2d');
|
this.canvas2d = this.canvas.getContext('2d');
|
||||||
|
|
||||||
|
// TODO: register event handlers on the canvas element.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function creates a new board.
|
// This function creates a new board.
|
||||||
@ -75,4 +79,10 @@ export default class SpikeWars {
|
|||||||
render(this.state, this.canvas2d); }
|
render(this.state, this.canvas2d); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startGame(): void { this.gameLoop(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// instantiate the instance of SpikeWars
|
||||||
|
window.spikeWars = new SpikeWars({fps: 30});
|
||||||
|
window.spikeWars.startGame();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user