Added old Java project for reference

This commit is contained in:
2020-04-18 09:10:24 -06:00
parent c868f03944
commit 7b68de9526
19 changed files with 2907 additions and 7 deletions

View File

@@ -2,16 +2,20 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<MonoGameContentReference Include="**\*.mgcb"/>
<MonoGameContentReference Include="**\*.mgcb" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.4"/>
<PackageReference Include="MonoGame.Framework.DesktopGL.Core" Version="3.7.0.7"/>
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" />
<PackageReference Include="MonoGame.Framework.DesktopGL.Core" Version="3.8.0.13" />
</ItemGroup>
<ItemGroup>
<Folder Include="LegacyJava" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,113 @@
package Collector.Character;
import Collector.Main;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Vector3;
import Collector.Dimension.Chunks;
import Collector.Restrictions;
import java.util.HashMap;
public class InputController implements Restrictions {
private Player player;
private HashMap<String, Animation<TextureAtlas.AtlasRegion>> animations;
private Mouse mouse;
int i = 0;
public InputController(Player player, Mouse mouse) {
this.player = player;
this.mouse = mouse;
animations = new HashMap<>();
animations.put("Up", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Up")));
animations.put("UpRight", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "UpRight")));
animations.put("UpLeft", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "UpLeft")));
animations.put("Down", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Down")));
animations.put("DownRight", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "DownRight")));
animations.put("DownLeft", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "DownLeft")));
animations.put("Left", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Left")));
animations.put("Right", new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + "Right")));
}
public void handleInput() {
i++;
if (Gdx.input.isKeyPressed(Input.Keys.Q)) {
Main.cam.zoom += 5;
}
if (Gdx.input.isKeyPressed(Input.Keys.E)) {
Main.cam.zoom -= 5;
}
if ((Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) || Gdx.input.isButtonJustPressed(Input.Buttons.RIGHT) )&& i > KEY_DELAY) {
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
Main.cam.unproject(mousePos);
int x = mouse.getSelectedX(mousePos) >> TILE_SHIFT;
int y = mouse.getSelectedY(mousePos) >> TILE_SHIFT;
if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)) {
i = 0;
Chunks.placeBlock(x, y, "wood");
}
if (Gdx.input.isButtonJustPressed(Input.Buttons.RIGHT)) {
i = 0;
Chunks.removeBlock(x,y);
}
}
if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
i = 0;
player.setAnimation(animations.get("UpLeft"));
Player.addX(-MOVEMENT_SPEED);
Player.addY(MOVEMENT_SPEED);
Main.cam.translate(-MOVEMENT_SPEED, MOVEMENT_SPEED);
}
else if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
i = 0;
player.setAnimation(animations.get("UpRight"));
Player.addX(MOVEMENT_SPEED);
Player.addY(MOVEMENT_SPEED);
Main.cam.translate(MOVEMENT_SPEED, MOVEMENT_SPEED);
}
else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
i = 0;
player.setAnimation(animations.get("DownLeft"));
Player.addX(-MOVEMENT_SPEED);
Player.addY(-MOVEMENT_SPEED);
Main.cam.translate(-MOVEMENT_SPEED, -MOVEMENT_SPEED);
}
else if (Gdx.input.isKeyPressed(Input.Keys.S) && Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
i = 0;
player.setAnimation(animations.get("DownRight"));
Player.addX(MOVEMENT_SPEED);
Player.addY(-MOVEMENT_SPEED);
Main.cam.translate(MOVEMENT_SPEED, -MOVEMENT_SPEED);
}
else if (Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
i = 0;
player.setAnimation(animations.get("Left"));
Player.addX(-MOVEMENT_SPEED);
Main.cam.translate(-MOVEMENT_SPEED, 0);
}
else if (Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
i = 0;
player.setAnimation(animations.get("Right"));
Player.addX(MOVEMENT_SPEED);
Main.cam.translate(MOVEMENT_SPEED, 0);
}
else if (Gdx.input.isKeyPressed(Input.Keys.S) && i > KEY_DELAY) {
i = 0;
player.setAnimation(animations.get("Down"));
Player.addY(-MOVEMENT_SPEED);
Main.cam.translate(0, -MOVEMENT_SPEED);
}
if (Gdx.input.isKeyPressed(Input.Keys.W) && i > KEY_DELAY) {
i = 0;
player.setAnimation(animations.get("Up"));
Player.addY(MOVEMENT_SPEED);
Main.cam.translate(0, MOVEMENT_SPEED);
}
Main.cam.update();
}
}

