Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/map/RPGScreenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/RPGTiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/boss_chest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/grassland.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/grassland_structures.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/grassland_trees.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/grassland_water.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/rottentower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/set_rules.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/tiled_collision.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map/tiled_grassland_2x2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/terrain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions core/src/com/cpa/project/Camera/OrthographicCamera.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cpa.project.Camera;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
Expand All @@ -9,6 +10,9 @@
public class OrthographicCamera extends com.badlogic.gdx.graphics.OrthographicCamera {
Entity target;
float lerp = 0.1f;
private float zoom = 1.0f;



Viewport viewport;

Expand All @@ -23,6 +27,12 @@ public void update(float dt) {
position.x = target.getSprite().getX() + target.getSprite().getWidth() / 2;
position.y = target.getSprite().getY() + target.getSprite().getHeight() / 2;
}

position.x += zoom * 0.5f;
position.y -= zoom * 0.25f;

position.lerp(new Vector3(position.x, position.y, 0), lerp);

viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}

Expand All @@ -41,4 +51,13 @@ public Viewport getViewport() {
public void setViewport(Viewport viewport) {
this.viewport = viewport;
}


public void setZoom(float zoom) {
this.zoom = zoom;
}

public float getZoom() {
return zoom;
}
}
21 changes: 12 additions & 9 deletions core/src/com/cpa/project/Survivors.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
Expand All @@ -13,7 +12,7 @@
import com.cpa.project.Entities.Actors.Mobs.Skeleton;
import com.cpa.project.Entities.Actors.Player;
import com.cpa.project.Entities.Entity;
import com.cpa.project.World.MapManager;
import com.cpa.project.World.Map;
import com.cpa.project.World.World;

