Skip to content

Commit

Permalink
Merge pull request #12 from davidgomes/globalobject-fix
Browse files Browse the repository at this point in the history
Fixes the global object issue.
  • Loading branch information
davidgomes committed Mar 11, 2014
2 parents 0a851ec + b814ebe commit ddb481e
Show file tree
Hide file tree
Showing 18 changed files with 1,004 additions and 1,124 deletions.
951 changes: 451 additions & 500 deletions build/pentagine.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions demos/circle_example/PlayState.js
@@ -1,20 +1,20 @@
function PlayState() {
this.setup = function() {

}
};

this.update = function() {

}
};

this.draw = function() {
clearCanvas();
penta.clearCanvas();

drawCircle(40, 40, 100, "#F00");
penta.drawCircle(40, 40, 100, "#F00");

drawLine(10, 10, 100, 100, "#F12");
}
penta.drawLine(10, 10, 100, 100, "#F12");
};
}

desiredFPS = 60;
switchState(new PlayState());
penta.desiredFPS = 60;
penta.switchState(new PlayState());
6 changes: 0 additions & 6 deletions demos/circle_example/index.html
Expand Up @@ -9,13 +9,7 @@
</body>

<!-- Include Pentagine -->
<script src="../../src/stats.min.js" type="text/javascript"></script>
<script src="../../src/main.js" type="text/javascript"></script>
<script src="../../src/Drawing.js" type="text/javascript"></script>
<script src="../../src/Camera.js" type="text/javascript"></script>
<script src="../../src/Sprite.js" type="text/javascript"></script>
<script src="../../src/SpriteList.js" type="text/javascript"></script>
<script src="../../src/Input.js" type="text/javascript"></script>

<!-- Include game classes -->
<script src="PlayState.js" type="text/javascript"></script>
Expand Down
32 changes: 16 additions & 16 deletions demos/helicopter_game/PlayState.js
@@ -1,21 +1,21 @@
function PlayState() {
this.setup = function() {
this.helicopter = new Sprite("helicopter1.png", 100, context.height / 2 - 100);
this.helicopter = new penta.Sprite("helicopter1.png", 100, penta.context.height / 2 - 100);
this.helicopter.vy = 5;

this.walls = [];
this.walls[context.width - 1] = 20;
this.walls[penta.context.width - 1] = 20;
this.speed = 30;

this.difficulty = 50;
this.score = 0;
}
};

this.update = function() {
if (isDown("up") || isDown("w"))
if (penta.isDown("up") || penta.isDown("w"))
this.helicopter.y -= 400 * this.dt;

if (isDown("down") || isDown("s"))
if (penta.isDown("down") || penta.isDown("s"))
this.helicopter.y += 200 * this.dt;

for (var i = 2; i < this.walls.length - this.speed; i++) {
Expand All @@ -24,7 +24,7 @@ function PlayState() {
}
}

if (this.walls.length == context.width) {
if (this.walls.length == penta.context.width) {
if (this.walls[this.walls.length - 2] < 250) {
if (Math.floor(Math.random() * 5) > 1)
this.walls[this.walls.length - 1] = this.walls[this.walls.length - 2] + Math.floor(Math.random() * 5) + 1;
Expand All @@ -43,25 +43,25 @@ function PlayState() {

this.difficulty += 0.1;
this.score++;
}
};

this.draw = function() {
clearCanvas();
penta.clearCanvas();

currentFont = "10px arial";
drawString("Score: " + this.score.toString(), 2, 10, "#FFF");
drawString("Delta Time: " + Math.floor((this.dt * 1000).toString()) + "ms", 2, 20, "#FFF");
drawString("FPS: " + Math.floor((1 / this.dt).toString()) + "", 2, 30, "#FFF");
penta.drawString("Score: " + this.score.toString(), 2, 10, "#FFF");
penta.drawString("Delta Time: " + Math.floor((this.dt * 1000).toString()) + "ms", 2, 20, "#FFF");
penta.drawString("FPS: " + Math.floor((1 / this.dt).toString()) + "", 2, 30, "#FFF");

for (var i = 0; i < this.walls.length; i++) {
drawRectangle(i, 0, 1, this.walls[i], "#123");
drawRectangle(i, context.height - this.walls[i], 1, this.walls[i], "#123");
penta.drawRectangle(i, 0, 1, this.walls[i], "#123");
penta.drawRectangle(i, penta.context.height - this.walls[i], 1, this.walls[i], "#123");
}

this.helicopter.draw();
}
};
}

desiredFPS = 30;
preventKeys("down", "right", "left", "right", "space");
switchState(new PlayState());
penta.preventKeys("down", "right", "left", "right", "space");
penta.switchState(new PlayState());
14 changes: 7 additions & 7 deletions demos/helicopter_game/index.html
Expand Up @@ -9,13 +9,13 @@
</body>

<!-- Include Pentagine -->
<script src="../../src/stats.min.js" type="text/javascript"></script>
<script src="../../src/main.js" type="text/javascript"></script>
<script src="../../src/Drawing.js" type="text/javascript"></script>
<script src="../../src/Camera.js" type="text/javascript"></script>
<script src="../../src/Sprite.js" type="text/javascript"></script>
<script src="../../src/Input.js" type="text/javascript"></script>
<!-- <script src="../../build/pentagine.js" type="text/javascript"></script> -->
<!-- <script src="../../src/stats.min.js" type="text/javascript"></script> -->
<!-- <script src="../../src/main.js" type="text/javascript"></script> -->
<!-- <script src="../../src/Drawing.js" type="text/javascript"></script> -->
<!-- <script src="../../src/Camera.js" type="text/javascript"></script> -->
<!-- <script src="../../src/Sprite.js" type="text/javascript"></script> -->
<!-- <script src="../../src/Input.js" type="text/javascript"></script> -->
<script src="../../build/pentagine.js" type="text/javascript"></script>

<!-- Include game classes -->
<script src="PlayState.js" type="text/javascript"></script>
Expand Down
22 changes: 11 additions & 11 deletions demos/sprite_list_example/PlayState.js
Expand Up @@ -2,33 +2,33 @@

function PlayState() {
this.setup = function() {
this.balls = new SpriteList();
this.balls = new penta.SpriteList();

for (var i = 0; i < 10; i++) {
this.balls.push(new Sprite("ball.png", 5, i * 40 + 5));
this.balls.push(new penta.Sprite("ball.png", 5, i * 40 + 5));
}
}
};

this.update = function() {
if (isDown("right")) {
if (penta.isDown("right")) {
this.balls.sprites.forEach(function(ball, index) {
ball.x += 5;
});
} else if (isDown("left")) {
} else if (penta.isDown("left")) {
this.balls.sprites.forEach(function(ball, index) {
ball.x -= 5;
});
}
}
};

this.draw = function() {
clearCanvas("#00F");
penta.clearCanvas("#00F");

drawString("Use RIGHT and LEFT arrow keys.", 2, 10);
penta.drawString("Use RIGHT and LEFT arrow keys.", 2, 10);

this.balls.draw();
}
};
}

