Added the camera object to the player class and added the teleport method. Also renamed Blocks.java to BlockMaterials.java. Also added Player object to the Main class
This commit is contained in:
@@ -12,12 +12,14 @@ public class Player implements Restrictions {
|
||||
private String spriteName;
|
||||
private TextureAtlas textureAtlas;
|
||||
private Animation<TextureAtlas.AtlasRegion> animation;
|
||||
private OrthographicCamera cam;
|
||||
|
||||
public Player(int x, int y, OrthographicCamera cam) {
|
||||
this.cam = cam;
|
||||
this.x = x*TILE_SIZE;
|
||||
this.y = y*TILE_SIZE;
|
||||
|
||||
cam.translate(this.x,this.y);
|
||||
this.cam.translate(this.x,this.y);
|
||||
|
||||
this.spriteName = "man";
|
||||
this.textureAtlas = new TextureAtlas("core/assets/" + spriteName + ".atlas");
|
||||
@@ -26,6 +28,12 @@ public class Player implements Restrictions {
|
||||
this.animation = new Animation<>(frameDuration, keyFrames);
|
||||
}
|
||||
|
||||
public static void teleport(Player player, int x, int y){
|
||||
player.x = x*TILE_SIZE;
|
||||
player.y = y*TILE_SIZE;
|
||||
player.cam.translate(x,y);
|
||||
}
|
||||
|
||||
public void render(Batch batch){
|
||||
float elapsedTime = 1f;
|
||||
batch.draw(getAnimation().getKeyFrame(elapsedTime, true), getX(), getY(), TILE_SIZE, TILE_SIZE);
|
||||
|
||||
@@ -4,12 +4,12 @@ import com.badlogic.gdx.graphics.Texture;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Blocks {
|
||||
public class BlockMaterials {
|
||||
public static HashMap<String,Block> materials = new HashMap<>();
|
||||
public static HashMap<String,Texture> textures = new HashMap<>();
|
||||
|
||||
//Private so the singleton can't be instantiated
|
||||
private Blocks() {}
|
||||
private BlockMaterials() {}
|
||||
|
||||
public Texture getTexture(String material) {
|
||||
return textures.get(material);
|
||||
@@ -18,7 +18,7 @@ public class Chunks {
|
||||
//Going from start of selected chunk to end of selected chunk in x and y
|
||||
for (int i = startX; i != endX; i++){
|
||||
for (int j = startY; j != endY; j++) {
|
||||
blocks.put(new Pair<>(i, j), Blocks.materials.get("grass"));
|
||||
blocks.put(new Pair<>(i, j), BlockMaterials.materials.get("grass"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.mygdx.game.Dimension;
|
||||
|
||||
import com.mygdx.game.Character.Player;
|
||||
import net.dermetfan.utils.Pair;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.mygdx.game.Restrictions.RENDER_DISTANCE;
|
||||
import static com.mygdx.game.Restrictions.CHUNK_SIZE;
|
||||
import static com.mygdx.game.Restrictions.SUPER_CHUNK_SIZE;
|
||||
|
||||
public class Superchunks {
|
||||
@@ -21,16 +22,16 @@ public class Superchunks {
|
||||
for (int i = startX; i != endX; i++){
|
||||
for (int j = startY; j != endY; j++) {
|
||||
Chunks chunks = new Chunks();
|
||||
Blocks.create();
|
||||
BlockMaterials.create();
|
||||
chunks.generateChunk(i, j);
|
||||
overworld.put(new Pair<>(i, j), chunks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateWithPlayer(){
|
||||
for (int i = -RENDER_DISTANCE; i < RENDER_DISTANCE; i++) {
|
||||
for (int j = -RENDER_DISTANCE; j < RENDER_DISTANCE; j++) {
|
||||
public static void generateWithPlayer(Player player){
|
||||
for (int i = -1+player.getX()/CHUNK_SIZE*SUPER_CHUNK_SIZE; i < 1+player.getX()/CHUNK_SIZE*SUPER_CHUNK_SIZE; i++) {
|
||||
for (int j = -1+player.getY()/CHUNK_SIZE*SUPER_CHUNK_SIZE; j < 1+player.getY()/CHUNK_SIZE*SUPER_CHUNK_SIZE; j++) {
|
||||
generateSuperchunk(i,j);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class WorldRenderer implements Restrictions {
|
||||
int drawingLocationX = chunkpair.getKey() * TILE_SIZE;
|
||||
int drawingLocationY = chunkpair.getValue()* TILE_SIZE;
|
||||
|
||||
batch.draw(Blocks.textures.get(name),drawingLocationX ,drawingLocationY);
|
||||
batch.draw(BlockMaterials.textures.get(name),drawingLocationX ,drawingLocationY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class Main extends ApplicationAdapter {
|
||||
private Label label;
|
||||
float physicsUpdateSpeed = 1/60f; //how often you want to do a physics-update, in this case every 1/60th of a sec
|
||||
float timeSinceLastUpdate = 0f; //accumulator
|
||||
private Player player;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -48,12 +49,13 @@ public class Main extends ApplicationAdapter {
|
||||
|
||||
|
||||
//Starting location of the player
|
||||
Player player = new Player(0,0, cam);
|
||||
player = new Player(0,0, cam);
|
||||
|
||||
cam.translate((float) TILE_SIZE / 2, (float) TILE_SIZE / 2);
|
||||
cam.zoom = 25f;
|
||||
|
||||
Superchunks.generateWithPlayer();
|
||||
Superchunks.generateWithPlayer(player);
|
||||
|
||||
|
||||
mouse = new Mouse(player);
|
||||
worldRenderer = new WorldRenderer(player, mouse,cam);
|
||||
@@ -67,6 +69,7 @@ public class Main extends ApplicationAdapter {
|
||||
|
||||
fixedStep();
|
||||
|
||||
|
||||
batch.begin();
|
||||
worldRenderer.render(batch);
|
||||
gui.render(batch);
|
||||
|
||||
Reference in New Issue
Block a user