1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2024-11-23 01:43:28 +00:00

Merge branch 'master' into dialog

This commit is contained in:
Rémi Heredero 2022-06-09 18:21:27 +02:00
commit 8991c6efb9
12 changed files with 127 additions and 304 deletions

2
.gitignore vendored
View File

@ -6,3 +6,5 @@ build
# Ignore bin
bin/
*.tiled-session
resources/map/Maps.tiled-session

BIN
resources/Base.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
resources/Character.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -7,24 +7,34 @@ import com.badlogic.gdx.math.Vector2;
import ch.hevs.gdx2d.lib.GdxGraphics;
public class Enemy extends Character{
private String map;
public TextEnemy textEnemy;
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);
//generate his text
this.textEnemy = new TextEnemy(name);
textEnemy.generateText();
//TODO Auto-generated constructor stub
this.map = map;
turn(Character.Direction.DOWN);
//generate the vector of fight
fightData = new FightData(name);
}
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
@ -32,11 +42,5 @@ public class Enemy extends Character{
// TODO Auto-generated method stub
}
@Override
public void draw(GdxGraphics arg0) {
// TODO Auto-generated method stub
}
}

View File

@ -36,7 +36,6 @@ public abstract class Entity implements DrawableObject {
}
public void init(){
}
public void graphicRender(GdxGraphics g){

View File

@ -14,7 +14,7 @@ public class Player extends Character{
private int xp;
public Player(int x, int y) {
super("Player", x, y, "lumberjack_sheet32");
super("Player", x, y, "Character");
}
public void addXp(int xp){
@ -46,7 +46,6 @@ public class Player extends Character{
// Is the move valid ?
if (sm.isWalkable(nextCell)) {
// Go
setSpeed(sm.getSpeed(nextCell));
go(goalDirection);
} else {
@ -73,7 +72,15 @@ public class Player extends Character{
}
}
public void move(int x, int y){
private boolean enemy() {
//Vector<Enemy> enemies = PokeMudry.getEnemies;
//for (Enemy enemy : enemies) {
//}
return false;
}
public void move(int x, int y){
}

View File

@ -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;
@ -10,8 +19,11 @@ public class PokeMudry extends PortableApplication {
public static final int HEIGHT = 800;
public static final int width = 800;
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) {
@ -20,29 +32,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);
}
}

View File

@ -1,189 +0,0 @@
package Screen;
import ch.hevs.gdx2d.components.bitmaps.Spritesheet;
import ch.hevs.gdx2d.lib.GdxGraphics;
import ch.hevs.gdx2d.lib.interfaces.DrawableObject;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector2;
/**
* Character for the demo.
*
* @author Alain Woeffray (woa)
* @author Pierre-André Mudry (mui)
*/
public class Hero implements DrawableObject {
public enum Direction{
UP,
DOWN,
RIGHT,
LEFT,
NULL
}
/**
* The currently selected sprite for animation
*/
int textureX = 0;
int textureY = 1;
float speed = 1;
float dt = 0;
int currentFrame = 0;
int nFrames = 4;
private final static int SPRITE_WIDTH = 32;
private final static int SPRITE_HEIGHT = 32;
final float FRAME_TIME = 0.1f; // Duration of each frime
Spritesheet ss;
Vector2 lastPosition;
Vector2 newPosition;
Vector2 position;
private boolean move = false;
/**
* Create the hero at the start position (0,0)
*/
public Hero(){
this(new Vector2(0,0));
}
/**
* Create the hero at the given start tile.
* @param x Column
* @param y Line
*/
public Hero(int x, int y){
this(new Vector2(SPRITE_WIDTH * x, SPRITE_HEIGHT * y));
}
/**
* Create the hero at the start position
* @param initialPosition Start position [px] on the map.
*/
public Hero(Vector2 initialPosition) {
lastPosition = new Vector2(initialPosition);
newPosition = new Vector2(initialPosition);
position = new Vector2(initialPosition);
ss = new Spritesheet("./resources/lumberjack_sheet32.png", SPRITE_WIDTH, SPRITE_HEIGHT);
}
/**
* @return the current position of the hero on the map.
*/
public Vector2 getPosition(){
return this.position;
}
public void setPosition(int x, int y){
lastPosition.set(x, y);
newPosition.set(x, y);
position.set(x, y);
}
/**
* Update the position and the texture of the hero.
* @param elapsedTime The time [s] elapsed since the last time which this method was called.
*/
public void animate(double elapsedTime) {
float frameTime = FRAME_TIME / speed;
position = new Vector2(lastPosition);
if(isMoving()) {
dt += elapsedTime;
float alpha = (dt+frameTime*currentFrame)/(frameTime*nFrames);
position.interpolate(newPosition, alpha,Interpolation.linear);
}else{
dt = 0;
}
if (dt > frameTime) {
dt -= frameTime;
currentFrame = (currentFrame + 1) % nFrames;
if(currentFrame == 0){
move = false;
lastPosition = new Vector2(newPosition);
position = new Vector2(newPosition);
}
}
}
/**
* @return True if the hero is actually doing a step.
*/
public boolean isMoving(){
return move;
}
/**
* @param speed The new speed of the hero.
*/
public void setSpeed(float speed){
this.speed = speed;
}
/**
* Do a step on the given direction
* @param direction The direction to go.
*/
public void go(Direction direction){
move = true;
switch(direction){
case RIGHT:
newPosition.add(SPRITE_WIDTH, 0);
break;
case LEFT:
newPosition.add(-SPRITE_WIDTH, 0);
break;
case UP:
newPosition.add(0, SPRITE_HEIGHT);
break;
case DOWN:
newPosition.add(0, -SPRITE_HEIGHT);
break;
default:
break;
}
turn(direction);
}
/**
* Turn the hero on the given direction without do any step.
* @param direction The direction to turn.
*/
public void turn(Direction direction){
switch(direction){
case RIGHT:
textureY = 2;
break;
case LEFT:
textureY = 1;
break;
case UP:
textureY = 3;
break;
case DOWN:
textureY = 0;
break;
default:
break;
}
}
/**
* Draw the character on the graphic object.
* @param g Graphic object.
*/
public void draw(GdxGraphics g) {
g.draw(ss.sprites[textureY][currentFrame], position.x, position.y);
}
}

View 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();
}
}

View File

@ -32,6 +32,7 @@ public class ScreenMap extends RenderingScreen{
public int tileWidth;
private int height;
public int tileHeight;
private void createMap(String name){
@ -53,7 +54,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) { }
@ -63,25 +64,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;
@ -89,7 +95,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;
@ -158,5 +164,4 @@ public class ScreenMap extends RenderingScreen{
nextY = null;
}
}
}

View File

@ -2,24 +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);
}
}
}

View File

@ -1,74 +0,0 @@
import com.badlogic.gdx.Input;
import Control.Controller;
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 Entity[] entities;
public testHER(){
controller = new Controller();
p1 = new Player(8, 15);
sm = new ScreenMap();
}
public static void main(String[] args) {
new testHER();
}
@Override
public void onInit() {
controller.init();
sm.init();
p1.init();
}
@Override
public void onGraphicRender(GdxGraphics g) {
g.clear();
p1.manageEntity(sm, controller);
sm.graphicRender(g, p1); // load p1 by Entity[]
p1.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);
}
}