1
0
mirror of https://github.com/fazo96/AIrium.git synced 2025-01-10 09:34:20 +01:00

fixed a bug with vision and added new vegetable_size setting

This commit is contained in:
Enrico Fasoli 2015-08-10 12:44:27 +02:00
parent c56c24e99d
commit 5c44b30cc6
4 changed files with 21 additions and 5 deletions

View File

@ -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"

View File

@ -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) {

View File

@ -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");

View File

@ -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);
}
}