This is a set of examples implementing some useful simple common game development related logic.
It features some techniques for game core logic structuring, layout manipulation, control handling, collision detection, and data calculation.
- โฌ Base:
- Define and render game screen.
- Create and run game loop.
- Define game object.
- Render ractangle game object.
- Render text game object.
- Render image (sprite) game object.
- Render animation from multiple images.
- Render animation from single image (spritesheet).
- ๐ Layout:
- Define size (width and height) of game object.
- Define position (x and y) of game object.
- Define hotspot (x and y) of game object.
- Handle hotspot-based positioning of game object.
- Define and handle parent-child hierarchy between game objects.
- Perform relative hierarchical positioning of game objects.
- Center position and hotspot of game object.
- Align game objects in horizontal and vertical line.
- Align game objects in grid.
- โจ๏ธ Control:
- Handle keyboard input.
- Read keyboard input always.
- Read keyboard input on first key press only.
- Handle mouse input.
- Move game object based on input (keyboard and mouse).
- ๐ฅ Collision:
- Detect point collision between game objects.
- Detect rectangle collision between game objects.
- Stop moving game object based on collision.
- Detect distance between game objects.
- ๐ฝ Data:
- Define game player data.
- Calculate health percentage of player.
- Calculate experience of player based on level.
- Move game object with tween animation effect.
- ๐ Movement:
- Implement basic top-down movement (eight directions movement).
- Add speed feature to top-down movement.
- Add acceleration and deceleration features to top-down movement.
- Implement platformer movement (side-scroller movement).
- Add speed, acceleration, and deceleration to platformer movement.
- Add basic fixed-height jump feature to platformer movement.
- Add variable-height jump feature.
- Add multiple jump (double jump or more) feature.
- ๐ฆ Viewport:
- Define layer and z-index for game objects.
- Render multiple layers (background and foreground) of game objects.
- Define scene game object with virtual size (width and height).
- Define camera (viewport) game object.
- Move camera and scroll across scene.
- Attain parallax effect between layers.
This is the main example that showcases all of the base, layout, control, collision, data, and movement/top-down objectives described above.
To fully check out this example:
- Drag any object with ๐ฑ๏ธ left mouse button.
- Move
๐บ actor
object in eight directions with โจ๏ธ arrow keys. - Move
โ map
object in eight directions with โจ๏ธ wasd keys. - Move
๐ enemy
object to cursor's location with โจ๏ธ space key. - Collide
๐บ actor
and๐ enemy
objects to decreaseโค๏ธ health bar
. - Collide
๐บ actor
and๐พ bottom-field
to increaseโค๏ธ health bar
. - Collide
๐บ actor
and๐พ top-field
to increase๐ experience bar
. - See
๐ญ mouse
cursor coordinates in bottom-right of game screen. - See
โ velocity
andโ direction
of movement (on x and y axis) in top-left of game screen.
This example showcases the movement/platformer objectives described above.
To fully check out this example:
- Move
๐บ actor
object right or left with โจ๏ธ arrow keys. - Make Jump
๐บ actor
object with โจ๏ธ space key. - Try multiple jumps in air.
- See
โ velocity
andโ direction
of movement (on x and y axis), andโ jumps
count (per maximum jumps) in top-left of game screen.
-
Clone the repository:
cd somewhere git clone https://github.com/practical-works/game-logic.git cd game-logic
-
Run an HTTP server (using any tool of your choice) in the root folder:
For example, using HTTP-Server, in the root folder, you can run:
http-server -c-1
๐ก This will by default run a local server on
http://localhost:8080
.
๐ก The-c-1
flag will prevent caching.
- Runtime: Chrome
- Editor: Sublime Text