Skip to content

Commit

Permalink
Added doors. They're hard to walk into.
Browse files Browse the repository at this point in the history
- Moved talk method from Interactive to NPC
- Added door noise, plays on open
- Fixed bug with tile walkability around inn
  • Loading branch information
ashes999 committed Jun 14, 2014
1 parent 4dd5c5e commit 05f26a2
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 43 deletions.
Binary file added assets/audio/open-door.mp3
Binary file not shown.
Binary file added assets/images/doors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions data/maps/worldMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ function worldMap() {
p.animate("MovingUp");
return ["The guards will recognize me. I must keep out of sight."];
}
},
{
type: 'Door',
sprite: 'door_lhs',
x: 39, y: 36,
initialize: function(me, player) {
me.transitionsTo('testHouse', 3, 3);
}
}
]

Expand Down
2 changes: 1 addition & 1 deletion data/maps/worldMap_tiles.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/maps/worldMap_tileset.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions src/components/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,5 @@ Crafty.c('Interactive', {
if (this.interactFunction != null) {
this.interactFunction();
}
},

talk: function() {
var obj = null;

// Do we have a message?
if (this.onTalk != null || this.messages.length > 0) {
// Initialize dialog.
// If there's no dialog, or multiple messages, do this.
if (typeof(dialog) == 'undefined' || this.messages.length > 0) {

if (typeof(dialog) == 'undefined') {
// no "var" keyword => global scope
dialog = Crafty.e('DialogBox');
}

if (this.onTalk != null) {
obj = this.onTalk();
} else {
obj = this.messages;
}

dialog.setSource(this, this.x, this.y);
dialog.message(obj);
} else {
dialog.close();
delete dialog;
}
}
}
});
21 changes: 17 additions & 4 deletions src/entities/door.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
// A door between two maps.
// A door between two maps. When something touches it, it opens.
Crafty.c('Door', {
init: function() {
this.transitioned = false;
this.requires('Actor, Collision');
this.isClosed = true;

this.requires('Actor, Collision, Interactive');
this.onInteract(function() { console.log('!'); this.open(); });

this.onHit('Solid', function(data) {
if (this.isClosed) {
this.open();
}

this.attr({ alpha: 0 });

if (!this.transitioned) {
var overlap = Math.abs(data[0].overlap);
var hit = data[0].obj;
// Magic number 11: sufficiently overlap the door.
// TODO: remove this when the player collision rect
// is only the bottom half of him.
if (hit.has('Player') && Math.abs(overlap) >= 11) {
var self = this;
Game.player.freeze();
Expand Down Expand Up @@ -41,5 +49,10 @@ Crafty.c('Door', {
this.destination = destination;
this.destinationX = x;
this.destinationY = y;
},

open: function() {
this.isClosed = false;
Crafty.audio.play('openDoor');
}
});
30 changes: 29 additions & 1 deletion src/entities/npcs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Don't use this. It's an "internal" entity.
// Contains animation and collision detection (bounces off solid objects).
Crafty.c('StandingNpc', {
init: function() {
Expand Down Expand Up @@ -115,6 +114,35 @@ Crafty.c('StandingNpc', {

disableCollisionCheck: function() {
this.checkCollisions = false;
},

talk: function() {
var obj = null;

// Do we have a message?
if (this.onTalk != null || this.messages.length > 0) {
// Initialize dialog.
// If there's no dialog, or multiple messages, do this.
if (typeof(dialog) == 'undefined' || this.messages.length > 0) {

if (typeof(dialog) == 'undefined') {
// no "var" keyword => global scope
dialog = Crafty.e('DialogBox');
}

if (this.onTalk != null) {
obj = this.onTalk();
} else {
obj = this.messages;
}

dialog.setSource(this, this.x, this.y);
dialog.message(obj);
} else {
dialog.close();
delete dialog;
}
}
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ Game = {
createObjectFrom: function(def, player) {
// Common properties
var name = def.type

if (typeof(def.components) != 'undefined') {
name = name + ', ' + def.components;
}
Expand Down Expand Up @@ -418,7 +419,7 @@ Game = {

initializeAndAdd: function(def, obj, player) {
// Did we define custom intialization? Call it. (eg. positional audio NPCs)
// First argument is the object itthis; second is the player.
// First argument is the object initializing; second is the player.
if (def.initialize != null) {
def.initialize(obj, player);
}
Expand Down
11 changes: 8 additions & 3 deletions src/scenes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Crafty.scene('Loading', function() {
'/assets/images/npc-1.png', '/assets/images/npc-2.png',
'/assets/images/npc-3.png', '/assets/images/default-sprite.png',
'/assets/images/chicken-white.png', '/assets/images/chicken-red.png',
'/assets/images/indoors.png',
'/assets/images/indoors.png', '/assets/images/doors.png',
'/assets/images/main-character.png', '/assets/images/old-man-avatar.png',
'/assets/images/hijabi-aunty.png', '/assets/images/npc-shaykh.png',
'/assets/images/student-1.png', '/assets/images/student-2.png',
Expand All @@ -30,7 +30,7 @@ Crafty.scene('Loading', function() {
'/assets/images/ui/titlescreen-newgame-text.png', '/assets/images/ui/titlescreen-options-text.png',
// Sounds
'/assets/audio/birds.mp3', '/assets/audio/chicken.mp3', '/assets/audio/chicken2.mp3',
'/assets/audio/points-positive.mp3', '/assets/audio/points-negative.mp3'
'/assets/audio/points-positive.mp3', '/assets/audio/points-negative.mp3', '/assets/audio/open-door.mp3'
];

for (var i = 0; i < assets.length; i++) {
Expand Down Expand Up @@ -79,7 +79,7 @@ Crafty.scene('Loading', function() {

Crafty.sprite(32, 32, gameUrl + '/assets/images/world.png', {
world_grass: [0, 0],
world_wall: [4, 0]
world_wall: [4, 0],
});

Crafty.sprite(32, 32, gameUrl + '/assets/images/indoors.png', {
Expand All @@ -104,12 +104,17 @@ Crafty.scene('Loading', function() {
kings_guard: [1, 0]
});

Crafty.sprite(32, 64, gameUrl + '/assets/images/doors.png', {
door_lhs: [0, 0]
});

Crafty.audio.add({
outside: [gameUrl + '/assets/audio/birds.mp3'],
chicken: [gameUrl + '/assets/audio/chicken.mp3'],
chicken2: [gameUrl + '/assets/audio/chicken2.mp3'],
pointsPos: [gameUrl + '/assets/audio/points-positive.mp3'],
pointsNeg: [gameUrl + '/assets/audio/points-negative.mp3'],
openDoor: [gameUrl + '/assets/audio/open-door.mp3']
// tone: [gameUrl + '/assets/audio/tone.mp3']
});

Expand Down
6 changes: 3 additions & 3 deletions tiled/worldMap.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<properties>
<property name="above" value="2-4,6-24,29-104"/>
<property name="ignore" value="1"/>
<property name="solid" value="6-8,14,16,21,22-24,25,29,41,105-107,113-115,121-123,129-131,137-139"/>
<property name="solid" value="6-8,14,16,21,22-24,25,29,41,89-93,97-101,105-107,113-115,121-123,129-131,137-139"/>
</properties>
<image source="../assets/images/world.png" width="256" height="576"/>
</tileset>
Expand All @@ -15,12 +15,12 @@
</layer>
<layer name="Buildings" width="50" height="50">
<data encoding="base64" compression="zlib">
eJztmcsKwjAQRYOK7/qu9fmR6kpdqSv1p72BFmYRisxmknIPHCiki3vJZDXOkSbRhb2AfctQCiZwGnBmGUpByj2qWfKzU9cj9hmrsvusde8j9ruRPeruI/YeTZyrlO8j1KMF27Dj0u0xgEM4gmOYuTR7zOECLuEK5i6NHmtYwE35vYU7uIcHeCzPCvEfIYQQQgghhBCi4QpvwrttHDUP+BS+bOOoecOP8Gsb5y9O8Cy82MZRw7cQFym+BUJIs/F7E7n/yWzjqPF7E7n/yW3jqAntf1IktP8hJCZ+3/0aag==
eJztmckKwkAQRBsV97jHuH6kelJP6kn9aWsggT4MQebSmaEePBDioYrpPrUISYku7HnsW4YKYAKnHmeWoQKIuUc1S2526no0fcaq7C5r3X40/W10j7r3aHqPFOcq5vfw9WjBNuxIvD0GcAhHcAwzibPHHC7gEq5gLnH0WMMCbsrfW7iDe3iAx/Jbof5HCCGEEEIIIYSEcIU35d02TjAP+FS+bOME84Yf5dc2zl+c4Fl5sY0TTGq7IJLGLojEswuEkLRxdxN9/8ls4wTj7ib6/pPbxgnGd/+JEd/9h5Am8QN7Rxle
</data>
</layer>
<layer name="Above Buildings" width="50" height="50">
<data encoding="base64" compression="zlib">
eJzt2btOAlEUheHzJIqJUUiM4AWJIhgUISAUCBYKFHIpFHz/1t/eyRwGyD4zWX/yFdOtE3aHcyqLHeAQOeMd23aCU+Sth2zZOYooWQ/ZIN8bCv3WfG8o9FvzvaE03ppSKtsdxXynpULMt1JKKaWUsusGF7jEFa5RjlAx2uhTHbe4QxX3qEV4MNro0987GnjEE5p4jhD6Ozro4gU99F36fo8WBnjFECO8uf/f0Tba6Ns7PjDGBFPbOYn7xAxzLLC0nZO4L3xjhTV+bOeojHVsPWBHnVkPUEoppfaY/v9RofcLHlkaVA==
eJzt2TtzAWEYhuH9JQ6NQxOHBJNEGCFMkCJCQSjiUCD+f+vW2/GxM97dneeeuYrtnm+8Hc9TcSyBJFLGO4KWQRY56yEBe0ABReshV+R6Q2G/NdcbCvutud5QFG9NKRXv0he+o1L+wrdSSimllLKrihLKeMQTKj5qRhtdauAZL3hFHW8+mkYbXTq9o4V3tNHBh4+wv+MTfQwwxJcXvd+ji2+M8IMxJt75d/SMNro2xQy/mGNhO+fm/rDECmtsbOfc3BY77PGPg+0cpZRSSil15/T/jwp7RwZMGgQ=
</data>
</layer>
<layer name="Even Higher" width="50" height="50">
Expand Down

0 comments on commit 05f26a2

Please sign in to comment.