From 5c44b30cc6c205c09511e47a7ebd1bcebe6e76aa Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Mon, 10 Aug 2015 12:44:27 +0200 Subject: [PATCH] fixed a bug with vision and added new vegetable_size setting --- core/src/com/mygdx/game/Serializer.java | 1 + core/src/logic/Vegetable.java | 2 +- core/src/logic/World.java | 1 + core/src/logic/creatures/Eye.java | 22 ++++++++++++++++++---- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/core/src/com/mygdx/game/Serializer.java b/core/src/com/mygdx/game/Serializer.java index 8ae7667..e5d5196 100644 --- a/core/src/com/mygdx/game/Serializer.java +++ b/core/src/com/mygdx/game/Serializer.java @@ -183,6 +183,7 @@ public class Serializer { + "nMutatedConnections = 0.5\n" + "number_of_creatures = 25.0\n" + "draw_sight_lines = 0.0\n" + + "vegetable_size = 5\n" + "creature_max_hp = 100\n" + "creature_fov = 1.5\n" + "creature_hp_decay = 0.5\n" diff --git a/core/src/logic/Vegetable.java b/core/src/logic/Vegetable.java index cf1eaca..51a8416 100644 --- a/core/src/logic/Vegetable.java +++ b/core/src/logic/Vegetable.java @@ -9,7 +9,7 @@ import com.mygdx.game.Game; */ public class Vegetable extends Element { - public static final float default_radius = 5; + public static float default_radius = 5; private float decayRate = 0; public Vegetable(float x, float y) { diff --git a/core/src/logic/World.java b/core/src/logic/World.java index 356210e..b0bad0a 100644 --- a/core/src/logic/World.java +++ b/core/src/logic/World.java @@ -289,6 +289,7 @@ public class World implements Runnable { Eye.fov = options.get("creature_fov"); Eye.sightRange = options.get("creature_sight_range"); Torso.hpDecay = options.get("creature_hp_decay"); + Vegetable.default_radius = options.get("vegetable_size"); Creature.hpForAttacking = options.get("creature_hp_for_attacking"); Creature.hpForEatingPlants = options.get("creature_hp_for_eating_plants"); Creature.pointsForAttacking = options.get("creature_points_for_attacking"); diff --git a/core/src/logic/creatures/Eye.java b/core/src/logic/creatures/Eye.java index fc9fbbc..ee91980 100644 --- a/core/src/logic/creatures/Eye.java +++ b/core/src/logic/creatures/Eye.java @@ -18,7 +18,8 @@ import logic.Vegetable; public class Eye extends BodyPart { private Sight sights[]; - private int seen; + private int farthest = -1, seen; + private float farthestDistance = 0; public static float fov = 2, sightRange = 30; public Eye(int nSights, float angle, Creature creature) { @@ -54,19 +55,32 @@ public class Eye extends BodyPart { j += 6; } seen = 0; + farthest = -1; + farthestDistance = 0; sights = new Sight[sights.length]; return ret; } - @Override public void interactWithElement(Element e, float distance, float angle) { - if (e != creature && distance < sightRange && Math.abs(angle) < fov / 2) { + if (e != creature && distance < sightRange && (distance < farthestDistance || seen < sights.length) && Math.abs(angle) < fov / 2) { if (seen < sights.length) { sights[seen] = new Sight(e, distance, angle); - Log.log(Log.DEBUG, "Saw " + e.getClass().getName() + " at " + distance + " with relative angle " + angle); + Log.log(Log.DEBUG,"Adding Sight number "+seen); seen++; + } else { + Log.log(Log.DEBUG,"Substituting Farthest"); + sights[farthest] = new Sight(e, distance, angle); + farthest = -1; } + for (int i = 0; i < seen; i++) { + Sight s = sights[i]; + if (s.getDistance() > farthestDistance || farthest < 0) { + farthestDistance = s.getDistance(); + farthest = i; + } + } + Log.log(Log.DEBUG,"Seen " + seen + "/" + sights.length + ". Farthest is now " + farthest + " at " + farthestDistance); } }