Add wandering sprites back to map via map objects

This commit is contained in:
2014-06-13 01:57:06 -07:00
parent 2fe0e4c9e8
commit ced3395d0b
2 changed files with 50 additions and 9 deletions

View File

@@ -123,6 +123,32 @@
"width":50, "width":50,
"x":0, "x":0,
"y":0 "y":0
},
{
"height":50,
"name":"AI",
"objects":[
{
"gid":3544,
"height":0,
"name":"FountainGuard",
"properties":
{
"sprite_group":"townsfolk-guard",
"sprite_name":"townsfolk-guard-1"
},
"type":"AISprites",
"visible":true,
"width":0,
"x":863,
"y":680
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"width":50,
"x":0,
"y":0
}], }],
"orientation":"orthogonal", "orientation":"orthogonal",
"properties": "properties":

View File

@@ -644,7 +644,7 @@ var moonlightDialog = {
} }
}; };
var AISprite = function(game, x, y, spritetype) { var AISprite = function(game, x, y, key, frame, spritetype) {
this.enableWordBubble = function() { this.enableWordBubble = function() {
this.enable_word_bubble = true; this.enable_word_bubble = true;
} }
@@ -737,6 +737,13 @@ var AISprite = function(game, x, y, spritetype) {
} }
} }
this.update_new_values = function() {
this.loadTexture(this.sprite_group, 0);
this.bubble = null;
this.clearWordBubble();
this.state = STATE_UNAWARE;
}
var spritenames_by_type = [ var spritenames_by_type = [
'townsfolk-male-1', 'townsfolk-male-1',
'townsfolk-male-2', 'townsfolk-male-2',
@@ -749,18 +756,18 @@ var AISprite = function(game, x, y, spritetype) {
'townsfolk-guard-1', 'townsfolk-guard-1',
'townsfolk-guard-2' 'townsfolk-guard-2'
]; ];
this.bubble = null; Phaser.Sprite.call(this, game, x, y, null);
this.clearWordBubble();
this.state = STATE_UNAWARE;
Phaser.Sprite.call(this, game, x, y, spritenames_by_type[spritetype]);
game.physics.arcade.enable(this); game.physics.arcade.enable(this);
this.body.collideWorldBounds = true; this.body.collideWorldBounds = true;
var ARGH = spritenames_by_type[spritetype]; var ARGH = spritenames_by_type[spritetype];
ARGH = ARGH.split("-"); ARGH = ARGH.split("-");
this.sprite_group = ARGH[0] + "-" + ARGH[1]; this.sprite_group = ARGH[0] + "-" + ARGH[1];
if ( (typeof this.sprite_name) !== undefined ) {
this.sprite_name = spritenames_by_type[spritetype];
} else {
this.sprite_name = "townsfolk-male-1"
}
addAnimation(this, 'bipedwalkleft'); addAnimation(this, 'bipedwalkleft');
addAnimation(this, 'bipedwalkright'); addAnimation(this, 'bipedwalkright');
@@ -770,6 +777,8 @@ var AISprite = function(game, x, y, spritetype) {
addAnimation(this, 'bipedrunright'); addAnimation(this, 'bipedrunright');
addAnimation(this, 'bipedrunup'); addAnimation(this, 'bipedrunup');
addAnimation(this, 'bipedrundown'); addAnimation(this, 'bipedrundown');
this.update_new_values();
} }
AISprite.prototype = Object.create(Phaser.Sprite.prototype); AISprite.prototype = Object.create(Phaser.Sprite.prototype);
@@ -828,6 +837,12 @@ GameState.prototype.create = function()
if ( lp['inject_sprites'] == true ) { if ( lp['inject_sprites'] == true ) {
this.aiSprites = game.add.group(); this.aiSprites = game.add.group();
player = this.add.sprite((20 * 32), (25 * 32), 'player'); player = this.add.sprite((20 * 32), (25 * 32), 'player');
this.map.createFromObjects('AI', 3544, 'player', 0, true, false, this.aiSprites, AISprite);
this.aiSprites.forEach(function(spr) {
spr.update_new_values();
console.log(spr);
}, this)
}; };
if ( lp['collides'] == true ) { if ( lp['collides'] == true ) {
this.map_collision_layers.push(layer); this.map_collision_layers.push(layer);
@@ -858,7 +873,6 @@ GameState.prototype.create = function()
); );
this.fpsText.fixedToCamera = true; this.fpsText.fixedToCamera = true;
// Create the wandering sprites
// for ( i = 0; i < 50 ; i++ ) { // for ( i = 0; i < 50 ; i++ ) {
// this.aiSprites.add( // this.aiSprites.add(
// new AISprite(game, // new AISprite(game,
@@ -871,6 +885,7 @@ GameState.prototype.create = function()
this.shadowTexture = game.add.bitmapData(game.world.width, game.world.height); this.shadowTexture = game.add.bitmapData(game.world.width, game.world.height);
// drop this lower to make the map darker // drop this lower to make the map darker
this.shadowTexturColor_Base = 30;
this.shadowTextureColor = 'rgb(30, 30, 30)'; this.shadowTextureColor = 'rgb(30, 30, 30)';
//this.shadowTextureColor = 'rgb(255, 255, 255)'; //this.shadowTextureColor = 'rgb(255, 255, 255)';
@@ -1008,7 +1023,7 @@ GameState.prototype.check_input = function()
setSpriteMovement(player, controls.up.shiftKey, 'right'); setSpriteMovement(player, controls.up.shiftKey, 'right');
} else { } else {
player.animations.stop(null, true); player.animations.stop(null, true);
} } else if ( controls.
} }
GameState.prototype.update = function() GameState.prototype.update = function()