Hi, how come this doesn't work when trying to new up the Game object:
I get TypeError: undefined is not a function for var game = new Game();
Code:
define(["require", "exports", "GameObjects"], function(require, exports, __GameObjects__) {
var GameObjects = __GameObjects__;
$(document).ready(function () {
var game = new Game();
$(document).keydown(game.onKeyDown);
$(document).keyup(game.onKeyUp);
$(document).keyup(game.onKeyUp);
});
function collides(a, b) {
return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
}
function handleCollisions() {
this.playerBullets.forEach(function (bullet) {
this.enemies.forEach(function (enemy) {
if(collides(bullet, enemy)) {
enemy.explode();
bullet.active = false;
}
});
});
}
var Game = (function () {
function Game() {
this.CANVAS_WIDTH = 400;
this.CANVAS_HEIGHT = 400;
this.FPS = 30;
this.enemies = [];
this.playerBullets = new Array[40]();
this.canvas = document.getElementById('canvas');
this.rightDown = false;
this.leftDown = false;
this.space = false;
this.context2D = this.canvas.getContext("2d");
this.canvas.width = this.CANVAS_WIDTH;
this.canvas.height = this.CANVAS_HEIGHT;
this.initGame();
}
Game.prototype.initGame = function () {
var player = new GameObjects.GameObjects.Player();
player.OnShoot = function (bullet) {
this.playerBullets.push(bullet);
};
};
Game.prototype.onKeyDown = function (evt) {
if(evt.keyCode == 39) {
this.rightDown = true;
} else {
if(evt.keyCode == 37) {
etc................