archer bewegt sich random

TODO: movementX u. Y aus Controller in Entity umlagern
master
GammelJan 6 years ago
parent f558d60fe7
commit 1141b109bc

@ -14,6 +14,7 @@ import com.dungeoncrawler.view.View;
import com.dungeoncrawler.model.Dungeon;
import com.dungeoncrawler.model.entities.Player;
import com.dungeoncrawler.model.entities.Archer;
import com.badlogic.gdx.utils.Timer;
public class Controller extends ApplicationAdapter implements InputProcessor{
SpriteBatch batch;
@ -23,7 +24,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
Archer a;
float movementX = 0f;
float movementY = 0f;
Timer t;
@Override
public void create(){
@ -33,22 +34,18 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
d = new Dungeon(p);
a = new Archer(500, 200, 1);
Gdx.input.setInputProcessor(this);
t = new Timer();
t.scheduleTask(new Timer.Task() {
@Override
public void run() {
a.rdmMove();
}
},0,0.1f);
}
@Override
public void render(){
switch((int) (Math.random() * 5)){
case 0: //left
a.move(-3,0);
case 1: //right
a.move(3,0);
case 2: //up
a.move(0,3);
case 3: //down
a.move(0,-3);
}
v.render(batch, movementX ,movementY, a.getxPos(), a.getyPos());
}
@Override

@ -1,7 +1,5 @@
package com.dungeoncrawler.model;
import com.dungeoncrawler.model.entities.Archer;
import com.dungeoncrawler.model.entities.Player;
import com.dungeoncrawler.model.entities.Swordsman;
public abstract class Entity {
@ -11,13 +9,18 @@ public abstract class Entity {
protected int maxhp;
protected int dmg;
protected int lvl;
protected int movementX;
protected int movementY;
public Entity(int xPos, int yPos, int lvl){
this.xPos = xPos;
this.yPos = yPos;
this.lvl = lvl;
this.movementX = 0;
this.movementY = 0;
}
public void attack(){
@ -33,8 +36,25 @@ public abstract class Entity {
yPos = yPos + movementY;
}
public void rdmMove(){
switch((int) (Math.random() * 5)){
case 0: //left
move(-3 , 0);
break;
case 1: //right
move(3 , 0);
break;
case 2: //up
move(0 , 3);
break;
case 3: //down
move(0 , -3);
break;
}
}
public int getxPos() {
return xPos;
}

@ -14,7 +14,7 @@ import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
import com.badlogic.gdx.utils.Timer;
/**
*
* @author jonathan

@ -140,6 +140,7 @@ public class View {
player.setY(player.getY()+y);
archer.setX(archerX);
archer.setY(archerY);
if(x == 3f){
trechts.start();
if(player.isFlipX() == true){

Loading…
Cancel
Save