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 ๐บ actorobject in eight directions with โจ๏ธ arrow keys.
- Move โ mapobject in eight directions with โจ๏ธ wasd keys.
- Move ๐ enemyobject to cursor's location with โจ๏ธ space key.
- Collide ๐บ actorand๐ enemyobjects to decreaseโค๏ธ health bar.
- Collide ๐บ actorand๐พ bottom-fieldto increaseโค๏ธ health bar.
- Collide ๐บ actorand๐พ top-fieldto increase๐ experience bar.
- See ๐ญ mousecursor coordinates in bottom-right of game screen.
- See โ velocityandโ directionof 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 ๐บ actorobject right or left with โจ๏ธ arrow keys.
- Make Jump ๐บ actorobject with โจ๏ธ space key.
- Try multiple jumps in air.
- See โ velocityandโ directionof movement (on x and y axis), andโ jumpscount (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-1flag will prevent caching.
- Runtime: Chrome
- Editor: Sublime Text

