1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2025-06-27 12:42:32 +00:00
This commit is contained in:
2022-06-02 12:38:42 +02:00
parent df0055edf7
commit ba9aa340be
14 changed files with 502 additions and 28 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -6479,19 +6479,19 @@
<tile id="801">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="802">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="803">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="804">
@ -6683,19 +6683,19 @@
<tile id="835">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="836">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="837">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="838">
@ -6887,19 +6887,19 @@
<tile id="869">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="870">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="871">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="872">
@ -8967,7 +8967,7 @@
</properties>
</tile>
</tileset>
<layer id="6" name="background" width="20" height="10">
<layer id="6" name="background" width="20" height="10" locked="1">
<data encoding="csv">
21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
@ -8981,7 +8981,7 @@
21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21
</data>
</layer>
<layer id="2" name="floor" width="20" height="10">
<layer id="2" name="floor" width="20" height="10" locked="1">
<data encoding="csv">
956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,
956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,
@ -8995,7 +8995,7 @@
921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921
</data>
</layer>
<objectgroup id="7" name="door">
<objectgroup id="7" name="door" locked="1">
<object id="4" name="test" gid="17" x="96" y="96" width="32" height="32">
<properties>
<property name="nextX" type="int" value="2"/>
@ -9021,7 +9021,7 @@
</properties>
</object>
</objectgroup>
<layer id="1" name="wall" width="20" height="10">
<layer id="1" name="wall" width="20" height="10" locked="1">
<data encoding="csv">
21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
40,40,40,8,9,40,40,40,40,40,40,40,40,40,40,8,9,40,40,40,

BIN
app/bin/main/testHER.class Normal file

Binary file not shown.

View File

@ -6,9 +6,11 @@ public class PokeMudry extends PortableApplication{
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() {

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("app/src/main/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

@ -1,5 +1,232 @@
package Screen;
import ch.hevs.gdx2d.lib.GdxGraphics;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
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.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 = "test_couloir";
public float zoom;
private int width;
private int tileWidth;
private int height;
private int tileHeight;
// position
Vector2 pannel = new Vector2(30, 30);
private void createMap(String name){
TiledMap tm =new TmxMapLoader().load("app/src/main/resources/map/"+ name + ".tmx");
tMap.put(name,tm);
tMapRenderer.put(name,new OrthogonalTiledMapRenderer(tm));
}
public void init() {
// Create hero
hero = new Hero(9, 4);
// 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");
}
public void graphicRender(GdxGraphics g) {
g.clear();
for (int i = 0; i < 100; i++) {
try { tiledLayer.add((TiledMapTileLayer) tMap.get(map).getLayers().get(i)); } catch (Exception e) { }
}
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) { }
// Hero activity
manageHero();
// System.out.println(hero.getPosition().x + " - " + hero.getPosition().y);
// 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 / width) + offsetX;
int y = (int) (position.y / height) + offsetY;
System.out.println("tl: " + tl);
TiledMapTile cell = tl.getCell(x, y).getTile();
try {
System.out.println("cell: "+ cell);
tiles.add(cell);
} catch (Exception e) { System.out.println("shit");}
}
return tiles;
}
private boolean isWalkable(Vector<TiledMapTile> tile) {
if (tile == null) return false;
boolean walkable = false;
System.out.println("tile: " + tile);
for (TiledMapTile tiledMapTile : tile) {
System.out.println("tiledMapTile: " + tiledMapTile);
Object test = tiledMapTile.getProperties().get("walkable");
walkable = Boolean.parseBoolean(test.toString()) ? true:walkable;
}
//System.out.println(" walkable: " + 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 String getName(TiledMap tile) {
Object test = tile.getProperties().get("name");
return test.toString();
}
private boolean isDoor(Vector2 position) {
boolean onDoor = false;
Integer x = null;
Integer y = null;
int ox = 0;
int oy = 0;
try {
x = (int) (position.x / 32); //tiledLayer.getTileWidth()
y = (int) (position.y / 32); //tiledLayer.getTileHeight()
} 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) { }
oy-=288;
oy/=-1;
ox /= 32;
oy /= 32;
String id = null;
try { id = mapProperties.get("id").toString(); } catch (Exception e) { }
//if(x != null && y != null) System.out.println(id + ": " + x + " x " + y + " - " + ox + " x " + oy);
if (x != null || y != null) onDoor = (x == ox && y == oy) ? true:onDoor;
}
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())){
/*
switch(getName(tMap.get(map))){
case "test":
if(hero.getPosition().x == 32 && hero.getPosition().y == 288){
hero.setPosition(576, 256);
map = "desert";
}
break;
default:
break;
}
*/
System.out.println("it's a door");
}
}
}
}

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 = 2.0f;
} else if (sm.zoom == 2.0) {
sm.zoom = 4;
} else {
sm.zoom = 1;
}
return;
default:
break;
}
sm.keyStatus.put(keycode, true);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -6479,19 +6479,19 @@
<tile id="801">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="802">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="803">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="804">
@ -6683,19 +6683,19 @@
<tile id="835">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="836">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="837">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="838">
@ -6887,19 +6887,19 @@
<tile id="869">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="870">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="871">
<properties>
<property name="speed" type="float" value="1"/>
<property name="walkable" type="bool" value="false"/>
<property name="walkable" type="bool" value="true"/>
</properties>
</tile>
<tile id="872">
@ -8967,7 +8967,7 @@
</properties>
</tile>
</tileset>
<layer id="6" name="background" width="20" height="10">
<layer id="6" name="background" width="20" height="10" locked="1">
<data encoding="csv">
21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
@ -8981,7 +8981,7 @@
21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21
</data>
</layer>
<layer id="2" name="floor" width="20" height="10">
<layer id="2" name="floor" width="20" height="10" locked="1">
<data encoding="csv">
956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,
956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,956,
@ -8995,7 +8995,7 @@
921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921,921
</data>
</layer>
<objectgroup id="7" name="door">
<objectgroup id="7" name="door" locked="1">
<object id="4" name="test" gid="17" x="96" y="96" width="32" height="32">
<properties>
<property name="nextX" type="int" value="2"/>
@ -9021,7 +9021,7 @@
</properties>
</object>
</objectgroup>
<layer id="1" name="wall" width="20" height="10">
<layer id="1" name="wall" width="20" height="10" locked="1">
<data encoding="csv">
21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
40,40,40,8,9,40,40,40,40,40,40,40,40,40,40,8,9,40,40,40,