diff --git a/TOUR.md b/TOUR.md index 800bb0d..1d949e9 100644 --- a/TOUR.md +++ b/TOUR.md @@ -72,10 +72,48 @@ In essence, a Popka game typically relies on three key functions: * An update function. * A finish function. +## Input + +Popka provides a set of input functions inside the `popka.engine` module. + +```d +bool isPressed(char key); +bool isPressed(Keyboard key); +bool isPressed(Mouse key); +bool isPressed(Gamepad key, int id = 0); + +bool isDown(char key); +bool isDown(Keyboard key); +bool isDown(Mouse key); +bool isDown(Gamepad key, int id = 0); + +bool isReleased(char key); +bool isReleased(Keyboard key); +bool isReleased(Mouse key); +bool isReleased(Gamepad key, int id = 0); +``` + +## Sound + +Popka provides a set of sound functions inside the `popka.engine` module. + +```d +void playSound(Sound sound); +void playSound(SoundId sound); +void stopSound(Sound sound); +void stopSound(SoundId sound); +void pauseSound(Sound sound); +void pauseSound(SoundId sound); +void resumeSound(Sound sound); +void resumeSound(SoundId sound); +void updateSound(Sound sound); +void updateSound(SoundId sound); +``` + ## Drawing Popka provides a set of drawing functions inside the `popka.engine` module. -While drawing is not pixel-perfect by default, you can enable pixel-perfect drawing by calling the `setIsPixelPerfect` function. +While drawing is not pixel-perfect by default, it can be by calling the `setIsPixelPerfect` function. ```d void drawRect(Rect area, Color color = white); @@ -133,3 +171,48 @@ They must be freed manually when no longer needed. Temporary resources are only valid until the function that provided them is called again. They don’t need to be freed manually. + +## Sprites and Tile Maps + +Sprites and tile maps can be implemented in various ways. +To avoid imposing a single approach, Popka offers additional modules for these features. This allows for someone to include or ignore them as needed. Popka's implementations are designed with simplicity and speed in mind. + +### Sprites + +Popka provides a sprite and a sprite animation type inside the `popka.sprite` module. + +```d +struct SpriteAnimation { + ubyte frameRow; + ubyte frameCount; + ubyte frameSpeed; +} + +struct Sprite { + int width; + int height; + ushort atlasLeft; + ushort atlasTop; + float frameProgress = 0.0f; + SpriteAnimation animation; +} +``` + +### Tile Maps + +Popka provides a tile and a tile map type inside the `popka.tilemap` module. + +```d +struct Tile { + int id; + int width; + int height; +} + +struct TileMap { + Grid!short data; + int tileWidth; + int tileHeight; + alias data this; +} +``` diff --git a/examples/README.md b/examples/README.md index 9def511..baa3e38 100644 --- a/examples/README.md +++ b/examples/README.md @@ -30,3 +30,7 @@ This example shows how to use the tile map structure of Popka. ## [Follower](follower.d) This example shows how to create an animated character that follows the mouse. + +## [Timer](timer.d) + +This example shows how to use the timer structure of Popka. diff --git a/examples/timer.d b/examples/timer.d new file mode 100644 index 0000000..8b0f86b --- /dev/null +++ b/examples/timer.d @@ -0,0 +1,26 @@ +/// This example shows how to use the timer structure of Popka. +import popka; + +// The game variables. +auto counter = 0; +auto timer = Timer(1, true); + +void ready() { + lockResolution(320, 180); + timer.start(); +} + +bool update(float dt) { + timer.update(dt); + if (timer.hasStopped) { + counter += 1; + } + + drawDebugText("Counter: {}".format(counter), Vec2(8)); + drawDebugText("\nTimer: {}".format(timer.time), Vec2(8)); + return false; +} + +void finish() { } + +mixin runGame!(ready, update, finish);