mirror of
https://github.com/Klagarge/PokeHES.git
synced 2024-11-26 19:13:27 +00:00
detect enemy
This commit is contained in:
parent
4c47120c40
commit
1466ba041a
@ -197,8 +197,8 @@
|
|||||||
"scale": 0.75,
|
"scale": 0.75,
|
||||||
"selectedLayer": 1,
|
"selectedLayer": 1,
|
||||||
"viewCenter": {
|
"viewCenter": {
|
||||||
"x": 640.6666666666667,
|
"x": 640,
|
||||||
"y": 640.6666666666666
|
"y": 640
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"desert.tmx#Desert": {
|
"desert.tmx#Desert": {
|
||||||
@ -212,8 +212,8 @@
|
|||||||
"scale": 1.5,
|
"scale": 1.5,
|
||||||
"selectedLayer": 1,
|
"selectedLayer": 1,
|
||||||
"viewCenter": {
|
"viewCenter": {
|
||||||
"x": 160.33333333333331,
|
"x": 159.33333333333331,
|
||||||
"y": 160.33333333333331
|
"y": 160.66666666666663
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test.tmx#test": {
|
"test.tmx#test": {
|
||||||
@ -227,8 +227,8 @@
|
|||||||
"scale": 1,
|
"scale": 1,
|
||||||
"selectedLayer": 4,
|
"selectedLayer": 4,
|
||||||
"viewCenter": {
|
"viewCenter": {
|
||||||
"x": 320.5,
|
"x": 351,
|
||||||
"y": 159.5
|
"y": 196
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test_couloir.tmx#Dungeon_Tileset": {
|
"test_couloir.tmx#Dungeon_Tileset": {
|
||||||
|
@ -7,6 +7,7 @@ import com.badlogic.gdx.maps.tiled.TiledMapTile;
|
|||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
import Control.Controller;
|
import Control.Controller;
|
||||||
|
import Main.PokeMudry;
|
||||||
import Screen.ScreenMap;
|
import Screen.ScreenMap;
|
||||||
|
|
||||||
public class Player extends Character{
|
public class Player extends Character{
|
||||||
@ -29,25 +30,34 @@ public class Player extends Character{
|
|||||||
// Compute direction and next cell
|
// Compute direction and next cell
|
||||||
Vector<TiledMapTile> nextCell = new Vector<>();
|
Vector<TiledMapTile> nextCell = new Vector<>();
|
||||||
Player.Direction goalDirection = Player.Direction.NULL;
|
Player.Direction goalDirection = Player.Direction.NULL;
|
||||||
|
Vector2 nextPos = position;
|
||||||
|
|
||||||
if (c.keyStatus.get(Input.Keys.RIGHT)) {
|
if (c.keyStatus.get(Input.Keys.RIGHT)) {
|
||||||
goalDirection = Player.Direction.RIGHT;
|
goalDirection = Player.Direction.RIGHT;
|
||||||
nextCell = sm.getTile(getPosition(), 1, 0);
|
nextCell = sm.getTile(getPosition(), 1, 0);
|
||||||
|
nextPos.x+=sm.tileWidth;
|
||||||
} else if (c.keyStatus.get(Input.Keys.LEFT)) {
|
} else if (c.keyStatus.get(Input.Keys.LEFT)) {
|
||||||
goalDirection = Player.Direction.LEFT;
|
goalDirection = Player.Direction.LEFT;
|
||||||
nextCell = sm.getTile(getPosition(), -1, 0);
|
nextCell = sm.getTile(getPosition(), -1, 0);
|
||||||
|
nextPos.x-=sm.tileWidth;
|
||||||
} else if (c.keyStatus.get(Input.Keys.UP)) {
|
} else if (c.keyStatus.get(Input.Keys.UP)) {
|
||||||
goalDirection = Player.Direction.UP;
|
goalDirection = Player.Direction.UP;
|
||||||
nextCell = sm.getTile(getPosition(), 0, 1);
|
nextCell = sm.getTile(getPosition(), 0, 1);
|
||||||
|
nextPos.y+=sm.tileHeight;
|
||||||
} else if (c.keyStatus.get(Input.Keys.DOWN)) {
|
} else if (c.keyStatus.get(Input.Keys.DOWN)) {
|
||||||
goalDirection = Player.Direction.DOWN;
|
goalDirection = Player.Direction.DOWN;
|
||||||
nextCell = sm.getTile(getPosition(), 0, -1);
|
nextCell = sm.getTile(getPosition(), 0, -1);
|
||||||
|
nextPos.y-=sm.tileHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the move valid ?
|
// Is the move valid ?
|
||||||
if (sm.isWalkable(nextCell)) {
|
if (sm.isWalkable(nextCell)) {
|
||||||
setSpeed(sm.getSpeed(nextCell));
|
if (enemy(sm, nextPos)) {
|
||||||
go(goalDirection);
|
System.out.println("It's a enemy !!");
|
||||||
|
} else {
|
||||||
|
setSpeed(sm.getSpeed(nextCell));
|
||||||
|
go(goalDirection);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Face the wall
|
// Face the wall
|
||||||
turn(goalDirection);
|
turn(goalDirection);
|
||||||
@ -72,11 +82,17 @@ public class Player extends Character{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean enemy() {
|
private boolean enemy(ScreenMap sm, Vector2 nextPos) {
|
||||||
//Vector<Enemy> enemies = PokeMudry.getEnemies;
|
Vector<Enemy> enemies = PokeMudry.getEnemies();
|
||||||
//for (Enemy enemy : enemies) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,17 +13,9 @@ import ch.hevs.gdx2d.desktop.PortableApplication;
|
|||||||
import ch.hevs.gdx2d.lib.GdxGraphics;
|
import ch.hevs.gdx2d.lib.GdxGraphics;
|
||||||
|
|
||||||
public class PokeMudry extends PortableApplication {
|
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 ScreenPlayer sp;
|
||||||
private Controller controller;
|
private Controller controller;
|
||||||
//private Player p1;
|
|
||||||
private static Vector<Enemy> enemies = new Vector<>();
|
private static Vector<Enemy> enemies = new Vector<>();
|
||||||
private static Vector<Entity> entities = new Vector<>();
|
private static Vector<Entity> entities = new Vector<>();
|
||||||
|
|
||||||
@ -48,7 +40,7 @@ public class PokeMudry extends PortableApplication {
|
|||||||
controller.init();
|
controller.init();
|
||||||
entities.add((Entity) sp.p);
|
entities.add((Entity) sp.p);
|
||||||
enemies.add(new Enemy("Mudry", 10, 15, "lumberjack_sheet32", "desert"));
|
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) {
|
for (Enemy enemy : enemies) {
|
||||||
entities.add(enemy);
|
entities.add(enemy);
|
||||||
|
@ -2,8 +2,8 @@ package Main;
|
|||||||
|
|
||||||
public class Settings {
|
public class Settings {
|
||||||
|
|
||||||
public final boolean ANDROID = false;
|
public static final boolean ANDROID = false;
|
||||||
public final int PLAYERS = 1;
|
public static final int PLAYERS = 1;
|
||||||
public static final int TIME = 10; // number of minutes for kill all enemy
|
public static final int TIME = 10; // number of minutes for kill all enemy
|
||||||
|
|
||||||
public static final int SIDE = 800;
|
public static final int SIDE = 800;
|
||||||
|
Loading…
Reference in New Issue
Block a user