mirror of
				https://github.com/Klagarge/PokeHES.git
				synced 2025-10-31 03:39:16 +00:00 
			
		
		
		
	Merge branch 'master' into dialog-screen-battle
This commit is contained in:
		| @@ -32,10 +32,9 @@ public abstract class Character extends Entity{ | ||||
|  | ||||
|     protected int pv; | ||||
|  | ||||
|     public Character(String name, int x, int y, String img){ | ||||
|         super(name, x, y); | ||||
|     public Character(String name, int x, int y, String img, String map){ | ||||
|         super(name, x, y, map); | ||||
|         this.img = img; | ||||
|          | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -3,12 +3,11 @@ package Entity; | ||||
| import com.badlogic.gdx.math.Vector2;  | ||||
|  | ||||
| public class Enemy extends Character{ | ||||
|     private String map; | ||||
|  | ||||
|  | ||||
|  | ||||
|     public Enemy(String name, int x, int y, String img, String map) { | ||||
|         super(name, x, y, img); | ||||
|         super(name, x, y, img, map); | ||||
|         //generate his text | ||||
|  | ||||
|         this.map = map; | ||||
| @@ -19,10 +18,6 @@ public class Enemy extends Character{ | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public String getMap() { | ||||
|         return map; | ||||
|     } | ||||
|  | ||||
|     public void setPosition(int x, int y, String map){ | ||||
|         position.set(x, y); | ||||
|         this.map = map; | ||||
|   | ||||
| @@ -8,6 +8,7 @@ import ch.hevs.gdx2d.lib.interfaces.DrawableObject; | ||||
|  | ||||
| public abstract class Entity implements DrawableObject { | ||||
|     protected String name; | ||||
|     protected String map; | ||||
|  | ||||
|     Spritesheet ss; | ||||
|      | ||||
| @@ -20,19 +21,17 @@ public abstract class Entity implements DrawableObject { | ||||
|  | ||||
|     protected boolean move = false; | ||||
|  | ||||
|     public Entity(String name){ | ||||
|         this(name, new Vector2(0,0)); | ||||
|  | ||||
|     public Entity(String name, int x, int y, String map){ | ||||
|         this(name, new Vector2(SPRITE_WIDTH * x, SPRITE_HEIGHT * y), map); | ||||
|     } | ||||
|  | ||||
|     public Entity(String name, int x, int y){ | ||||
|         this(name, new Vector2(SPRITE_WIDTH * x, SPRITE_HEIGHT * y)); | ||||
|     } | ||||
|  | ||||
|     public Entity(String name, Vector2 initialPosition){ | ||||
|     public Entity(String name, Vector2 initialPosition, String map){ | ||||
|         this.name = name; | ||||
|         lastPosition = new Vector2(initialPosition); | ||||
|         newPosition = new Vector2(initialPosition); | ||||
|         position = new Vector2(initialPosition); | ||||
|         this.map = map; | ||||
|     } | ||||
|  | ||||
|     public void init(){ | ||||
| @@ -58,4 +57,8 @@ public abstract class Entity implements DrawableObject { | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     public String getMap() { | ||||
|         return map; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package Entity; | ||||
|  | ||||
| import java.util.TreeMap; | ||||
| import java.util.Vector; | ||||
|  | ||||
| import com.badlogic.gdx.Input; | ||||
| @@ -7,14 +8,17 @@ 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{ | ||||
|  | ||||
|     private int xp; | ||||
| 	public Enemy lastEnemy = null; | ||||
| 	public boolean frontOfEnemy = false; | ||||
|  | ||||
|     public Player(int x, int y) { | ||||
|         super("Player", x, y, "Character"); | ||||
|     public Player(int x, int y, String map) { | ||||
|         super("Player", x, y, "Character", map); | ||||
|     } | ||||
|  | ||||
|     public void addXp(int xp){ | ||||
| @@ -29,25 +33,36 @@ 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)) { | ||||
| 					//turn(goalDirection); | ||||
| 					System.out.println("It's a enemy !!"); | ||||
| 				} else { | ||||
| 					setSpeed(sm.getSpeed(nextCell)); | ||||
| 					go(goalDirection); | ||||
| 				} | ||||
| 			} else { | ||||
| 				// Face the wall | ||||
| 				turn(goalDirection); | ||||
| @@ -65,29 +80,31 @@ public class Player extends Character{ | ||||
| 				} catch (Exception e) { } | ||||
| 				ScreenMap.Door.reset(); | ||||
| 				if (nMap == null || x == null || y == null) return; | ||||
| 				sm.map = nMap; | ||||
| 				map = nMap; | ||||
| 				setPosition(x*sm.tileWidth, y*sm.tileHeight); | ||||
| 				System.out.println("Go to: " + sm.map + " in " + x + " x " + y); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|     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) { | ||||
| 				lastEnemy = enemy; | ||||
| 				frontOfEnemy = true; | ||||
| 				return true; | ||||
| 			} | ||||
| 		} | ||||
| 		return false; | ||||
| 	} | ||||
|  | ||||
| 	public void move(int x, int y){ | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public void move(Vector2 vMove){ | ||||
|         move((int)vMove.x, (int)vMove.y); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void removedPv(int pv) { | ||||
|         // TODO Auto-generated method stub | ||||
|   | ||||
| @@ -4,8 +4,8 @@ import ch.hevs.gdx2d.lib.GdxGraphics; | ||||
|  | ||||
| public class Stuff extends Entity{ | ||||
|  | ||||
|     public Stuff(String name) { | ||||
|         super(name); | ||||
|     public Stuff(String name, int x, int y, String map) { | ||||
|         super(name, x, y, map); | ||||
|         //TODO Auto-generated constructor stub | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user