View File

@@ -0,0 +1,25 @@
package Collector.Character;
import Collector.Restrictions;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector3;
public class Mouse implements Restrictions {
Texture crosshair;
public Mouse() {
this.crosshair = new Texture("assets/crosshair.png");
}
public Texture getCrosshair() {
return crosshair;
}
public int getSelectedX(Vector3 mousePos) {
return ((int)(mousePos.x)>>4)<<4;
}
public int getSelectedY(Vector3 mousePos) {
return ((int)(mousePos.y)>>4)<<4;
}
}

View File

@@ -0,0 +1,68 @@
package Collector.Character;
import Collector.Restrictions;
import Collector.Dimension.Inventory;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Array;
public class Player implements Restrictions {
public static int x;
public static int y;
private String spriteName;
private TextureAtlas textureAtlas;
private Animation<TextureAtlas.AtlasRegion> animation;
private Inventory playerInventory;
public Player(int x, int y) {
//Player location
Player.x = x<<TILE_SHIFT;
Player.y = y<<TILE_SHIFT;
//Player Inventory
playerInventory = new Inventory();
//Player animation
spriteName = "man";
textureAtlas = new TextureAtlas("man.atlas");
Array<TextureAtlas.AtlasRegion> keyFrames = textureAtlas.findRegions(spriteName + "_Down");
float frameDuration = 1 / 4f;
animation = new Animation<>(frameDuration, keyFrames);
}
public static int getX() {
return x;
}
public static int getY() {
return y;
}
public static void addX(int x){
Player.x += x;
}
public static void addY(int y){
Player.y += y;
}
public String getSpriteName() {
return spriteName;
}
public Animation<TextureAtlas.AtlasRegion> getAnimation() {
return animation;
}
public void setAnimation(Animation<TextureAtlas.AtlasRegion> animationTemp) {
animation = animationTemp;
}
public void dispose(){
textureAtlas.dispose();
}
public TextureAtlas getTextureAtlas() {
return textureAtlas;
}
}

View File

