A browser-based 2D platformer and level editor built with HTML5 Canvas and modular JavaScript.
This project is a complete game project combining a playable action platformer with a level editor. The player controls a king character who navigates tile-based levels, battles enemy pigs, avoids hazards, and interacts with doors and environmental objects.
The codebase is divided into two main parts:
src/main/– game UI, menu, level select screen, game canvas, and editor interfacesrc/– core game engine, level loading, entities, objects, inputs, and utilities
- Open
src/main/index.htmlin a browser. - Use the main menu to choose
PlayorEditor. - In the level selector, choose an unlocked level and click
START LEVEL. - Press
Escapefrom the game screen to return to the main menu.
AorArrowLeft– move leftDorArrowRight– move rightWorArrowUp– attempt to enter an entry doorSpace– jump- Left mouse button – attack
Escape– exit game screen or editor, return to menu
- Defeat pig enemies
- Use doors to enter and exit levels correctly
- Avoid enemy attacks, projectiles, boxes, and bombs
- Progress through levels by navigating the environment and eliminating threats
- Tile-based world loaded from PNG data
- Player and enemies use tile collision detection via
HelperMethods.js - Gravity, jumping, falling, and ground checks are supported for all moving entities
- Camera scrolls around the player using horizontal and vertical border thresholds
- Player has a melee attack box that damages nearby enemies
- Enemies have collision-based damage when attacking or throwing objects
- Player automatically regenerates health slowly over time when not dead
- Enemies and player transition through sprite animation states for idle, run, attack, hit, jump, fall, death, and more
Pig– basic melee enemy that chases and attacks the playerKingPig– stronger enemy with longer chase logic and more damagePigWithBoxes– carries a box, can throw it, and can pick one back upPigWithBomb– carries a bomb, throws it, and can pick bombs back upPigWithMatch– uses matches to fire nearby cannonsCannon– shoots projectiles at the playerBombandBox– throwable hazards that explode on collisionProjectile– cannon-fired objects that travel, arc with gravity, and explode
- Entry and exit doors control the timing of starting and leaving levels
- Clicking
WorArrowUpnear an entry door triggers entry animation - Exit doors open after a countdown and allow the player to finish the level
- Objects are loaded from map pixels and positioned in the world using game data
The built-in editor is a full design tool for creating tile maps and object layouts.
- tile palette to paint terrain
- enemy palette to place pig enemies and special enemies
- object palette for cannons, doors, bombs, and boxes
- grid generation with custom row/column dimensions
- panning with
Space+ drag - toggleable grid overlay
- eraser mode
- undo/redo support with
Ctrl+ZandCtrl+Y - right-click context menu for placed objects:
- pick up object
- flip horizontally
- mark entry/exit door
- delete
- The editor can export the tile map as a PNG file
- Level data is encoded inside the image channels so that gameplay can load the level directly from the exported PNG
- Import support reads image pixel data, reconstructs tiles and objects, and restores flipped or door type metadata
src/main/index.html– main menusrc/main/level_selector.html– level selection UIsrc/main/game.html– gameplay canvas containersrc/main/editor.html– map editor UIsrc/main/js/– editor supporting scriptssrc/players/,src/entities/,src/objects/– game actors and objectssrc/level/– level manager and level definitionssrc/utilities/– game utilities, helper methods, constants, sprite loadingsrc/main/Main.js– game entry pointsrc/main/Game.js– game loop and main world update/render logic
- Game levels are parsed from PNG files using pixel values
- Red channel encodes terrain tile indices
- Blue channel encodes object/enemy types
- Green channel encodes metadata such as flip state and door type
- Assets are loaded using image atlas techniques
- Animation frames are extracted from spritesheets based on entity states
- The game uses a fixed-step update loop with separate render and update timing
- Entities share collision helpers and a simple
Rectangle2Dbounding-box system - The world uses an offscreen canvas representation of the level for efficient rendering
This project does not require a build tool. It can be run as a static website.
- Serve the
src/directory with a local web server.- Example (Python):
python -m http.server 8000 - Example (Node):
npx http-server src
- Example (Python):
- Open
http://localhost:8000/main/index.html
- If your browser allows file-based assets, open
src/main/index.htmldirectly - Note: some browsers may block local image loading when opened via
file://, so a local server is more reliable
- The current world loader points to a single tile and level image path in
src/level/Levels.js - The project is structured for extension: new levels, enemy types, and game mechanics can be added by expanding the PNG map data and section constants
- Project structure and game logic implemented in modular JavaScript - by PrithwisK07
Enjoy exploring the game and building new levels with the editor!
.png)





