Skip to content

Commit

Permalink
chapel action
Browse files Browse the repository at this point in the history
--HG--
rename : js/gate.js => js/lib/gate.js
rename : js/jester.js => js/lib/jester.js
  • Loading branch information
ondras committed Feb 24, 2013
1 parent 9f3cbda commit 24f4238
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 44 deletions.
6 changes: 4 additions & 2 deletions index.html
Expand Up @@ -20,17 +20,19 @@
<script src="js/common/lib/cells.js"></script>
<script src="js/common/lib/items.js"></script>

<script src="js/display.js"></script>
<script src="js/ai.js"></script>
<script src="js/intro.js"></script>
<script src="js/story.js"></script>
<script src="js/status.js"></script>
<script src="js/stats.js"></script>
<script src="js/legend.js"></script>
<script src="js/gate.js"></script>
<script src="js/jester.js"></script>
<script src="js/player.js"></script>
<script src="js/lib/gate.js"></script>
<script src="js/lib/bride.js"></script>
<script src="js/lib/beings.js"></script>
<script src="js/lib/cells.js"></script>
<script src="js/lib/items.js"></script>

<script src="levels/forest.js"></script>
<script src="levels/castle.js"></script>
Expand Down
8 changes: 6 additions & 2 deletions js/common/being.js
Expand Up @@ -112,10 +112,14 @@ Game.Being.prototype.getMaxHP = function() {

Game.Being.prototype.adjustHP = function(diff) {
this._hp = Math.max(0, this._hp + diff);
if (!this._hp) { this._die(); }
if (!this._hp) { this.die(); }
return this;
}

Game.Being.prototype.getWeapon = function() {
return this._weapon;
}

Game.Being.prototype.attack = function(target) {
/* FIXME probably refactor to a dedicated attack logic? */

Expand Down Expand Up @@ -151,7 +155,7 @@ Game.Being.prototype.attack = function(target) {
Game.status.show(str);
}

Game.Being.prototype._die = function() {
Game.Being.prototype.die = function() {
var corpse = Game.Items.create("corpse", {color:this._color, name:this._name+" corpse"});
this._level.setItem(corpse, this._position[0], this._position[1]);
this._level.removeBeing(this);
Expand Down
8 changes: 5 additions & 3 deletions js/common/level.js
Expand Up @@ -3,7 +3,7 @@ Game.Level = function() {
this.beings = {};
this.items = {};

this._display = new ROT.Display({fontFamily:"droid sans mono, monospace"});
this._display = new Game.Display({fontFamily:"droid sans mono, monospace"});
this._ambientLight = [130, 130, 130];
this._sightRange = 8;

Expand Down Expand Up @@ -290,7 +290,10 @@ Game.Level.prototype._draw = function(x, y) {
if (!(key in this._visibleArea)) { return; }

var entity = this.beings[key] || this.items[key] || this.cells[key];
if (entity) { this._display.draw(x, y, entity.getChar(), ROT.Color.toRGB(entity.getColor())); }
if (entity) {
this._display.draw(x, y, entity.getChar(), ROT.Color.toRGB(entity.getColor()));
if (entity == Game.player) { this._display.setCursor(x, y); }
}
}

Game.Level.prototype._drawFog = function(x, y) {
Expand All @@ -309,7 +312,6 @@ Game.Level.prototype._drawFog = function(x, y) {
/* 3. average */
var gray = (color[0]+color[1]+color[2])/3;


var c1 = 0.4;
var c2 = 1-c1;

Expand Down
10 changes: 5 additions & 5 deletions js/common/lib/beings.js
Expand Up @@ -4,17 +4,18 @@ Game.Beings.define("animal", {
tasks: ["wander"]
});

Game.Beings.define("humanoid", {
tasks: ["wander"],
"char": "@"
});

Game.Beings.define("dog", {
extend: "animal",
name: "dog",
color: [204, 204, 102],
"char": "d"
});

Game.Beings.define("humanoid", {
tasks: ["wander"],
});

Game.Beings.define("rat", {
extend: "animal",
name: "rat",
Expand All @@ -24,7 +25,6 @@ Game.Beings.define("rat", {

Game.Beings.define("mugger", {
extend: "humanoid",
"char": "M",
name: "mugger",
color: [160, 100, 100],
chats: [
Expand Down
14 changes: 0 additions & 14 deletions js/common/lib/cells.js
Expand Up @@ -77,20 +77,6 @@ Game.Cells.define("tree", {
name: "tree"
});

Game.Cells.define("flower", {
"char": "*",
colors: [
[240, 60, 60],
[60, 60, 240],
[240, 120, 30],
[240, 120, 120],
[240, 240, 30],
[240, 30, 240],
[240, 240, 240],
],
name: "flower"
});

/* features */

Game.Cells.define("staircase-up", {
Expand Down
5 changes: 3 additions & 2 deletions js/common/repository.js
Expand Up @@ -15,7 +15,7 @@ Game.Repository.prototype.is = function(type, parent) {
}

Game.Repository.prototype.define = function(type, template) {
if (template.extend) { /* create prototype link to parent definition */
if ("extend" in template) { /* create prototype link to parent definition */
if (!(template.extend in this._storage)) {
throw new Error("Repository type '"+type+"' cannot extend '"+template.extend+"'");
}
Expand All @@ -34,7 +34,8 @@ Game.Repository.prototype.create = function(type, template) {
var finalTemplate = Object.create(this._storage[type]);
for (var p in template) { finalTemplate[p] = template[p]; }

var ctor = finalTemplate.ctor || this._defaultCtor; /* constructor function */
/* constructor function; ternary operator guarantees crash instead of wrong ctor */
var ctor = ("ctor" in finalTemplate ? finalTemplate.ctor : this._defaultCtor);
return new ctor(type).fromTemplate(finalTemplate);
}

Expand Down
30 changes: 30 additions & 0 deletions js/display.js
@@ -0,0 +1,30 @@
Game.Display = function(options) {
var o = options || {};
o.layout = "rectCursor";
ROT.Display.call(this, o);
this._cursor = "";
}
Game.Display.extend(ROT.Display);

Game.Display.prototype.setCursor = function(x, y) {
this._cursor = x+","+y;
}

Game.Display.prototype._draw = function(key, clearBefore) {
ROT.Display.prototype._draw.call(this, key, clearBefore);
if (key == this._cursor) {
var parts = this._cursor.split(",");
this._backend.drawCursor(parseInt(parts[0]), parseInt(parts[1]), this._data[key][3]);
}
}

ROT.Display.RectCursor = function(context) {
ROT.Display.Rect.call(this, context);
}
ROT.Display.RectCursor.extend(ROT.Display.Rect);

ROT.Display.RectCursor.prototype.drawCursor = function(x, y, color) {
var height = Math.round(this._spacingY / 10);
this._context.fillStyle = color;
this._context.fillRect(x*this._spacingX, (y+1)*this._spacingY - height, this._spacingX, height);
}
3 changes: 3 additions & 0 deletions js/game.js
Expand Up @@ -3,6 +3,9 @@ var Game = {
player: null,
level: null,
story: null,
storyFlags: {
wantsFlower: false
},

init: function() {
window.addEventListener("load", this);
Expand Down
29 changes: 24 additions & 5 deletions js/lib/beings.js
@@ -1,6 +1,5 @@
Game.Beings.define("player", {
extend: "humanoid",
"char": "@",
pv: 3,
hp: 10,
damage: 3,
Expand All @@ -11,23 +10,43 @@ Game.Beings.define("player", {
Game.Beings.define("guard", {
extend: "humanoid",
name: "guard",
"char": "G",
tasks: [],
color: [220, 140, 140]
});

Game.Beings.define("jester", {
extend: "humanoid",
"char": "J",
ctor: Game.Being.Jester,
chats: ["There is a secret passage to the kitchen, hidden in the throne room. But only the King shall know about it!"],
name: "jester",
color: [240, 100, 100]
});

Game.Beings.define("gardener", {
extend: "humanoid",
"char": "G",
name: "gardener",
chats: ["Good day to you, sir!", "Watch these flowers blossom!", "This garden needs my attention."],
color: [100, 240, 100],
});

Game.Beings.define("bride", {
extend: "humanoid",
ctor: Game.Being.Bride,
tasks: [],
name: "bride",
color: [240, 240, 240]
});

Game.Beings.define("groom", {
extend: "humanoid",
tasks: [],
name: "groom",
color: [80, 80, 80]
});

Game.Beings.define("priest", {
extend: "humanoid",
tasks: [],
chats: ["You would like to talk to the bride - and you brought her nothing? Shame on you!"],
name: "priest",
color: [200, 30, 200]
});
5 changes: 5 additions & 0 deletions js/lib/bride.js
@@ -0,0 +1,5 @@
Game.Being.Bride = function(type) {
Game.Being.call(this, type);
}
Game.Being.Bride.extend(Game.Being);

File renamed without changes.
15 changes: 15 additions & 0 deletions js/lib/items.js
@@ -0,0 +1,15 @@
Game.Items.define("flower", {
extend: "weapon",
damage: 0,
"char": "*",
colors: [
[240, 60, 60],
[60, 60, 240],
[240, 120, 30],
[240, 120, 120],
[240, 240, 30],
[240, 30, 240],
[240, 240, 240],
],
name: "flower"
});
File renamed without changes.
9 changes: 5 additions & 4 deletions js/player.js
@@ -1,4 +1,5 @@
Game.Player = function(type) {
this._debug = true;
Game.Being.call(this, type);

this._light = [30, 30, 30];
Expand Down Expand Up @@ -90,7 +91,7 @@ Game.Player.prototype.setPosition = function(x, y, level) {

Game.Player.prototype.updateVisibility = function() {
var visibility = this._getVisibleArea();
this._level.setVisibility(/*true ||*/ visibility);
this._level.setVisibility(this._debug || visibility);
}

Game.Player.prototype._getVisibleArea = function() {
Expand Down Expand Up @@ -166,7 +167,7 @@ Game.Player.prototype._pickItem = function(x, y) {
return;
}

if (Game.Items.is(type, "weapon")) {
if (Game.Items.is(type, "weapon") && (type != "flower" || Game.storyFlags.wantsFlower)) {
this._level.removeItem(item);

if (this._weapon) {
Expand Down Expand Up @@ -194,8 +195,8 @@ Game.Player.prototype.adjustHP = function(diff) {
this._updateStats();
}

Game.Player.prototype._die = function() {
Game.Being.prototype._die.call(this);
Game.Player.prototype.die = function() {
Game.Being.prototype.die.call(this);
this._char = "☠";
this._color = [255, 255, 255];
Game.over();
Expand Down
10 changes: 10 additions & 0 deletions levels/castle.js
Expand Up @@ -6,6 +6,7 @@ Game.Level.Castle = function() {
this._gates = [];
this._guards = [];
this._jester = null;
this._gardener = null;
this._rats = [];
}
Game.Level.Castle.extend(Game.Level);
Expand All @@ -23,6 +24,7 @@ Game.Level.Castle.prototype.fromTemplate = function(map, def) {
if (being.getType() == "guard") { this._guards.push(being); }
if (being.getType() == "jester") { this._jester = being; }
if (being.getType() == "rat") { this._rats.push(being); }
if (being.getType() == "gardener") { this._gardener = being; }
}

this._initStory();
Expand Down Expand Up @@ -114,4 +116,12 @@ Game.Level.Castle.prototype._initStory = function() {
Game.story.newChapter("Me versus rats – 3:0. Nice. Now let's get to that chapel before the wedding is over!");
return true;
});

this._addRule(function() {
return Game.storyFlags.wantsFlower;
}, function() {
this.removeBeing(this._gardener);
Game.engine.removeActor(this._gardener);
return true;
});
}
3 changes: 2 additions & 1 deletion levels/castle.txt
Expand Up @@ -74,7 +74,8 @@ T==========w# ##################5####
"item": "gold"
},
"f": {
"cell": "flower"
"cell": "grass",
"item": "flower"
},
"W": {
"cell": "well"
Expand Down
41 changes: 41 additions & 0 deletions levels/chapel.js
@@ -1,13 +1,27 @@
Game.Level.Chapel = function() {
/* FIXME druhy blocker krom priesta; konverzace a AI guestu */
Game.Level.call(this);

this._lighting.setOptions({range:8});

this._priest = null;
this._bride = null;
this._groom = null;
this._guests = [];
}
Game.Level.Chapel.extend(Game.Level);

Game.Level.Chapel.prototype.fromTemplate = function(map, def) {
Game.Level.prototype.fromTemplate.call(this, map, def);

for (var key in this.beings) {
var being = this.beings[key];
if (being.getType() == "guest") { this._guests.push(being); }
if (being.getType() == "priest") { this._priest = being; }
if (being.getType() == "bride") { this._bride = being; }
if (being.getType() == "groom") { this._groom = being; }
}

this._initStory();
return this;
}
Expand All @@ -19,4 +33,31 @@ Game.Level.Chapel.prototype._initStory = function() {
Game.story.newChapter("I finally arrived at the chapel. By this time the wedding ceremony is probably already over, so I should at least get in and give my congratulations. I guess a lot of people are attending...");
return true; /* remove from rule list */
});

this._addRule(function() {
return this._priest.chattedWith();
}, function() {
Game.story.addChapter("Indeed, it would be polite to bring some gift to the bride. I was in a hurry, so I brought nothing. Fortunately, I noticed some beautifully blossoming flowers in the castle garden.");
Game.story.setTask("Get back to castle garden and bring a flower.");
Game.storyFlags.wantsFlower = 1;
return true;
});

this._addRule(function() {
var weapon = Game.player.getWeapon();
return (weapon && weapon.getType() == "flower");
}, function() {
this._groom.die(); /* :-/ */

var pos = this.getCellById("window").getPosition();
var floor = Game.Cells.create("floor");
this.setCell(floor, pos[0], pos[1]);

var pos = this.getCellById("exit").getPosition();
var staircase = Game.Cells.create("staircase-down");
this.setCell(staircase, pos[0], pos[1]);


return true;
});
}

0 comments on commit 24f4238

Please sign in to comment.