Updated Libgdx to a newer version to add gui to the game. This sadly broke the player sprite :/

This commit is contained in:
2020-04-11 07:55:19 -06:00
parent d6c54921d8
commit 57f806983e
80 changed files with 812 additions and 513 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

View File

@@ -1,2 +0,0 @@
cd /d %~dp0
start javaw -Xms64m -Xmx1024m -XX:+UseG1GC -XX:MinHeapFreeRatio=15 -XX:MaxHeapFreeRatio=30 -jar gdx-texturepacker.jar %*

View File

@@ -1,3 +0,0 @@
SCRIPTDIR=$(dirname "$0")
cd $SCRIPTDIR
java -Xms64m -Xmx1024m -XX:+UseG1GC -XX:MinHeapFreeRatio=15 -XX:MaxHeapFreeRatio=30 -jar ./gdx-texturepacker.jar

View File

@@ -1,7 +0,0 @@
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c launcher.bat "
For Each arg In Wscript.Arguments
strArgs = strArgs + arg
Next
oShell.Run strArgs, 0, false

View File

@@ -1,27 +0,0 @@
Gdx Texture Packer GUI
Simple utility to help you pack and manage texture atlases for LibGDX game framework. It's mostly just visual wrapper over LibGDX TexturePacker classes and offers more convenient way of using it.
For further details visit GitHub project page:
https://github.com/crashinvaders/gdx-texture-packer-gui
Requirements:
- Java 7 JRE (or higher) (can be donwnloaded here http://www.oracle.com/technetwork/java/javase/downloads/index.html)
- OpenGL support
How to launch:
Application is packed into JAR executable file. To launch it, issue next command
java -jar gdx-texturepacker.jar
MacOS and UNIX
You may execute launch.sh bash script to launch application
Windows
launch.bat - starts application
launcher_no_cmd.vbs - does exactly what launch.bat does, but CMD window won't appear in that case
If you got any questions or would like to share some ideas, reach me out at anton@crashinvaders.com
Hope you will enjoy it!
Anton Chekulaev

View File

@@ -1,3 +0,0 @@
You can define/override you own keyboard shortcuts for some actions.
For the details look at the default hotkey configuration file.
https://github.com/crashinvaders/gdx-texture-packer-gui/blob/master/assets/hotkeys_default.txt

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -1,229 +0,0 @@
man.png
size: 256, 128
format: RGBA8888
filter: Nearest,Nearest
repeat: none
man_Up
rotate: false
xy: 0,0
size: 32,32
orig: 32,32
offset: 0,0
index: 0
man_Up
rotate: false
xy: 32,0
size: 32,32
orig: 32,32
offset: 0,0
index: 1
man_Up
rotate: false
xy: 64,0
size: 32,32
orig: 32,32
offset: 0,0
index: 2
man_Up
rotate: false
xy: 96,0
size: 32,32
orig: 32,32
offset: 0,0
index: 3
man_Down
rotate: false
xy: 128,0
size: 32,32
orig: 32,32
offset: 0,0
index: 0
man_Down
rotate: false
xy: 160,0
size: 32,32
orig: 32,32
offset: 0,0
index: 1
man_Down
rotate: false
xy: 192,0
size: 32,32
orig: 32,32
offset: 0,0
index: 2
man_Down
rotate: false
xy: 224,0
size: 32,32
orig: 32,32
offset: 0,0
index: 3
man_Left
rotate: false
xy: 0,32
size: 32,32
orig: 32,32
offset: 0,0
index: 0
man_Left
rotate: false
xy: 32,32
size: 32,32
orig: 32,32
offset: 0,0
index: 1
man_Left
rotate: false
xy: 64,32
size: 32,32
orig: 32,32
offset: 0,0
index: 2
man_Left
rotate: false
xy: 96,32
size: 32,32
orig: 32,32
offset: 0,0
index: 3
man_Right
rotate: false
xy: 128,32
size: 32,32
orig: 32,32
offset: 0,0
index: 0
man_Right
rotate: false
xy: 160,32
size: 32,32
orig: 32,32
offset: 0,0
index: 1
man_Right
rotate: false
xy: 192,32
size: 32,32
orig: 32,32
offset: 0,0
index: 2
man_Right
rotate: false
xy: 224,32
size: 32,32
orig: 32,32
offset: 0,0
index: 3
man_UpLeft
rotate: false
xy: 0,64
size: 32,32
orig: 32,32
offset: 0,0
index: 0
man_UpLeft
rotate: false
xy: 32,64
size: 32,32
orig: 32,32
offset: 0,0
index: 1
man_UpLeft
rotate: false
xy: 64,64
size: 32,32
orig: 32,32
offset: 0,0
index: 2
man_UpLeft
rotate: false
xy: 96,64
size: 32,32
orig: 32,32
offset: 0,0
index: 3
man_UpRight
rotate: false
xy: 128,64
size: 32,32
orig: 32,32
offset: 0,0
index: 0
man_UpRight
rotate: false
xy: 160,64
size: 32,32
orig: 32,32
offset: 0,0
index: 1
man_UpRight
rotate: false
xy: 192,64
size: 32,32
orig: 32,32
offset: 0,0
index: 2
man_UpRight
rotate: false
xy: 224,64
size: 32,32
orig: 32,32
offset: 0,0
index: 3
man_DownLeft
rotate: false
xy: 0,96
size: 32,32
orig: 32,32
offset: 0,0
index: 0
man_DownLeft
rotate: false
xy: 32,96
size: 32,32
orig: 32,32
offset: 0,0
index: 1
man_DownLeft
rotate: false
xy: 64,96
size: 32,32
orig: 32,32
offset: 0,0
index: 2
man_DownLeft
rotate: false
xy: 96,96
size: 32,32
orig: 32,32
offset: 0,0
index: 3
man_DownRight
rotate: false
xy: 128,96
size: 32,32
orig: 32,32
offset: 0,0
index: 0
man_DownRight
rotate: false
xy: 160,96
size: 32,32
orig: 32,32
offset: 0,0
index: 1
man_DownRight
rotate: false
xy: 192,96
size: 32,32
orig: 32,32
offset: 0,0
index: 2
man_DownRight
rotate: false
xy: 224,96
size: 32,32
orig: 32,32
offset: 0,0
index: 3

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -1,62 +0,0 @@
world.png
size: 128,16
format: RGBA8888
filter: Nearest,Nearest
repeat: none
crosshair
rotate: false
xy: 48, 0
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
grass
rotate: false
xy: 96, 0
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
jungleGrass
rotate: false
xy: 112, 0
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
sand
rotate: false
xy: 16, 0
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
snow
rotate: false
xy: 0, 0
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
stone
rotate: false
xy: 64, 0
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
water
rotate: false
xy: 32, 0
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
wood
rotate: false
xy: 80, 0
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -1,8 +1,23 @@
apply plugin: "java"
sourceCompatibility = 1.7
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
eclipse.project.name = appName + '-core'
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project.name = appName + "-core"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-ai:$aiVersion"
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
api "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
api "com.badlogicgames.ashley:ashley:$ashleyVersion"
api "com.badlogicgames.box2dlights:box2dlights:$box2dlightsVersion"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
api "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
api "com.github.czyzby:noise4j:$noise4jVersion"
api "com.github.ykrasik:jaci-libgdx-cli-gwt:$jaciGwtVersion"
api "com.sudoplay.joise:joise:$joiseVersion"
api "com.github.czyzby:gdx-kiwi:$kiwiVersion"
api "de.tomgrill.gdxdialogs:gdx-dialogs-core:$dialogsVersion"
api "com.strongjoshua:libgdx-inGameConsole:$inGameConsoleVersion"
api "net.dermetfan.libgdx-utils:libgdx-utils:$utilsVersion"
api "net.dermetfan.libgdx-utils:libgdx-utils-box2d:$utilsBox2dVersion"
api "com.underwaterapps.overlap2druntime:overlap2d-runtime-libgdx:$overlap2dVersion"
api "com.github.ykrasik:jaci-libgdx-cli-java:$jaciVersion"
}

