Skip to content
Snippets Groups Projects
objects.js 766 B
Newer Older
  • Learn to ignore specific revisions
  • Bye's avatar
    Bye committed
    class GameObject {
    
    Bye's avatar
    Bye committed
        draw() {}
        step() {}
    }
    
    
    Bye's avatar
    Bye committed
    
    
    Bye's avatar
    Bye committed
    class Room extends GameObject {
    
    Bye's avatar
    Bye committed
        constructor(name="") {
    
    Bye's avatar
    Bye committed
            super();
            this.objects = [];
    
    Bye's avatar
    Bye committed
            this.name = name; // needs to be unique, otherwise the searching code will just use the first one it finds.
    
    Bye's avatar
    Bye committed
            this.background = "#000000";
    
    Bye's avatar
    Bye committed
        }
    
    
    Bye's avatar
    Bye committed
        init(){}
    
    
    Bye's avatar
    Bye committed
        draw() {
    
    Bye's avatar
    Bye committed
            for (const item of this.objects) {
                item.draw();
    
    Bye's avatar
    Bye committed
            }
        }
    
        drawGUI() {
    
        }
    
    
    Bye's avatar
    Bye committed
        keyDown(key) {
    
    Bye's avatar
    Bye committed
            for (const item of this.objects) {
                item.keyDown(key);
            }
    
    Bye's avatar
    Bye committed
        }
    
        keyUp(key) {
        }
    
    
    Bye's avatar
    Bye committed
        onclick(pos){
    
        }
    
    
    Bye's avatar
    Bye committed
    
    
    
    Bye's avatar
    Bye committed
        step() {
            for (let i = 0; i < this.objects.length; i++) {
                this.objects[i].step();
            }
        }
    }
    
    
    
    
    Bye's avatar
    Bye committed
    export { GameObject, Room };