Close #19 : Player lightmeter bases off the ambient light of the world
This commit is contained in:
@@ -325,100 +325,6 @@
|
||||
"width":0,
|
||||
"x":158,
|
||||
"y":830
|
||||
},
|
||||
{
|
||||
"gid":3544,
|
||||
"height":0,
|
||||
"name":"BigTopCustomer2",
|
||||
"properties":
|
||||
{
|
||||
"sprite_group":"townsfolk-male",
|
||||
"sprite_name":"townsfolk-male-3"
|
||||
},
|
||||
"type":"AI",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":613,
|
||||
"y":581
|
||||
},
|
||||
{
|
||||
"gid":3544,
|
||||
"height":0,
|
||||
"name":"BigTopCustomer2",
|
||||
"properties":
|
||||
{
|
||||
"sprite_canmove":"true",
|
||||
"sprite_group":"townsfolk-female",
|
||||
"sprite_name":"townsfolk-female-2"
|
||||
},
|
||||
"type":"AI",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":771,
|
||||
"y":610
|
||||
},
|
||||
{
|
||||
"gid":3544,
|
||||
"height":0,
|
||||
"name":"HousingPerson1",
|
||||
"properties":
|
||||
{
|
||||
"sprite_canmove":"true",
|
||||
"sprite_group":"townsfolk-female",
|
||||
"sprite_name":"townsfolk-female-4"
|
||||
},
|
||||
"type":"AI",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":564,
|
||||
"y":678
|
||||
},
|
||||
{
|
||||
"gid":3544,
|
||||
"height":0,
|
||||
"name":"BigTopCustomer2",
|
||||
"properties":
|
||||
{
|
||||
"sprite_group":"townsfolk-male",
|
||||
"sprite_name":"townsfolk-male-3"
|
||||
},
|
||||
"type":"AI",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":660,
|
||||
"y":664
|
||||
},
|
||||
{
|
||||
"gid":3544,
|
||||
"height":0,
|
||||
"name":"BigTopCustomer2",
|
||||
"properties":
|
||||
{
|
||||
"sprite_canmove":"true",
|
||||
"sprite_group":"townsfolk-female",
|
||||
"sprite_name":"townsfolk-female-2"
|
||||
},
|
||||
"type":"AI",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":718,
|
||||
"y":699
|
||||
},
|
||||
{
|
||||
"gid":3544,
|
||||
"height":0,
|
||||
"name":"HousingPerson1",
|
||||
"properties":
|
||||
{
|
||||
"sprite_canmove":"true",
|
||||
"sprite_group":"townsfolk-female",
|
||||
"sprite_name":"townsfolk-female-4"
|
||||
},
|
||||
"type":"AI",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":623,
|
||||
"y":737
|
||||
}],
|
||||
"opacity":1,
|
||||
"type":"objectgroup",
|
||||
|
||||
@@ -22,6 +22,7 @@ STATE_MOVING = 1 << 10;
|
||||
|
||||
STATE_RUNNINGTOLIGHT = 1 << 11;
|
||||
STATE_RUNNINGTOREPORT = 1 << 12;
|
||||
STATE_LOOKINGFORTARGET = 1 << 13;
|
||||
|
||||
STATES_AWARENESS = (STATE_UNAWARE | STATE_CONCERNED | STATE_ALERTED | STATE_LOSTHIM);
|
||||
STATES_MOVEMENT = (STATE_MOVING | STATE_RUNNING);
|
||||
|
||||
@@ -82,7 +82,7 @@ GameState.prototype.create = function()
|
||||
|
||||
this.shadowTexture = game.add.bitmapData(game.world.width, game.world.height);
|
||||
// drop this lower to make the map darker
|
||||
this.shadowTextureColor = 'rgb(60, 60, 60)';
|
||||
this.shadowTextureColor = [60, 60, 60];
|
||||
this.shadowSprite = game.add.image(0, 0, this.shadowTexture);
|
||||
|
||||
this.shadowSprite.blendMode = Phaser.blendModes.MULTIPLY;
|
||||
@@ -125,7 +125,8 @@ GameState.prototype.create = function()
|
||||
}
|
||||
|
||||
GameState.prototype.updateShadowTexture = function() {
|
||||
this.shadowTexture.context.fillStyle = this.shadowTextureColor;
|
||||
var cv = this.shadowTextureColor;
|
||||
this.shadowTexture.context.fillStyle = "rgb(" + cv[0] + "," + cv[1] + "," + cv[2] + ")";
|
||||
this.shadowTexture.context.fillRect(0, 0, game.world.width, game.world.height);
|
||||
|
||||
this.staticLights.forEach(function(light) {
|
||||
@@ -202,6 +203,7 @@ GameState.prototype.check_input = function()
|
||||
}
|
||||
|
||||
GameState.prototype.update_player_lightmeter = function() {
|
||||
player.lightmeter = (Number(array_average(this.shadowTextureColor)) / 255.0);
|
||||
lightValue = 0;
|
||||
this.staticLights.forEach(function(light) {
|
||||
var left = player.x;
|
||||
@@ -221,11 +223,9 @@ GameState.prototype.update_player_lightmeter = function() {
|
||||
lightValue = lv;
|
||||
}
|
||||
}, this)
|
||||
player.lightmeter = lightValue;
|
||||
this.lightbar_crop.width = Math.min(
|
||||
this.lightbar_image.width,
|
||||
((this.lightbar_image.width /2) + ((this.lightbar_image.width/2)* lightValue))
|
||||
);
|
||||
player.lightmeter += lightValue;
|
||||
player.lightmeter = Math.min(player.lightmeter, 1.0);
|
||||
this.lightbar_crop.width = ((this.lightbar_image.width) * player.lightmeter);
|
||||
this.lightbar.crop(this.lightbar_crop);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,13 @@ function array_unique(arr) {
|
||||
return a;
|
||||
}
|
||||
|
||||
function array_average(arr) {
|
||||
return arr.reduce(function (a,b) {
|
||||
return (a + b);
|
||||
}) / arr.length;
|
||||
}
|
||||
|
||||
|
||||
function stringSize(str, font)
|
||||
{
|
||||
var width = 0;
|
||||
|
||||
Reference in New Issue
Block a user