Skip to content

Commit

Permalink
Merge pull request #28 from jamesroutley/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jamesroutley authored Sep 6, 2020
2 parents 1e0892a + 36017c6 commit bf93a4e
Show file tree
Hide file tree
Showing 30 changed files with 1,172 additions and 890 deletions.
99 changes: 83 additions & 16 deletions build/engine.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ declare enum Direction {
*/
interface GameConfig {
/**
* `create` is a function which is called once, just before the game starts
* running. You can use it to initialise game state, if needed.
* `create(game)` is a function which is called once, just before the game
* starts running. You can use it to initialise game state, if needed.
*/
create?: (game: Game) => void;
/**
* `update` is repeatedly called as the game runs. You can use it to define
* the main functionality of your game.
* `update(game)` is repeatedly called as the game runs. You can use it to
* define the main functionality of your game.
*/
update?: (game: Game) => void;
/**
* `onKeyPress` is a function which is called when the player presses one of
* the arrow keys.
* `onKeyPress(direction)` is a function which is called when the player
* presses one of the arrow keys.
*/
onKeyPress?: (direction: Direction) => void;
/**
* `onDotClicked` is a function which is called when the player clicks on a
* dot.
* `onDotClicked(x, y)` is a function which is called when the player clicks
* on a dot.
*/
onDotClicked?: (x: number, y: number) => void;
/**
* The ID of a container to create the canvas in
* The ID of a container to create the canvas in.
*/
containerId?: string;
/**
Expand All @@ -62,17 +62,32 @@ interface GameConfig {
*/
defaultDotColor?: Color;
/**
* @ignore
*
* Sets the width of the grid
* Sets the width of the grid. By default, this is set to 24.
*/
gridWidth?: number;
/**
*
* Sets the height of the grid. By default, this is set to 24.
*/
gridHeight?: number;
/**
* @ignore
*/
_gridWidth?: number;
/**
* @ignore
*
* Sets the height of the grid
*/
_gridHeight?: number;
/**
* Specifies whether 24a2 should clear the grid at the beginning of each
* frame. 24a2 clears the grid by setting the colour of every dot to
* {@Link GameConfig.defaultDotColor}. Setting clearGrid to false lets you
* simplify the code for some games by letting 24a2 store the state for each
* dot. You can use {@Link Game.getDot} to read back the colour of dots. By
* default, this is set to true.
*/
clearGrid?: boolean;
}
/**
* Game is the object that controls the actual running of the game. You
Expand All @@ -95,10 +110,11 @@ declare class Game {
private _ended;
private _frameCount;
private _dots;
private _dotSize;
private _gapSize;
private _gridHeight;
private _gridWidth;
private _clear;
private _renderer?;
private _interval?;
constructor(config: GameConfig);
/**
* 24a2 games have a line of text below the grid which can be set to show
Expand Down Expand Up @@ -135,7 +151,58 @@ declare class Game {
* Calling `run` starts the game.
*/
run(): void;
private _drawGrid;
/**
* The internal function that's called on every frame.
*/
private _update;
private _clearGrid;
private _render;
}
/**
* @ignore
* IOManager is the interface used by {@Link Game} to manage the game's input
* (e.g. keyboard or mouse events) and output (drawing the game).
* IOManager does not form part of 24a2's public API, and can change without
* warning
*/
interface IOManager {
setDot: (x: number, y: number, val: Color) => void;
setText: (text: string) => void;
registerDotClicked: (dotClicked: (x: number, y: number) => void) => void;
registerKeyPressed: (keyPressed: (direction: Direction) => void) => void;
}
/**
* @ignore
* CanvasIOManager is the object that manages 24a2's input (capturing keyboard
* and mouse events) and output (rendering the game to a HTML Canvas). It's the
* only bit of 24a2 which is aware we're running in a browser.
* CanvasIOManager does not form part of 24a2's public API, and can change
* without warning
*/
declare class CanvasIOManager {
private _gridHeight;
private _gridWidth;
private _dotSize;
private _gapSize;
private _canvas;
private _ctx;
private _dotClicked?;
private _keyPressed?;
constructor(gridHeight: number, gridWidth: number, containerId?: string);
registerDotClicked(dotClicked: (x: number, y: number) => void): void;
registerKeyPressed(keyPressed: (direction: Direction) => void): void;
private _listenForMouseClick;
private _listenForKeyPress;
private _createCanvasContext;
/**
* Returns the element that should be our canvas's parent.
* - If a containerId is specified, it'll be the element with that ID
* - If one isn't, the parent will be the <main> element
* - If a <main> element doesn't exist, we'll append one to the <body>
* - If multiple <main> elements exist, the first will be the parent
*/
private _getCanvasParent;
setDot(x: number, y: number, val: Color): void;
private _getCSSColor;
setText(text: string): void;
}
Loading

0 comments on commit bf93a4e

Please sign in to comment.