1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2024-11-26 19:13:27 +00:00

detect enemy

This commit is contained in:
Rémi Heredero 2022-06-09 21:07:13 +02:00
parent 4c47120c40
commit 1466ba041a
4 changed files with 32 additions and 24 deletions

View File

@ -197,8 +197,8 @@
"scale": 0.75,
"selectedLayer": 1,
"viewCenter": {
"x": 640.6666666666667,
"y": 640.6666666666666
"x": 640,
"y": 640
}
},
"desert.tmx#Desert": {
@ -212,8 +212,8 @@
"scale": 1.5,
"selectedLayer": 1,
"viewCenter": {
"x": 160.33333333333331,
"y": 160.33333333333331
"x": 159.33333333333331,
"y": 160.66666666666663
}
},
"test.tmx#test": {
@ -227,8 +227,8 @@
"scale": 1,
"selectedLayer": 4,
"viewCenter": {
"x": 320.5,
"y": 159.5
"x": 351,
"y": 196
}
},
"test_couloir.tmx#Dungeon_Tileset": {

View File

@ -7,6 +7,7 @@ import com.badlogic.gdx.maps.tiled.TiledMapTile;
import com.badlogic.gdx.math.Vector2;
import Control.Controller;
import Main.PokeMudry;
import Screen.ScreenMap;
public class Player extends Character{
@ -29,25 +30,34 @@ public class Player extends Character{
// Compute direction and next cell
Vector<TiledMapTile> nextCell = new Vector<>();
Player.Direction goalDirection = Player.Direction.NULL;
Vector2 nextPos = position;
if (c.keyStatus.get(Input.Keys.RIGHT)) {
goalDirection = Player.Direction.RIGHT;
nextCell = sm.getTile(getPosition(), 1, 0);
nextPos.x+=sm.tileWidth;
} else if (c.keyStatus.get(Input.Keys.LEFT)) {
goalDirection = Player.Direction.LEFT;
nextCell = sm.getTile(getPosition(), -1, 0);
nextPos.x-=sm.tileWidth;
} else if (c.keyStatus.get(Input.Keys.UP)) {
goalDirection = Player.Direction.UP;
nextCell = sm.getTile(getPosition(), 0, 1);
nextPos.y+=sm.tileHeight;
} else if (c.keyStatus.get(Input.Keys.DOWN)) {
goalDirection = Player.Direction.DOWN;
nextCell = sm.getTile(getPosition(), 0, -1);
nextPos.y-=sm.tileHeight;
}
// Is the move valid ?
if (sm.isWalkable(nextCell)) {
setSpeed(sm.getSpeed(nextCell));
go(goalDirection);
if (enemy(sm, nextPos)) {
System.out.println("It's a enemy !!");
} else {
setSpeed(sm.getSpeed(nextCell));
go(goalDirection);
}
} else {
// Face the wall
turn(goalDirection);
@ -72,11 +82,17 @@ public class Player extends Character{
}
}
private boolean enemy() {
//Vector<Enemy> enemies = PokeMudry.getEnemies;
//for (Enemy enemy : enemies) {
//}
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;
}
return false;
}

View File

@ -13,17 +13,9 @@ import ch.hevs.gdx2d.desktop.PortableApplication;
import ch.hevs.gdx2d.lib.GdxGraphics;
public class PokeMudry extends PortableApplication {
public final boolean ANDROID = false;
public final int PLAYERS = 1;
public static final int TIME = 10; // number of minutes for kill all enemy
public static final int HEIGHT = 800;
public static final int width = 800;
private ScreenPlayer sp;
private Controller controller;
//private Player p1;
private static Vector<Enemy> enemies = new Vector<>();
private static Vector<Entity> entities = new Vector<>();
@ -48,7 +40,7 @@ public class PokeMudry extends PortableApplication {
controller.init();
entities.add((Entity) sp.p);
enemies.add(new Enemy("Mudry", 10, 15, "lumberjack_sheet32", "desert"));
enemies.add(new Enemy("Pignat", 12, 15, "lumberjack_sheet32", "desert"));
enemies.add(new Enemy("Pignat", 5, 1, "lumberjack_sheet32", "test"));
for (Enemy enemy : enemies) {
entities.add(enemy);

View File

@ -2,8 +2,8 @@ package Main;
public class Settings {
public final boolean ANDROID = false;
public final int PLAYERS = 1;
public static final boolean ANDROID = false;
public static final int PLAYERS = 1;
public static final int TIME = 10; // number of minutes for kill all enemy
public static final int SIDE = 800;