Skip to content
Browse files

Castle and Dwarf stubs

  • Loading branch information...
1 parent cbce268 commit 97c298ebf48a19ac3cdbb0b05db725bb362aa5d9 @lqc lqc committed
View
25 client/src/battle_scene.js
@@ -1,10 +1,11 @@
var gamejs = require("gamejs"),
matrix = require("gamejs/utils/matrix"),
world = require("world"),
- font = require("gamejs/font");
+ font = require("gamejs/font"),
+ Castle = require("elements/castle").Castle;
-var BattleScene = exports.BattleScene = function(director) {
+var BattleScene = exports.BattleScene = function(director, playerA, playerB) {
this.director = director;
this.width = 1600;
this.height = this.director.height;
@@ -30,6 +31,13 @@ var BattleScene = exports.BattleScene = function(director) {
/* predraw the background */
this.drawBackground();
+
+
+ this.playerA = playerA;
+ this.playerB = playerB;
+
+ this.add(new Castle(director, playerA.name, new gamejs.Rect(150, 270, 250, 300)));
+ this.add(new Castle(director, playerB.name, new gamejs.Rect(1150, 270, 250, 300)));
};
BattleScene.prototype.drawBackground = function() {
@@ -59,20 +67,9 @@ BattleScene.prototype.drawBackground = function() {
// draw ground
this._surface_battle_bg.blit(this.groundLeft,[0, this.height-96]);
this._surface_battle_bg.blit(this.groundRight,[this.width-528, this.height-96]);
+
// draw grass
this._surface_battle_bg.blit(this.grassImg, [0, this.height-75]);
-
- //
- this._surface_battle_bg.blit(this._font.render("A"), [200, this.height-60]);
- this._surface_battle_bg.blit(this._font.render("B"), [this.width-200, this.height-60]);
-
- // draw an example dwarf
- this.dwarf = world.get_image("dwarf");
- this._surface_battle_bg.blit(this.dwarf, [100, this.height-200]);
- this._surface_battle_bg.blit(this.dwarf, [180, this.height-200]);
- this._surface_battle_bg.blit(this.dwarf, [240, this.height-200]);
-
-
}
BattleScene.prototype.handleEvent = function handleEvent(event) {
View
24 client/src/elements/castle.js
@@ -0,0 +1,24 @@
+/**
+ * Sprite representing the players castle.
+ */
+var gamejs = require("gamejs"),
+ sprite = require("gamejs/sprite"),
+ game_world = require("world"),
+ transform = require("gamejs/transform");
+
+/**
+ * @param elements - Castle pieces.
+ */
+var Castle = exports.Castle = function Castle(director, name, bbox, elements) {
+ Castle.superConstructor.apply(this, arguments);
+ this.name = name;
+ this.elements = elements || [];
+ this.rect = bbox.clone();
+};
+
+gamejs.utils.objects.extend(Castle, sprite.Group);
+
+Castle.prototype.draw = function(canvas) {
+ sprite.Group.prototype.draw.apply(this, arguments);
+ // canvas.blit(this._font.render(this.name), [this.rect.left, this.rect.top]);
+};
View
35 client/src/elements/dwarf.js
@@ -0,0 +1,35 @@
+/**
+ * Sprite representing the players castle.
+ */
+var gamejs = require("gamejs"),
+ sprite = require("gamejs/sprite"),
+ game_world = require("world"),
+ transform = require("gamejs/transform");
+
+/**
+ * @param elements - Castle pieces.
+ */
+var Dwarf = exports.Dwarf = function Castle(director, health, id) {
+ Dwarf.superConstructor.apply(this, arguments);
+ this.id = id || "dwarf";
+ this.image = game_world.get_image(id);
+ this.max_health = this.health = health;
+ this.director = director;
+};
+
+gamejs.utils.objects.extend(Dwarf, sprite.Sprite);
+
+Dwarf.prototype.draw = function(canvas) {
+ Sprite.prototype.draw.apply(this, arguments);
+ gamejs.draw.rect(canvas,
+ new gamejs.Rect(this.rect.left,
+ this.rect.top-20,
+ this.rect.width,
+ 20), "red");
+
+ gamejs.draw.rect(canvas,
+ new gamejs.Rect(this.rect.left,
+ this.rect.top-20,
+ this.rect.width * (this.healt/this.max_health),
+ 20), "green")
+};
View
2 client/src/main.js
@@ -75,7 +75,7 @@ gamejs.ready(function() {
document.getElementById("start").onclick = function() {
this.style.display = "none";
- battle_scene = new BattleScene(director);
+ battle_scene = new BattleScene(director, {name: "Zuber"}, {name: "Ślimak"});
director.start(battle_scene);
};
/*
View
14 client/src/player_castle.js
@@ -1,14 +0,0 @@
-/**
- * Sprite representing the players castle.
- */
-var gamejs = require("gamejs"),
- sprite = require("gamejs/sprite"),
- game_world = require("world"),
- transform = require("gamejs/transform");
-
-var Castle = exports.Castle = function Castle() {
- Castle.superConstructor.apply(this, arguments);
-
-};
-
-gamejs.utils.objects.extend(Castle, sprite.Group);
View
9 client/src/splash_scene.js
@@ -0,0 +1,9 @@
+var gamejs = require("gamejs");
+
+var SplashScene = exports.SplashScene = function SplashScene(director) {
+ this.director = director;
+ this.image = gamejs.image.load('./statics/images/startScreen.png');
+ this.rect = new gamejs.Rect(0, 0, director.width, director.height);
+};
+
+gamejs.utils.objects.extend(SplashScene, gamejs.sprite.Sprite);

0 comments on commit 97c298e

Please sign in to comment.
Something went wrong with that request. Please try again.