@@ -0,0 +1,13 @@
package Collector.Dimension;
public class Block {
private final String name;
public Block(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

View File

@@ -0,0 +1,29 @@
package Collector.Dimension;
import com.badlogic.gdx.graphics.Texture;
import java.util.HashMap;
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 BlockMaterials() {}
public static void create(){
materials.put("grass",new Block("grass"));
materials.put("wood",new Block("wood"));
materials.put("water",new Block("water"));
materials.put("stone",new Block("stone"));
materials.put("snow",new Block("snow"));
materials.put("sand",new Block("sand"));
materials.put("air",new Block("air"));
materials.put("roof",new Block("roof"));
materials.put("wall",new Block("wall"));
for (String s:BlockMaterials.materials.keySet()) {
textures.put(s,new Texture("assets/" + s + ".png"));
}
}
}

View File

@@ -0,0 +1,192 @@
//https://www.redblobgames.com/maps/terrain-from-noise/
package Collector.Dimension;
import com.github.czyzby.kiwi.util.tuple.immutable.Triple;
import Collector.ThirdPartyCode.OpenSimplexNoise;
import java.util.HashMap;
import static Collector.Dimension.BlockMaterials.materials;
import static Collector.Restrictions.*;
public class Chunks {
public static HashMap<Triple<Integer, Integer, Integer>, Block> loadedChunks = new HashMap<>();
public static HashMap<Triple<Integer, Integer,Integer>, Block> savedChunks = new HashMap<>();
public static OpenSimplexNoise gen1 = new OpenSimplexNoise(SEED + 1);
public static OpenSimplexNoise gen2 = new OpenSimplexNoise(SEED);
public static void createStructures() {
int i = 10;
setBlock(3 + i, 2,1,"wall");
setBlock(4 + i, 2,1,"wall");
setBlock(3 + i, 3,1, "roof");
setBlock(4 + i, 3,1,"roof");
}
public static void setBlock(int x, int y,int z, String name) {
loadedChunks.put(new Triple<>(x, y, z), materials.get(name));
savedChunks.put(new Triple<>(x, y, z), materials.get(name));
}
public static void placeBlock(int x, int y, String name){
Triple<Integer, Integer, Integer> triple = new Triple<>(x, y, 1);
if(Chunks.loadedChunks.get(triple).getName().equals("air")) {
Chunks.loadedChunks.replace(triple, Chunks.loadedChunks.get(triple), materials.get(name));
Chunks.savedChunks.replace(triple, Chunks.savedChunks.get(triple), materials.get(name));
}
}
public static void removeBlock(int x, int y){
Triple<Integer, Integer, Integer> triple = new Triple<>(x, y, 1);
if(!Chunks.loadedChunks.get(triple).getName().equals("air")) {
Chunks.loadedChunks.replace(triple, Chunks.loadedChunks.get(triple), materials.get("air"));
Chunks.savedChunks.replace(triple, Chunks.savedChunks.get(triple), materials.get("air"));
}
}
public static void ungenerateChunk(int x, int y) {
int startX = x << CHUNK_SHIFT;
int startY = y << CHUNK_SHIFT;
int endX = startX + CHUNK_SIZE;
int endY = startY + CHUNK_SIZE;
//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++) {
loadedChunks.remove(new Triple<>(i, j, 0), getTerrain(i, j));
}
}
//Second Layer
for (int i = startX; i != endX; i++){
for (int j = startY; j != endY; j++) {
Triple<Integer,Integer,Integer> triple = new Triple<>(i, j,1);
loadedChunks.remove(triple, loadedChunks.get(triple));
}
}
}
public static void generateChunk(int x, int y) {
int startX = x << CHUNK_SHIFT;
int startY = y << CHUNK_SHIFT;
int endX = startX + CHUNK_SIZE;
int endY = startY + CHUNK_SIZE;
//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++) {
Triple<Integer, Integer, Integer> triple = new Triple<>(i, j, 0);
if(savedChunks.get(triple) != null){
loadedChunks.put(triple,savedChunks.get(triple));
}
else {
loadedChunks.put(triple, getTerrain(i, j));
savedChunks.put(triple, getTerrain(i,j));
}
}
}
//Second Layer
for (int i = startX; i != endX; i++){
for (int j = startY; j != endY; j++) {
Triple<Integer,Integer,Integer> triple = new Triple<>(i, j,1);
loadedChunks.put(triple, getBlocks(i,j,1));
savedChunks.put(triple, getBlocks(i,j,1));
}
}
}
public static Block getBlocks(int x, int y, int z) {
return savedChunks.getOrDefault(new Triple<>(x, y, z), new Block("air"));
}
public static double noise1(double nx, double ny) {
return gen1.eval(nx, ny) / 2 + 0.5;
}
public static double noise2(double nx, double ny) {
return gen2.eval(nx, ny) / 2 + 0.5;
}
public static Block getTerrain(int x, int y) {
double moisture, elevation, nx, ny;
double scale = 0.01;
nx = x * scale;
ny = y * scale;
elevation = (0.17 * noise1(1 * nx, 1 * ny)
+ 0.42 * noise1(2 * nx, 2 * ny)
+ 0.16 * noise1(4 * nx, 4 * ny)
+ 0.00 * noise1(8 * nx, 8 * ny)
+ 0.00 * noise1(16 * nx, 16 * ny)
+ 0.03 * noise1(32 * nx, 32 * ny));
elevation /= (0.17+0.42+0.16+0.00+0.00+0.03);
elevation = Math.pow(elevation, 3.00);
moisture = (1.00 * noise2( 1 * nx, 1 * ny)
+ 0.00 * noise2( 2 * nx, 2 * ny)
+ 1.00 * noise2( 4 * nx, 4 * ny)
+ 0.00 * noise2( 8 * nx, 8 * ny)
+ 0.00 * noise2(16 * nx, 16 * ny)
+ 0.00 * noise2(32 * nx, 32 * ny));
moisture /= (0.00+1.00+0.00+0.00+0.00+0.00);
return getBiomeBlock(moisture, elevation);
}
public static Block getBiomeBlock(double moisture, double elevation) {
String biome = getBiome(moisture, elevation);
if (biome.equals("Tundra")) return materials.get("snow");
if (biome.equals("Taiga")) return materials.get("snow");
if (biome.equals("Snow")) return materials.get("snow");
if (biome.equals("Grassland")) return materials.get("grass");
if (biome.equals("Shrubland")) return materials.get("grass");
if (biome.equals("TemperateDeciduousForest")) return materials.get("grass");
if (biome.equals("TemperateRainForest")) return materials.get("grass");
if (biome.equals("TropicalSeasonalForest")) return materials.get("grass");
if (biome.equals("TropicalForest")) return materials.get("grass");
if (biome.equals("TropicalRainForest")) return materials.get("grass");
if (biome.equals("Beach")) return materials.get("sand");
if (biome.equals("Bare")) return materials.get("sand");
if (biome.equals("Scorched")) return materials.get("sand");
if (biome.equals("TemperateDesert")) return materials.get("sand");
if (biome.equals("SubtropicalDesert")) return materials.get("sand");
return materials.get("water");
}
public static String getBiome(double moisture, double elevation) {
if (elevation < 0.1) return "Ocean";
if (elevation < 0.12) return "Beach";
if (elevation > 0.8) {
if (moisture < 0.1) return "Scorched";
if (moisture < 0.2) return "Bare";
if (moisture < 0.5) return "Tundra";
return "Snow";
}
if (elevation > 0.6) {
if (moisture < 0.33) return "TemperateDesert";
if (moisture < 0.66) return "Shrubland";
return "Taiga";
}
if (elevation > 0.3) {
if (moisture < 0.16) return "TemperateDesert";
if (moisture < 0.50) return "Grassland";
if (moisture < 0.83) return "TemperateDeciduousForest";
return "TemperateRainForest";
}
if (moisture < 0.16) return "SubtropicalDesert";
if (moisture < 0.33) return "Grassland";
if (moisture < 0.66) return "TropicalSeasonalForest";
return "TropicalRainForest";
}
public static Boolean isEmpty(int x, int y){
return loadedChunks.get(new Triple<>(x * 8, y * 8,0)) == null;
}
}

View File

@@ -0,0 +1,23 @@
package Collector.Dimension;
import java.util.LinkedList;
public class Inventory {
private LinkedList<ItemStack> inventory = new LinkedList<ItemStack>();
public LinkedList<ItemStack> getInventory() {
return inventory;
}
public void setInventory(LinkedList<ItemStack> inventory) {
this.inventory = inventory;
}
public void addItem(Block block){
inventory.add((ItemStack) block);
}
public void removeItem(ItemStack itemStack){
inventory.remove(itemStack);
}
}

View File

@@ -0,0 +1,14 @@
package Collector.Dimension;
import Collector.Dimension.Block;
public class ItemStack extends Block {
int value;
int quantity;
public ItemStack(String name, int value, int quantity) {
super(name);
this.value = value;
this.quantity = quantity;
}
}

View File

@@ -0,0 +1,56 @@
package Collector.Dimension;
import Collector.Character.Player;
import static Collector.Restrictions.*;
public class World {
public static void generateWorld(int x, int y) {
if (Chunks.isEmpty(x, y)) {
Chunks.generateChunk(x, y);
}
}
public static void ungenerateWorld(int x, int y) {
if (!Chunks.isEmpty(x, y)) {
Chunks.ungenerateChunk(x, y);
}
}
public static void loadChunks() {
for (int i = -(RENDER_DISTANCE); i < RENDER_DISTANCE; i++) {
for (int j = -(RENDER_DISTANCE); j < RENDER_DISTANCE; j++) {
generateWorld(
i + Player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE),
j + Player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)
);
}
}
}
public static void unloadChunks() {
for (int i = -RENDER_DISTANCE; i < RENDER_DISTANCE+1; i++) {
//Down
ungenerateWorld(
Player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)+i,
(Player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE))+3
);
//Up
ungenerateWorld(
Player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)+i-1,
(Player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE))-4
);
//Right
ungenerateWorld(
Player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)-4,
(Player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE))+i
);
//Left
ungenerateWorld(
Player.getX() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE)+3,
(Player.getY() / (TILE_SIZE * SUPER_CHUNK_SIZE * CHUNK_SIZE))+i
);
}
}
}