View File

@@ -1,31 +0,0 @@
package com.mygdx.game.Dimension;
import com.badlogic.gdx.graphics.Texture;
public class Block {
private String name;
private Texture texture;
private Boolean harvestable;
private Boolean breakable;
private Boolean passable;
public Block(String name) {
this.name = name;
this.texture = new Texture("core/assets/" + name + ".png");
this.harvestable = true;
this.breakable = true;
this.passable = false;
}
public String getName() {
return name;
}
public Texture getTexture() {
return texture;
}
public void setTexture(Texture texture) {
this.texture = texture;
}
}

View File

@@ -1,4 +0,0 @@
package com.mygdx.game;
public class Storage {
}

View File

@@ -1,24 +1,26 @@
package com.mygdx.game.Character;
package Collector.Character;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.math.Vector3;
import com.mygdx.game.Dimension.Chunks;
import com.mygdx.game.Restrictions;
import Collector.Dimension.Chunks;
import Collector.Restrictions;
import java.util.HashMap;
import static com.mygdx.game.Main.cam;
import static Collector.Main.cam;
public class InputController implements Restrictions {
private Player player;
private final Player player;
int i = 0;
private final HashMap<String, Animation<com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion>> animations;
public InputController(Player player) {
this.player = player;
animations = new HashMap<>();
/*
animations.put("Up", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "Up")));
animations.put("UpRight", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "UpRight")));
animations.put("UpLeft", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "UpLeft")));
@@ -28,7 +30,7 @@ public class InputController implements Restrictions {
animations.put("Left", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "Left")));
animations.put("Right", new Animation<>(1 / 4f, player.textureAtlas.findRegions(player.getSpriteName() + "_" + "Right")));
this.player = player;
*/
}
public void handleInput() {
@@ -59,28 +61,28 @@ public class InputController implements Restrictions {
if (Gdx.input.isKeyPressed(Input.Keys.W) && Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
i = 0;
directionAnimation("UpLeft");
//player.setAnimation(animations.get("UpLeft"));
Player.addX(-MOVEMENT_SPEED);
Player.addY(MOVEMENT_SPEED);
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;
directionAnimation("UpRight");
//player.setAnimation(animations.get("UpRight"));
Player.addX(MOVEMENT_SPEED);
Player.addY(MOVEMENT_SPEED);
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;
directionAnimation("DownLeft");
//player.setAnimation(animations.get("DownLeft"));
Player.addX(-MOVEMENT_SPEED);
Player.addY(-MOVEMENT_SPEED);
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;
directionAnimation("DownRight");
//player.setAnimation(animations.get("DownRight"));
Player.addX(MOVEMENT_SPEED);
Player.addY(-MOVEMENT_SPEED);
@@ -88,33 +90,29 @@ public class InputController implements Restrictions {
}
else if (Gdx.input.isKeyPressed(Input.Keys.A) && i > KEY_DELAY) {
i = 0;
directionAnimation("Left");
//player.setAnimation(animations.get("Left"));
Player.addX(-MOVEMENT_SPEED);
cam.translate(-MOVEMENT_SPEED, 0);
}
else if (Gdx.input.isKeyPressed(Input.Keys.D) && i > KEY_DELAY) {
i = 0;
directionAnimation("Right");
//player.setAnimation(animations.get("Right"));
Player.addX(MOVEMENT_SPEED);
cam.translate(MOVEMENT_SPEED, 0);
}
else if (Gdx.input.isKeyPressed(Input.Keys.S) && i > KEY_DELAY) {
i = 0;
directionAnimation("Down");
//player.setAnimation(animations.get("Down"));
Player.addY(-MOVEMENT_SPEED);
cam.translate(0, -MOVEMENT_SPEED);
}
if (Gdx.input.isKeyPressed(Input.Keys.W) && i > KEY_DELAY) {
i = 0;
directionAnimation("Up");
//player.setAnimation(animations.get("Up"));
Player.addY(MOVEMENT_SPEED);
cam.translate(0, MOVEMENT_SPEED);
}
cam.update();
}
public void directionAnimation(String direction) {
player.setAnimation(animations.get(direction));
}
}

View File

@@ -1,24 +1,22 @@
package com.mygdx.game.Character;
package Collector.Character;
import Collector.Main;
import Collector.Restrictions;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.mygdx.game.Restrictions;
import static com.mygdx.game.Main.cam;
public class Mouse implements Restrictions {
Texture crosshair;
public Mouse() {
this.crosshair = new Texture("core/assets/crosshair.png");
this.crosshair = new Texture("assets/crosshair.png");
}
public void selectedTile(SpriteBatch batch) {
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
cam.unproject(mousePos);
Main.cam.unproject(mousePos);
int x = getSelectedX(mousePos);
int y = getSelectedY(mousePos);
batch.draw(crosshair, x, y);
@@ -32,20 +30,9 @@ public class Mouse implements Restrictions {
return ((int)(mousePos.y)>>4)<<4;
}
public int getTileX(OrthographicCamera cam){
Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0);
cam.unproject(mousePos);
return (getSelectedX(mousePos) + Player.getX()>>1)/TILE_SIZE;
}
public int getTileY(OrthographicCamera cam){
Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0);
cam.unproject(mousePos);
return (getSelectedY(mousePos) + Player.getY()>>1)/TILE_SIZE;
}
public void render(SpriteBatch batch) {
selectedTile(batch);
//System.out.println("X = " + getTileX(cam) + " Y = "+ getTileY(cam));
}
}

View File

@@ -1,20 +1,20 @@
package com.mygdx.game.Character;
package Collector.Character;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Array;
import com.mygdx.game.Main;
import com.mygdx.game.Restrictions;
import Collector.Restrictions;
public class Player implements Restrictions {
private static int x;
private static int y;
private OrthographicCamera cam;
public static int x;
public static int y;
private final String spriteName;
public TextureAtlas textureAtlas;
private Animation<TextureAtlas.AtlasRegion> animation;
public static Sprite sprite;
public Player(OrthographicCamera cam, int x, int y) {
Player.x = x<<TILE_SHIFT;
@@ -23,20 +23,11 @@ public class Player implements Restrictions {
spriteName = "man";
textureAtlas = new TextureAtlas("core/assets/" + spriteName + ".atlas");
Array<TextureAtlas.AtlasRegion> keyFrames = textureAtlas.findRegions(spriteName + "_Down");
//textureAtlas = new TextureAtlas("man.atlas");
//Array<TextureAtlas.AtlasRegion> keyFrames = textureAtlas.findRegions(spriteName + "_Down");
float frameDuration = 1 / 4f;
animation = new Animation<>(frameDuration, keyFrames);
}
public static void teleport(int x, int y){
Player.x = x<<TILE_SHIFT;
Player.y = y<<TILE_SHIFT;
Main.cam.translate(x,y);
}
public void render(Batch batch, float timeSinceLastUpdate){
batch.draw(getAnimation().getKeyFrame(timeSinceLastUpdate, true), getX(), getY(),TILE_SIZE,TILE_SIZE);
//animation = new Animation<>(frameDuration, keyFrames);
}
public static int getX() {
@@ -59,6 +50,7 @@ public class Player implements Restrictions {
return spriteName;
}
/*
public Animation<TextureAtlas.AtlasRegion> getAnimation() {
return animation;
}
@@ -67,4 +59,6 @@ public class Player implements Restrictions {
animation = animationTemp;
}
*/
}

View File

@@ -0,0 +1,39 @@
package Collector.Dimension;
import com.badlogic.gdx.graphics.Texture;
public class Block {
private final String name;
private final Boolean harvestable;
private final Boolean breakable;
private final Boolean passable;
private final Texture texture;
public Block(String name) {
this.name = name;
this.texture = new Texture("assets/" + name + ".png");
this.harvestable = true;
this.breakable = true;
this.passable = false;
}
public String getName() {
return name;
}
public Texture getTexture() {
return texture;
}
public Boolean getPassable() {
return passable;
}
public Boolean getBreakable() {
return breakable;
}
public Boolean getHarvestable() {
return harvestable;
}
}

View File

@@ -1,4 +1,4 @@
package com.mygdx.game.Dimension;
package Collector.Dimension;
import java.util.HashMap;

View File

@@ -1,14 +1,14 @@
//https://www.redblobgames.com/maps/terrain-from-noise/
package com.mygdx.game.Dimension;
package Collector.Dimension;
import com.github.czyzby.kiwi.util.tuple.immutable.Pair;
import com.github.czyzby.kiwi.util.tuple.immutable.Triple;
import com.mygdx.game.OpenSimplexNoise;
import Collector.OpenSimplexNoise;
import java.util.HashMap;
import static com.mygdx.game.Dimension.BlockMaterials.materials;
import static com.mygdx.game.Restrictions.*;
import static Collector.Dimension.BlockMaterials.materials;
import static Collector.Restrictions.*;
public class Chunks {
public static HashMap<Triple<Integer, Integer, Integer>, Block> blocks = new HashMap<>();

View File

@@ -1,8 +1,8 @@
package com.mygdx.game.Dimension;
package Collector.Dimension;
import com.mygdx.game.Character.Player;
import Collector.Character.Player;
import static com.mygdx.game.Restrictions.*;
import static Collector.Restrictions.*;
public class World {
public static void generateWorld(int x, int y) {

View File

@@ -1,17 +1,17 @@
package com.mygdx.game.Dimension;
package Collector.Dimension;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.github.czyzby.kiwi.util.tuple.immutable.Triple;
import com.mygdx.game.Character.InputController;
import com.mygdx.game.Character.Mouse;
import com.mygdx.game.Restrictions;
import Collector.Character.InputController;
import Collector.Character.Mouse;
import Collector.Restrictions;
import static com.mygdx.game.Main.cam;
import static Collector.Main.cam;
public class WorldRenderer implements Restrictions {
private Mouse mouse;
private InputController inputController;
private final Mouse mouse;
private final InputController inputController;
public WorldRenderer(Mouse mouse, InputController inputController) {
this.mouse = mouse;
@@ -20,7 +20,7 @@ public class WorldRenderer implements Restrictions {
public void drawWorld(Batch batch, int layer) {
for (Triple<Integer, Integer, Integer> chunkpair : Chunks.blocks.keySet()) {
if(chunkpair.getThird() == layer) {
if (chunkpair.getThird() == layer) {
batch.draw(
Chunks.blocks.get(chunkpair).getTexture(),
chunkpair.getFirst() << TILE_SHIFT,

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.8.2//EN" "http://gwtproject.org/doctype/2.8.2/gwt-module.dtd">
<module>
<source path="" />
</module>

View File

@@ -1,4 +1,4 @@
package com.mygdx.game;
package Collector;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
@@ -6,16 +6,16 @@ import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.mygdx.game.Character.InputController;
import com.mygdx.game.Character.Mouse;
import com.mygdx.game.Character.Player;
import com.mygdx.game.Dimension.BlockMaterials;
import com.mygdx.game.Dimension.Chunks;
import com.mygdx.game.Dimension.World;
import com.mygdx.game.Dimension.WorldRenderer;
import com.mygdx.game.UI.GUI;
import Collector.Character.InputController;
import Collector.Character.Mouse;
import Collector.Character.Player;
import Collector.Dimension.BlockMaterials;
import Collector.Dimension.Chunks;
import Collector.Dimension.World;
import Collector.Dimension.WorldRenderer;
import Collector.UI.GUI;
import static com.mygdx.game.Restrictions.*;
import static Collector.Restrictions.*;
public class Main extends ApplicationAdapter {
private SpriteBatch batch;
@@ -32,14 +32,14 @@ public class Main extends ApplicationAdapter {
@Override
public void create () {
Gdx.graphics.setWindowedMode(1024,576);
Gdx.graphics.setWindowedMode(1024, 576);
cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
player = new Player(cam,0,0);
fitViewport = new FitViewport(VIEWPORT_WIDTH,VIEWPORT_HEIGHT, cam);
player = new Player(cam, 0, 0);
fitViewport = new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, cam);
mouse = new Mouse();
gui = new GUI(mouse,fitViewport);
gui = new GUI(fitViewport);
inputController = new InputController(player);
worldRenderer = new WorldRenderer(mouse,inputController);
worldRenderer = new WorldRenderer(mouse, inputController);
batch = new SpriteBatch();
BlockMaterials.create();
@@ -47,7 +47,7 @@ public class Main extends ApplicationAdapter {
//Starting location of the player
cam.translate(TILE_SIZE >> 1, TILE_SIZE >> 1);
cam.translate(TILE_SIZE >> 1, TILE_SIZE >> 1);
cam.zoom = 25f;
}
@@ -55,21 +55,22 @@ public class Main extends ApplicationAdapter {
public void render () {
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
timeSinceLastUpdate += Gdx.graphics.getDeltaTime(); //Accumulate delta time
batch.begin();
if(timeSinceLastUpdate > 1/10f){
worldRenderer.render(batch);
}
player.render(batch,timeSinceLastUpdate);
delta +=Gdx.graphics.getDeltaTime();
if(delta > RENDER_TIME) {
delta += Gdx.graphics.getDeltaTime();
if (delta > RENDER_TIME) {
delta -= RENDER_TIME;
World.loadChunks();
World.unloadChunks();
}
gui.render(batch);
gui.render();
batch.draw(BlockMaterials.materials.get("wood").getTexture(), Player.x, Player.y,TILE_SIZE,TILE_SIZE);
batch.end();
}

View File

@@ -1,4 +1,4 @@
package com.mygdx.game;/*
package Collector;/*
* OpenSimplex Noise in Java.
* by Kurt Spencer
*
@@ -22,171 +22,67 @@ public class OpenSimplexNoise {
private static final double SQUISH_CONSTANT_3D = 1.0 / 3; //(Math.sqrt(3+1)-1)/3;
private static final double STRETCH_CONSTANT_4D = -0.138196601125011; //(1/Math.sqrt(4+1)-1)/4;
private static final double SQUISH_CONSTANT_4D = 0.309016994374947; //(Math.sqrt(4+1)-1)/4;
private static final double NORM_CONSTANT_2D = 47;
private static final double NORM_CONSTANT_3D = 103;
private static final double NORM_CONSTANT_4D = 30;
private static final long DEFAULT_SEED = 0;
private short[] perm;
private short[] permGradIndex3D;
//Gradients for 2D. They approximate the directions to the
//vertices of an octagon from the center.
private static final byte[] gradients2D = new byte[]{
5, 2, 2, 5,
-5, 2, -2, 5,
5, -2, 2, -5,
-5, -2, -2, -5,
};
//Gradients for 3D. They approximate the directions to the
//vertices of a rhombicuboctahedron from the center, skewed so
//that the triangular and square facets can be inscribed inside
//circles of the same radius.
private static final byte[] gradients3D = new byte[]{
-11, 4, 4, -4, 11, 4, -4, 4, 11,
11, 4, 4, 4, 11, 4, 4, 4, 11,
-11, -4, 4, -4, -11, 4, -4, -4, 11,
11, -4, 4, 4, -11, 4, 4, -4, 11,
-11, 4, -4, -4, 11, -4, -4, 4, -11,
11, 4, -4, 4, 11, -4, 4, 4, -11,
-11, -4, -4, -4, -11, -4, -4, -4, -11,
11, -4, -4, 4, -11, -4, 4, -4, -11,
};
public OpenSimplexNoise() {
this(DEFAULT_SEED);
}
public OpenSimplexNoise(short[] perm) {
this.perm = perm;
permGradIndex3D = new short[256];
for (int i = 0; i < 256; i++) {
//Since 3D has 24 gradients, simple bitmask won't work, so precompute modulo array.
permGradIndex3D[i] = (short)((perm[i] % (gradients3D.length / 3)) * 3);
}
}
//Initializes the class using a permutation array generated from a 64-bit seed.
//Generates a proper permutation (i.e. doesn't merely perform N successive pair swaps on a base array)
//Uses a simple 64-bit LCG.
public OpenSimplexNoise(long seed) {
perm = new short[256];
permGradIndex3D = new short[256];
short[] source = new short[256];
for (short i = 0; i < 256; i++)
source[i] = i;
seed = seed * 6364136223846793005l + 1442695040888963407l;
seed = seed * 6364136223846793005l + 1442695040888963407l;
seed = seed * 6364136223846793005l + 1442695040888963407l;
for (int i = 255; i >= 0; i--) {
seed = seed * 6364136223846793005l + 1442695040888963407l;
int r = (int)((seed + 31) % (i + 1));
if (r < 0)
r += (i + 1);
perm[i] = source[r];
permGradIndex3D[i] = (short)((perm[i] % (gradients3D.length / 3)) * 3);
source[r] = source[i];
}
}
//2D OpenSimplex Noise.
public double eval(double x, double y) {
//Place input coordinates onto grid.
double stretchOffset = (x + y) * STRETCH_CONSTANT_2D;
double xs = x + stretchOffset;
double ys = y + stretchOffset;
//Floor to get grid coordinates of rhombus (stretched square) super-cell origin.
int xsb = fastFloor(xs);
int ysb = fastFloor(ys);
//Skew out to get actual coordinates of rhombus origin. We'll need these later.
double squishOffset = (xsb + ysb) * SQUISH_CONSTANT_2D;
double xb = xsb + squishOffset;
double yb = ysb + squishOffset;
//Compute grid coordinates relative to rhombus origin.
double xins = xs - xsb;
double yins = ys - ysb;
//Sum those together to get a value that determines which region we're in.
double inSum = xins + yins;
//Positions relative to origin point.
double dx0 = x - xb;
double dy0 = y - yb;
//We'll be defining these inside the next block and using them afterwards.
double dx_ext, dy_ext;
int xsv_ext, ysv_ext;
double value = 0;
//Gradients for 4D. They approximate the directions to the
//vertices of a disprismatotesseractihexadecachoron from the center,
//skewed so that the tetrahedral and cubic facets can be inscribed inside
//spheres of the same radius.
private static final byte[] gradients4D = new byte[]{
3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3,
-3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3,
3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3,
-3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3,
3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3,
-3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3,
3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3,
-3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3,
3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3,
-3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3,
3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3,
-3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3,
3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3,
-3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3,
3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3,
-3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3,
};
private final short[] perm;
//Contribution (1,0)
double dx1 = dx0 - 1 - SQUISH_CONSTANT_2D;
double dy1 = dy0 - 0 - SQUISH_CONSTANT_2D;
double attn1 = 2 - dx1 * dx1 - dy1 * dy1;
if (attn1 > 0) {
attn1 *= attn1;
value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, dx1, dy1);
}
//Contribution (0,1)
double dx2 = dx0 - 0 - SQUISH_CONSTANT_2D;
double dy2 = dy0 - 1 - SQUISH_CONSTANT_2D;
double attn2 = 2 - dx2 * dx2 - dy2 * dy2;
if (attn2 > 0) {
attn2 *= attn2;
value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, dx2, dy2);
}
if (inSum <= 1) { //We're inside the triangle (2-Simplex) at (0,0)
double zins = 1 - inSum;
if (zins > xins || zins > yins) { //(0,0) is one of the closest two triangular vertices
if (xins > yins) {
xsv_ext = xsb + 1;
ysv_ext = ysb - 1;
dx_ext = dx0 - 1;
dy_ext = dy0 + 1;
} else {
xsv_ext = xsb - 1;
ysv_ext = ysb + 1;
dx_ext = dx0 + 1;
dy_ext = dy0 - 1;
}
} else { //(1,0) and (0,1) are the closest two vertices.
xsv_ext = xsb + 1;
ysv_ext = ysb + 1;
dx_ext = dx0 - 1 - 2 * SQUISH_CONSTANT_2D;
dy_ext = dy0 - 1 - 2 * SQUISH_CONSTANT_2D;
}
} else { //We're inside the triangle (2-Simplex) at (1,1)
double zins = 2 - inSum;
if (zins < xins || zins < yins) { //(0,0) is one of the closest two triangular vertices
if (xins > yins) {
xsv_ext = xsb + 2;
ysv_ext = ysb + 0;
dx_ext = dx0 - 2 - 2 * SQUISH_CONSTANT_2D;
dy_ext = dy0 + 0 - 2 * SQUISH_CONSTANT_2D;
} else {
xsv_ext = xsb + 0;
ysv_ext = ysb + 2;
dx_ext = dx0 + 0 - 2 * SQUISH_CONSTANT_2D;
dy_ext = dy0 - 2 - 2 * SQUISH_CONSTANT_2D;
}
} else { //(1,0) and (0,1) are the closest two vertices.
dx_ext = dx0;
dy_ext = dy0;
xsv_ext = xsb;
ysv_ext = ysb;
}
xsb += 1;
ysb += 1;
dx0 = dx0 - 1 - 2 * SQUISH_CONSTANT_2D;
dy0 = dy0 - 1 - 2 * SQUISH_CONSTANT_2D;
}
//Contribution (0,0) or (1,1)
double attn0 = 2 - dx0 * dx0 - dy0 * dy0;
if (attn0 > 0) {
attn0 *= attn0;
value += attn0 * attn0 * extrapolate(xsb, ysb, dx0, dy0);
}
//Extra Vertex
double attn_ext = 2 - dx_ext * dx_ext - dy_ext * dy_ext;
if (attn_ext > 0) {
attn_ext *= attn_ext;
value += attn_ext * attn_ext * extrapolate(xsv_ext, ysv_ext, dx_ext, dy_ext);
}
return value / NORM_CONSTANT_2D;
}
//3D OpenSimplex Noise.
public double eval(double x, double y, double z) {
//Place input coordinates on simplectic honeycomb.
double stretchOffset = (x + y + z) * STRETCH_CONSTANT_3D;
double xs = x + stretchOffset;
@@ -2065,7 +1961,7 @@ public class OpenSimplexNoise {
return gradients2D[index] * dx
+ gradients2D[index + 1] * dy;
}
private double extrapolate(int xsb, int ysb, int zsb, double dx, double dy, double dz)
{
int index = permGradIndex3D[(perm[(perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF];
@@ -2073,65 +1969,157 @@ public class OpenSimplexNoise {
+ gradients3D[index + 1] * dy
+ gradients3D[index + 2] * dz;
}
private final short[] permGradIndex3D;
//Initializes the class using a permutation array generated from a 64-bit seed.
//Generates a proper permutation (i.e. doesn't merely perform N successive pair swaps on a base array)
//Uses a simple 64-bit LCG.
public OpenSimplexNoise(long seed) {
perm = new short[256];
permGradIndex3D = new short[256];
short[] source = new short[256];
for (short i = 0; i < 256; i++)
source[i] = i;
seed = seed * 6364136223846793005L + 1442695040888963407L;
seed = seed * 6364136223846793005L + 1442695040888963407L;
seed = seed * 6364136223846793005L + 1442695040888963407L;
for (int i = 255; i >= 0; i--) {
seed = seed * 6364136223846793005L + 1442695040888963407L;
int r = (int) ((seed + 31) % (i + 1));
if (r < 0)
r += (i + 1);
perm[i] = source[r];
permGradIndex3D[i] = (short) ((perm[i] % (gradients3D.length / 3)) * 3);
source[r] = source[i];
}
}
private static int fastFloor(double x) {
int xi = (int) x;
return x < xi ? xi - 1 : xi;
}
//2D OpenSimplex Noise.
public double eval(double x, double y) {
//Place input coordinates onto grid.
double stretchOffset = (x + y) * STRETCH_CONSTANT_2D;
double xs = x + stretchOffset;
double ys = y + stretchOffset;
//Floor to get grid coordinates of rhombus (stretched square) super-cell origin.
int xsb = fastFloor(xs);
int ysb = fastFloor(ys);
//Skew out to get actual coordinates of rhombus origin. We'll need these later.
double squishOffset = (xsb + ysb) * SQUISH_CONSTANT_2D;
double xb = xsb + squishOffset;
double yb = ysb + squishOffset;
//Compute grid coordinates relative to rhombus origin.
double xins = xs - xsb;
double yins = ys - ysb;
//Sum those together to get a value that determines which region we're in.
double inSum = xins + yins;
//Positions relative to origin point.
double dx0 = x - xb;
double dy0 = y - yb;
//We'll be defining these inside the next block and using them afterwards.
double dx_ext, dy_ext;
int xsv_ext, ysv_ext;
double value = 0;
//Contribution (1,0)
double dx1 = dx0 - 1 - SQUISH_CONSTANT_2D;
double dy1 = dy0 - 0 - SQUISH_CONSTANT_2D;
double attn1 = 2 - dx1 * dx1 - dy1 * dy1;
if (attn1 > 0) {
attn1 *= attn1;
value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, dx1, dy1);
}
//Contribution (0,1)
double dx2 = dx0 - 0 - SQUISH_CONSTANT_2D;
double dy2 = dy0 - 1 - SQUISH_CONSTANT_2D;
double attn2 = 2 - dx2 * dx2 - dy2 * dy2;
if (attn2 > 0) {
attn2 *= attn2;
value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, dx2, dy2);
}
if (inSum <= 1) { //We're inside the triangle (2-Simplex) at (0,0)
double zins = 1 - inSum;
if (zins > xins || zins > yins) { //(0,0) is one of the closest two triangular vertices
if (xins > yins) {
xsv_ext = xsb + 1;
ysv_ext = ysb - 1;
dx_ext = dx0 - 1;
dy_ext = dy0 + 1;
} else {
xsv_ext = xsb - 1;
ysv_ext = ysb + 1;
dx_ext = dx0 + 1;
dy_ext = dy0 - 1;
}
} else { //(1,0) and (0,1) are the closest two vertices.
xsv_ext = xsb + 1;
ysv_ext = ysb + 1;
dx_ext = dx0 - 1 - 2 * SQUISH_CONSTANT_2D;
dy_ext = dy0 - 1 - 2 * SQUISH_CONSTANT_2D;
}
} else { //We're inside the triangle (2-Simplex) at (1,1)
double zins = 2 - inSum;
if (zins < xins || zins < yins) { //(0,0) is one of the closest two triangular vertices
if (xins > yins) {
xsv_ext = xsb + 2;
ysv_ext = ysb + 0;
dx_ext = dx0 - 2 - 2 * SQUISH_CONSTANT_2D;
dy_ext = dy0 + 0 - 2 * SQUISH_CONSTANT_2D;
} else {
xsv_ext = xsb + 0;
ysv_ext = ysb + 2;
dx_ext = dx0 + 0 - 2 * SQUISH_CONSTANT_2D;
dy_ext = dy0 - 2 - 2 * SQUISH_CONSTANT_2D;
}
} else { //(1,0) and (0,1) are the closest two vertices.
dx_ext = dx0;
dy_ext = dy0;
xsv_ext = xsb;
ysv_ext = ysb;
}
xsb += 1;
ysb += 1;
dx0 = dx0 - 1 - 2 * SQUISH_CONSTANT_2D;
dy0 = dy0 - 1 - 2 * SQUISH_CONSTANT_2D;
}
//Contribution (0,0) or (1,1)
double attn0 = 2 - dx0 * dx0 - dy0 * dy0;
if (attn0 > 0) {
attn0 *= attn0;
value += attn0 * attn0 * extrapolate(xsb, ysb, dx0, dy0);
}
//Extra Vertex
double attn_ext = 2 - dx_ext * dx_ext - dy_ext * dy_ext;
if (attn_ext > 0) {
attn_ext *= attn_ext;
value += attn_ext * attn_ext * extrapolate(xsv_ext, ysv_ext, dx_ext, dy_ext);
}
return value / NORM_CONSTANT_2D;
}
private double extrapolate(int xsb, int ysb, int zsb, int wsb, double dx, double dy, double dz, double dw)
{
int index = perm[(perm[(perm[(perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF] + wsb) & 0xFF] & 0xFC;
return gradients4D[index] * dx
+ gradients4D[index + 1] * dy
+ gradients4D[index + 2] * dz
+ gradients4D[index + 3] * dw;
+ gradients4D[index + 1] * dy
+ gradients4D[index + 2] * dz
+ gradients4D[index + 3] * dw;
}
private static int fastFloor(double x) {
int xi = (int)x;
return x < xi ? xi - 1 : xi;
}
//Gradients for 2D. They approximate the directions to the
//vertices of an octagon from the center.
private static byte[] gradients2D = new byte[] {
5, 2, 2, 5,
-5, 2, -2, 5,
5, -2, 2, -5,
-5, -2, -2, -5,
};
//Gradients for 3D. They approximate the directions to the
//vertices of a rhombicuboctahedron from the center, skewed so
//that the triangular and square facets can be inscribed inside
//circles of the same radius.
private static byte[] gradients3D = new byte[] {
-11, 4, 4, -4, 11, 4, -4, 4, 11,
11, 4, 4, 4, 11, 4, 4, 4, 11,
-11, -4, 4, -4, -11, 4, -4, -4, 11,
11, -4, 4, 4, -11, 4, 4, -4, 11,
-11, 4, -4, -4, 11, -4, -4, 4, -11,
11, 4, -4, 4, 11, -4, 4, 4, -11,
-11, -4, -4, -4, -11, -4, -4, -4, -11,
11, -4, -4, 4, -11, -4, 4, -4, -11,
};
//Gradients for 4D. They approximate the directions to the
//vertices of a disprismatotesseractihexadecachoron from the center,
//skewed so that the tetrahedral and cubic facets can be inscribed inside
//spheres of the same radius.
private static byte[] gradients4D = new byte[] {
3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3,
-3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3,
3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3,
-3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3,
3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3,
-3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3,
3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3,
-3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3,
3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3,
-3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3,
3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3,
-3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3,
3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3,
-3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3,
3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3,
-3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3,
};
}

View File

@@ -1,4 +1,4 @@
package com.mygdx.game;
package Collector;
public interface Restrictions {
int SEED = 1;

View File

@@ -1,38 +1,32 @@
package com.mygdx.game.UI;
package Collector.UI;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.mygdx.game.Character.Mouse;
import com.mygdx.game.Restrictions;
import Collector.Restrictions;
public class GUI implements Restrictions {
private final Stage stage;
private final Label label;
private final Mouse mouse;
private final BitmapFont font;
private final FitViewport fitViewport;
public GUI(Mouse mouse, FitViewport fitViewport) {
public GUI(FitViewport fitViewport) {
font = new BitmapFont();
stage = new Stage(fitViewport);
label = new Label("Start", new Label.LabelStyle(font, new Color(Color.WHITE)));
this.mouse = mouse;
this.fitViewport = fitViewport;
Label label = new Label("Start", new Label.LabelStyle(font, new Color(Color.WHITE)));
Gdx.input.setInputProcessor(stage);
stage.addActor(label);
}
public void render(SpriteBatch batch){
public void render() {
stage.act();
stage.draw();
//font.draw(batch, "x: "+ mouse.getTileX(cam) + "y: " + mouse.getTileY(cam),-10, 0);
}
public void dispose(){