Close #7 and Close #6 : Player can now steal from AI and it increases their score

This commit is contained in:
2014-06-29 12:13:02 -07:00
parent a7eb935f54
commit d23d9969f7
4 changed files with 45 additions and 7 deletions

View File

@@ -621,7 +621,7 @@ var AISprite = function(game, x, y, key, frame) {
this.carries_light = parseBoolean(this.carries_light);
this.sprite_has_treasure = parseBoolean(this.sprite_has_treasure);
if ( this.sprite_has_treasure ) {
this.treasure = getRandomTreasure();
this.sprite_treasure = getRandomTreasure();
}
this.path_maximum_steps = parseInt(this.path_maximum_steps);

View File

@@ -30,6 +30,7 @@ STATE_MOVING = 1 << 10;
STATE_RUNNINGTOLIGHT = 1 << 11;
STATE_RUNNINGTOREPORT = 1 << 12;
STATE_LOOKINGFORTARGET = 1 << 13;
STATE_STEALING = 1 << 13;
STATES_AWARENESS = (STATE_UNAWARE | STATE_CONCERNED | STATE_ALERTED | STATE_LOSTHIM);
STATES_MOVEMENT = (STATE_MOVING | STATE_RUNNING);
@@ -58,3 +59,5 @@ SCORE_ALERTED = -50;
SCORE_CONCERNED = 0;
MAX_TREASURES = 384;
STEAL_DISTANCE = 16;

View File

@@ -82,6 +82,7 @@ GameState.prototype.create = function()
this.camera.follow(player, Phaser.Camera.FOLLOW_TOPDOWN);
controls = game.input.keyboard.createCursorKeys();
controls.steal = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
this.effectSprites = game.add.group();
this.map.createFromObjects('EffectSprites', 5, 'player', 0, true, false, this.effectSprites, EffectSprite);
@@ -215,6 +216,10 @@ GameState.prototype.check_input = function()
velocityMod = 0;
var newstate = 0;
if ( controls.steal.justReleased() == true ) {
addState(player, STATE_STEALING);
}
if ( controls.up.isDown) {
if ( controls.up.shiftKey ) {
newstate = (STATE_FACE_UP | STATE_MOVING | STATE_RUNNING);
@@ -240,7 +245,7 @@ GameState.prototype.check_input = function()
newstate = (STATE_FACE_RIGHT | STATE_MOVING );
}
} else {
newstate = STATE_NONE;
newstate = getFaceState(player);
}
setMovingState(player, newstate);
@@ -301,9 +306,7 @@ GameState.prototype.update = function()
return;
if ( x.canSeeSprite(player, false) == true ) {
x.lastSawPlayerAt = new Phaser.Sprite(game, player.x, player.y, null);
if ( this.physics.arcade.collide(x, player) ) {
x.setAwarenessEffect(STATE_ALERTED);
} else if ( player.lightmeter >= x.sprite_can_see_lightmeter ) {
if ( player.lightmeter >= x.sprite_can_see_lightmeter ) {
x.setAwarenessEffect(STATE_ALERTED);
} else {
x.setAwarenessEffect(STATE_CONCERNED);
@@ -318,7 +321,39 @@ GameState.prototype.update = function()
x.setAwarenessEffect(STATE_UNAWARE);
}
}
this.physics.arcade.collide(x, player);
if ( this.physics.arcade.collide(x, player) == true )
x.setAwarenessEffect(STATE_ALERTED);
if ( hasState(player, STATE_STEALING) == true ) {
delState(player, STATE_STEALING);
var prevpos = player.body.position;
player.body.position = new Phaser.Point();
player.body.x = prevpos.x;
player.body.y = prevpos.y;
switch ( getFaceState(player) ) {
case STATE_FACE_LEFT: {
player.body.x -= STEAL_DISTANCE;
break;
}
case STATE_FACE_RIGHT: {
player.body.x += STEAL_DISTANCE;
break;
}
case STATE_FACE_DOWN: {
player.body.y += STEAL_DISTANCE;
break;
}
case STATE_FACE_UP: {
player.body.y -= STEAL_DISTANCE;
break;
}
}
if ( this.physics.arcade.collide(x, player) == true ) {
x.sprite_has_treasure = false;
player.score += moonlightTreasures[x.sprite_treasure]['value'];
x.sprite_treasure = null;
}
player.body.position = prevpos;
}
}
this.effectSprites.forEach(_inner_collide, this);

View File

@@ -252,7 +252,7 @@ function setSpriteMovement(spr, velocity)
velocity = ( typeof velocity == undefined ? velocity : [SPEED_WALKING,
SPEED_RUNNING] );
spr.body.setSize(16, 16, 8, 16);
//spr.body.setSize(16, 16, 8, 16);
if ( hasState(spr, STATE_RUNNING) ) {
if ( velocity !== false )