Permalink
Browse files

Merge branch 'master' of github.com:psubocz/garden-dWARves

  • Loading branch information...
2 parents 504978b + 871dafb commit f74738f188e681f654d4328805f72947009ad345 @psubocz committed Apr 14, 2012
View
27 client/src/battle_scene.js
@@ -1,4 +1,7 @@
-var gamejs = require("gamejs"), matrix = require("gamejs/utils/matrix"), font = require("gamejs/font");
+var gamejs = require("gamejs"),
+ matrix = require("gamejs/utils/matrix"),
+ font = require("gamejs/font"),
+ BulletSprite = require("bullet_sprite").Bullet;
var BattleScene = exports.BattleScene = function(director) {
this.director = director;
@@ -22,6 +25,7 @@ var BattleScene = exports.BattleScene = function(director) {
this._surface_battle = new gamejs.Surface(this.width, this.height);
this._surface_battle_bg = new gamejs.Surface(this.width, this.height);
+ this._bullets = [];
/* predraw the background */
@@ -104,9 +108,19 @@ BattleScene.prototype.handleEvent = function handleEvent(event) {
};
+BattleScene.prototype.update = function(msDuration) {
+ this._bullets = this._bullets.filter(function(b) {
+ return !b.update(msDuration);
+ }, this);
+};
+
+
BattleScene.prototype.draw = function(display) {
this._surface_battle.blit(this._surface_battle_bg);
- display.clear();
+ this._bullets.forEach(function(b) {
+ b.draw(this._surface_battle);
+ }, this);
+
var vp = this._viewport;
display.raw_blit(this._surface_battle,
vp.left, vp.top, vp.width, vp.height,
@@ -157,12 +171,17 @@ BattleScene.prototype.scrollTo = function(x, y, duration) {
if(total > duration) {
this._viewport.left = tx;
this._viewport.top = ty;
- gamejs.time.deleteCallback(scroller, 30);
+ gamejs.time.deleteCallback(scroller, 50);
this.locked = false;
return;
}
this.scrollNowBy(msElapsed * speedx, msElapsed * speedy);
}
- gamejs.time.fpsCallback(scroller, this, 30);
+ gamejs.time.fpsCallback(scroller, this, 50);
+};
+
+
+BattleScene.prototype.animateShot = function(sx, sy, dx, dy) {
+ this._bullets.push(new BulletSprite(sx, sy, dx, dy));
};
View
23 client/src/main.js
@@ -3,7 +3,7 @@ var gamejs = require('gamejs'),
StartScene = require("intro_screen").StartScene,
BattleScene = require("battle_scene").BattleScene;
-gamejs.preload([ "./statics/images/logo.png" ]);
+gamejs.preload(["./statics/images/logo.png","./statics/images/cannonball.png" ]);
gamejs.Surface.prototype.raw_blit = function(src, sx, sy, sw, sh, dx, dy, dw,
dh) {
@@ -29,7 +29,7 @@ gamejs.ready(function() {
this.display = gamejs.display.setMode([ width, height ]);
- gamejs.time.fpsCallback(this.tick, this, 30);
+ gamejs.time.fpsCallback(this.tick, this, 50);
}
Director.prototype.tick = function tick(msDuration) {
@@ -71,10 +71,12 @@ gamejs.ready(function() {
var director = new Director(1024, 550);
var battle_scene = new BattleScene(director);
- document.getElementById("start").onclick = function() {
- document.getElementById("gjs-canvas").style.display = "block";
- director.start(battle_scene);
- };
+// document.getElementById("start").onclick = function() {
+// document.getElementById("gjs-canvas").style.display = "block";
+// director.start(battle_scene);
+// };
+
+ director.start(battle_scene);
// display.blit(
// (new gamejs.font.Font('30px Sans-serif')).render('Hello World')
@@ -88,9 +90,8 @@ gamejs.ready(function() {
document.getElementById("btnB").onclick = function() {
battle_scene.scrollTo(1300, 450);
};
-
- /**
- * function tick(msDuration) { // game loop return; };
- * gamejs.time.fpsCallback(tick, this, 26);
- */
+
+ document.getElementById("shot").onclick = function() {
+ battle_scene.animateShot(50, 200, 500, 200);
+ };
});
View
BIN client/statics/images/startScreen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3 client/statics/index.html
@@ -22,9 +22,10 @@
<button type="button" id="start">Start</button>
<button type="button" id="btnA">Goto A</button>
<button type="button" id="btnB">Goto B</button>
+ <button type="button" id="shot">Test shot</button>
<div id="container">
<div id="gjs-loader">Loading...</div>
- <canvas id="gjs-canvas" style="display: none;">Your browser doesn't support HTML5 canvas</canvas>
+ <canvas id="gjs-canvas">Your browser doesn't support HTML5 canvas</canvas>
</div>
<p>

0 comments on commit f74738f

Please sign in to comment.