import java.util.HashSet;
Expand All @@ -22,15 +21,18 @@
public class Survivors extends Game {
SpriteBatch batch;
World world;
MapManager mapManager;
ShapeRenderer shapeRenderer;
OrthographicCamera camera;

Player player ;

Map map;

@Override
public void create() {
batch = new SpriteBatch();
Player player = new Player(new Vector2(800, 240), new Sprite(new Texture("threeformsPrev.png")));
player.setSpeed(50);
player = new Player(new Vector2(800, 240), new Sprite(new Texture("threeformsPrev.png")));
player.setSpeed(25);
player.setHealth(10);
Set<Entity> entities = new HashSet<>();
entities.add(player);
Expand All @@ -39,21 +41,22 @@ public void create() {
camera = new OrthographicCamera();
camera.setTarget(player);
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
mapManager = new MapManager(camera ,1);
map = new Map(batch, camera, player.getPosition());
world = new World(player, entities, camera );
shapeRenderer = new ShapeRenderer();
// change the player position to the center of the map
player.setPosition(new Vector2((float) (map.getWidth() * 48) / 2, (float) (map.getHeight() * 48) / 2));
}

@Override
public void render() {
ScreenUtils.clear(0, 1, 0, 0.2f);
this.camera.update(Gdx.graphics.getDeltaTime());

mapManager.update(Gdx.graphics.getDeltaTime(),batch, shapeRenderer, world.getPlayer().getPosition());

map.render( this.player.getPosition());

batch.setProjectionMatrix(this.world.getCamera().combined);
batch.begin();

world.update(Gdx.graphics.getDeltaTime());
world.getPlayer().getSprite().draw(batch);
for (Entity entity : world.getEntities()) {
Expand Down
203 changes: 203 additions & 0 deletions core/src/com/cpa/project/Tiles/Tile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package com.cpa.project.Tiles;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
import com.badlogic.gdx.math.Vector2;

import java.util.Arrays;

public class Tile extends StaticTiledMapTile {
private int id ;
private BlendMode blendMode = BlendMode.ALPHA; // on utilise le mode alpha par défaut
private MapProperties properties ;
private TextureRegion textureRegion ;
private boolean isReacheable ;

private Vector2 position;

public Tile(int id , TextureRegion textureRegion) {
super(textureRegion);
this.id = id ;
this.textureRegion = textureRegion ;
this.properties = new MapProperties();
this.isReacheable = true ;
}

public Tile(int id , TextureRegion textureRegion , Boolean isReacheable) {
super(textureRegion);
this.id = id ;
this.textureRegion = textureRegion ;
this.properties = new MapProperties();
this.isReacheable = isReacheable ;
}

public void setPosition(Vector2 position) {
this.position = position;
}

public Vector2 getPosition() {
return this.position;
}


public void setIsReachable(boolean value)
{
this.isReacheable = value;
}

public boolean isReachable()
{
return this.isReacheable;
}

@Override
public int getId()
{
return this.id;
}

@Override
public void setId(int id)
{
this.id = id;

}

@Override
public BlendMode getBlendMode()
{
return this.blendMode;
}

@Override
public void setBlendMode(BlendMode blendMode)
{
this.blendMode = blendMode;

}

@Override
public TextureRegion getTextureRegion()
{
return this.textureRegion;
}

@Override
public MapProperties getProperties()
{
return this.properties;
}

public void update(float dt , SpriteBatch batch , float x , float y ) {
// draw the tile
batch.draw(textureRegion, x, y);
}

public Tile clone(int id) {
return new Tile(id, this.textureRegion);
}

public boolean isIn(int[] ids) {
for (int i = 0; i < ids.length; i++) {
if (this.id == ids[i]) {
return true;
}
}
return false;
}

public TileType getTileType() {
//System.out.println("this.id : " + this.id);
//System.out.println("List.of(terrainFloorTiles.SAND) : " );
//System.out.println(Arrays.toString(terrainFloorTiles.SAND));
if (isIn(terrainFloorTiles.SAND)) {
return TileType.Sand;
}
if (isIn(terrainFloorTiles.GRASS)) {
return TileType.Grass;
}
if (isIn(terrainFloorTiles.ROCK)) {
return TileType.Rock;
}
if (isIn(terrainFloorTiles.WATER)) {
return TileType.Water;
}

return TileType.None;
}

public Tile getTransition(TileType top, TileType right, TileType bottom, TileType left,
TileType topLeft, TileType topRight, TileType bottomLeft, TileType bottomRight) {
TileType centerType = getTileType();
if (centerType == TileType.Sand) {
if (top == TileType.Grass && left == TileType.Grass) {
return terrainFloorTiles.sandCenterWGrass[0][0];
}
if (top == TileType.Grass && right == TileType.Grass) {
return terrainFloorTiles.sandCenterWGrass[0][2];
}
if (bottom == TileType.Grass && left == TileType.Grass) {
return terrainFloorTiles.sandCenterWGrass[2][0];
}
if (bottom == TileType.Grass && right == TileType.Grass) {
return terrainFloorTiles.sandCenterWGrass[2][2];
}
if (left == TileType.Grass && right == TileType.Grass){
if (bottom == TileType.Sand && top == TileType.Sand){
return terrainFloorTiles.sandCenterWGrass[1][1];
}
return terrainFloorTiles.sandCenterWGrass[1][1];
}

if (top == TileType.Grass) {
return terrainFloorTiles.sandCenterWGrass[0][1];
}
if (right == TileType.Grass) {
return terrainFloorTiles.sandCenterWGrass[1][2];
}
if (bottom == TileType.Grass) {
return terrainFloorTiles.sandCenterWGrass[2][1];
}
if (left == TileType.Grass) {
return terrainFloorTiles.sandCenterWGrass[1][0];
}

}

if (centerType == TileType.Rock) {
if (top == TileType.Sand && left == TileType.Sand) {
return terrainFloorTiles.rockCenterWSand[0][0];
}
if (top == TileType.Sand && right == TileType.Sand) {
return terrainFloorTiles.rockCenterWSand[0][2];
}
if (bottom == TileType.Sand && left == TileType.Sand) {
return terrainFloorTiles.rockCenterWSand[2][0];
}
if (bottom == TileType.Sand && right == TileType.Sand) {
return terrainFloorTiles.rockCenterWSand[2][2];
}
if (top == TileType.Sand) {
return terrainFloorTiles.rockCenterWSand[0][1];
}
if (right == TileType.Sand) {
return terrainFloorTiles.rockCenterWSand[1][2];
}
if (bottom == TileType.Sand) {
return terrainFloorTiles.rockCenterWSand[2][1];
}
if (left == TileType.Sand) {
return terrainFloorTiles.rockCenterWSand[1][0];
}
}
if (centerType == TileType.Water) {
return terrainFloorTiles.waterTiles[1][1];
}

return this;
}


}
5 changes: 5 additions & 0 deletions core/src/com/cpa/project/Tiles/TileType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.cpa.project.Tiles;

public enum TileType {
Sand, Grass, Rock, Water, None // etc.
}
Loading