Game Engine

Game.contructor(viewport=document.body)



The viewport is the element that all the Objects of this game will show up in.

Game.running



This variable defaults to false, but turns to true when the Game's start method is called.

Game.viewport



This is the element that was passed to the constuctor, all game Objects will be made in this element.

Game.OBJECTS



This is an array of all the objects defined within this Game.

Game.width



Represents the width of the Game's viewport

Game.height



Represents the height of the Game's viewport

Game.camera



Game.camera.scaleX


The scale x of the camera.

Game.camera.scaleY


The scale y of the camera.

Game.camera.offsetX


The offset of the viewing point on the x axis. This will move the camera (viewport) and everything in its view on the x axis.

Game.camera.offsetY


The offset of the viewing point on the y axis. This will move the camera (viewport) and everything in its view on the y axis.

Game.camera.rotation


The rotation of the viewport. This is measured in degrees. This value will rotate everything in the view of the camera (everything in the viewport).



Game.WindowGameLoop(elapsed)



This is the Game Loop that is called every frame. This defaults to a blank function. The variable elapsed represents how much time has passed since the previous frame, allowing for smoother animations.

Game.ZoomTo(scale)



Sets the Game's scale attribute to scale. This will zoom in or zoom out the Game's viewport.

Game.start()



Sets the Game's running attribute to true, which starts all animations and movements. This must be called before any movement may happen.



Object.contructor(game, height, width, id_value="", class_value="", background="")



Object.element



This is a HTMLElement object that represents the element the object is made of.

Object.game



The Game object that this Object is a part of.

Object.x



The x position of the Object.

Object.y



The y position of the Object.

Object.rotation



The current rotation of the object.

Object.width



The width value of the Object.

Object.height



The height value of the Object.

Object.halfWidth



Half of the width value of the Object.

Object.halfHeight



Half of the height value of the Object.

Object.velocity



Object.velocity.x


The x velocity of the Object.
Object.velocity.y


The y velocity of the Object.
Object.velocity.rotation


The rotation speed of the Object.


Object.OBJ_ID



The ID of this object.

Object.moveX(amount)



Moves the object amountpx on the x axis.

Object.moveY(amount)



Moves the object amountpx on the y axis.

Object.setPos(x, y)



Sets the position of the object to (x, y)

Object.Rotate(degrees)



Adds degrees to the object's current rotation.

Object.RotateTo(degrees)



Sets the object's current rotation to degrees

Object.stop()



Sets all the object's velocities to 0.

Object.Animation(name, duration, timingFunction="linear", delay=0)



Starts a CSS animation as specified.

Object.clone()



Creates and returns an exact copy of the object.

KEYS



KEYS.pressed



An array of all the keys currently being held down. Stored as keycodes.

KEYS.pressedKey



An array of all the keys currently being held down. Stored as actual keys. Works best for keys such as letters, numbers, arrow keys, shift, control, or command.

KEYS.bindKey(funct, key, repeat=false)



key can either be an Array or a String. If an array then it will be looped through. funct will be called if any of the keys in the array are in either KEYS.pressed or KEYS.pressedKey. If repeat is true, then the function will be called every frame with a argument telling how much time has elapsed since the last frame. Otherwise, if repeat is false, then it will only be called on keydown.



removeItem(array, value)



Removes value from array and returns the new array.

Touching(obj1, obj2)



Detects if Object obj1 and Object obj2 are touching. Returns a dictionary with touching, touchingX, touchingY, and side. touching is either true or false, if it is false then touchingX and touchingY will be false too. touchingX is true if the touch is on the x axis, touchingY is true if it is on the y axis. side tells the specific side that the touch occured on: "left", "right", "top", or "bottom".



isPressed(button)



Used to detect if a gamepad button is being pressed or not. Takes one gamepad button as a argument and returns either true or false.



KeyData(keycode)



Takes a keycode as an input and returns a not-so-accurate guess as to what key it may represent.



Sleep(milisecs, funct)



Similar to setTimeout, except this works with the game loop and is much more optimised than setTimeout. Using this will have little to no preformance loss.



OnDocumentClick(event)



Defaults to a blank function. Meant to be redefined by the user. event is a click event. This is automaticly called everytime a click happens.Do not redefine onclick, use this function instead or parts of the game engine may not work properly.



handleKeyPress(keycode)



Defaults to a blank function. Meant to be redefined by the user. keycode is the keycode of the key that was pressed. This is automaticly called everytime on keydown. Do not redefine onkeydown, use this function instead or parts of the game engine may not work properly.



handleKeyUnPress(keycode)



Defaults to a blank function. Meant to be redefined by the user. keycode is the keycode of the key that was lifted. This is automaticly called everytime on keyup. Do not redefine onkeyup, use this function instead or parts of the game engine may not work properly.



pointDistance(x1, y1, x2, y2)



Returns the distance between points (x1, y1) and (x2, y2).