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

Merge branch 'master' into battle-game

This commit is contained in:
Rémi Heredero 2022-06-12 14:33:26 +02:00 committed by GitHub
commit ac5ce35a19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 72 additions and 19 deletions

26
src/Control/Keyboard.java Normal file
View File

@ -0,0 +1,26 @@
package Control;
import com.badlogic.gdx.Input;
import Screen.ScreenPlayer;
public class Keyboard {
public void keyDown(int keycode, ScreenPlayer sp, Controller c) {
switch (keycode) {
case Input.Keys.Z:
if (sp.sm.zoom == 1.0) {
sp.sm.zoom = 0.5f;
} else {
sp.sm.zoom = 1;
}
return;
default:
break;
}
c.keyStatus.put(keycode, true);
}
public void onKeyUp(int keycode, ScreenPlayer sp, Controller c) {
c.keyStatus.put(keycode, false);
}
}

View File

@ -32,6 +32,14 @@ public abstract class Character extends Entity{
protected int pv; protected int pv;
/**
* Create a character on the world
* @param name Name of the new character
* @param x initial x position
* @param y initial y position
* @param img the name of the spritesheet for this character
* @param map the initial map
*/
public Character(String name, int x, int y, String img, String map){ public Character(String name, int x, int y, String img, String map){
super(name, x, y, map); super(name, x, y, map);
this.img = img; this.img = img;
@ -87,7 +95,7 @@ public abstract class Character extends Entity{
} }
/** /**
* @param speed The new speed of the hero. * @param speed The new speed of the character.
*/ */
public void setSpeed(float speed){ public void setSpeed(float speed){
this.speed = speed; this.speed = speed;

View File

@ -22,10 +22,23 @@ public abstract class Entity implements DrawableObject {
protected boolean move = false; protected boolean move = false;
/**
* Create an entity
* @param name The name of this new entity
* @param x The initial x position
* @param y The initial y position
* @param map The initial map
*/
public Entity(String name, int x, int y, String map){ public Entity(String name, int x, int y, String map){
this(name, new Vector2(SPRITE_WIDTH * x, SPRITE_HEIGHT * y), map); this(name, new Vector2(SPRITE_WIDTH * x, SPRITE_HEIGHT * y), map);
} }
/**
* Create an entity
* @param name The name of this new entity
* @param initialPosition The initial position by a Vector2
* @param map The initial map
*/
public Entity(String name, Vector2 initialPosition, String map){ public Entity(String name, Vector2 initialPosition, String map){
this.name = name; this.name = name;
lastPosition = new Vector2(initialPosition); lastPosition = new Vector2(initialPosition);

View File

@ -1,6 +1,5 @@
package Entity; package Entity;
import java.util.TreeMap;
import java.util.Vector; import java.util.Vector;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
@ -57,7 +56,7 @@ public class Player extends Character{
if (sm.isWalkable(nextCell)) { if (sm.isWalkable(nextCell)) {
if (enemy(sm, nextPos)) { if (enemy(sm, nextPos)) {
//turn(goalDirection); turn(goalDirection);
System.out.println("It's a enemy !!"); System.out.println("It's a enemy !!");
} else { } else {
setSpeed(sm.getSpeed(nextCell)); setSpeed(sm.getSpeed(nextCell));
@ -95,7 +94,7 @@ public class Player extends Character{
int pY = (int) nextPos.y/sm.tileHeight; int pY = (int) nextPos.y/sm.tileHeight;
int eX = (int) enemy.position.x/sm.tileWidth; int eX = (int) enemy.position.x/sm.tileWidth;
int eY = (int) enemy.position.y/sm.tileHeight; 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) { if(bMap && pX==eX && pY==eY) {
lastEnemy = enemy; lastEnemy = enemy;
frontOfEnemy = true; frontOfEnemy = true;

View File

@ -7,7 +7,6 @@ import java.util.Map.Entry;
import org.lwjgl.opencl.CLSampler; import org.lwjgl.opencl.CLSampler;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import Control.Controller; import Control.Controller;
import Entity.Enemy; import Entity.Enemy;
import Entity.Entity; import Entity.Entity;
@ -44,12 +43,14 @@ public class PokeMudry extends PortableApplication {
public void onInit() { public void onInit() {
sp.init(); sp.init();
controller.init(); controller.init();
// add player, create and add all enemies in entities
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", 5, 1, "lumberjack_sheet32", "test")); enemies.add(new Enemy("Pignat", 5, 1, "lumberjack_sheet32", "test"));
for (Enemy enemy : enemies) { entities.add(enemy); } for (Enemy enemy : enemies) { entities.add(enemy); }
//Init all entities
for (Entity entity : entities) { entity.init(); } for (Entity entity : entities) { entity.init(); }
} }
@ -60,13 +61,20 @@ public class PokeMudry extends PortableApplication {
sp.sb.manage(controller); sp.sb.manage(controller);
sp.render(g); sp.render(g);
//System.out.println(ScreenMap.class); //System.out.println(ScreenMap.class);
for (Entity entity : entities) {
if (entity.getMap().equals(sp.sm.map) && sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class)) boolean onMapScreen = sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class);
if(onMapScreen) sp.p.manageEntity(sp.sm, controller);
sp.render(g);
for (Entity entity : entities) {
// Render only entities on the good map
if (entity.getMap().equals(sp.sm.map) && onMapScreen)
entity.graphicRender(g); entity.graphicRender(g);
} }
if (sp.p.frontOfEnemy && sp.screenManager.getActiveScreen().getClass().equals(ScreenMap.class)){ // Switch screen
if (sp.p.frontOfEnemy && onMapScreen){
sp.e = sp.p.lastEnemy; sp.e = sp.p.lastEnemy;
sp.screenManager.activateNextScreen(); sp.screenManager.activateNextScreen();
g.resetCamera(); g.resetCamera();

View File

@ -27,7 +27,7 @@ public class ScreenMap extends RenderingScreen{
private MapObjects doors; private MapObjects doors;
Map<String,TiledMap> tMap = new TreeMap<String,TiledMap>(); Map<String,TiledMap> tMap = new TreeMap<String,TiledMap>();
Map<String,TiledMapRenderer> tMapRenderer = new TreeMap<String,TiledMapRenderer>(); Map<String,TiledMapRenderer> tMapRenderer = new TreeMap<String,TiledMapRenderer>();
public String map = "test_couloir"; public String map;
public float zoom; public float zoom;
private int width; private int width;
public int tileWidth; public int tileWidth;
@ -35,8 +35,6 @@ public class ScreenMap extends RenderingScreen{
public int tileHeight; public int tileHeight;
private Player player; private Player player;
private void createMap(String name){ private void createMap(String name){
TiledMap tm =new TmxMapLoader().load("./resources/map/"+ name + ".tmx"); TiledMap tm =new TmxMapLoader().load("./resources/map/"+ name + ".tmx");
tMap.put(name,tm); tMap.put(name,tm);
@ -79,12 +77,9 @@ public class ScreenMap extends RenderingScreen{
// Render the tileMap // Render the tileMap
try {
g.zoom(zoom); g.zoom(zoom);
g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight); try {g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight);}
} catch (Exception e) { catch (Exception e) {System.out.println("Fail to move camera");}
//TODO: handle exception
}
tMapRenderer.get(map).setView(g.getCamera()); tMapRenderer.get(map).setView(g.getCamera());
tMapRenderer.get(map).render(); tMapRenderer.get(map).render();

View File

@ -12,7 +12,11 @@ public class ScreenPlayer {
public ScreenBattle sb; public ScreenBattle sb;
public void init(){ public void init(){
// One player by ScreenPlayer
p = new Player(8, 15, "desert"); p = new Player(8, 15, "desert");
// Create both type of screen and record for reuse
screenManager.registerScreen(ScreenMap.class); screenManager.registerScreen(ScreenMap.class);
screenManager.registerScreen(ScreenBattle.class); screenManager.registerScreen(ScreenBattle.class);
sb = screenManager.getScreenBattle(); sb = screenManager.getScreenBattle();