Goro's Memex

ごろうのミーメックス

Logo

Osu Clone

Wed May 10 2023 00:00:00 GMT+0000 (Coordinated Universal Time)

SITUATION

In October 2021, a week after my bootcamp began, I was tasked with writing an interactive game utilizing Javascript and the Canvas API.

INFORMATION

ANALYSIS

DEVELOPMENT CHALLENGES & IMPLEMENTATION

IMPACT AND RESULTS

RECCOMENDATIONS

FOLLOWUP

Taking a more game-development approach, the code has been modularized into a set of managers with a core EventManager class orchestrating the other managers. This allows me to take a more event-centric approach, where I can dispatch events with more control.

In practice, this allows me to seperate various concerns and decouple rendering and updates into their own modules.

Additionally, I have taken great efforts to integrate the Menu into the dispatch system but am currently figuring out the best-practices regarding HTML overlays over Canvas Elements.

export default class GameManager {
    constructor(globalWindow) {
        this.EventManager = EventManager
        this.RenderManager = new RenderManager(this.EventManager, 600, 600);
        this.ObjectManager = new ObjectManager(this.EventManager, this.RenderManager);
        this.CollisionManager = new CollisionManager(this.EventManager, this.ObjectManager);
        this.InputManager = new InputManager(this.EventManager, globalWindow, this.RenderManager, this.ObjectManager);
        this.isRunning = false;
        this.initialize();
    }
    initialize() {
        this.registerEventListeners();
        this.start()

    }
    registerEventListeners() {
        console.log("....registering...")
    }

    start() {
        if (this.isRunning) return;
        this.isRunning = true;
        this.ObjectManager.createTestObject(20)
        this.GameLoop();
    }
    stop() {
        this.isRunning = false;
    }
    GameLoop() {
        if (!this.isRunning) return;
        this.update();
        this.render();
        requestAnimationFrame(this.GameLoop.bind(this));
    }
    update() {
        this.ObjectManager.updateAll();
    }
    render() {
        const entities = this.ObjectManager.getAllEntities();
        this.RenderManager.render(entities);
    }
    handleGameOver() {
        this.stop();
    }
}


CONCLUSION