From cc0ef3397748e4f63214fc19b70855c70f99150f Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Thu, 2 Jul 2015 14:25:49 +0200 Subject: [PATCH] they evolve! for a while.. --- core/src/com/mygdx/game/Camera.java | 17 +++++++++++++++++ core/src/com/mygdx/game/Game.java | 23 ++++++++++++----------- core/src/logic/Creature.java | 10 +++++----- core/src/logic/Vegetable.java | 2 +- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/core/src/com/mygdx/game/Camera.java b/core/src/com/mygdx/game/Camera.java index fd8d753..a57cc9f 100644 --- a/core/src/com/mygdx/game/Camera.java +++ b/core/src/com/mygdx/game/Camera.java @@ -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; + } + } diff --git a/core/src/com/mygdx/game/Game.java b/core/src/com/mygdx/game/Game.java index 6d4eec8..3dabd9f 100644 --- a/core/src/com/mygdx/game/Game.java +++ b/core/src/com/mygdx/game/Game.java @@ -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; } diff --git a/core/src/logic/Creature.java b/core/src/logic/Creature.java index ee54bcd..16e7554 100644 --- a/core/src/logic/Creature.java +++ b/core/src/logic/Creature.java @@ -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() { diff --git a/core/src/logic/Vegetable.java b/core/src/logic/Vegetable.java index 5f58312..e0c6ac3 100644 --- a/core/src/logic/Vegetable.java +++ b/core/src/logic/Vegetable.java @@ -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()); } }