mirror of
				https://github.com/Klagarge/PokeHES.git
				synced 2025-10-30 11:19:17 +00:00 
			
		
		
		
	done
This commit is contained in:
		| @@ -7,11 +7,13 @@ import com.badlogic.gdx.math.Vector2; | |||||||
| import ch.hevs.gdx2d.lib.GdxGraphics; | import ch.hevs.gdx2d.lib.GdxGraphics; | ||||||
|  |  | ||||||
| public class Enemy extends Character{ | public class Enemy extends Character{ | ||||||
|  |     private String map; | ||||||
|  |  | ||||||
|     public FightData fightData; |     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); |         super(name, x, y, img); | ||||||
|  |         this.map = map; | ||||||
|  |  | ||||||
|         turn(Character.Direction.DOWN); |         turn(Character.Direction.DOWN); | ||||||
|         //generate the vector of fight |         //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){ |     public void setPosition(int x, int y, String map){ | ||||||
|         setPosition((int)vPosition.x, (int)vPosition.y); |         position.set(x, y); | ||||||
|  |         this.map = map; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void setPosition(Vector2 vPosition, String map){ | ||||||
|  |         setPosition((int)vPosition.x, (int)vPosition.y, map); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
| @@ -46,14 +46,9 @@ public class Player extends Character{ | |||||||
|  |  | ||||||
| 			// Is the move valid ? | 			// Is the move valid ? | ||||||
| 			if (sm.isWalkable(nextCell)) { | 			if (sm.isWalkable(nextCell)) { | ||||||
| 				if(!enemy()){ |  | ||||||
| 					// Go |  | ||||||
| 				setSpeed(sm.getSpeed(nextCell)); | 				setSpeed(sm.getSpeed(nextCell)); | ||||||
| 				go(goalDirection); | 				go(goalDirection); | ||||||
| 			} else { | 			} else { | ||||||
| 					 |  | ||||||
| 				} |  | ||||||
| 			} else { |  | ||||||
| 				// Face the wall | 				// Face the wall | ||||||
| 				turn(goalDirection); | 				turn(goalDirection); | ||||||
| 			} | 			} | ||||||
| @@ -78,12 +73,10 @@ public class Player extends Character{ | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
|     private boolean enemy() { |     private boolean enemy() { | ||||||
| 		/* | 		//Vector<Enemy> enemies = PokeMudry.getEnemies; | ||||||
| 		Vector<Entity> entities = testHER.getEntities; | 		//for (Enemy enemy : enemies) { | ||||||
| 		for (Entity entity : entities) { |  | ||||||
| 			 | 			 | ||||||
| 		} | 		//} | ||||||
| 		*/ |  | ||||||
| 		return false; | 		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 Screen.ScreenPlayer; | ||||||
| import ch.hevs.gdx2d.desktop.PortableApplication; | import ch.hevs.gdx2d.desktop.PortableApplication; | ||||||
| import ch.hevs.gdx2d.lib.GdxGraphics; | import ch.hevs.gdx2d.lib.GdxGraphics; | ||||||
| @@ -7,7 +16,11 @@ public class PokeMudry extends PortableApplication { | |||||||
|     public final int PLAYERS = 1; |     public 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 | ||||||
|  |  | ||||||
|     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) { |     public static void main(String[] args) { | ||||||
| @@ -16,29 +29,68 @@ public class PokeMudry extends PortableApplication { | |||||||
|  |  | ||||||
|     PokeMudry(){ |     PokeMudry(){ | ||||||
|         super(1000, 800); |         super(1000, 800); | ||||||
|  |         controller = new Controller(); | ||||||
|  |         sp = new ScreenPlayer(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public static Vector<Enemy> getEnemies() { | ||||||
|  | 		return enemies; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void onInit() { |     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 |     @Override | ||||||
|     public void onGraphicRender(GdxGraphics g) { |     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 |     //key gestion | ||||||
|     @Override |     @Override | ||||||
|     public void onKeyDown(int keycode) { |     public void onKeyDown(int keycode) { | ||||||
|         screenPlayer.screenManager.getActiveScreen().onKeyDown(keycode); |  | ||||||
|         super.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 |     @Override | ||||||
|     public void onKeyUp(int keycode) { |     public void onKeyUp(int keycode) { | ||||||
|         screenPlayer.screenManager.getActiveScreen().onKeyUp(keycode); |  | ||||||
|         super.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(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -65,14 +65,12 @@ public class ScreenMap extends RenderingScreen{ | |||||||
|         tileWidth = (int) tl.getTileWidth(); |         tileWidth = (int) tl.getTileWidth(); | ||||||
|         height = tl.getHeight(); |         height = tl.getHeight(); | ||||||
|         tileHeight = (int) tl.getTileHeight(); |         tileHeight = (int) tl.getTileHeight(); | ||||||
|  |          | ||||||
|         //System.out.println(width + " x " + height + " - " + tileWidth + " x " + tileHeight); |         //System.out.println(width + " x " + height + " - " + tileWidth + " x " + tileHeight); | ||||||
| 		try { | 		try { | ||||||
|             doors = tMap.get(map).getLayers().get("door").getObjects(); |             doors = tMap.get(map).getLayers().get("door").getObjects(); | ||||||
| 		} catch (Exception e) {	doors = null; } | 		} 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 | 		// Render the tileMap | ||||||
| 		tMapRenderer.get(map).setView(g.getCamera()); | 		tMapRenderer.get(map).setView(g.getCamera()); | ||||||
| @@ -81,9 +79,16 @@ public class ScreenMap extends RenderingScreen{ | |||||||
| 		g.drawFPS(); | 		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) { |     public Vector<TiledMapTile> getTile(Vector2 position, int offsetX, int offsetY) { | ||||||
|         Vector<TiledMapTile> tiles = new Vector<>(); |         Vector<TiledMapTile> tiles = new Vector<>(); | ||||||
|  |  | ||||||
|         for (TiledMapTileLayer tl : tiledLayer) { |         for (TiledMapTileLayer tl : tiledLayer) { | ||||||
|             int x = (int) (position.x / tileWidth) + offsetX; |             int x = (int) (position.x / tileWidth) + offsetX; | ||||||
|             int y = (int) (position.y / tileHeight) + offsetY; |             int y = (int) (position.y / tileHeight) + offsetY; | ||||||
| @@ -91,7 +96,7 @@ public class ScreenMap extends RenderingScreen{ | |||||||
| 				Cell cell = tl.getCell(x, y); | 				Cell cell = tl.getCell(x, y); | ||||||
| 				if (cell == null) continue; | 				if (cell == null) continue; | ||||||
|                 tiles.add(cell.getTile()); |                 tiles.add(cell.getTile()); | ||||||
|             } catch (Exception e) { } |             } catch (Exception e) { System.out.println("error: cell");} | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return tiles; |         return tiles; | ||||||
| @@ -160,5 +165,4 @@ public class ScreenMap extends RenderingScreen{ | |||||||
| 			nextY = null; | 			nextY = null; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 		 |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,25 +2,23 @@ package Screen; | |||||||
|  |  | ||||||
| import Entity.Player; | import Entity.Player; | ||||||
| import ch.hevs.gdx2d.lib.GdxGraphics; | import ch.hevs.gdx2d.lib.GdxGraphics; | ||||||
| import ch.hevs.gdx2d.lib.ScreenManager; |  | ||||||
|  |  | ||||||
| public class ScreenPlayer { | 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(){ |     public void init(){ | ||||||
|          |  | ||||||
|         player = new Player(8, 15); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         screenManager.registerScreen(ScreenMap.class); |         screenManager.registerScreen(ScreenMap.class); | ||||||
|         screenManager.registerScreen(ScreenBattle.class); |         screenManager.registerScreen(ScreenBattle.class); | ||||||
|  |         sm = screenManager.getScreenMap(); | ||||||
|  |         p = new Player(8, 15); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void render(GdxGraphics g){ |     public void render(GdxGraphics g){ | ||||||
|         screenManager.render(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); |  | ||||||
| 	} |  | ||||||
|      |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user