Commit 7cdf3048 authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

fix foodItemPool bug

parent a8f87bd5
......@@ -4,8 +4,6 @@ function FoodSprite(texture)
this.food_value = 0;
this.decay_rate = 0;
this.item_id = 0;
this.anchor.set(0.5);
this.textureRadius = 32;
this.tint = this.GetRandomTint();
}
......@@ -16,8 +14,12 @@ FoodSprite.prototype.SetData = function(decay_rate, food_id, pos_x, pos_y, value
this.decay_rate = decay_rate;
this.food_value = value;
this.item_id = food_id;
this.textureRadius = this.texture.width / 2;
this.anchor.set(0.5);
this.x = pos_x;
this.y = pos_y;
this.tint = this.GetRandomTint();
this.visible = true;
this.UpdateSize();
};
......
......@@ -105,21 +105,15 @@ GameVisualization.prototype.HandleTickMessage = function(frame_id)
this.snakes[snake_id].AnimateEat();
}
this.nextFoodDecayRow = (this.nextFoodDecayRow + 1) % 64;
if ((this.nextFoodDecayRow % 8) == 0)
{
for (let food_id in this.foodItems)
{
this.foodItems[food_id].Decay(8);
}
}
let nth = 16;
this.nextFoodDecayRow = (this.nextFoodDecayRow + 1) % nth;
if (this.nextFoodDecayRow == 0)
{
for (let food_id in this.foodItems)
{
let item = this.foodItems[food_id];
item.Decay(nth);
if (!item.visible)
{
delete this.foodItems[food_id];
......
......@@ -50,20 +50,20 @@ ParticleGeoMap.prototype.RemoveItem = function(item_id)
ParticleGeoMap.prototype.CleanUp = function()
{
for (let key in this._geoMap)
for (let container of this._geoMap)
{
let container = this._geoMap[key];
for (let i in container.children)
{
let child = container.children[i];
if (child.visible)
{
continue;
}
this.RemoveInvisibleFromContainer(container);
}
};
ParticleGeoMap.prototype.RemoveInvisibleFromContainer = function(container)
{
for (let child of container.children)
{
if (!child.visible)
{
let key = this._itemIdKeyMap[child.item_id];
delete this._itemIdKeyMap[key];
container.removeChild(child);
}
}
......
......@@ -184,7 +184,7 @@ Snake.prototype.AnimateEat = function()
if (dist < radius)
{
food.visible = false;
this._foodContainer.removeChild(food);
food.parent.removeChild(food);
}
let factor = (dist-food.speed) / dist;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment