1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2025-06-27 12:42:32 +00:00

convert with lib

This commit is contained in:
2022-06-06 13:48:20 +02:00
parent 4c99bb5629
commit 622e072481
50 changed files with 466 additions and 802 deletions

16
src/Entity/Character.java Normal file
View File

@ -0,0 +1,16 @@
package Entity;
public abstract class Character extends Entity{
public Character(String name) {
super(name);
//TODO Auto-generated constructor stub
}
private int pv;
public int getPv() {
return pv;
}
abstract protected void removedPv(int pv);
}

25
src/Entity/Enemy.java Normal file
View File

@ -0,0 +1,25 @@
package Entity;
import com.badlogic.gdx.math.Vector2;
public class Enemy extends Character{
public Enemy(String name) {
super(name);
}
public void setPosition(int x, int y){
}
public void setPosition(Vector2 vPosition){
setPosition((int)vPosition.x, (int)vPosition.y);
}
@Override
protected void removedPv(int pv) {
// TODO Auto-generated method stub
}
}

20
src/Entity/Entity.java Normal file
View File

@ -0,0 +1,20 @@
package Entity;
import com.badlogic.gdx.math.Vector2;
public abstract class Entity {
private Vector2 position;
private String name;
public Entity(String name){
this.name = name;
}
public Vector2 getPosition() {
return position;
}
public String getName() {
return name;
}
}

31
src/Entity/Player.java Normal file
View File

@ -0,0 +1,31 @@
package Entity;
import com.badlogic.gdx.math.Vector2;
public class Player extends Character{
private int xp;
public Player(String name) {
super(name);
//TODO Auto-generated constructor stub
}
public void addXp(int xp){
}
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
}
}

10
src/Entity/Stuff.java Normal file
View File

@ -0,0 +1,10 @@
package Entity;
public class Stuff extends Entity{
public Stuff(String name) {
super(name);
//TODO Auto-generated constructor stub
}
}

26
src/PokeMudry.java Normal file
View File

@ -0,0 +1,26 @@
import ch.hevs.gdx2d.desktop.PortableApplication;
import ch.hevs.gdx2d.lib.GdxGraphics;
public class PokeMudry extends PortableApplication{
public final boolean ANDROID = false;
public final int PLAYERS = 1;
public static final int TIME = 10; // number of minutes for kill all enemy
/*
public static void main(String[] args) {
}
*/
@Override
public void onInit() {
// TODO Auto-generated method stub
}
@Override
public void onGraphicRender(GdxGraphics g) {
// TODO Auto-generated method stub
}
}

189
src/Screen/Hero.java Normal file
View File

@ -0,0 +1,189 @@
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,5 @@
package Screen;
public class ScreenBattle {
}

232
src/Screen/ScreenMap.java Normal file
View File

@ -0,0 +1,232 @@
package Screen;
import ch.hevs.gdx2d.lib.GdxGraphics;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.MapObjects;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.*;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector2;
import java.util.Map;
import java.util.TreeMap;
import java.util.Vector;
public class ScreenMap {
// key management
public Map<Integer, Boolean> keyStatus = new TreeMap<Integer, Boolean>();
// character
private Hero hero;
// tiles management
private Vector<TiledMapTileLayer> tiledLayer = new Vector<>();
private MapObjects doors;
Map<String,TiledMap> tMap = new TreeMap<String,TiledMap>();
Map<String,TiledMapRenderer> tMapRenderer = new TreeMap<String,TiledMapRenderer>();
private String map = "desert";
public float zoom;
private int width;
private int tileWidth;
private int height;
private int tileHeight;
private void createMap(String name){
TiledMap tm =new TmxMapLoader().load("./resources/map/"+ name + ".tmx");
tMap.put(name,tm);
tMapRenderer.put(name,new OrthogonalTiledMapRenderer(tm));
}
public void init() {
// Create hero
hero = new Hero(8, 15);
// Set initial zoom
zoom = 1;
// init keys status
keyStatus.put(Input.Keys.UP, false);
keyStatus.put(Input.Keys.DOWN, false);
keyStatus.put(Input.Keys.LEFT, false);
keyStatus.put(Input.Keys.RIGHT, false);
// create map
createMap("test");
createMap("test_couloir");
createMap("desert");
}
public void graphicRender(GdxGraphics g) {
g.clear();
tiledLayer.clear();
for (int i = 0; i < 50; i++) {
try { tiledLayer.add((TiledMapTileLayer) tMap.get(map).getLayers().get(i)); } catch (Exception e) { }
}
//System.out.println(tiledLayer.size() + " layers imported");
TiledMapTileLayer tl = tiledLayer.get(0);
width = tl.getWidth();
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();
} catch (Exception e) { doors = null; }
// Hero activity
manageHero();
System.out.println("Hero: " + (int)hero.getPosition().x/tileWidth + " x " + (int)hero.getPosition().y/tileHeight);
// Camera follows the hero
g.zoom(zoom);
g.moveCamera(hero.getPosition().x, hero.getPosition().y, width * tileWidth, height * tileHeight);
// Render the tileMap
tMapRenderer.get(map).setView(g.getCamera());
tMapRenderer.get(map).render();
// Draw the hero
hero.animate(Gdx.graphics.getDeltaTime());
hero.draw(g);
g.drawFPS();
}
private 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;
try {
Cell cell = tl.getCell(x, y);
if (cell == null) continue;
tiles.add(cell.getTile());
} catch (Exception e) { }
}
return tiles;
}
private boolean isWalkable(Vector<TiledMapTile> tile) {
if (tile == null) return false;
boolean walkable = false;
for (TiledMapTile tiledMapTile : tile) {
Object test = tiledMapTile.getProperties().get("walkable");
walkable = Boolean.parseBoolean(test.toString()) ? true:walkable;
}
return walkable;
}
private float getSpeed(Vector<TiledMapTile> tile) {
float speed = 0;
for (TiledMapTile tiledMapTile : tile) {
Object test = tiledMapTile.getProperties().get("speed");
float newSpeed = Float.parseFloat(test.toString());
speed = newSpeed > speed ? newSpeed:speed;
}
return speed;
}
private boolean isDoor(Vector2 position) {
if (doors == null) return false;
boolean onDoor = false;
Integer x = null;
Integer y = null;
int ox = 0;
int oy = 0;
try {
x = (int) (position.x / tileWidth);
y = (int) (position.y / tileHeight);
} catch (Exception e) { }
for (MapObject object : doors){
MapProperties mapProperties = null;
try { mapProperties = object.getProperties(); } catch (Exception e) { }
try { ox = (int) ((float) mapProperties.get("x")); } catch (Exception e) { }
try { oy = (int) ((float) mapProperties.get("y")); } catch (Exception e) { }
ox /= tileWidth;
oy /= tileHeight;
if ((x != null || y != null) && (x == ox && y == oy)) {
onDoor = true;
try { Door.nextMap = mapProperties.get("nextMap").toString(); } catch (Exception e) { System.out.println("shit 1"); }
try { Door.nextX = Integer.parseInt(mapProperties.get("nextX").toString()); } catch (Exception e) { System.out.println("shit 2"); }
try { Door.nextY = Integer.parseInt(mapProperties.get("nextY").toString()); } catch (Exception e) { System.out.println("shit 3"); }
}
}
return onDoor;
}
private void manageHero() {
// Do nothing if hero is already moving
if (!hero.isMoving()) {
// Compute direction and next cell
Vector<TiledMapTile> nextCell = new Vector<>();
Hero.Direction goalDirection = Hero.Direction.NULL;
if (keyStatus.get(Input.Keys.RIGHT)) {
goalDirection = Hero.Direction.RIGHT;
nextCell = getTile(hero.getPosition(), 1, 0);
} else if (keyStatus.get(Input.Keys.LEFT)) {
goalDirection = Hero.Direction.LEFT;
nextCell = getTile(hero.getPosition(), -1, 0);
} else if (keyStatus.get(Input.Keys.UP)) {
goalDirection = Hero.Direction.UP;
nextCell = getTile(hero.getPosition(), 0, 1);
} else if (keyStatus.get(Input.Keys.DOWN)) {
goalDirection = Hero.Direction.DOWN;
nextCell = getTile(hero.getPosition(), 0, -1);
}
// Is the move valid ?
if (isWalkable(nextCell)) {
// Go
hero.setSpeed(getSpeed(nextCell));
hero.go(goalDirection);
} else {
// Face the wall
hero.turn(goalDirection);
}
if(isDoor(hero.getPosition())){
String nMap = null;
Integer x = null;
Integer y = null;
try {
nMap = Door.nextMap;
x = Door.nextX;
y = Door.nextY;
} catch (Exception e) { }
Door.reset();
if (nMap == null || x == null || y == null) return;
map = nMap;
hero.setPosition(x*tileWidth, y*tileHeight);
System.out.println("Go to: " + map + " in " + x + " x " + y);
}
}
}
static class Door {
static String nextMap;
static Integer nextX;
static Integer nextY;
static void reset(){
nextMap = null;
nextX = null;
nextY = null;
}
}
}

View File

@ -0,0 +1,17 @@
package Screen;
import ch.hevs.gdx2d.lib.ScreenManager;
public class ScreenPlayer {
private ScreenManager screenManager;
private ScreenMap screenMap;
private ScreenBattle screenBattle;
public void init(){
}
public void render(){
}
}

55
src/testHER.java Normal file
View File

@ -0,0 +1,55 @@
import com.badlogic.gdx.Input;
import Screen.ScreenMap;
import ch.hevs.gdx2d.desktop.PortableApplication;
import ch.hevs.gdx2d.lib.GdxGraphics;
public class testHER extends PortableApplication{
private static ScreenMap sm;
public static void main(String[] args) {
sm = new ScreenMap();
new testHER();
}
@Override
public void onInit() {
sm.init();
}
@Override
public void onGraphicRender(GdxGraphics g) {
sm.graphicRender(g);
}
@Override
public void onKeyUp(int keycode) {
super.onKeyUp(keycode);
sm.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;
}
sm.keyStatus.put(keycode, true);
}
}