View File

@@ -0,0 +1,57 @@
package Collector.Dimension;
import Collector.Character.Player;
import Collector.Main;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.github.czyzby.kiwi.util.tuple.immutable.Triple;
import Collector.Character.InputController;
import Collector.Character.Mouse;
import Collector.Restrictions;
import java.util.Iterator;
public class WorldRenderer implements Restrictions {
private Mouse mouse;
private InputController inputController;
private Player player;
public WorldRenderer(InputController inputController, Mouse mouse, Player player) {
this.inputController = inputController;
this.mouse = mouse;
this.player = player;
}
public void drawWorld(SpriteBatch batch, int layer) {
for (Triple<Integer, Integer, Integer> chunkpair : Chunks.loadedChunks.keySet()) {
if (chunkpair.getThird() == layer) {
batch.draw(
BlockMaterials.textures.get(Chunks.loadedChunks.get(chunkpair).getName()),
chunkpair.getFirst() << TILE_SHIFT,
chunkpair.getSecond() << TILE_SHIFT
);
}
}
}
private void mouseCrosshair(SpriteBatch batch) {
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
Main.cam.unproject(mousePos);
int x = mouse.getSelectedX(mousePos);
int y = mouse.getSelectedY(mousePos);
batch.draw(mouse.getCrosshair(), x, y);
}
public void render(SpriteBatch batch, float timeSinceLastUpdate) {
//Higher means draws in a lower layer
drawWorld(batch,0);
batch.draw(player.getAnimation().getKeyFrame(timeSinceLastUpdate, true), Player.x, Player.y,TILE_SIZE,TILE_SIZE);
drawWorld(batch,1);
mouseCrosshair(batch);
inputController.handleInput();
batch.setProjectionMatrix(Main.cam.combined);
}
}

View File

