diff --git a/docs/gamelib.md b/docs/gamelib.md index cfb103e..f215dfb 100644 --- a/docs/gamelib.md +++ b/docs/gamelib.md @@ -6,7 +6,10 @@ A type of string. -Represents HTML colors. This includes [named colors](https://developer.mozilla.org/en-US/docs/Web/CSS/named-color) such as `blue`, `red`, `blanchedalmond`, `lavenderblush`, and rgb/hex when used with proper format. You can use `lib.rgb(r, g, b)` to generate a properly formatted rgb color code. +Represents HTML colors. This includes +[named colors](https://developer.mozilla.org/en-US/docs/Web/CSS/named-color) such as `blue`, `red`, +`blanchedalmond`, `lavenderblush`, and rgb/hex when used with proper format. You can use +`lib.rgb(r, g, b)` to generate a properly formatted rgb color code. Example: @@ -19,7 +22,8 @@ lib.drawRect(100, 0, 100, 100, lib.rgb(192, 127, 172)); A type of string. -Represents JavaScript's `KeyboardEvent.key` ([link](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)) property. +Represents JavaScript's `KeyboardEvent.key` +([link](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)) property. Example: @@ -30,7 +34,8 @@ Example: " ": Spacebar was pressed. ``` -/* todo: include a little html tool that listens to key events when focused and outputs what key was pressed */ +/* todo: include a little html tool that listens to key events when focused and outputs what key was +pressed */ ### `KeyEventFunc` @@ -41,11 +46,10 @@ Works both as a named and anonymous function. Example: ```ts - let playerX = 0; // anonymous function -lib.onPress("a", function() { +lib.onPress("a", function () { playerX -= 20; }); @@ -53,16 +57,21 @@ lib.onPress("a", function() { function dWasPressed() { playerX += 20; } -lib.onPress("a", dWasPressed); /* note the lack of () after dWasPressed - we are not calling the function, we are referring to it as a variable */ +lib.onPress( + "a", + dWasPressed, +); /* note the lack of () after dWasPressed - we are not calling the function, we are referring to it as a variable */ ``` ### `LoopFunc` -A function with a single parameters (`deltaT`) that is called whenever a game tick should run - usually about 1/60 times a second. +A function with a single parameters (`deltaT`) that is called whenever a game tick should run - +usually about 1/60 times a second. The `deltaT` parameter describes the time difference between the last tick and now, in seconds. -The name used for `deltaT` can be anything, it functions as any other function parameter. I.e. `loopFunction(timeSinceLastCall)`, `loopFunction(fooBar)`, etc. +The name used for `deltaT` can be anything, it functions as any other function parameter. I.e. +`loopFunction(timeSinceLastCall)`, `loopFunction(fooBar)`, etc. For example: @@ -77,11 +86,10 @@ Works both as a named and anonymous function. Example: ```ts - let playerX = 0; // anonymous function -lib.startGameLoop(function(deltaT) { +lib.startGameLoop(function (deltaT) { playerX += 20 * deltaT; }); @@ -89,7 +97,9 @@ lib.startGameLoop(function(deltaT) { function loopFunction(deltaTime) { playerX += 20 * deltaTime; } -lib.startGameFunction(loopFunction); /* note the lack of () after loopFunction - we are not calling the function, we are using it as a variable */ +lib.startGameFunction( + loopFunction, +); /* note the lack of () after loopFunction - we are not calling the function, we are using it as a variable */ ``` ## Functions @@ -113,7 +123,7 @@ It is a thursday. ### `lib.startGameLoop(loopFunction: LoopFunc) -> void` -Registers a gameloop function, that is called on every tick. +Registers a gameloop function, that is called on every tick. See also: `Models.LoopFunc` @@ -127,7 +137,7 @@ Example: ```ts let playerX = 0; -lib.startGameLoop(function(deltaT) { +lib.startGameLoop(function (deltaT) { if (lib.isPressed("a")) { playerX -= 20 * deltaT; } @@ -147,11 +157,11 @@ Example: ```ts let isJumping = false; -lib.onPress(" ", function() { +lib.onPress(" ", function () { isJumping = true; }); -lib.onRelease(" ", function() { +lib.onRelease(" ", function () { isJumping = false; }); ``` @@ -171,7 +181,7 @@ Example: ```ts lib.drawRect(100, 0, 100, 100, lib.rgb(192, 127, 172)); ``` - + ### `lib.clear(color: Color) -> void` Paints the entire screen `color`. @@ -215,7 +225,6 @@ See also: `Models.Color` Example: ```ts - function drawCloud(x, y) { lib.drawRect(x, y, 20, 10, "white"); } diff --git a/index.html b/index.html index db92df5..9f3ebf3 100644 --- a/index.html +++ b/index.html @@ -61,7 +61,12 @@