@kenzoobryan/my-engine
v0.3.0
Published
Minimalist 2D Game Engine
Readme
My Engine
Minimalist, robust, and magic-free 2D game engine for the browser.
@kenzoobryan/my-engine is a JavaScript library designed for developers who want to keep pure control over their game loop. No editor, no heavy dependencies, just the essential bricks to build games like Snake, Tetris, or Shoot'em ups.
Key Features
- Solid Game Loop: Managed delta time, death spiral protection.
- Scene Management: Simple transitions between Menu, Game, and Game Over.
- 2D Canvas Rendering: Lightweight abstractions for performant drawing.
- Unified Input: Normalized Keyboard and Mouse.
- Zero Magic: No global variables, no unpredictable side-effects.
Installation
npm install @kenzoobryan/my-engineQuick Start
import { Game, Scene, World, System, Component, Vector2 } from '@kenzoobryan/my-engine';
// 1. Define Components
class Position extends Component {
constructor(x, y) { super(); this.vec = new Vector2(x, y); }
}
class Velocity extends Component {
constructor(x, y) { super(); this.vec = new Vector2(x, y); }
}
// 2. Define Systems
class PhysicsSystem extends System {
update(dt) {
const entities = this.world.getEntitiesWith([Position, Velocity]);
for (const entity of entities) {
const pos = entity.getComponent(Position);
const vel = entity.getComponent(Velocity);
pos.vec = pos.vec.add(vel.vec.scale(dt));
}
}
}
// 3. Create a Scene
class MainScene extends Scene {
onEnter() {
this.world = new World();
this.world.addSystem(new PhysicsSystem());
const player = this.world.createEntity();
player.addComponent(new Position(100, 100));
player.addComponent(new Velocity(50, 0));
}
update(dt) {
this.world.update(dt);
// Input Handling
if (this.game.input.isKeyDown('Space')) {
console.log("JUMP!");
}
}
draw(ctx) {
// ... Rendering ...
}
}
// 4. Start the game
const game = new Game({ width: 800, height: 600 });
game.scene_manager.push(new MainScene());
game.start();Documentation
- Vision & Philosophy: Why this engine?
- Architecture: How it works under the hood.
- API Reference: Classes and methods.
- Roadmap: Project future.
License
MIT © Kenzoobryan