@@ -0,0 +1,94 @@
package Collector;
import Collector.Dimension.*;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import Collector.Character.InputController;
import Collector.Character.Mouse;
import Collector.Character.Player;
import Collector.UI.GUI;
import static Collector.Restrictions.*;
public class Main extends ApplicationAdapter {
private Stage stage;
private SpriteBatch batch;
private WorldRenderer worldRenderer;
private GUI gui;
private ExtendViewport extendViewport;
public static float chunkLoadingTime = 0;
float playerAnimationTime = 0f; //accumulator
public static OrthographicCamera cam;
private InputController inputController;
private Mouse mouse;
private Player player;
@Override
public void create () {
Gdx.graphics.setWindowedMode(1024, 576);
//Declaring all objects needed for the game
cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
extendViewport = new ExtendViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, cam);
mouse = new Mouse();
player = new Player(0, 0);
inputController = new InputController(player,mouse);
worldRenderer = new WorldRenderer(inputController,mouse,player);
batch = new SpriteBatch();
stage = new Stage();
gui = new GUI(stage);
Gdx.input.setInputProcessor(stage);
BlockMaterials.create();
Chunks.createStructures();
//cam.translate(TILE_SIZE, TILE_SIZE);
cam.zoom = 25f;
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void render () {
float deltaTime = Gdx.graphics.getDeltaTime();
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
playerAnimationTime += deltaTime;
chunkLoadingTime += deltaTime;
gui.debugInfo(stage,mouse);
stage.act(deltaTime);
batch.begin();
worldRenderer.render(batch,playerAnimationTime);
if (chunkLoadingTime > RENDER_TIME) {
chunkLoadingTime -= RENDER_TIME;
World.loadChunks();
World.unloadChunks();
}
cam.update();
batch.end();
stage.draw();
}
@Override
public void dispose () {
gui.dispose();
player.dispose();
stage.dispose();
batch.dispose();
}
}

View File

@@ -0,0 +1,23 @@
package Collector;
public interface Restrictions {
int SEED = 1;
float VIEWPORT_HEIGHT = 9/2f;
float VIEWPORT_WIDTH = 16/2f;
int MOVEMENT_SPEED = 16;
int FREE_SPEED = 2;
int KEY_DELAY = 0;
int TILE_SIZE = 16;
int CHUNK_SIZE = 8;
int SUPER_CHUNK_SIZE = 1;
int TILE_SHIFT = (int)(Math.log(TILE_SIZE)/Math.log(2));
int CHUNK_SHIFT = (int)(Math.log(CHUNK_SIZE)/Math.log(2));
//int SUPER_CHUNK_SHIFT = (int)(Math.log(SUPER_CHUNK_SIZE)/Math.log(2));
int RENDER_DISTANCE = 3;
float RENDER_TIME = 1/60f;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,55 @@
package Collector.UI;
import Collector.Character.Mouse;
import Collector.Main;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import Collector.Restrictions;
public class GUI implements Restrictions {
private final BitmapFont font;
private ExtendViewport guiViewport;
private final Table table;
private final Label label;
public GUI(Stage stage) {
font = new BitmapFont();
table = new Table();
table.setDebug(true);
guiViewport = new ExtendViewport(Gdx.graphics.getWidth(),Gdx.graphics.getHeight(),stage.getCamera());
stage.setViewport(guiViewport);
//Creating block selection debug menu
table.top().left();
label = new Label("x=N/A y=N/A", new Label.LabelStyle(font,Color.WHITE));
table.add(label);
//Creating Minimap
}
public void debugInfo(Stage stage, Mouse mouse){
table.setFillParent(true);
stage.addActor(table);
//Mouse position
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
Main.cam.unproject(mousePos);
int x = mouse.getSelectedX(mousePos) >> TILE_SHIFT;
int y = mouse.getSelectedY(mousePos) >> TILE_SHIFT;
label.setText("x="+ x + " y=" + y);
}
public void dispose(){
font.dispose();
}
}

View File

@@ -0,0 +1,4 @@
package Collector.UI;
public class InventoryInterface {
}

View File

@@ -0,0 +1,5 @@
package Collector.UI;
public class MiniMap {
}

View File

@@ -4,12 +4,12 @@ using Microsoft.Xna.Framework.Input;
namespace Collector
{
public class Game1 : Game
public class Main : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
public Main()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";

View File

@@ -7,7 +7,7 @@ namespace Collector
[STAThread]
static void Main()
{
using (var game = new Game1())
using (var game = new Main())
game.Run();
}
}