mirror of
https://github.com/Klagarge/PokeHES.git
synced 2024-11-23 01:43:28 +00:00
done
This commit is contained in:
parent
5573b545e0
commit
3d05c1e5fa
@ -7,11 +7,13 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import ch.hevs.gdx2d.lib.GdxGraphics;
|
||||
|
||||
public class Enemy extends Character{
|
||||
private String map;
|
||||
|
||||
public FightData fightData;
|
||||
|
||||
public Enemy(String name, int x, int y, String img) {
|
||||
public Enemy(String name, int x, int y, String img, String map) {
|
||||
super(name, x, y, img);
|
||||
this.map = map;
|
||||
|
||||
turn(Character.Direction.DOWN);
|
||||
//generate the vector of fight
|
||||
@ -20,12 +22,17 @@ public class Enemy extends Character{
|
||||
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y){
|
||||
|
||||
public String getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setPosition(Vector2 vPosition){
|
||||
setPosition((int)vPosition.x, (int)vPosition.y);
|
||||
public void setPosition(int x, int y, String map){
|
||||
position.set(x, y);
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public void setPosition(Vector2 vPosition, String map){
|
||||
setPosition((int)vPosition.x, (int)vPosition.y, map);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,13 +46,8 @@ public class Player extends Character{
|
||||
|
||||
// Is the move valid ?
|
||||
if (sm.isWalkable(nextCell)) {
|
||||
if(!enemy()){
|
||||
// Go
|
||||
setSpeed(sm.getSpeed(nextCell));
|
||||
go(goalDirection);
|
||||
} else {
|
||||
|
||||
}
|
||||
setSpeed(sm.getSpeed(nextCell));
|
||||
go(goalDirection);
|
||||
} else {
|
||||
// Face the wall
|
||||
turn(goalDirection);
|
||||
@ -78,12 +73,10 @@ public class Player extends Character{
|
||||
}
|
||||
|
||||
private boolean enemy() {
|
||||
/*
|
||||
Vector<Entity> entities = testHER.getEntities;
|
||||
for (Entity entity : entities) {
|
||||
//Vector<Enemy> enemies = PokeMudry.getEnemies;
|
||||
//for (Enemy enemy : enemies) {
|
||||
|
||||
}
|
||||
*/
|
||||
//}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,12 @@
|
||||
import java.util.Vector;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
import Control.Controller;
|
||||
import Entity.Enemy;
|
||||
import Entity.Entity;
|
||||
import Entity.Player;
|
||||
import Screen.ScreenMap;
|
||||
import Screen.ScreenPlayer;
|
||||
import ch.hevs.gdx2d.desktop.PortableApplication;
|
||||
import ch.hevs.gdx2d.lib.GdxGraphics;
|
||||
@ -7,7 +16,11 @@ public class PokeMudry extends PortableApplication {
|
||||
public final int PLAYERS = 1;
|
||||
public static final int TIME = 10; // number of minutes for kill all enemy
|
||||
|
||||
private ScreenPlayer screenPlayer = new ScreenPlayer();
|
||||
private ScreenPlayer sp;
|
||||
private Controller controller;
|
||||
//private Player p1;
|
||||
private static Vector<Enemy> enemies = new Vector<>();
|
||||
private static Vector<Entity> entities = new Vector<>();
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -16,29 +29,68 @@ public class PokeMudry extends PortableApplication {
|
||||
|
||||
PokeMudry(){
|
||||
super(1000, 800);
|
||||
controller = new Controller();
|
||||
sp = new ScreenPlayer();
|
||||
}
|
||||
|
||||
|
||||
public static Vector<Enemy> getEnemies() {
|
||||
return enemies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
screenPlayer.init();
|
||||
sp.init();
|
||||
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"));
|
||||
|
||||
for (Enemy enemy : enemies) {
|
||||
entities.add(enemy);
|
||||
}
|
||||
|
||||
for (Entity entity : entities) {
|
||||
entity.init();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGraphicRender(GdxGraphics g) {
|
||||
screenPlayer.render(g);
|
||||
g.clear();
|
||||
sp.p.manageEntity(sp.sm, controller);
|
||||
sp.render(g);
|
||||
for (Entity entity : entities) {
|
||||
entity.graphicRender(g);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//key gestion
|
||||
@Override
|
||||
public void onKeyDown(int keycode) {
|
||||
screenPlayer.screenManager.getActiveScreen().onKeyDown(keycode);
|
||||
super.onKeyDown(keycode);
|
||||
|
||||
switch (keycode) {
|
||||
case Input.Keys.Z:
|
||||
if (sp.sm.zoom == 1.0) {
|
||||
sp.sm.zoom = 0.5f;
|
||||
} else if (sp.sm.zoom == 0.5) {
|
||||
sp.sm.zoom = 0.25f;
|
||||
} else {
|
||||
sp.sm.zoom = 1;
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
controller.keyStatus.put(keycode, true);
|
||||
sp.screenManager.getActiveScreen().onKeyUp(keycode);
|
||||
}
|
||||
@Override
|
||||
public void onKeyUp(int keycode) {
|
||||
screenPlayer.screenManager.getActiveScreen().onKeyUp(keycode);
|
||||
super.onKeyUp(keycode);
|
||||
controller.keyStatus.put(keycode, false);
|
||||
sp.screenManager.getActiveScreen().onKeyDown(keycode);
|
||||
}
|
||||
}
|
||||
|
19
src/Screen/ManagerOfScreen.java
Normal file
19
src/Screen/ManagerOfScreen.java
Normal file
@ -0,0 +1,19 @@
|
||||
package Screen;
|
||||
|
||||
import ch.hevs.gdx2d.lib.ScreenManager;
|
||||
|
||||
public class ManagerOfScreen extends ScreenManager{
|
||||
ManagerOfScreen(){
|
||||
|
||||
}
|
||||
|
||||
ScreenMap getScreenMap(){
|
||||
this.activateScreen(0);
|
||||
return (ScreenMap)this.getActiveScreen();
|
||||
}
|
||||
|
||||
ScreenBattle getScreenBattle(){
|
||||
this.activateScreen(1);
|
||||
return (ScreenBattle)this.getActiveScreen();
|
||||
}
|
||||
}
|
@ -55,7 +55,7 @@ public class ScreenMap extends RenderingScreen{
|
||||
|
||||
@Override
|
||||
public void onGraphicRender(GdxGraphics g) {
|
||||
|
||||
|
||||
tiledLayer.clear();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
try { tiledLayer.add((TiledMapTileLayer) tMap.get(map).getLayers().get(i)); } catch (Exception e) { }
|
||||
@ -65,25 +65,30 @@ public class ScreenMap extends RenderingScreen{
|
||||
tileWidth = (int) tl.getTileWidth();
|
||||
height = tl.getHeight();
|
||||
tileHeight = (int) tl.getTileHeight();
|
||||
|
||||
//System.out.println(width + " x " + height + " - " + tileWidth + " x " + tileHeight);
|
||||
try {
|
||||
doors = tMap.get(map).getLayers().get("door").getObjects();
|
||||
doors = tMap.get(map).getLayers().get("door").getObjects();
|
||||
} catch (Exception e) { doors = null; }
|
||||
|
||||
// Camera follows the hero
|
||||
g.zoom(zoom);
|
||||
//g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight);
|
||||
|
||||
|
||||
// Render the tileMap
|
||||
tMapRenderer.get(map).setView(g.getCamera());
|
||||
tMapRenderer.get(map).render();
|
||||
|
||||
|
||||
g.drawFPS();
|
||||
}
|
||||
|
||||
void camera(GdxGraphics g, Player player){
|
||||
g.zoom(zoom);
|
||||
g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Vector<TiledMapTile> getTile(Vector2 position, int offsetX, int offsetY) {
|
||||
Vector<TiledMapTile> tiles = new Vector<>();
|
||||
|
||||
for (TiledMapTileLayer tl : tiledLayer) {
|
||||
int x = (int) (position.x / tileWidth) + offsetX;
|
||||
int y = (int) (position.y / tileHeight) + offsetY;
|
||||
@ -91,7 +96,7 @@ public class ScreenMap extends RenderingScreen{
|
||||
Cell cell = tl.getCell(x, y);
|
||||
if (cell == null) continue;
|
||||
tiles.add(cell.getTile());
|
||||
} catch (Exception e) { }
|
||||
} catch (Exception e) { System.out.println("error: cell");}
|
||||
}
|
||||
|
||||
return tiles;
|
||||
@ -160,5 +165,4 @@ public class ScreenMap extends RenderingScreen{
|
||||
nextY = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,25 +2,23 @@ package Screen;
|
||||
|
||||
import Entity.Player;
|
||||
import ch.hevs.gdx2d.lib.GdxGraphics;
|
||||
import ch.hevs.gdx2d.lib.ScreenManager;
|
||||
|
||||
public class ScreenPlayer {
|
||||
public ScreenManager screenManager = new ScreenManager();
|
||||
public ManagerOfScreen screenManager = new ManagerOfScreen();
|
||||
public Player p;
|
||||
public ScreenMap sm;
|
||||
|
||||
private Player player;
|
||||
|
||||
public void init(){
|
||||
|
||||
player = new Player(8, 15);
|
||||
|
||||
|
||||
screenManager.registerScreen(ScreenMap.class);
|
||||
screenManager.registerScreen(ScreenBattle.class);
|
||||
|
||||
sm = screenManager.getScreenMap();
|
||||
p = new Player(8, 15);
|
||||
}
|
||||
|
||||
public void render(GdxGraphics g){
|
||||
screenManager.render(g);
|
||||
|
||||
sm.camera(g, p);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
import java.util.Vector;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
import Control.Controller;
|
||||
import Entity.Enemy;
|
||||
import Entity.Entity;
|
||||
import Entity.Player;
|
||||
import Screen.ScreenMap;
|
||||
import ch.hevs.gdx2d.desktop.PortableApplication;
|
||||
import ch.hevs.gdx2d.lib.GdxGraphics;
|
||||
|
||||
|
||||
public class testHER extends PortableApplication{
|
||||
|
||||
private Controller controller;
|
||||
private ScreenMap sm;
|
||||
private Player p1;
|
||||
private static Vector<Entity> entities = new Vector<>();
|
||||
private static Vector<Player> players = new Vector<>();
|
||||
|
||||
|
||||
public testHER(){
|
||||
controller = new Controller();
|
||||
sm = new ScreenMap();
|
||||
}
|
||||
|
||||
public static Vector<Entity> getEntities() {
|
||||
return entities;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
new testHER();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
controller.init();
|
||||
sm.init();
|
||||
p1 = new Player(8, 15);
|
||||
entities.add((Entity) p1);
|
||||
entities.add(new Enemy("Mudry", 10, 15, "lumberjack_sheet32"));
|
||||
entities.add(new Enemy("Pignat", 12, 15, "lumberjack_sheet32"));
|
||||
|
||||
for (Entity entity : entities) {
|
||||
entity.init();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGraphicRender(GdxGraphics g) {
|
||||
g.clear();
|
||||
p1.manageEntity(sm, controller);
|
||||
sm.graphicRender(g, p1);
|
||||
|
||||
for (Entity entity : entities) {
|
||||
entity.graphicRender(g);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyUp(int keycode) {
|
||||
super.onKeyUp(keycode);
|
||||
|
||||
controller.keyStatus.put(keycode, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyDown(int keycode) {
|
||||
super.onKeyDown(keycode);
|
||||
|
||||
switch (keycode) {
|
||||
case Input.Keys.Z:
|
||||
if (sm.zoom == 1.0) {
|
||||
sm.zoom = 0.5f;
|
||||
} else if (sm.zoom == 0.5) {
|
||||
sm.zoom = 0.25f;
|
||||
} else {
|
||||
sm.zoom = 1;
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
controller.keyStatus.put(keycode, true);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user