mirror of
https://github.com/fazo96/AIrium.git
synced 2025-01-10 09:34:20 +01:00
some code fixes
This commit is contained in:
parent
cc0ef33977
commit
4f55625056
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package com.mygdx.game;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author fazo
|
|
||||||
*/
|
|
||||||
public class Camera {
|
|
||||||
|
|
||||||
private int x, y, speed;
|
|
||||||
private float scale = 1;
|
|
||||||
|
|
||||||
public Camera() {
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
speed = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void translate(int deltaX, int deltaY) {
|
|
||||||
x += deltaX;
|
|
||||||
y += deltaY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void zoomOut() {
|
|
||||||
scale -= 0.001f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void zoomIn() {
|
|
||||||
scale += 0.001f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setX(int x) {
|
|
||||||
this.x = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setY(int y) {
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSpeed() {
|
|
||||||
return speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpeed(int speed) {
|
|
||||||
this.speed = speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getScale() {
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScale(float scale) {
|
|
||||||
this.scale = scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -30,22 +30,22 @@ public class Game extends ApplicationAdapter {
|
|||||||
world.newGen(false);
|
world.newGen(false);
|
||||||
}
|
}
|
||||||
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
|
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
|
||||||
shaper.translate(-cameraSpeed, 0,0);
|
shaper.translate(-cameraSpeed, 0, 0);
|
||||||
}
|
}
|
||||||
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
|
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
|
||||||
shaper.translate(cameraSpeed, 0,0);
|
shaper.translate(cameraSpeed, 0, 0);
|
||||||
}
|
}
|
||||||
if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
|
if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
|
||||||
shaper.translate(0, -cameraSpeed,0);
|
shaper.translate(0, -cameraSpeed, 0);
|
||||||
}
|
}
|
||||||
if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
|
if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
|
||||||
shaper.translate(0, cameraSpeed,0);
|
shaper.translate(0, cameraSpeed, 0);
|
||||||
}
|
}
|
||||||
if (Gdx.input.isKeyJustPressed(Input.Keys.PLUS)) {
|
if (Gdx.input.isKeyJustPressed(Input.Keys.PLUS)) {
|
||||||
shaper.scale(0.3f, 0.3f, 1);
|
shaper.scale(0.5f, 0.5f, 1);
|
||||||
}
|
}
|
||||||
if (Gdx.input.isKeyJustPressed(Input.Keys.MINUS)) {
|
if (Gdx.input.isKeyJustPressed(Input.Keys.MINUS)) {
|
||||||
shaper.scale(1f, 1f, 1);
|
shaper.scale(1.5f, 1.5f, 1);
|
||||||
}
|
}
|
||||||
// Update
|
// Update
|
||||||
world.update();
|
world.update();
|
||||||
@ -55,7 +55,12 @@ public class Game extends ApplicationAdapter {
|
|||||||
shaper.setColor(1, 1, 1, 1);
|
shaper.setColor(1, 1, 1, 1);
|
||||||
shaper.begin(ShapeRenderer.ShapeType.Line);
|
shaper.begin(ShapeRenderer.ShapeType.Line);
|
||||||
for (Element e : world.getElements()) {
|
for (Element e : world.getElements()) {
|
||||||
e.render(shaper);
|
try {
|
||||||
|
e.render(shaper);
|
||||||
|
} catch (ArrayIndexOutOfBoundsException ex) {
|
||||||
|
// No idea why it happens, but it's rendering so meh
|
||||||
|
//Log.log(Log.ERROR, ex+"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
shaper.setColor(0.3f, 0.3f, 0.3f, 1);
|
shaper.setColor(0.3f, 0.3f, 0.3f, 1);
|
||||||
shaper.rect(0, 0, world.getWidth(), world.getHeight());
|
shaper.rect(0, 0, world.getWidth(), world.getHeight());
|
||||||
|
@ -31,7 +31,7 @@ public class Creature extends Element {
|
|||||||
sightRange = 100;
|
sightRange = 100;
|
||||||
fov = (float) Math.PI / 2.5f;
|
fov = (float) Math.PI / 2.5f;
|
||||||
fitness = 0;
|
fitness = 0;
|
||||||
brain = new Brain(4, 3, 1, 6);
|
brain = new Brain(4, 3, 1, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,8 +18,8 @@ import logic.neural.Brain;
|
|||||||
*/
|
*/
|
||||||
public class World {
|
public class World {
|
||||||
|
|
||||||
public static final int creatPerGen = 10;
|
|
||||||
private int width, height, generation = 0;
|
private int width, height, generation = 0;
|
||||||
|
private final int nPlants, creatPerGen;
|
||||||
public ArrayList<Element> elements;
|
public ArrayList<Element> elements;
|
||||||
public ArrayList<Creature> creatures;
|
public ArrayList<Creature> creatures;
|
||||||
public ArrayList<Creature> graveyard;
|
public ArrayList<Creature> graveyard;
|
||||||
@ -31,6 +31,8 @@ public class World {
|
|||||||
this.height = height;
|
this.height = height;
|
||||||
elements = new ArrayList();
|
elements = new ArrayList();
|
||||||
creatures = new ArrayList();
|
creatures = new ArrayList();
|
||||||
|
creatPerGen = Math.min(Math.round(width * height / 20000), 50);
|
||||||
|
nPlants = Math.round(width * height / 5000);
|
||||||
plants = new ArrayList();
|
plants = new ArrayList();
|
||||||
deadPlants = new ArrayList();
|
deadPlants = new ArrayList();
|
||||||
graveyard = new ArrayList();
|
graveyard = new ArrayList();
|
||||||
@ -47,7 +49,7 @@ public class World {
|
|||||||
// All dead, next gen
|
// All dead, next gen
|
||||||
newGen(false);
|
newGen(false);
|
||||||
}
|
}
|
||||||
while (plants.size() < (width*height)/5000) {
|
while (plants.size() < nPlants) {
|
||||||
spawnVegetable();
|
spawnVegetable();
|
||||||
}
|
}
|
||||||
for (Element e : elements) {
|
for (Element e : elements) {
|
||||||
|
@ -7,6 +7,9 @@ import com.mygdx.game.Game;
|
|||||||
public class DesktopLauncher {
|
public class DesktopLauncher {
|
||||||
public static void main (String[] arg) {
|
public static void main (String[] arg) {
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||||
|
config.height = 600;
|
||||||
|
config.width = 800;
|
||||||
|
config.resizable = false;
|
||||||
new LwjglApplication(new Game(), config);
|
new LwjglApplication(new Game(), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user