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

they evolve! for a while..

This commit is contained in:
Enrico Fasoli 2015-07-02 14:25:49 +02:00
parent 54e5dbb30f
commit cc0ef33977
4 changed files with 35 additions and 17 deletions

View File

@ -12,6 +12,7 @@ package com.mygdx.game;
public class Camera {
private int x, y, speed;
private float scale = 1;
public Camera() {
x = 0;
@ -24,6 +25,14 @@ public class Camera {
y += deltaY;
}
public void zoomOut() {
scale -= 0.001f;
}
public void zoomIn() {
scale += 0.001f;
}
public int getX() {
return x;
}
@ -48,4 +57,12 @@ public class Camera {
this.speed = speed;
}
public float getScale() {
return scale;
}
public void setScale(float scale) {
this.scale = scale;
}
}

View File

@ -12,15 +12,14 @@ public class Game extends ApplicationAdapter {
private static Game game;
ShapeRenderer shaper;
private Camera camera;
private World world;
private float cameraSpeed = 5;
@Override
public void create() {
game = this;
world = new World(1920, 1080);
shaper = new ShapeRenderer();
camera = new Camera();
//shaper.setAutoShapeType(true);
}
@ -31,16 +30,22 @@ public class Game extends ApplicationAdapter {
world.newGen(false);
}
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
camera.translate(-camera.getSpeed(), 0);
shaper.translate(-cameraSpeed, 0,0);
}
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
camera.translate(1+camera.getSpeed(), 0);
shaper.translate(cameraSpeed, 0,0);
}
if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
camera.translate(0, -camera.getSpeed());
shaper.translate(0, -cameraSpeed,0);
}
if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
camera.translate(0, camera.getSpeed());
shaper.translate(0, cameraSpeed,0);
}
if (Gdx.input.isKeyJustPressed(Input.Keys.PLUS)) {
shaper.scale(0.3f, 0.3f, 1);
}
if (Gdx.input.isKeyJustPressed(Input.Keys.MINUS)) {
shaper.scale(1f, 1f, 1);
}
// Update
world.update();
@ -53,7 +58,7 @@ public class Game extends ApplicationAdapter {
e.render(shaper);
}
shaper.setColor(0.3f, 0.3f, 0.3f, 1);
shaper.rect(camera.getX(), camera.getY(), world.getWidth(), world.getHeight());
shaper.rect(0, 0, world.getWidth(), world.getHeight());
shaper.end();
}
@ -61,10 +66,6 @@ public class Game extends ApplicationAdapter {
return world;
}
public Camera getCamera() {
return camera;
}
public static Game get() {
return game;
}

View File

@ -28,8 +28,8 @@ public class Creature extends Element {
hp = 100;
speed = 0;//(float) Math.random() * 3;
rotSpeed = 0;//(float) Math.random() - 0.5f;
sightRange = 60;
fov = (float) Math.PI / 1.5f;
sightRange = 100;
fov = (float) Math.PI / 2.5f;
fitness = 0;
brain = new Brain(4, 3, 1, 6);
}
@ -114,7 +114,7 @@ public class Creature extends Element {
public void render(ShapeRenderer s) {
// Body
s.setColor(1 - (hp / 100), hp / 100, 0, 1);
s.circle(getX() + Game.get().getCamera().getX(), getY() + Game.get().getCamera().getY(), getSize());
s.circle(getX() , getY(), getSize());
// Eye
double relX = Math.cos(dir) * getSize(), relY = Math.sin(dir) * getSize();
s.setColor(1, 1, 1, 1);
@ -126,12 +126,12 @@ public class Creature extends Element {
s.setColor(0, c, 0, 1);
}
}
s.circle((float) relX + getX() + Game.get().getCamera().getX(), (float) relY + getY() + Game.get().getCamera().getY(), 3);
s.circle((float) relX + getX() , (float) relY + getY() , 3);
//FOV
float degrees = fov * 180f / (float) Math.PI;
float orient = dir * 180f / (float) Math.PI - degrees / 2;
s.setColor(0.3f, 0.3f, 0.3f, 1);
s.arc((float) relX + getX() + Game.get().getCamera().getX(), (float) relY + getY() + Game.get().getCamera().getY(), sightRange, orient, degrees);
s.arc((float) relX + getX() , (float) relY + getY() , sightRange, orient, degrees);
}
public Sight look() {

View File

@ -31,6 +31,6 @@ public class Vegetable extends Element {
@Override
public void render(ShapeRenderer s) {
s.setColor(1, 1, 1, 1);
s.circle(getX() + Game.get().getCamera().getX(), getY() + Game.get().getCamera().getY(), getSize());
s.circle(getX(), getY(), getSize());
}
}