diff --git a/.gitignore b/.gitignore index eee0adf..144401e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ build # Ignore bin bin/ +*.tiled-session +resources/map/Maps.tiled-session diff --git a/resources/Base.png b/resources/Base.png new file mode 100644 index 0000000..3485b12 Binary files /dev/null and b/resources/Base.png differ diff --git a/resources/Character.png b/resources/Character.png new file mode 100644 index 0000000..69c716e Binary files /dev/null and b/resources/Character.png differ diff --git a/src/Entity/Enemy.java b/src/Entity/Enemy.java index bf8a4d7..5fb1d14 100644 --- a/src/Entity/Enemy.java +++ b/src/Entity/Enemy.java @@ -12,6 +12,8 @@ public class Enemy extends Character{ public Enemy(String name, int x, int y, String img) { super(name, x, y, img); + + turn(Character.Direction.DOWN); //generate the vector of fight fightData = new FightData(name); //TODO Auto-generated constructor stub @@ -31,11 +33,5 @@ public class Enemy extends Character{ // TODO Auto-generated method stub } - - @Override - public void draw(GdxGraphics arg0) { - // TODO Auto-generated method stub - - } } diff --git a/src/Entity/Entity.java b/src/Entity/Entity.java index 079c676..42b8728 100644 --- a/src/Entity/Entity.java +++ b/src/Entity/Entity.java @@ -36,7 +36,6 @@ public abstract class Entity implements DrawableObject { } public void init(){ - } public void graphicRender(GdxGraphics g){ diff --git a/src/Entity/Player.java b/src/Entity/Player.java index 21e1e9f..ff577ed 100644 --- a/src/Entity/Player.java +++ b/src/Entity/Player.java @@ -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,9 +46,13 @@ public class Player extends Character{ // Is the move valid ? if (sm.isWalkable(nextCell)) { - // Go - setSpeed(sm.getSpeed(nextCell)); - go(goalDirection); + if(!enemy()){ + // Go + setSpeed(sm.getSpeed(nextCell)); + go(goalDirection); + } else { + + } } else { // Face the wall turn(goalDirection); @@ -73,7 +77,17 @@ public class Player extends Character{ } } - public void move(int x, int y){ + private boolean enemy() { + /* + Vector entities = testHER.getEntities; + for (Entity entity : entities) { + + } + */ + return false; + } + + public void move(int x, int y){ } diff --git a/src/Screen/Hero.java b/src/Screen/Hero.java deleted file mode 100644 index 484fffd..0000000 --- a/src/Screen/Hero.java +++ /dev/null @@ -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); - } -} diff --git a/src/Screen/ScreenMap.java b/src/Screen/ScreenMap.java index 8012e55..4e9f955 100644 --- a/src/Screen/ScreenMap.java +++ b/src/Screen/ScreenMap.java @@ -33,6 +33,7 @@ public class ScreenMap extends RenderingScreen{ public int tileWidth; private int height; public int tileHeight; + private void createMap(String name){ diff --git a/src/testHER.java b/src/testHER.java index b177a7c..a11d713 100644 --- a/src/testHER.java +++ b/src/testHER.java @@ -1,6 +1,9 @@ +import java.util.Vector; + import com.badlogic.gdx.Input; import Control.Controller; +import Entity.Enemy; import Entity.Entity; import Entity.Player; import Screen.ScreenMap; @@ -13,15 +16,19 @@ public class testHER extends PortableApplication{ private Controller controller; private ScreenMap sm; private Player p1; - private static Entity[] entities; + private static Vector entities = new Vector<>(); + private static Vector players = new Vector<>(); public testHER(){ controller = new Controller(); - p1 = new Player(8, 15); sm = new ScreenMap(); } + public static Vector getEntities() { + return entities; + } + public static void main(String[] args) { @@ -32,15 +39,25 @@ public class testHER extends PortableApplication{ public void onInit() { controller.init(); sm.init(); - p1.init(); + p1 = new Player(8, 15); + entities.add((Entity) p1); + entities.add(new Enemy("Mudry", 10, 15, "lumberjack_sheet32")); + entities.add(new Enemy("Pignat", 12, 15, "lumberjack_sheet32")); + + for (Entity entity : entities) { + entity.init(); + } } @Override public void onGraphicRender(GdxGraphics g) { g.clear(); p1.manageEntity(sm, controller); - sm.graphicRender(g, p1); // load p1 by Entity[] - p1.graphicRender(g); + sm.graphicRender(g, p1); + + for (Entity entity : entities) { + entity.graphicRender(g); + } } @Override