desiredFPS = 60;
switchState(new PlayState());
penta.desiredFPS = 60;
penta.switchState(new PlayState());
6 changes: 0 additions & 6 deletions demos/sprite_list_example/index.html
Expand Up @@ -9,13 +9,7 @@
</body>

<!-- Include Pentagine -->
<script src="../../src/stats.min.js" type="text/javascript"></script>
<script src="../../src/main.js" type="text/javascript"></script>
<script src="../../src/Drawing.js" type="text/javascript"></script>
<script src="../../src/Camera.js" type="text/javascript"></script>
<script src="../../src/Sprite.js" type="text/javascript"></script>
<script src="../../src/SpriteList.js" type="text/javascript"></script>
<script src="../../src/Input.js" type="text/javascript"></script>

<!-- Include game classes -->
<script src="PlayState.js" type="text/javascript"></script>
Expand Down
48 changes: 24 additions & 24 deletions demos/states_example/Game.js
@@ -1,18 +1,18 @@
function TitleScreenState() {
this.setup = function() {

}
};

this.update = function() {
if (isDown("space"))
switchState(new GameState());
}
if (penta.isDown("space"))
penta.switchState(new GameState());
};

this.draw = function() {
clearCanvas();
penta.clearCanvas();

drawString("Press [SPACE] to start playing.", 200, 200);
}
penta.drawString("Press [SPACE] to start playing.", 200, 200);
};
}

function GameState() {
Expand All @@ -21,29 +21,29 @@ function GameState() {

this.setup = function() {
setTimeout(function() {
switchState(new TitleScreenState());
penta.switchState(new TitleScreenState());
}, 10000);
}
};

this.update = function() {
if (isDown("right")) {
this.playerX += 20;
} else if (isDown("left")) {
this.playerX -= 20;
} else if (isDown("down")) {
this.playerY += 20;
} else if (isDown("up")) {
this.playerY -= 20;
if (penta.isDown("right")) {
this.playerX += 5;
} else if (penta.isDown("left")) {
this.playerX -= 5;
} else if (penta.isDown("down")) {
this.playerY += 5;
} else if (penta.isDown("up")) {
this.playerY -= 5;
}
}
};

this.draw = function() {
clearCanvas();
penta.clearCanvas();

drawRectangle(this.playerX, this.playerY, 40, 40);
}
penta.drawRectangle(this.playerX, this.playerY, 40, 40);
};
}

desiredFPS = 30;
preventKeys("down", "right", "left", "right", "space");
switchState(new TitleScreenState());
penta.desiredFPS = 30;
penta.preventKeys(["down", "right", "left", "right", "space"]);
penta.switchState(new TitleScreenState());
6 changes: 0 additions & 6 deletions demos/states_example/index.html
Expand Up @@ -9,13 +9,7 @@
</body>

<!-- Include Pentagine -->
<script src="../../src/stats.min.js" type="text/javascript"></script>
<script src="../../src/main.js" type="text/javascript"></script>
<script src="../../src/Drawing.js" type="text/javascript"></script>
<script src="../../src/Camera.js" type="text/javascript"></script>
<script src="../../src/Sprite.js" type="text/javascript"></script>
<script src="../../src/Input.js" type="text/javascript"></script>
<!-- <script src="../../build/pentagine.js" type="text/javascript"></script> -->

<!-- Include game classes -->
<script src="Game.js" type="text/javascript"></script>
Expand Down
11 changes: 0 additions & 11 deletions src/Animation.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/Camera.js

This file was deleted.

49 changes: 0 additions & 49 deletions src/Drawing.js

This file was deleted.

0 comments on commit ddb481e

Please sign in to comment.