JSFiddle - React, Tailwind, and code Playground
JavaScript
function Program()
{
var gameobjects = [];
gameobject.push(new Box(this, 10, 10, 10, 10));
gameobject.push(new Box(this, 10, 10, 30, 30));
gameobject.push(new Box(this, 10, 10, 50, 50));
this.dt = 0; // dt is updated in some game loop
}
Program.prototype.draw = function()
{
for(var i = 0; i < this.gameobjects.length; i++)
{
this.gameobjects[i].draw();
}
}
Program.prototype.update = function()
{
for(var i = 0; i < this.gameobjects.length; i++)
{
this.gameobjects[i].update(this.dt);
}
}
function GameObject(program)
{
this.program = program;
this.graphics = null;
}
GameObject.prototype.update(dt)
{
}
GameObject.prototype.draw()
{
// Here graphics would be the graphics of the child class,
// because the graphics would be replaced with the child class' graphics
if(this.graphics !== null)
this.program.renderer.render(this.graphics);
}
function Box(program, width, height, x, y)
{
// Call base constructor here?
this.width = width;
this.height = height;
this.x = x;
this.y = y;
}