Skip to content

Commit

Permalink
splitting to use requirejs
Browse files Browse the repository at this point in the history
  • Loading branch information
databyss committed Apr 2, 2012
1 parent d4c1669 commit ab90103
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -2,7 +2,7 @@
<head>
<title>databyss/shuttle @ GitHub</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="js/shuttle.js"></script>
<script data-main="js/shuttle" src="js/lib/require.js"></script>
<link rel="stylesheet" href="css/site.css" />
</head>
<body>
Expand Down
14 changes: 8 additions & 6 deletions js/background.js
@@ -1,5 +1,5 @@
// background class from canvasbg project http://www.github.com/databyss/canvasbg
function Background() {
function Background(c, ctx) {
"use strict";
this.image = null;
this.scale = 1;
Expand All @@ -15,6 +15,8 @@ function Background() {
x: 0,
y: 0
};
this.c = c;
this.ctx = ctx;
}

// returns the drawn width of image
Expand Down Expand Up @@ -52,19 +54,19 @@ Background.prototype.update = function (ms) {
};

// render the background to the canvas
Background.prototype.draw = function (c, ctx, gameWorld, clearScreen) {
Background.prototype.draw = function (gameWorld, clearScreen) {
var xPoint, yPoint;
if (clearScreen) {
ctx.clearRect(0, 0, c.width, c.height);
this.ctx.clearRect(0, 0, this.c.width, this.c.height);
}
if (this.image !== null) {
xPoint = this.scroll.x - ((gameWorld.xOffset * this.scrollFactor.x) % this.gameWidth()) - (this.gameWidth() * 2); // replace by scroll and scrollFactor
yPoint = this.scroll.y - ((gameWorld.yOffset * this.scrollFactor.y) % this.gameHeight()) - (this.gameHeight() * 2);

while (xPoint < c.width) {
while (yPoint < c.height) {
while (xPoint < this.c.width) {
while (yPoint < this.c.height) {
//TODO: if image is too big, only draw to edge of canvas
ctx.drawImage(this.image, xPoint, yPoint, this.gameWidth(), this.gameHeight());
this.ctx.drawImage(this.image, xPoint, yPoint, this.gameWidth(), this.gameHeight());
yPoint += this.gameHeight();
}
yPoint = this.scroll.y - ((gameWorld.yOffset * this.scrollFactor.y) % this.gameHeight()) - (this.gameHeight() * 2);
Expand Down
4 changes: 2 additions & 2 deletions js/shuttle.js
Expand Up @@ -924,9 +924,9 @@ define(['imageloader', 'background'], function() {
if (this.backgrounds[i] !== null) {
if (i === 0) {
// clear bg on first one
this.backgrounds[i].draw(c, ctx, this.levels[this.currentLevel], true);
this.backgrounds[i].draw(this.levels[this.currentLevel], true);
} else {
this.backgrounds[i].draw(c, ctx, this.levels[this.currentLevel], false);
this.backgrounds[i].draw(this.levels[this.currentLevel], false);
}
}
}
Expand Down

0 comments on commit ab90103

Please sign in to comment.