| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Small and very simple Browser Based Kirby Game to explore Kaboom JS and practice typescript a little more. Consists of 2 levels only.
Left Left Arrow Key | Right Right Arrow Key | Up & Double Power Jump Up Arrow Key | Let Kirby Cook Key Z
This Code renders and works perfectly on my machine pr browser [Chrome]. But it might not render properly on your machine or browser or monitor of different size and aspect ratio. If you clone this repo and then the game does not render properly and all the characters keep falling then open kaboomCtx.ts and try different values of width and height. Thank you
| Topics Covered |
|---|
| Demo of the Project |
| Exploring Kaboom Js |
| What is Tiled |
| Understanding Important Functions |
| How to Run this |
Kaboom.js is a JavaScript library designed to simplify the development of 2D games. It offers a range of features and components that help developers create interactive and dynamic game experiences with ease.
Game objects are the primary entities in a Kaboom.js game, representing everything from characters to obstacles.
Example:
const playerBlueprint = make([
pos(100, 100), // Initial position
scale(2), // Size scaling
sprite("player"),// Sprite image
area(), // Collision area
body(), // Physics properties
health(3) // Health points
]);
const player = add(playerBlueprint);Components are modular pieces of functionality that can be added to game objects to define their behavior and appearance.
Optional: As I continue to expand the Domain of my Knowledge I explored Kaboom Js. Did some more practice of TypeScript. This video from FCC helped in completion of this Game. Learned a lot about TypeScript and Kaboom Js.
These interfaces define the types and behaviors of various components:
Kaboom.js objects can have arbitrary properties to store custom data, allowing for flexible game mechanics and attributes.
Example:
const player = add([
pos(100, 100),
scale(2),
sprite("player"),
area(),
body(),
health(3),
{
speed: 200, // Custom property for movement speed
}
]);
player.speed = 250; // Updating the custom propertyThe onUpdate function allows you to define behavior that should be executed every frame, enabling dynamic interactions and game mechanics.
Example:
const player = add([
pos(100, 100),
scale(2),
sprite("player"),
area(),
body(),
health(3),
{
speed: 200,
}
]);
player.onUpdate(() => {
if (keyIsDown("left")) {
player.move(-player.speed, 0); // Move left
} else if (keyIsDown("right")) {
player.move(player.speed, 0); // Move right
}
});The wait function can be used to delay actions for a certain amount of time, useful for timing events in your game.
Example:
wait(2, () => {
player.move(player.speed, 0); // Move player after 2 seconds
});Kaboom.js provides a straightforward approach to game development with its modular components and flexible game object creation system. By combining different components and utilizing functions like onUpdate and wait, developers can easily build complex and interactive 2D games.
Tiled is a powerful 2D level/map editor commonly used in game development. It allows you to create visually appealing game maps using tilesets. Here's how it works:
Tilesets: You define a set of tiles (small images) that represent different parts of your game world (e.g., terrain, objects, characters).
Layers: You organize your map into layers. Each layer can contain different types of information:
Custom Properties: You can add custom properties to tiles and objects. These properties can store additional data (e.g., health points, interaction flags).
Tiled can export maps as JSON files. When you create a map in Tiled, it generates a .tmx (Tiled Map XML) file, which is essentially a structured JSON representation of your map. Here are some key fields found in a Tiled JSON file:
Exporting: To export your Tiled map as JSON, select "File > Export As" and choose the JSON file type.
Parsing in Your Game:
Integration with Code:
{
"width": 10,
"height": 8,
"tilewidth": 32,
"tileheight": 32,
"layers": [
// Tile layers and object layers go here
],
// Other properties like tilesets, version, etc.
}This file defines various game entities, including the player and different types of enemies. It also sets up interactions and controls for the player.
makePlayer
Creates and configures the player character with various components and properties.
Initialization: Adds sprite, area, body, position, scale, double jump, health, and opacity components. Sets custom properties like speed, direction, isInhaling, and isFull.
Collision Handling:
Inhale Effect Setup: Adds and configures inhale effect and inhale zone. Updates inhale zone and effect positions based on player direction.
Fall Check: Restarts the scene if the player falls below a certain position.
setControls
Sets up controls for the player character.
makeInhalable
Configures an enemy to be inhalable by the player.
makeFlameEnemy, makeGuyEnemy, makeBirdEnemy
Creates different types of enemies with specific behaviors and states.
This file sets up the game, loads assets, and defines game scenes.
gameSetup
Initializes the game by loading assets and setting up scenes.
The gameSetup function orchestrates the initial game setup and starts the first scene.
Node should be installed Make a new Folder or directory and cd in it
Create Vite choose vanila and typescript
npm create vite@latest .
Install kaboom
npm install kaboom
Clone this Repo
git clone [repo_name]
Compare the cloned repo with your folder then add and remove required files
| Back | FazBrowse Home | New Git URL |