2022-05-25 15:32:53 +02:00
|
|
|
package Entity;
|
|
|
|
|
2022-06-07 21:35:13 +02:00
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
import com.badlogic.gdx.Input;
|
|
|
|
import com.badlogic.gdx.maps.tiled.TiledMapTile;
|
2022-06-01 16:47:53 +02:00
|
|
|
import com.badlogic.gdx.math.Vector2;
|
|
|
|
|
2022-06-07 21:35:13 +02:00
|
|
|
import Control.Controller;
|
2022-06-09 21:07:13 +02:00
|
|
|
import Main.PokeMudry;
|
2022-06-07 21:35:13 +02:00
|
|
|
import Screen.ScreenMap;
|
|
|
|
|
2022-05-25 15:32:53 +02:00
|
|
|
public class Player extends Character{
|
2022-06-01 16:47:53 +02:00
|
|
|
|
|
|
|
private int xp;
|
|
|
|
|
2022-06-10 16:39:50 +02:00
|
|
|
public Player(int x, int y, String map) {
|
|
|
|
super("Player", x, y, "lumberjack_sheet32", map);
|
2022-06-01 16:47:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void addXp(int xp){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-07 21:35:13 +02:00
|
|
|
public void manageEntity(ScreenMap sm, Controller c) {
|
|
|
|
|
|
|
|
// Do nothing if hero is already moving
|
|
|
|
if (!isMoving()) {
|
|
|
|
|
|
|
|
// Compute direction and next cell
|
|
|
|
Vector<TiledMapTile> nextCell = new Vector<>();
|
|
|
|
Player.Direction goalDirection = Player.Direction.NULL;
|
2022-06-09 21:07:13 +02:00
|
|
|
Vector2 nextPos = position;
|
2022-06-07 21:35:13 +02:00
|
|
|
|
|
|
|
if (c.keyStatus.get(Input.Keys.RIGHT)) {
|
|
|
|
goalDirection = Player.Direction.RIGHT;
|
|
|
|
nextCell = sm.getTile(getPosition(), 1, 0);
|
2022-06-09 21:07:13 +02:00
|
|
|
nextPos.x+=sm.tileWidth;
|
2022-06-07 21:35:13 +02:00
|
|
|
} else if (c.keyStatus.get(Input.Keys.LEFT)) {
|
|
|
|
goalDirection = Player.Direction.LEFT;
|
|
|
|
nextCell = sm.getTile(getPosition(), -1, 0);
|
2022-06-09 21:07:13 +02:00
|
|
|
nextPos.x-=sm.tileWidth;
|
2022-06-07 21:35:13 +02:00
|
|
|
} else if (c.keyStatus.get(Input.Keys.UP)) {
|
|
|
|
goalDirection = Player.Direction.UP;
|
|
|
|
nextCell = sm.getTile(getPosition(), 0, 1);
|
2022-06-09 21:07:13 +02:00
|
|
|
nextPos.y+=sm.tileHeight;
|
2022-06-07 21:35:13 +02:00
|
|
|
} else if (c.keyStatus.get(Input.Keys.DOWN)) {
|
|
|
|
goalDirection = Player.Direction.DOWN;
|
|
|
|
nextCell = sm.getTile(getPosition(), 0, -1);
|
2022-06-09 21:07:13 +02:00
|
|
|
nextPos.y-=sm.tileHeight;
|
2022-06-07 21:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Is the move valid ?
|
|
|
|
if (sm.isWalkable(nextCell)) {
|
2022-06-10 16:39:50 +02:00
|
|
|
|
2022-06-09 21:07:13 +02:00
|
|
|
if (enemy(sm, nextPos)) {
|
|
|
|
System.out.println("It's a enemy !!");
|
|
|
|
} else {
|
|
|
|
setSpeed(sm.getSpeed(nextCell));
|
|
|
|
go(goalDirection);
|
|
|
|
}
|
2022-06-07 21:35:13 +02:00
|
|
|
} else {
|
|
|
|
// Face the wall
|
|
|
|
turn(goalDirection);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(sm.isDoor(getPosition())){
|
|
|
|
String nMap = null;
|
|
|
|
Integer x = null;
|
|
|
|
Integer y = null;
|
|
|
|
try {
|
|
|
|
nMap = ScreenMap.Door.nextMap;
|
|
|
|
x = ScreenMap.Door.nextX;
|
|
|
|
y = ScreenMap.Door.nextY;
|
|
|
|
} catch (Exception e) { }
|
|
|
|
ScreenMap.Door.reset();
|
|
|
|
if (nMap == null || x == null || y == null) return;
|
2022-06-10 16:39:50 +02:00
|
|
|
map = nMap;
|
2022-06-07 21:35:13 +02:00
|
|
|
setPosition(x*sm.tileWidth, y*sm.tileHeight);
|
|
|
|
System.out.println("Go to: " + sm.map + " in " + x + " x " + y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-09 21:07:13 +02:00
|
|
|
private boolean enemy(ScreenMap sm, Vector2 nextPos) {
|
|
|
|
Vector<Enemy> enemies = PokeMudry.getEnemies();
|
|
|
|
for (Enemy enemy : enemies) {
|
|
|
|
boolean bMap = sm.map.equals(enemy.getMap());
|
|
|
|
int pX = (int) nextPos.x/sm.tileWidth;
|
|
|
|
int pY = (int) nextPos.y/sm.tileHeight;
|
|
|
|
int eX = (int) enemy.position.x/sm.tileWidth;
|
|
|
|
int eY = (int) enemy.position.y/sm.tileHeight;
|
|
|
|
//System.out.println("Player: " + pX + " x " + pY + " - Enemy: " + eX + " x " + eY);
|
|
|
|
if(bMap && pX==eX && pY==eY) return true;
|
|
|
|
}
|
2022-06-08 20:08:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void move(int x, int y){
|
2022-06-01 16:47:53 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void move(Vector2 vMove){
|
|
|
|
move((int)vMove.x, (int)vMove.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void removedPv(int pv) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
2022-05-25 15:32:53 +02:00
|
|
|
}
|