Added bullets, chunks, extra blocks, the world.
This commit is contained in:
parent
58bf1877f9
commit
6299f8a2c8
|
|
@ -1,23 +1,40 @@
|
||||||
package shootergame;
|
package shootergame;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import javax.swing.text.html.parser.Entity;
|
||||||
|
|
||||||
import mainloop.manager.MainloopManager;
|
import mainloop.manager.MainloopManager;
|
||||||
|
import shootergame.display.DisplayStatsEventHandler;
|
||||||
import shootergame.display.DisplayWindow;
|
import shootergame.display.DisplayWindow;
|
||||||
import shootergame.entity.EntityEventHandler;
|
import shootergame.entity.EntityEventHandler;
|
||||||
import shootergame.entity.player.Player;
|
import shootergame.entity.EntityZombie;
|
||||||
|
import shootergame.entity.player.EntityPlayer;
|
||||||
|
import shootergame.init.Entities;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.input.JoystickCallback;
|
||||||
import shootergame.mainloop.MainloopEventHandler;
|
import shootergame.mainloop.MainloopEventHandler;
|
||||||
|
import shootergame.util.math.MathHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.world.World;
|
||||||
|
import shootergame.world.chunk.ChunkEventHandler;
|
||||||
|
import shootergame.world.layer.layergen.LayerGenEarth;
|
||||||
|
|
||||||
public class Main
|
public class Main
|
||||||
{
|
{
|
||||||
public static MainloopManager mainloop;
|
public static MainloopManager mainloop;
|
||||||
public static DisplayWindow window;
|
public static DisplayWindow window;
|
||||||
public static Player player = new Player();
|
public static EntityPlayer player = new EntityPlayer();
|
||||||
|
public static World world;
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
// Create the mainloop
|
// Create the mainloop
|
||||||
mainloop = new MainloopManager(MainloopEventHandler.MAINLOOP_EVENT_HANDLER);
|
mainloop = new MainloopManager(MainloopEventHandler.MAINLOOP_EVENT_HANDLER);
|
||||||
mainloop.register(MainloopEventHandler.MAINLOOP_EVENT_HANDLER);
|
mainloop.register(MainloopEventHandler.MAINLOOP_EVENT_HANDLER);
|
||||||
|
mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER);
|
||||||
|
mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER);
|
||||||
|
mainloop.register(JoystickCallback.JOYSTICK_CALLBACK);
|
||||||
|
|
||||||
// Create the display
|
// Create the display
|
||||||
window = new DisplayWindow("ShooterGame");
|
window = new DisplayWindow("ShooterGame");
|
||||||
|
|
@ -26,6 +43,12 @@ public class Main
|
||||||
// Initialise the textures
|
// Initialise the textures
|
||||||
Textures.initTextures(window);
|
Textures.initTextures(window);
|
||||||
|
|
||||||
|
// Initialize the gamepad
|
||||||
|
JoystickCallback.JOYSTICK_CALLBACK.init();
|
||||||
|
|
||||||
|
// Create the world
|
||||||
|
world = new World(new Random(), new LayerGenEarth());
|
||||||
|
|
||||||
// Initialise the entities
|
// Initialise the entities
|
||||||
mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER);
|
mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,15 @@ public class Camera
|
||||||
{
|
{
|
||||||
public Vec3d pos;
|
public Vec3d pos;
|
||||||
public Vec2d angle;
|
public Vec2d angle;
|
||||||
|
public int renderDistance;
|
||||||
|
public double cameraDistance;
|
||||||
|
|
||||||
public Camera(Vec3d pos, Vec2d angle, double distance)
|
public Camera(Vec3d pos, Vec2d angle, double cameraDistance, int renderDistance)
|
||||||
{
|
{
|
||||||
Vec3d p = new Vec3d(pos.x, pos.y+5, pos.z);
|
|
||||||
this.angle = new Vec2d(angle.x, -angle.y);
|
this.angle = new Vec2d(angle.x, -angle.y);
|
||||||
this.pos = pos.subtract(MathHelpers.moveTowards3(
|
this.pos = pos.subtract(MathHelpers.moveTowards3(
|
||||||
10, new Vec2d(Math.toRadians(angle.x), Math.toRadians(-angle.y))));
|
cameraDistance, new Vec2d(Math.toRadians(angle.x), Math.toRadians(-angle.y))));
|
||||||
|
this.cameraDistance = cameraDistance;
|
||||||
|
this.renderDistance = renderDistance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,22 +6,19 @@ import org.joml.Matrix4f;
|
||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
import org.lwjgl.system.MemoryStack;
|
import org.lwjgl.system.MemoryStack;
|
||||||
|
|
||||||
import mainloop.task.MainloopTask;
|
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
import shootergame.display.transparent.TransparentObjects;
|
import shootergame.display.transparent.TransparentObjects;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.player.EntityPlayer;
|
||||||
import shootergame.entity.player.Player;
|
|
||||||
import shootergame.init.Entities;
|
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
import shootergame.init.Tiles;
|
import shootergame.text.Text;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.math.MathHelpers;
|
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
|
||||||
import shootergame.util.math.vec.Vec3d;
|
import shootergame.util.math.vec.Vec3d;
|
||||||
|
|
||||||
public class DisplayRender
|
public class DisplayRender
|
||||||
{
|
{
|
||||||
|
public static int fps = 0;
|
||||||
|
|
||||||
public static void render(int w, int h)
|
public static void render(int w, int h)
|
||||||
{
|
{
|
||||||
// Setup GL and clear the colour
|
// Setup GL and clear the colour
|
||||||
|
|
@ -34,9 +31,9 @@ public class DisplayRender
|
||||||
|
|
||||||
// Enable some stuff
|
// Enable some stuff
|
||||||
GlHelpers.enableTexture2d();
|
GlHelpers.enableTexture2d();
|
||||||
|
GlHelpers.enableDepthTest();
|
||||||
GlHelpers.enableBlend();
|
GlHelpers.enableBlend();
|
||||||
GlHelpers.enableAlpha();
|
GlHelpers.enableAlpha();
|
||||||
GlHelpers.enableDepthTest();
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// Set the colour to white
|
// Set the colour to white
|
||||||
|
|
@ -70,37 +67,33 @@ public class DisplayRender
|
||||||
0.0f, 0.0f, 0.0f,
|
0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 1.0f, 0.0f);
|
0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
Player player = Main.player;
|
EntityPlayer player = Main.player;
|
||||||
Camera camera = new Camera(new Vec3d(player.pos.x, player.pos.y, 0), new Vec2d(player.angle, 45), 0);
|
Camera camera = new Camera(new Vec3d(player.pos.x, player.pos.y, 0), new Vec2d(player.angle, 45), 10, 2);
|
||||||
|
|
||||||
//GlHelpers.translate(0, 0, -5);
|
//GlHelpers.translate(0, 0, -5);
|
||||||
GlHelpers.rotate(camera.angle.y, 1, 0, 0);
|
GlHelpers.rotate(camera.angle.y, 1, 0, 0);
|
||||||
GlHelpers.rotate(camera.angle.x, 0, 0, 1);
|
GlHelpers.rotate(camera.angle.x, 0, 0, 1);
|
||||||
GlHelpers.translate(-camera.pos.x, -camera.pos.y, -camera.pos.z);
|
GlHelpers.translate(-camera.pos.x, -camera.pos.y, -camera.pos.z);
|
||||||
|
|
||||||
int c = 20;
|
// Render the world and the player
|
||||||
for(int x=-c;x<c;x++) {
|
Main.world.render(camera);
|
||||||
for(int y=-c;y<c;y++) {
|
player.doRender(player.pos, camera);
|
||||||
Tiles.GRASS.doRender(new Vec2d(x, y), camera);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c = 4;
|
|
||||||
for(int x=-c;x<c;x++) {
|
|
||||||
for(int y=-c;y<c;y++) {
|
|
||||||
Tiles.TREE.doRender(new Vec2d(x, y), camera);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Entity e : Entities.entities) {
|
|
||||||
e.doRender(player.pos, camera);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Render the sorted transparent objects
|
||||||
TransparentObjects.render(camera);
|
TransparentObjects.render(camera);
|
||||||
|
|
||||||
GlHelpers.popMatrix();
|
GlHelpers.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the fps and the position
|
||||||
|
GlHelpers.pushMatrix();
|
||||||
|
GlHelpers.translate(-9.5, 9.5, 0);
|
||||||
|
GlHelpers.color3(1, 1, 0);
|
||||||
|
Text.render("FPS: " + fps, new Vec2d(0.5, 0.2));
|
||||||
|
GlHelpers.translate(0, -0.5, 0);
|
||||||
|
Text.render("x: " + (int) Main.player.pos.x + ", y: " + (int) Main.player.pos.y, new Vec2d(0.5, 0.2));
|
||||||
|
GlHelpers.popMatrix();
|
||||||
|
|
||||||
// Unbind the texmap
|
// Unbind the texmap
|
||||||
Textures.texmap.unbindTexture();
|
Textures.texmap.unbindTexture();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package shootergame.display;
|
||||||
|
|
||||||
|
import mainloop.task.IMainloopTask;
|
||||||
|
import shootergame.mainloop.MainloopEventHandler;
|
||||||
|
|
||||||
|
public class DisplayStatsEventHandler implements IMainloopTask
|
||||||
|
{
|
||||||
|
public static final DisplayStatsEventHandler DISPLAY_STATS_EVENT_HANDLER = new DisplayStatsEventHandler();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopDelay(long millis) {
|
||||||
|
return millis > 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopRepeat() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MainLoopUpdate()
|
||||||
|
{
|
||||||
|
// Set the fps from mspf every second
|
||||||
|
long mspf = MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf;
|
||||||
|
DisplayRender.fps = (int)(1000 / mspf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ import mainloop.task.IMainloopTask;
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
import shootergame.input.CursorEnterCallback;
|
import shootergame.input.CursorEnterCallback;
|
||||||
import shootergame.input.CursorPosCallback;
|
import shootergame.input.CursorPosCallback;
|
||||||
|
import shootergame.input.JoystickCallback;
|
||||||
import shootergame.input.KeyCallback;
|
import shootergame.input.KeyCallback;
|
||||||
import shootergame.input.KeyCharCallback;
|
import shootergame.input.KeyCharCallback;
|
||||||
import shootergame.input.MouseButtonCallback;
|
import shootergame.input.MouseButtonCallback;
|
||||||
|
|
@ -67,6 +68,7 @@ public class DisplayWindow implements IMainloopTask
|
||||||
GLFW.glfwSetCursorEnterCallback(this.window, new CursorEnterCallback());
|
GLFW.glfwSetCursorEnterCallback(this.window, new CursorEnterCallback());
|
||||||
GLFW.glfwSetMouseButtonCallback(this.window, new MouseButtonCallback());
|
GLFW.glfwSetMouseButtonCallback(this.window, new MouseButtonCallback());
|
||||||
GLFW.glfwSetKeyCallback(this.window, new KeyCallback());
|
GLFW.glfwSetKeyCallback(this.window, new KeyCallback());
|
||||||
|
GLFW.glfwSetJoystickCallback(JoystickCallback.JOYSTICK_CALLBACK);
|
||||||
|
|
||||||
// Show the window
|
// Show the window
|
||||||
GLFW.glfwShowWindow(this.window);
|
GLFW.glfwShowWindow(this.window);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
package shootergame.entity;
|
package shootergame.entity;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.display.transparent.ITransparentObject;
|
import shootergame.display.transparent.ITransparentObject;
|
||||||
import shootergame.display.transparent.TransparentObjects;
|
import shootergame.display.transparent.TransparentObjects;
|
||||||
import shootergame.init.Entities;
|
import shootergame.init.Entities;
|
||||||
|
import shootergame.tiles.Tile;
|
||||||
|
import shootergame.util.math.MathHelpers;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
public class Entity implements ITransparentObject
|
public class Entity implements ITransparentObject
|
||||||
{
|
{
|
||||||
|
|
@ -26,7 +32,7 @@ public class Entity implements ITransparentObject
|
||||||
this(new Vec2d(0, 0), 0);
|
this(new Vec2d(0, 0), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick() {
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -48,4 +54,29 @@ public class Entity implements ITransparentObject
|
||||||
public boolean isOpaqueTile() {
|
public boolean isOpaqueTile() {
|
||||||
return this.opaqueTile;
|
return this.opaqueTile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void moveForward(double speed) {
|
||||||
|
Vec2d pos = this.pos.add(MathHelpers.moveTowards2(speed, Math.toRadians(this.angle)));
|
||||||
|
if(this.moveIsLegal(new Vec2d(this.pos.x, pos.y))) this.pos.y = pos.y;
|
||||||
|
if(this.moveIsLegal(new Vec2d(pos.x, this.pos.y))) this.pos.x = pos.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveBackward(double speed) {
|
||||||
|
Vec2d pos = this.pos.add(MathHelpers.moveTowards2(-speed, Math.toRadians(this.angle)));
|
||||||
|
if(this.moveIsLegal(new Vec2d(this.pos.x, pos.y))) this.pos.y = pos.y;
|
||||||
|
if(this.moveIsLegal(new Vec2d(pos.x, this.pos.y))) this.pos.x = pos.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveForward() {
|
||||||
|
this.moveForward(0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveBackward() {
|
||||||
|
this.moveBackward(0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean moveIsLegal(Vec2d pos)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
package shootergame.entity;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityBullet extends Entity
|
||||||
|
{
|
||||||
|
private int time = 0;
|
||||||
|
|
||||||
|
public EntityBullet()
|
||||||
|
{
|
||||||
|
// Set some settings
|
||||||
|
this.opaqueTile = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
// Move forward in the bullets angle, very quickly
|
||||||
|
this.moveForward(0.1);
|
||||||
|
|
||||||
|
// Loop over the nearby entities
|
||||||
|
for(Entity e : chunk.getNearbyEntities(pos, 2))
|
||||||
|
{
|
||||||
|
// Is this a zombie
|
||||||
|
if(e instanceof EntityZombie)
|
||||||
|
{
|
||||||
|
System.out.println("Found Zombie");
|
||||||
|
|
||||||
|
chunk.killEntity(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increase time
|
||||||
|
time++;
|
||||||
|
|
||||||
|
if(time > 40) {
|
||||||
|
chunk.killEntity(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera)
|
||||||
|
{
|
||||||
|
// Call super
|
||||||
|
super.render(pos, camera);
|
||||||
|
|
||||||
|
// Push the matrix, disable textures, colour, and translate the bullet
|
||||||
|
GlHelpers.pushMatrix();
|
||||||
|
GlHelpers.color3(1, 1, 0);
|
||||||
|
GlHelpers.translate(pos.x, pos.y, 0.4);
|
||||||
|
GlHelpers.disableTexture2d();
|
||||||
|
|
||||||
|
// Get the angle between the camera and the bullet
|
||||||
|
double angle_r = camera.angle.x;
|
||||||
|
|
||||||
|
// Make the bullet upright
|
||||||
|
GlHelpers.translate(0.1, 0, 0);
|
||||||
|
GlHelpers.translate(pos.x, pos.y, 0);
|
||||||
|
GlHelpers.rotate(-angle_r, 0, 0, 1);
|
||||||
|
GlHelpers.translate(-0.1, 0, 0);
|
||||||
|
|
||||||
|
// Draw the bullet
|
||||||
|
GlHelpers.begin();
|
||||||
|
{
|
||||||
|
GlHelpers.vertex3(0.0f, 0, 0.0f);
|
||||||
|
GlHelpers.vertex3(0.2f, 0, 0.0f);
|
||||||
|
GlHelpers.vertex3(0.2f, 0, 0.2f);
|
||||||
|
GlHelpers.vertex3(0.0f, 0, 0.2f);
|
||||||
|
}
|
||||||
|
GlHelpers.end();
|
||||||
|
|
||||||
|
// Pop the matrix, remove the colour, and enable textures
|
||||||
|
GlHelpers.popMatrix();
|
||||||
|
GlHelpers.enableTexture2d();
|
||||||
|
GlHelpers.color3(1, 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package shootergame.entity;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import mainloop.task.IMainloopTask;
|
import mainloop.task.IMainloopTask;
|
||||||
|
import shootergame.Main;
|
||||||
import shootergame.init.Entities;
|
import shootergame.init.Entities;
|
||||||
|
|
||||||
public class EntityEventHandler implements IMainloopTask
|
public class EntityEventHandler implements IMainloopTask
|
||||||
|
|
@ -22,9 +23,11 @@ public class EntityEventHandler implements IMainloopTask
|
||||||
@Override
|
@Override
|
||||||
public void MainLoopUpdate()
|
public void MainLoopUpdate()
|
||||||
{
|
{
|
||||||
// Update each entity
|
// Update the world and spawn random entities
|
||||||
for(Entity e : Entities.entities) {
|
Main.world.tickEntities();
|
||||||
e.tick();
|
Main.world.spawnRandomEntities();
|
||||||
}
|
Main.player.tick(null, Main.world.getLayer());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
package shootergame.entity;
|
package shootergame.entity;
|
||||||
|
|
||||||
import shootergame.Main;
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.entity.player.Player;
|
|
||||||
import shootergame.util.gl.GlHelpers;
|
|
||||||
import shootergame.util.gl.VerticalRender;
|
import shootergame.util.gl.VerticalRender;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
@ -11,16 +8,23 @@ import shootergame.util.math.vec.Vec2d;
|
||||||
public class EntityVertical extends Entity
|
public class EntityVertical extends Entity
|
||||||
{
|
{
|
||||||
private TextureReference tex;
|
private TextureReference tex;
|
||||||
private double h;
|
private double height;
|
||||||
|
|
||||||
|
public EntityVertical() {
|
||||||
|
}
|
||||||
|
|
||||||
public EntityVertical(TextureReference tex, double height) {
|
public EntityVertical(TextureReference tex, double height) {
|
||||||
|
this.height = height;
|
||||||
this.tex = tex;
|
this.tex = tex;
|
||||||
this.h = height;
|
}
|
||||||
|
|
||||||
|
public void render(Vec2d pos, Camera camera, TextureReference tex, double height) {
|
||||||
|
super.render(pos, camera);
|
||||||
|
VerticalRender.render(pos, camera, tex, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Vec2d pos, Camera camera) {
|
public void render(Vec2d pos, Camera camera) {
|
||||||
super.render(pos, camera);
|
this.render(pos, camera, tex, height);
|
||||||
VerticalRender.render(pos, camera, tex, h);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package shootergame.entity;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.math.random.OpenSimplexNoise;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
public class EntityZombie extends EntityVertical
|
||||||
|
{
|
||||||
|
private Random rand;
|
||||||
|
private OpenSimplexNoise noise;
|
||||||
|
private double time;
|
||||||
|
|
||||||
|
public EntityZombie() {
|
||||||
|
super(Textures.ENTITY_ZOMBIE, 1);
|
||||||
|
rand = new Random();
|
||||||
|
noise = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(Chunk chunk, Layer layer) {
|
||||||
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
|
double angle = Math.atan2(pos.x - Main.player.pos.x, pos.y - Main.player.pos.y);
|
||||||
|
|
||||||
|
this.angle = Math.toDegrees(angle) + 180;
|
||||||
|
this.angle += noise.eval(time, 0)*60;
|
||||||
|
time += 0.001;
|
||||||
|
|
||||||
|
this.moveForward(0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package shootergame.entity.player;
|
package shootergame.entity.player;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
import shootergame.entity.EntityVertical;
|
import shootergame.entity.EntityVertical;
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
|
@ -7,46 +8,58 @@ import shootergame.util.gl.texture.TextureReference;
|
||||||
import shootergame.util.math.MathHelpers;
|
import shootergame.util.math.MathHelpers;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
public class Player extends EntityVertical
|
public class EntityPlayer extends EntityVertical
|
||||||
{
|
{
|
||||||
public Player() {
|
|
||||||
super(Textures.ENTITY_PLAYER, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean MOVE_FORWARD = false;
|
public boolean MOVE_FORWARD = false;
|
||||||
public boolean MOVE_BACKWARD = false;
|
public boolean MOVE_BACKWARD = false;
|
||||||
public boolean MOVE_LEFT = false;
|
public boolean MOVE_LEFT = false;
|
||||||
public boolean MOVE_RIGHT = false;
|
public boolean MOVE_RIGHT = false;
|
||||||
|
public boolean moving = false;
|
||||||
|
|
||||||
|
public EntityPlayer() {
|
||||||
|
this.pos = new Vec2d(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void tick(Chunk chunk, Layer layer)
|
||||||
{
|
{
|
||||||
// Call super
|
// Call super
|
||||||
super.tick();
|
super.tick(chunk, layer);
|
||||||
|
|
||||||
// Rotate left
|
// Rotate left
|
||||||
if(MOVE_LEFT) {
|
if(MOVE_LEFT) {
|
||||||
this.angle -= 1;
|
this.angle -= 1;
|
||||||
this.angle %= 360;
|
this.angle = MathHelpers.mod(this.angle, 360);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate right
|
// Rotate right
|
||||||
if(MOVE_RIGHT) {
|
if(MOVE_RIGHT) {
|
||||||
this.angle += 1;
|
this.angle += 1;
|
||||||
this.angle %= 360;
|
this.angle = MathHelpers.mod(this.angle, 360);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move forward
|
// Move forward
|
||||||
if(MOVE_FORWARD) {
|
if(MOVE_FORWARD) {
|
||||||
Vec2d t = MathHelpers.moveTowards2(0.1, Math.toRadians(angle));
|
this.moveForward();
|
||||||
pos = new Vec2d(t.x+pos.x, t.y+pos.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move backward
|
// Move backward
|
||||||
if(MOVE_BACKWARD) {
|
if(MOVE_BACKWARD) {
|
||||||
Vec2d t = MathHelpers.moveTowards2(-0.1, Math.toRadians(angle));
|
this.moveBackward();
|
||||||
pos = new Vec2d(t.x+pos.x, t.y+pos.y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera)
|
||||||
|
{
|
||||||
|
// Moving
|
||||||
|
if(MOVE_BACKWARD || MOVE_FORWARD || moving)
|
||||||
|
super.render(pos, camera, Textures.ENTITY_PLAYER_MOVING, 1);
|
||||||
|
|
||||||
|
// Standing still
|
||||||
|
else super.render(pos, camera, Textures.ENTITY_PLAYER_STILL, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,39 +23,120 @@ public class Textures
|
||||||
|
|
||||||
public static final ArrayList<AnimationReference> animations = new ArrayList<AnimationReference>();
|
public static final ArrayList<AnimationReference> animations = new ArrayList<AnimationReference>();
|
||||||
|
|
||||||
public static final TextureMap texmap = new TextureMap(
|
public static final TextureMap texmap = new TextureMap(16,
|
||||||
"/home/josua/eclipse-workspace/ShooterGame/src/shootergame/resources/texmap.png");
|
"/home/josua/eclipse-workspace/ShooterGame/src/shootergame/resources/texmap.png");
|
||||||
|
|
||||||
public static final TextureReference TILE_GRASS = texmap.getTextureReference(0, 16, 0, 16);
|
public static final TextureReference TILE_GRASS = texmap.getTextureReference(0, 1, 0, 1);
|
||||||
public static final TextureReference TILE_SAND = texmap.getTextureReference(16, 32, 0, 16);
|
public static final TextureReference TILE_SAND = texmap.getTextureReference(1, 2, 0, 1);
|
||||||
public static final TextureReference TILE_STONE = texmap.getTextureReference(32, 48, 0, 16);
|
public static final TextureReference TILE_STONE = texmap.getTextureReference(2, 3, 0, 1);
|
||||||
public static final TextureReference TILE_DIRT = texmap.getTextureReference(48, 64, 0, 16);
|
public static final TextureReference TILE_DIRT = texmap.getTextureReference(3, 4, 0, 1);
|
||||||
public static final TextureReference TILE_TREE = texmap.getTextureReference(64, 80, 0, 64);
|
public static final TextureReference TILE_TREE = texmap.getTextureReference(4, 5, 0, 4);
|
||||||
|
public static final TextureReference TILE_ROCK = texmap.getTextureReference(4, 5, 4, 5);
|
||||||
|
|
||||||
// Fire
|
// Fire
|
||||||
public static final TextureReference TILE_FIRE_0 = texmap.getTextureReference(0, 16, 16, 32);
|
public static final TextureReference TILE_FIRE_0 = texmap.getTextureReference(0, 1, 1, 2);
|
||||||
public static final TextureReference TILE_FIRE_1 = texmap.getTextureReference(16, 32, 16, 32);
|
public static final TextureReference TILE_FIRE_1 = texmap.getTextureReference(1, 2, 1, 2);
|
||||||
public static final TextureReference TILE_FIRE_2 = texmap.getTextureReference(32, 48, 16, 32);
|
public static final TextureReference TILE_FIRE_2 = texmap.getTextureReference(2, 3, 1, 2);
|
||||||
public static final TextureReference TILE_FIRE_3 = texmap.getTextureReference(48, 64, 16, 32);
|
public static final TextureReference TILE_FIRE_3 = texmap.getTextureReference(3, 4, 1, 2);
|
||||||
public static final TextureReference TILE_FIRE = new AnimationReference(
|
public static final TextureReference TILE_FIRE = new AnimationReference(
|
||||||
8, TILE_FIRE_0, TILE_FIRE_1, TILE_FIRE_2, TILE_FIRE_3);
|
8, TILE_FIRE_0, TILE_FIRE_1, TILE_FIRE_2, TILE_FIRE_3);
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
public static final TextureReference ENTITY_PLAYER_0 = texmap.getTextureReference(0, 16, 32, 48);
|
public static final TextureReference ENTITY_PLAYER_STILL = texmap.getTextureReference(0, 1, 2, 3);
|
||||||
public static final TextureReference ENTITY_PLAYER_1 = texmap.getTextureReference(16, 32, 32, 48);
|
public static final TextureReference ENTITY_PLAYER_MOVING = new AnimationReference(10,
|
||||||
public static final TextureReference ENTITY_PLAYER_2 = texmap.getTextureReference(32, 48, 32, 48);
|
texmap.getTextureReference(0, 1, 2, 3),
|
||||||
public static final TextureReference ENTITY_PLAYER_3 = texmap.getTextureReference(48, 64, 32, 48);
|
texmap.getTextureReference(1, 2, 2, 3),
|
||||||
public static final TextureReference ENTITY_PLAYER = new AnimationReference(
|
texmap.getTextureReference(2, 3, 2, 3),
|
||||||
10, ENTITY_PLAYER_0, ENTITY_PLAYER_1, ENTITY_PLAYER_2, ENTITY_PLAYER_3);
|
texmap.getTextureReference(3, 4, 2, 3)
|
||||||
|
);
|
||||||
|
|
||||||
// Zombie
|
// Zombie
|
||||||
public static final TextureReference ENTITY_ZOMBIE_0 = texmap.getTextureReference(0, 16, 48, 64);
|
public static final TextureReference ENTITY_ZOMBIE = new AnimationReference(10,
|
||||||
public static final TextureReference ENTITY_ZOMBIE_1 = texmap.getTextureReference(16, 32, 48, 64);
|
texmap.getTextureReference(0, 1, 3, 4),
|
||||||
public static final TextureReference ENTITY_ZOMBIE_2 = texmap.getTextureReference(32, 48, 48, 64);
|
texmap.getTextureReference(1, 2, 3, 4),
|
||||||
public static final TextureReference ENTITY_ZOMBIE_3 = texmap.getTextureReference(48, 64, 48, 64);
|
texmap.getTextureReference(2, 3, 3, 4),
|
||||||
public static final TextureReference ENTITY_ZOMBIE = new AnimationReference(
|
texmap.getTextureReference(3, 4, 3, 4)
|
||||||
10, ENTITY_ZOMBIE_0, ENTITY_ZOMBIE_1, ENTITY_ZOMBIE_2, ENTITY_ZOMBIE_3);
|
);
|
||||||
|
|
||||||
|
// Water
|
||||||
|
public static final TextureReference TILE_WATER = new AnimationReference(20,
|
||||||
|
texmap.getTextureReference(0, 1, 8, 9),
|
||||||
|
texmap.getTextureReference(1, 2, 8, 9),
|
||||||
|
texmap.getTextureReference(2, 3, 8, 9),
|
||||||
|
texmap.getTextureReference(3, 4, 8, 9),
|
||||||
|
texmap.getTextureReference(4, 5, 8, 9),
|
||||||
|
texmap.getTextureReference(5, 6, 8, 9),
|
||||||
|
texmap.getTextureReference(6, 7, 8, 9),
|
||||||
|
texmap.getTextureReference(7, 8, 8, 9),
|
||||||
|
texmap.getTextureReference(8, 9, 8, 9),
|
||||||
|
texmap.getTextureReference(9, 10, 8, 9),
|
||||||
|
texmap.getTextureReference(10, 11, 8, 9),
|
||||||
|
texmap.getTextureReference(11, 12, 8, 9),
|
||||||
|
texmap.getTextureReference(12, 13, 8, 9),
|
||||||
|
texmap.getTextureReference(13, 14, 8, 9),
|
||||||
|
texmap.getTextureReference(14, 15, 8, 9),
|
||||||
|
texmap.getTextureReference(15, 16, 8, 9)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Lava
|
||||||
|
public static final TextureReference TILE_LAVA = new AnimationReference(10,
|
||||||
|
texmap.getTextureReference(0, 1, 6, 7),
|
||||||
|
texmap.getTextureReference(1, 2, 6, 7),
|
||||||
|
texmap.getTextureReference(2, 3, 6, 7),
|
||||||
|
texmap.getTextureReference(3, 4, 6, 7),
|
||||||
|
texmap.getTextureReference(4, 5, 6, 7),
|
||||||
|
texmap.getTextureReference(5, 6, 6, 7),
|
||||||
|
texmap.getTextureReference(6, 7, 6, 7),
|
||||||
|
texmap.getTextureReference(7, 8, 6, 7),
|
||||||
|
texmap.getTextureReference(8, 9, 6, 7),
|
||||||
|
texmap.getTextureReference(9, 10, 6, 7),
|
||||||
|
texmap.getTextureReference(10, 11, 6, 7),
|
||||||
|
texmap.getTextureReference(11, 12, 6, 7),
|
||||||
|
texmap.getTextureReference(12, 13, 6, 7),
|
||||||
|
texmap.getTextureReference(13, 14, 6, 7),
|
||||||
|
texmap.getTextureReference(14, 15, 6, 7),
|
||||||
|
texmap.getTextureReference(15, 16, 6, 7)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Water flow
|
||||||
|
public static final TextureReference TILE_WATER_FLOW = new AnimationReference(20,
|
||||||
|
texmap.getTextureReference(0, 1, 9, 10),
|
||||||
|
texmap.getTextureReference(1, 2, 9, 10),
|
||||||
|
texmap.getTextureReference(2, 3, 9, 10),
|
||||||
|
texmap.getTextureReference(3, 4, 9, 10),
|
||||||
|
texmap.getTextureReference(4, 5, 9, 10),
|
||||||
|
texmap.getTextureReference(5, 6, 9, 10),
|
||||||
|
texmap.getTextureReference(6, 7, 9, 10),
|
||||||
|
texmap.getTextureReference(7, 8, 9, 10),
|
||||||
|
texmap.getTextureReference(8, 9, 9, 10),
|
||||||
|
texmap.getTextureReference(9, 10, 9, 10),
|
||||||
|
texmap.getTextureReference(10, 11, 9, 10),
|
||||||
|
texmap.getTextureReference(11, 12, 9, 10),
|
||||||
|
texmap.getTextureReference(12, 13, 9, 10),
|
||||||
|
texmap.getTextureReference(13, 14, 9, 10),
|
||||||
|
texmap.getTextureReference(14, 15, 9, 10),
|
||||||
|
texmap.getTextureReference(15, 16, 9, 10)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Lava flow
|
||||||
|
public static final TextureReference TILE_LAVA_FLOW = new AnimationReference(10,
|
||||||
|
texmap.getTextureReference(0, 1, 7, 8),
|
||||||
|
texmap.getTextureReference(1, 2, 7, 8),
|
||||||
|
texmap.getTextureReference(2, 3, 7, 8),
|
||||||
|
texmap.getTextureReference(3, 4, 7, 8),
|
||||||
|
texmap.getTextureReference(4, 5, 7, 8),
|
||||||
|
texmap.getTextureReference(5, 6, 7, 8),
|
||||||
|
texmap.getTextureReference(6, 7, 7, 8),
|
||||||
|
texmap.getTextureReference(7, 8, 7, 8),
|
||||||
|
texmap.getTextureReference(8, 9, 7, 8),
|
||||||
|
texmap.getTextureReference(9, 10, 7, 8),
|
||||||
|
texmap.getTextureReference(10, 11, 7, 8),
|
||||||
|
texmap.getTextureReference(11, 12, 7, 8),
|
||||||
|
texmap.getTextureReference(12, 13, 7, 8),
|
||||||
|
texmap.getTextureReference(13, 14, 7, 8),
|
||||||
|
texmap.getTextureReference(14, 15, 7, 8),
|
||||||
|
texmap.getTextureReference(15, 16, 7, 8)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,15 @@ import shootergame.tiles.Tile;
|
||||||
import shootergame.tiles.TileDirt;
|
import shootergame.tiles.TileDirt;
|
||||||
import shootergame.tiles.TileFire;
|
import shootergame.tiles.TileFire;
|
||||||
import shootergame.tiles.TileGrass;
|
import shootergame.tiles.TileGrass;
|
||||||
|
import shootergame.tiles.TileLava;
|
||||||
|
import shootergame.tiles.TileLavaFlow;
|
||||||
|
import shootergame.tiles.TileRock;
|
||||||
import shootergame.tiles.TileSand;
|
import shootergame.tiles.TileSand;
|
||||||
import shootergame.tiles.TileStone;
|
import shootergame.tiles.TileStone;
|
||||||
import shootergame.tiles.TileTree;
|
import shootergame.tiles.TileTree;
|
||||||
|
import shootergame.tiles.TileVoid;
|
||||||
|
import shootergame.tiles.TileWater;
|
||||||
|
import shootergame.tiles.TileWaterFlow;
|
||||||
|
|
||||||
public class Tiles
|
public class Tiles
|
||||||
{
|
{
|
||||||
|
|
@ -16,4 +22,10 @@ public class Tiles
|
||||||
public static final Tile STONE = new TileStone("stone");
|
public static final Tile STONE = new TileStone("stone");
|
||||||
public static final Tile DIRT = new TileDirt("dirt");
|
public static final Tile DIRT = new TileDirt("dirt");
|
||||||
public static final Tile TREE = new TileTree("tree");
|
public static final Tile TREE = new TileTree("tree");
|
||||||
|
public static final Tile VOID = new TileVoid("void");
|
||||||
|
public static final Tile ROCK = new TileRock("rock");
|
||||||
|
public static final Tile LAVA = new TileLava("lava");
|
||||||
|
public static final Tile WATER = new TileWater("water");
|
||||||
|
public static final Tile LAVA_FLOW = new TileLavaFlow("lava_flow");
|
||||||
|
public static final Tile WATER_FLOW = new TileWaterFlow("water_flow");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,189 @@
|
||||||
|
package shootergame.input;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.CharBuffer;
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.lwjgl.glfw.GLFWGamepadState;
|
||||||
|
import org.lwjgl.glfw.GLFWJoystickCallbackI;
|
||||||
|
|
||||||
|
import mainloop.task.IMainloopTask;
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.entity.EntityBullet;
|
||||||
|
import shootergame.util.math.MathHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
|
||||||
|
{
|
||||||
|
public static final JoystickCallback JOYSTICK_CALLBACK = new JoystickCallback();
|
||||||
|
private ArrayList<Integer> connections = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(int jid, int event)
|
||||||
|
{
|
||||||
|
// Gamepad connect
|
||||||
|
if(event == GLFW.GLFW_CONNECTED)
|
||||||
|
{
|
||||||
|
// Log the event and add the connection
|
||||||
|
System.out.println("Gamepad "+jid+" connected");
|
||||||
|
connections.add(jid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gamepad disconnect
|
||||||
|
else if(event == GLFW.GLFW_DISCONNECTED)
|
||||||
|
{
|
||||||
|
// Log the event
|
||||||
|
System.out.println("Gamepad "+jid+" disconnected");
|
||||||
|
|
||||||
|
// Loop over the connections
|
||||||
|
for(int i=0;i<connections.size();i++)
|
||||||
|
{
|
||||||
|
// Is this connection the connection that disconnected
|
||||||
|
if(connections.get(i).intValue() == jid)
|
||||||
|
{
|
||||||
|
// Remove the connection and reduce i
|
||||||
|
connections.remove(i);
|
||||||
|
i -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
// Loop over all the gamepads
|
||||||
|
for(int i=0;i<=GLFW.GLFW_JOYSTICK_LAST;i++)
|
||||||
|
{
|
||||||
|
// Is this gamepad present; add the gamepad
|
||||||
|
if(GLFW.glfwJoystickPresent(i)) {
|
||||||
|
if(GLFW.glfwJoystickIsGamepad(i)) {
|
||||||
|
System.out.println("Gamepad "+i+" connected");
|
||||||
|
connections.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopDelay(long millis) {
|
||||||
|
return millis > 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopRepeat() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float combineJoystickAxis(float a, float b)
|
||||||
|
{
|
||||||
|
if(b > 0.2 || b < -0.2) a += b;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MainLoopUpdate()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
// Gamepad properties
|
||||||
|
float left_x = 0;
|
||||||
|
float left_y = 0;
|
||||||
|
float left_trigger = 0;
|
||||||
|
float right_x = 0;
|
||||||
|
float right_y = 0;
|
||||||
|
float right_trigger = 0;
|
||||||
|
boolean left_stick_button = false;
|
||||||
|
boolean right_stick_button = false;
|
||||||
|
boolean button_a = false;
|
||||||
|
boolean button_b = false;
|
||||||
|
boolean button_x = false;
|
||||||
|
boolean button_y = false;
|
||||||
|
boolean button_start = false;
|
||||||
|
boolean button_back = false;
|
||||||
|
boolean button_home = false;
|
||||||
|
boolean dpad_up = false;
|
||||||
|
boolean dpad_down = false;
|
||||||
|
boolean dpad_left = false;
|
||||||
|
boolean dpad_right = false;
|
||||||
|
boolean shoulder_left = false;
|
||||||
|
boolean shoulder_right = false;
|
||||||
|
|
||||||
|
// Loop over all the connected gamepads
|
||||||
|
for(int jid : connections)
|
||||||
|
{
|
||||||
|
// Get all the axes
|
||||||
|
FloatBuffer axes = GLFW.glfwGetJoystickAxes(jid);
|
||||||
|
|
||||||
|
// Store all the axes data
|
||||||
|
left_x = combineJoystickAxis(left_x, axes.get(0));
|
||||||
|
left_y = combineJoystickAxis(left_y, axes.get(1));
|
||||||
|
right_x = combineJoystickAxis(right_x, axes.get(3));
|
||||||
|
right_y = combineJoystickAxis(right_y, axes.get(4));
|
||||||
|
left_trigger = combineJoystickAxis(left_trigger, axes.get(2));
|
||||||
|
right_trigger = combineJoystickAxis(right_trigger, axes.get(5));
|
||||||
|
|
||||||
|
// Get all the buttons
|
||||||
|
ByteBuffer buttons = GLFW.glfwGetJoystickButtons(jid);
|
||||||
|
|
||||||
|
// Store all the button data
|
||||||
|
button_a = buttons.get(0) == 1 || button_a;
|
||||||
|
button_b = buttons.get(1) == 1 || button_b;
|
||||||
|
button_x = buttons.get(2) == 1 || button_x;
|
||||||
|
button_y = buttons.get(3) == 1 || button_y;
|
||||||
|
shoulder_left = buttons.get(4) == 1 || shoulder_left;
|
||||||
|
shoulder_right = buttons.get(5) == 1 || shoulder_right;
|
||||||
|
button_back = buttons.get(6) == 1 || button_back;
|
||||||
|
button_start = buttons.get(7) == 1 || button_start;
|
||||||
|
button_home = buttons.get(8) == 1 || button_home;
|
||||||
|
left_stick_button = buttons.get(9) == 1 || left_stick_button;
|
||||||
|
right_stick_button = buttons.get(10) == 1 || right_stick_button;
|
||||||
|
dpad_left = buttons.get(11) == 1 || buttons.get(18) == 1 || dpad_left;
|
||||||
|
dpad_right = buttons.get(12) == 1 || buttons.get(16) == 1 || dpad_right;
|
||||||
|
dpad_up = buttons.get(13) == 1 || buttons.get(15) == 1 || dpad_up;
|
||||||
|
dpad_down = buttons.get(14) == 1 || buttons.get(17) == 1 || dpad_down;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is the left stick moved into a position (movement stick)
|
||||||
|
if(left_x > 0.3 || left_x < -0.3 || left_y > 0.3 || left_y < -0.3)
|
||||||
|
{
|
||||||
|
// Get the the angle
|
||||||
|
double angle = Math.toDegrees(Math.atan2(left_y, left_x)) + 90;
|
||||||
|
|
||||||
|
// Move the player in the left sticks angle
|
||||||
|
Main.player.angle += angle;
|
||||||
|
Main.player.moveForward();
|
||||||
|
Main.player.angle -= angle;
|
||||||
|
|
||||||
|
// Set the players moving to true
|
||||||
|
Main.player.moving = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the players moving to false
|
||||||
|
else Main.player.moving = false;
|
||||||
|
|
||||||
|
// Is the right stick moved into a position (gun stick)
|
||||||
|
if(right_x > 0.3 || right_x < -0.3 || right_y > 0.3 || right_y < -0.3)
|
||||||
|
{
|
||||||
|
// Get the the angle
|
||||||
|
double angle = Math.toDegrees(Math.atan2(right_y, right_x)) + 90;
|
||||||
|
|
||||||
|
// Summon bullets at this angle relative to the player
|
||||||
|
Entity bullet = new EntityBullet();
|
||||||
|
bullet.angle = angle + Main.player.angle;
|
||||||
|
bullet.pos = new Vec2d(Main.player.pos.x / 2, Main.player.pos.y / 2);
|
||||||
|
Main.world.getLayer().spawnEntity(bullet);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shoulder_left) {
|
||||||
|
Main.player.angle -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shoulder_right) {
|
||||||
|
Main.player.angle += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ public class MainloopEventHandler implements IMainloopEvent, IMainloopTask
|
||||||
public static final MainloopEventHandler MAINLOOP_EVENT_HANDLER = new MainloopEventHandler();
|
public static final MainloopEventHandler MAINLOOP_EVENT_HANDLER = new MainloopEventHandler();
|
||||||
|
|
||||||
public long mspf = 1000/60;
|
public long mspf = 1000/60;
|
||||||
|
private long max_mspf = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
|
|
@ -18,7 +19,7 @@ public class MainloopEventHandler implements IMainloopEvent, IMainloopTask
|
||||||
@Override
|
@Override
|
||||||
public void onEarly() {
|
public void onEarly() {
|
||||||
mspf -= 1;
|
mspf -= 1;
|
||||||
if(mspf < 1) mspf = 1;
|
if(mspf < max_mspf) mspf = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
{
|
||||||
|
"protocol_version" : "0.0.2",
|
||||||
|
"configuration" : {
|
||||||
|
"version" : "5.18.0.240 (Debian 5.18.0.240+dfsg-2ubuntu2 Wed Apr 17 23:39:09 UTC 2019)",
|
||||||
|
"tlc" : "__thread",
|
||||||
|
"sigsgev" : "altstack",
|
||||||
|
"notifications" : "epoll",
|
||||||
|
"architecture" : "amd64",
|
||||||
|
"disabled_features" : "none",
|
||||||
|
"smallconfig" : "disabled",
|
||||||
|
"bigarrays" : "disabled",
|
||||||
|
"softdebug" : "enabled",
|
||||||
|
"interpreter" : "enabled",
|
||||||
|
"llvm_support" : "disabled",
|
||||||
|
"suspend" : "preemptive"
|
||||||
|
},
|
||||||
|
"memory" : {
|
||||||
|
"minor_gc_time" : "378907",
|
||||||
|
"major_gc_time" : "34891",
|
||||||
|
"minor_gc_count" : "24",
|
||||||
|
"major_gc_count" : "1",
|
||||||
|
"major_gc_time_concurrent" : "29295"
|
||||||
|
},
|
||||||
|
"threads" : [
|
||||||
|
{
|
||||||
|
"is_managed" : false,
|
||||||
|
"crashed" : true,
|
||||||
|
"managed_thread_ptr" : "0x0",
|
||||||
|
"native_thread_id" : "0x7fee3d843700",
|
||||||
|
"thread_info_addr" : "0x0",
|
||||||
|
"thread_name" : "Finalizer",
|
||||||
|
"ctx" : {
|
||||||
|
"IP" : "0x7fee40fd8ed7",
|
||||||
|
"SP" : "0x7fee3d842690",
|
||||||
|
"BP" : "0x7fee3d8429e0"
|
||||||
|
},
|
||||||
|
"managed_frames" : [
|
||||||
|
{
|
||||||
|
"native_address" : "unregistered"
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
"unmanaged_frames" : [
|
||||||
|
{
|
||||||
|
"native_address" : "unregistered"
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"is_managed" : false,
|
||||||
|
"crashed" : false,
|
||||||
|
"managed_thread_ptr" : "0x0",
|
||||||
|
"native_thread_id" : "0x7fee40f90780",
|
||||||
|
"thread_info_addr" : "0x0",
|
||||||
|
"thread_name" : "mono",
|
||||||
|
"ctx" : {
|
||||||
|
"IP" : "0x7fee410a6729",
|
||||||
|
"SP" : "0x7ffe255e5640",
|
||||||
|
"BP" : "0x3"
|
||||||
|
},
|
||||||
|
"managed_frames" : [
|
||||||
|
{
|
||||||
|
"native_address" : "unregistered"
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
"unmanaged_frames" : [
|
||||||
|
{
|
||||||
|
"native_address" : "unregistered"
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
{
|
||||||
|
"protocol_version" : "0.0.2",
|
||||||
|
"configuration" : {
|
||||||
|
"version" : "5.18.0.240 (Debian 5.18.0.240+dfsg-2ubuntu2 Wed Apr 17 23:39:09 UTC 2019)",
|
||||||
|
"tlc" : "__thread",
|
||||||
|
"sigsgev" : "altstack",
|
||||||
|
"notifications" : "epoll",
|
||||||
|
"architecture" : "amd64",
|
||||||
|
"disabled_features" : "none",
|
||||||
|
"smallconfig" : "disabled",
|
||||||
|
"bigarrays" : "disabled",
|
||||||
|
"softdebug" : "enabled",
|
||||||
|
"interpreter" : "enabled",
|
||||||
|
"llvm_support" : "disabled",
|
||||||
|
"suspend" : "preemptive"
|
||||||
|
},
|
||||||
|
"memory" : {
|
||||||
|
"minor_gc_time" : "41590",
|
||||||
|
"major_gc_time" : "0",
|
||||||
|
"minor_gc_count" : "2",
|
||||||
|
"major_gc_count" : "0",
|
||||||
|
"major_gc_time_concurrent" : "0"
|
||||||
|
},
|
||||||
|
"threads" : [
|
||||||
|
{
|
||||||
|
"is_managed" : false,
|
||||||
|
"crashed" : false,
|
||||||
|
"managed_thread_ptr" : "0x0",
|
||||||
|
"native_thread_id" : "0x7fa2fae57780",
|
||||||
|
"thread_info_addr" : "0x0",
|
||||||
|
"thread_name" : "mono",
|
||||||
|
"ctx" : {
|
||||||
|
"IP" : "0x7fa2faef4be9",
|
||||||
|
"SP" : "0x7ffee36a8db0",
|
||||||
|
"BP" : "0x100"
|
||||||
|
},
|
||||||
|
"managed_frames" : [
|
||||||
|
{
|
||||||
|
"native_address" : "unregistered"
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
"unmanaged_frames" : [
|
||||||
|
{
|
||||||
|
"native_address" : "unregistered"
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"is_managed" : false,
|
||||||
|
"crashed" : true,
|
||||||
|
"managed_thread_ptr" : "0x0",
|
||||||
|
"native_thread_id" : "0x7fa2f753d700",
|
||||||
|
"thread_info_addr" : "0x0",
|
||||||
|
"thread_name" : "Finalizer",
|
||||||
|
"ctx" : {
|
||||||
|
"IP" : "0x7fa2fae9fed7",
|
||||||
|
"SP" : "0x7fa2f753c690",
|
||||||
|
"BP" : "0x7fa2f753c9e0"
|
||||||
|
},
|
||||||
|
"managed_frames" : [
|
||||||
|
{
|
||||||
|
"native_address" : "unregistered"
|
||||||
|
}
|
||||||
|
|
||||||
|
],
|
||||||
|
"unmanaged_frames" : [
|
||||||
|
{
|
||||||
|
"native_address" : "unregistered"
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 53 KiB |
Binary file not shown.
|
|
@ -0,0 +1,176 @@
|
||||||
|
package shootergame.text;
|
||||||
|
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class Text
|
||||||
|
{
|
||||||
|
public static final TextureReference CHAR_A = Textures.texmap.getTextureReference(5, 6, 0, 1);
|
||||||
|
public static final TextureReference CHAR_B = Textures.texmap.getTextureReference(6, 7, 0, 1);
|
||||||
|
public static final TextureReference CHAR_C = Textures.texmap.getTextureReference(7, 8, 0, 1);
|
||||||
|
public static final TextureReference CHAR_D = Textures.texmap.getTextureReference(8, 9, 0, 1);
|
||||||
|
public static final TextureReference CHAR_E = Textures.texmap.getTextureReference(9, 10, 0, 1);
|
||||||
|
public static final TextureReference CHAR_F = Textures.texmap.getTextureReference(10, 11, 0, 1);
|
||||||
|
public static final TextureReference CHAR_G = Textures.texmap.getTextureReference(11, 12, 0, 1);
|
||||||
|
public static final TextureReference CHAR_H = Textures.texmap.getTextureReference(12, 13, 0, 1);
|
||||||
|
public static final TextureReference CHAR_I = Textures.texmap.getTextureReference(13, 14, 0, 1);
|
||||||
|
public static final TextureReference CHAR_J = Textures.texmap.getTextureReference(14, 15, 0, 1);
|
||||||
|
public static final TextureReference CHAR_K = Textures.texmap.getTextureReference(15, 16, 0, 1);
|
||||||
|
public static final TextureReference CHAR_L = Textures.texmap.getTextureReference(5, 6, 1, 2);
|
||||||
|
public static final TextureReference CHAR_M = Textures.texmap.getTextureReference(6, 7, 1, 2);
|
||||||
|
public static final TextureReference CHAR_N = Textures.texmap.getTextureReference(7, 8, 1, 2);
|
||||||
|
public static final TextureReference CHAR_O = Textures.texmap.getTextureReference(8, 9, 1, 2);
|
||||||
|
public static final TextureReference CHAR_P = Textures.texmap.getTextureReference(9, 10, 1, 2);
|
||||||
|
public static final TextureReference CHAR_Q = Textures.texmap.getTextureReference(10, 11, 1, 2);
|
||||||
|
public static final TextureReference CHAR_R = Textures.texmap.getTextureReference(11, 12, 1, 2);
|
||||||
|
public static final TextureReference CHAR_S = Textures.texmap.getTextureReference(12, 13, 1, 2);
|
||||||
|
public static final TextureReference CHAR_T = Textures.texmap.getTextureReference(13, 14, 1, 2);
|
||||||
|
public static final TextureReference CHAR_U = Textures.texmap.getTextureReference(14, 15, 1, 2);
|
||||||
|
public static final TextureReference CHAR_V = Textures.texmap.getTextureReference(15, 16, 1, 2);
|
||||||
|
public static final TextureReference CHAR_W = Textures.texmap.getTextureReference(5, 6, 2, 3);
|
||||||
|
public static final TextureReference CHAR_X = Textures.texmap.getTextureReference(6, 7, 2, 3);
|
||||||
|
public static final TextureReference CHAR_Y = Textures.texmap.getTextureReference(7, 8, 2, 3);
|
||||||
|
public static final TextureReference CHAR_Z = Textures.texmap.getTextureReference(8, 9, 2, 3);
|
||||||
|
public static final TextureReference CHAR_a = Textures.texmap.getTextureReference(9, 10, 2, 3);
|
||||||
|
public static final TextureReference CHAR_b = Textures.texmap.getTextureReference(10, 11, 2, 3);
|
||||||
|
public static final TextureReference CHAR_c = Textures.texmap.getTextureReference(11, 12, 2, 3);
|
||||||
|
public static final TextureReference CHAR_d = Textures.texmap.getTextureReference(12, 13, 2, 3);
|
||||||
|
public static final TextureReference CHAR_e = Textures.texmap.getTextureReference(13, 14, 2, 3);
|
||||||
|
public static final TextureReference CHAR_f = Textures.texmap.getTextureReference(14, 15, 2, 3);
|
||||||
|
public static final TextureReference CHAR_g = Textures.texmap.getTextureReference(15, 16, 2, 3);
|
||||||
|
public static final TextureReference CHAR_h = Textures.texmap.getTextureReference(5, 6, 3, 4);
|
||||||
|
public static final TextureReference CHAR_i = Textures.texmap.getTextureReference(6, 7, 3, 4);
|
||||||
|
public static final TextureReference CHAR_j = Textures.texmap.getTextureReference(7, 8, 3, 4);
|
||||||
|
public static final TextureReference CHAR_k = Textures.texmap.getTextureReference(8, 9, 3, 4);
|
||||||
|
public static final TextureReference CHAR_l = Textures.texmap.getTextureReference(9, 10, 3, 4);
|
||||||
|
public static final TextureReference CHAR_m = Textures.texmap.getTextureReference(10, 11, 3, 4);
|
||||||
|
public static final TextureReference CHAR_n = Textures.texmap.getTextureReference(11, 12, 3, 4);
|
||||||
|
public static final TextureReference CHAR_o = Textures.texmap.getTextureReference(12, 13, 3, 4);
|
||||||
|
public static final TextureReference CHAR_p = Textures.texmap.getTextureReference(13, 14, 3, 4);
|
||||||
|
public static final TextureReference CHAR_q = Textures.texmap.getTextureReference(14, 15, 3, 4);
|
||||||
|
public static final TextureReference CHAR_r = Textures.texmap.getTextureReference(15, 16, 3, 4);
|
||||||
|
public static final TextureReference CHAR_s = Textures.texmap.getTextureReference(5, 6, 4, 5);
|
||||||
|
public static final TextureReference CHAR_t = Textures.texmap.getTextureReference(6, 7, 4, 5);
|
||||||
|
public static final TextureReference CHAR_u = Textures.texmap.getTextureReference(7, 8, 4, 5);
|
||||||
|
public static final TextureReference CHAR_v = Textures.texmap.getTextureReference(8, 9, 4, 5);
|
||||||
|
public static final TextureReference CHAR_w = Textures.texmap.getTextureReference(9, 10, 4, 5);
|
||||||
|
public static final TextureReference CHAR_x = Textures.texmap.getTextureReference(10, 11, 4, 5);
|
||||||
|
public static final TextureReference CHAR_y = Textures.texmap.getTextureReference(11, 12, 4, 5);
|
||||||
|
public static final TextureReference CHAR_z = Textures.texmap.getTextureReference(12, 13, 4, 5);
|
||||||
|
public static final TextureReference CHAR_0 = Textures.texmap.getTextureReference(13, 14, 4, 5);
|
||||||
|
public static final TextureReference CHAR_1 = Textures.texmap.getTextureReference(14, 15, 4, 5);
|
||||||
|
public static final TextureReference CHAR_2 = Textures.texmap.getTextureReference(15, 16, 4, 5);
|
||||||
|
public static final TextureReference CHAR_3 = Textures.texmap.getTextureReference(5, 6, 5, 6);
|
||||||
|
public static final TextureReference CHAR_4 = Textures.texmap.getTextureReference(6, 7, 5, 6);
|
||||||
|
public static final TextureReference CHAR_5 = Textures.texmap.getTextureReference(7, 8, 5, 6);
|
||||||
|
public static final TextureReference CHAR_6 = Textures.texmap.getTextureReference(8, 9, 5, 6);
|
||||||
|
public static final TextureReference CHAR_7 = Textures.texmap.getTextureReference(9, 10, 5, 6);
|
||||||
|
public static final TextureReference CHAR_8 = Textures.texmap.getTextureReference(10, 11, 5, 6);
|
||||||
|
public static final TextureReference CHAR_9 = Textures.texmap.getTextureReference(11, 12, 5, 6);
|
||||||
|
public static final TextureReference CHAR_PEROID = Textures.texmap.getTextureReference(12, 13, 5, 6);
|
||||||
|
public static final TextureReference CHAR_COLON = Textures.texmap.getTextureReference(13, 14, 5, 6);
|
||||||
|
public static final TextureReference CHAR_COMMA = Textures.texmap.getTextureReference(14, 15, 5, 6);
|
||||||
|
public static final TextureReference CHAR_EXMARK = Textures.texmap.getTextureReference(15, 16, 5, 6);
|
||||||
|
|
||||||
|
public static void render(String text, Vec2d size)
|
||||||
|
{
|
||||||
|
// Get the bytes from the string
|
||||||
|
byte[] text_b = text.getBytes();
|
||||||
|
|
||||||
|
double sx = size.x;
|
||||||
|
double sy = size.y;
|
||||||
|
|
||||||
|
// Begin quads
|
||||||
|
GlHelpers.begin();
|
||||||
|
|
||||||
|
// Loop over the bytes
|
||||||
|
for(int i=0;i<text_b.length;i++)
|
||||||
|
{
|
||||||
|
// Get the character from the string
|
||||||
|
TextureReference l = null;
|
||||||
|
switch(text_b[i]) {
|
||||||
|
case('Q'): l = CHAR_Q; break;
|
||||||
|
case('W'): l = CHAR_W; break;
|
||||||
|
case('E'): l = CHAR_E; break;
|
||||||
|
case('R'): l = CHAR_R; break;
|
||||||
|
case('T'): l = CHAR_T; break;
|
||||||
|
case('Y'): l = CHAR_Y; break;
|
||||||
|
case('U'): l = CHAR_U; break;
|
||||||
|
case('I'): l = CHAR_I; break;
|
||||||
|
case('O'): l = CHAR_O; break;
|
||||||
|
case('P'): l = CHAR_P; break;
|
||||||
|
case('A'): l = CHAR_A; break;
|
||||||
|
case('S'): l = CHAR_S; break;
|
||||||
|
case('D'): l = CHAR_D; break;
|
||||||
|
case('F'): l = CHAR_F; break;
|
||||||
|
case('G'): l = CHAR_G; break;
|
||||||
|
case('H'): l = CHAR_H; break;
|
||||||
|
case('J'): l = CHAR_J; break;
|
||||||
|
case('K'): l = CHAR_K; break;
|
||||||
|
case('L'): l = CHAR_L; break;
|
||||||
|
case('Z'): l = CHAR_Z; break;
|
||||||
|
case('X'): l = CHAR_X; break;
|
||||||
|
case('C'): l = CHAR_C; break;
|
||||||
|
case('V'): l = CHAR_V; break;
|
||||||
|
case('B'): l = CHAR_B; break;
|
||||||
|
case('N'): l = CHAR_N; break;
|
||||||
|
case('M'): l = CHAR_M; break;
|
||||||
|
case('q'): l = CHAR_q; break;
|
||||||
|
case('w'): l = CHAR_w; break;
|
||||||
|
case('e'): l = CHAR_e; break;
|
||||||
|
case('r'): l = CHAR_r; break;
|
||||||
|
case('t'): l = CHAR_t; break;
|
||||||
|
case('y'): l = CHAR_y; break;
|
||||||
|
case('u'): l = CHAR_u; break;
|
||||||
|
case('i'): l = CHAR_i; break;
|
||||||
|
case('o'): l = CHAR_o; break;
|
||||||
|
case('p'): l = CHAR_p; break;
|
||||||
|
case('a'): l = CHAR_a; break;
|
||||||
|
case('s'): l = CHAR_s; break;
|
||||||
|
case('d'): l = CHAR_d; break;
|
||||||
|
case('f'): l = CHAR_f; break;
|
||||||
|
case('g'): l = CHAR_g; break;
|
||||||
|
case('h'): l = CHAR_h; break;
|
||||||
|
case('j'): l = CHAR_j; break;
|
||||||
|
case('k'): l = CHAR_k; break;
|
||||||
|
case('l'): l = CHAR_l; break;
|
||||||
|
case('z'): l = CHAR_z; break;
|
||||||
|
case('x'): l = CHAR_x; break;
|
||||||
|
case('c'): l = CHAR_c; break;
|
||||||
|
case('v'): l = CHAR_v; break;
|
||||||
|
case('b'): l = CHAR_b; break;
|
||||||
|
case('n'): l = CHAR_n; break;
|
||||||
|
case('m'): l = CHAR_m; break;
|
||||||
|
case('0'): l = CHAR_0; break;
|
||||||
|
case('1'): l = CHAR_1; break;
|
||||||
|
case('2'): l = CHAR_2; break;
|
||||||
|
case('3'): l = CHAR_3; break;
|
||||||
|
case('4'): l = CHAR_4; break;
|
||||||
|
case('5'): l = CHAR_5; break;
|
||||||
|
case('6'): l = CHAR_6; break;
|
||||||
|
case('7'): l = CHAR_7; break;
|
||||||
|
case('8'): l = CHAR_8; break;
|
||||||
|
case('9'): l = CHAR_9; break;
|
||||||
|
case(':'): l = CHAR_COLON; break;
|
||||||
|
case(','): l = CHAR_COMMA; break;
|
||||||
|
case('.'): l = CHAR_PEROID; break;
|
||||||
|
case('!'): l = CHAR_EXMARK; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is the letter not null
|
||||||
|
if(l != null)
|
||||||
|
{
|
||||||
|
// Render the character
|
||||||
|
l.texCoord(0, 1); GlHelpers.vertex3(sy*(i-1), 0, 0);
|
||||||
|
l.texCoord(0, 0); GlHelpers.vertex3(sy*(i-1), sx, 0);
|
||||||
|
l.texCoord(1, 0); GlHelpers.vertex3(sy*i, sx, 0);
|
||||||
|
l.texCoord(1, 1); GlHelpers.vertex3(sy*i, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop drawing quads
|
||||||
|
GlHelpers.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ package shootergame.tiles;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.display.transparent.ITransparentObject;
|
import shootergame.display.transparent.ITransparentObject;
|
||||||
import shootergame.display.transparent.TransparentObjects;
|
import shootergame.display.transparent.TransparentObjects;
|
||||||
import shootergame.entity.player.Player;
|
import shootergame.entity.player.EntityPlayer;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
import shootergame.util.math.vec.Vec2i;
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
|
||||||
|
|
@ -11,6 +11,8 @@ public class Tile implements ITransparentObject
|
||||||
{
|
{
|
||||||
private String id;
|
private String id;
|
||||||
public boolean opaqueTile = false;
|
public boolean opaqueTile = false;
|
||||||
|
public boolean tileSolid = false;
|
||||||
|
public boolean tileWalkable = true;
|
||||||
|
|
||||||
public Tile(String id) {
|
public Tile(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package shootergame.tiles;
|
package shootergame.tiles;
|
||||||
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.entity.player.Player;
|
import shootergame.entity.player.EntityPlayer;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class TileLava extends TileFlat
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileLava(String id) {
|
||||||
|
super(id, Textures.TILE_LAVA);
|
||||||
|
|
||||||
|
this.tileWalkable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera) {
|
||||||
|
GlHelpers.pushMatrix();
|
||||||
|
GlHelpers.translate(0, 0, 0.001);
|
||||||
|
super.render(pos, camera);
|
||||||
|
GlHelpers.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class TileLavaFlow extends TileFlat
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileLavaFlow(String id) {
|
||||||
|
super(id, Textures.TILE_LAVA_FLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera) {
|
||||||
|
GlHelpers.pushMatrix();
|
||||||
|
GlHelpers.translate(0, 0, 0.001);
|
||||||
|
super.render(pos, camera);
|
||||||
|
GlHelpers.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
|
||||||
|
public class TileRock extends TileVertical
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileRock(String id) {
|
||||||
|
super(id, Textures.TILE_ROCK, 1);
|
||||||
|
|
||||||
|
// Set some settings
|
||||||
|
this.opaqueTile = true;
|
||||||
|
this.tileSolid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ public class TileTree extends TileVertical
|
||||||
|
|
||||||
// Set some settings
|
// Set some settings
|
||||||
this.opaqueTile = true;
|
this.opaqueTile = true;
|
||||||
|
this.tileSolid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package shootergame.tiles;
|
||||||
|
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.entity.player.Player;
|
import shootergame.entity.player.EntityPlayer;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.gl.VerticalRender;
|
import shootergame.util.gl.VerticalRender;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
public class TileVoid extends Tile {
|
||||||
|
|
||||||
|
public TileVoid(String id) {
|
||||||
|
super(id);
|
||||||
|
|
||||||
|
// Set some settings
|
||||||
|
this.tileSolid = true;
|
||||||
|
this.tileWalkable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class TileWater extends TileFlat
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileWater(String id) {
|
||||||
|
super(id, Textures.TILE_WATER);
|
||||||
|
|
||||||
|
this.tileWalkable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera) {
|
||||||
|
GlHelpers.pushMatrix();
|
||||||
|
GlHelpers.translate(0, 0, 0.001);
|
||||||
|
super.render(pos, camera);
|
||||||
|
GlHelpers.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package shootergame.tiles;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.gl.GlHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
public class TileWaterFlow extends TileFlat
|
||||||
|
{
|
||||||
|
|
||||||
|
public TileWaterFlow(String id) {
|
||||||
|
super(id, Textures.TILE_WATER_FLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Vec2d pos, Camera camera) {
|
||||||
|
GlHelpers.pushMatrix();
|
||||||
|
GlHelpers.translate(0, 0, 0.001);
|
||||||
|
super.render(pos, camera);
|
||||||
|
GlHelpers.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package shootergame.util.gl;
|
package shootergame.util.gl;
|
||||||
|
|
||||||
import shootergame.display.Camera;
|
import shootergame.display.Camera;
|
||||||
import shootergame.entity.player.Player;
|
import shootergame.entity.player.EntityPlayer;
|
||||||
import shootergame.util.gl.texture.TextureReference;
|
import shootergame.util.gl.texture.TextureReference;
|
||||||
import shootergame.util.math.vec.Vec2d;
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
|
|
@ -15,12 +15,12 @@ public class VerticalRender
|
||||||
GlHelpers.pushMatrix();
|
GlHelpers.pushMatrix();
|
||||||
|
|
||||||
// Get the angle between the camera and the tile
|
// Get the angle between the camera and the tile
|
||||||
double angle_r = Math.atan2(pos.y - camera.pos.y, pos.x - camera.pos.x);
|
double angle_r = camera.angle.x;
|
||||||
|
|
||||||
// Make the tile upright
|
// Make the tile upright
|
||||||
GlHelpers.translate(0.5, 0, 0);
|
GlHelpers.translate(0.5, 0, 0);
|
||||||
GlHelpers.translate(pos.x, pos.y, 0);
|
GlHelpers.translate(pos.x, pos.y, 0);
|
||||||
GlHelpers.rotate(Math.toDegrees(angle_r)+90, 0, 0, 1);
|
GlHelpers.rotate(-angle_r, 0, 0, 1);
|
||||||
GlHelpers.translate(-0.5, 0, 0);
|
GlHelpers.translate(-0.5, 0, 0);
|
||||||
|
|
||||||
// Render the tile
|
// Render the tile
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package shootergame.util.gl.texture;
|
package shootergame.util.gl.texture;
|
||||||
|
|
||||||
import shootergame.init.Textures;
|
import shootergame.init.Textures;
|
||||||
|
import shootergame.util.math.MathHelpers;
|
||||||
|
|
||||||
public class AnimationReference extends TextureReference
|
public class AnimationReference extends TextureReference
|
||||||
{
|
{
|
||||||
|
|
@ -29,7 +30,7 @@ public class AnimationReference extends TextureReference
|
||||||
{
|
{
|
||||||
// Cycle through all the textures
|
// Cycle through all the textures
|
||||||
upto += 1;
|
upto += 1;
|
||||||
upto %= references.length * speed;
|
upto = MathHelpers.mod(upto, references.length * speed);
|
||||||
c = references[upto / speed];
|
c = references[upto / speed];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,11 @@ public class TextureMap
|
||||||
private String path;
|
private String path;
|
||||||
private int max_x;
|
private int max_x;
|
||||||
private int max_y;
|
private int max_y;
|
||||||
|
private int scale;
|
||||||
|
|
||||||
public TextureMap(String path) {
|
public TextureMap(int scale, String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
this.scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init()
|
public void init()
|
||||||
|
|
@ -38,7 +40,7 @@ public class TextureMap
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextureReference getTextureReference(int start_x, int end_x, int start_y, int end_y) {
|
public TextureReference getTextureReference(int start_x, int end_x, int start_y, int end_y) {
|
||||||
return new TextureReference(start_x, end_x, start_y, end_y)
|
return new TextureReference(start_x * scale, end_x * scale, start_y * scale, end_y * scale)
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -50,4 +50,12 @@ public class MathHelpers
|
||||||
|
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double mod(double a, double b) {
|
||||||
|
return (((a % b) + b) % b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int mod(int a, int b) {
|
||||||
|
return (((a % b) + b) % b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ public class Map2D<T> implements Iterable<Map2DElement<T>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send back an empty (unloaded) chunk
|
// Send back an empty object
|
||||||
return this.map2d_i.getEmpty(pos);
|
return this.map2d_i.getEmpty(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,6 +65,24 @@ public class Map2D<T> implements Iterable<Map2DElement<T>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean contains(Vec2i pos)
|
||||||
|
{
|
||||||
|
// Loop over the elements
|
||||||
|
for(int i=0;i<elements.size();i++)
|
||||||
|
{
|
||||||
|
// Get the element
|
||||||
|
Map2DElement<T> e = this.elements.get(i);
|
||||||
|
|
||||||
|
// Return true if the position is the same
|
||||||
|
if(e.pos.equal(pos)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return false if nothing was found
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Map2DElement<T>> iterator() {
|
public Iterator<Map2DElement<T>> iterator() {
|
||||||
return new Iterator<Map2DElement<T>>()
|
return new Iterator<Map2DElement<T>>()
|
||||||
|
|
|
||||||
|
|
@ -40,4 +40,8 @@ public class Vec2d
|
||||||
public Vec2d divide(Vec2d other) {
|
public Vec2d divide(Vec2d other) {
|
||||||
return new Vec2d(this.x / other.x, this.y / other.y);
|
return new Vec2d(this.x / other.x, this.y / other.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vec2d copy() {
|
||||||
|
return new Vec2d(x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ public class Vec2i
|
||||||
|
|
||||||
public static Vec2i fromId(Range2i range, int id)
|
public static Vec2i fromId(Range2i range, int id)
|
||||||
{
|
{
|
||||||
int x = id % range.mx;
|
int x = MathHelpers.mod(id, range.mx);
|
||||||
id -= x;
|
id -= x;
|
||||||
id /= range.mx;
|
id /= range.mx;
|
||||||
int y = id % range.my;
|
int y = MathHelpers.mod(id, range.my);
|
||||||
|
|
||||||
return new Vec2i(x, y);
|
return new Vec2i(x, y);
|
||||||
}
|
}
|
||||||
|
|
@ -63,4 +63,8 @@ public class Vec2i
|
||||||
public Vec2i divide(Vec2i other) {
|
public Vec2i divide(Vec2i other) {
|
||||||
return new Vec2i(this.x / other.x, this.y / other.y);
|
return new Vec2i(this.x / other.x, this.y / other.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vec2i copy() {
|
||||||
|
return new Vec2i(x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,4 +42,8 @@ public class Vec3d
|
||||||
public Vec3d divide(Vec3d other) {
|
public Vec3d divide(Vec3d other) {
|
||||||
return new Vec3d(this.x / other.x, this.y / other.y, this.z / other.z);
|
return new Vec3d(this.x / other.x, this.y / other.y, this.z / other.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vec3d copy() {
|
||||||
|
return new Vec3d(x, y, z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,13 @@ public class Vec3i
|
||||||
|
|
||||||
public static Vec3i fromId(Range3i range, int id)
|
public static Vec3i fromId(Range3i range, int id)
|
||||||
{
|
{
|
||||||
int x = id % range.mx;
|
int x = MathHelpers.mod(id, range.mx);
|
||||||
id -= x;
|
id -= x;
|
||||||
id /= range.mx;
|
id /= range.mx;
|
||||||
int y = id % range.my;
|
int y = MathHelpers.mod(id, range.my);
|
||||||
id -= y;
|
id -= y;
|
||||||
id /= range.my;
|
id /= range.my;
|
||||||
int z = id % range.mz;
|
int z = MathHelpers.mod(id, range.mz);
|
||||||
|
|
||||||
return new Vec3i(x, y, z);
|
return new Vec3i(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
@ -70,4 +70,8 @@ public class Vec3i
|
||||||
public Vec3i divide(Vec3i other) {
|
public Vec3i divide(Vec3i other) {
|
||||||
return new Vec3i(this.x / other.x, this.y / other.y, this.z / other.z);
|
return new Vec3i(this.x / other.x, this.y / other.y, this.z / other.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vec3i copy() {
|
||||||
|
return new Vec3i(x, y, z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package shootergame.world;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
import shootergame.world.layer.layergen.LayerGen;
|
||||||
|
|
||||||
|
public class World
|
||||||
|
{
|
||||||
|
private ArrayList<Layer> layers = new ArrayList<Layer>();
|
||||||
|
private int layer_id = 0;
|
||||||
|
private Layer layer;
|
||||||
|
|
||||||
|
public World(Random rand, LayerGen ... layergen)
|
||||||
|
{
|
||||||
|
// Loop over the layer generators
|
||||||
|
for(LayerGen lg : layergen)
|
||||||
|
{
|
||||||
|
// Create new layers
|
||||||
|
layers.add(new Layer(rand, lg));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the current layer
|
||||||
|
layer = layers.get(layer_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(Camera camera) {
|
||||||
|
layer.render(camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tickEntities() {
|
||||||
|
layer.tickEntities();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawnRandomEntities() {
|
||||||
|
layer.spawnRandomEntities();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLayerID() {
|
||||||
|
return layer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLayerID(int id) {
|
||||||
|
layer_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Layer getLayer() {
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,180 @@
|
||||||
|
package shootergame.world.chunk;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.init.Tiles;
|
||||||
|
import shootergame.tiles.Tile;
|
||||||
|
import shootergame.util.math.MathHelpers;
|
||||||
|
import shootergame.util.math.range.Range2i;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
public class Chunk
|
||||||
|
{
|
||||||
|
public static final Range2i CHUNK_SIZE = new Range2i(16, 16);
|
||||||
|
public static final Chunk CHUNK_EMPTY = new ChunkEmpty();
|
||||||
|
public static final int CHUNK_INDEX = CHUNK_SIZE.mx * CHUNK_SIZE.my;
|
||||||
|
public static final int SIMULATION_DISTANCE = 5;
|
||||||
|
|
||||||
|
private Tile tiles_back[] = new Tile[CHUNK_INDEX];
|
||||||
|
private Tile tiles_front[] = new Tile[CHUNK_INDEX];
|
||||||
|
private ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||||
|
private Random rand;
|
||||||
|
private Layer layer;
|
||||||
|
private Vec2i c_pos;
|
||||||
|
|
||||||
|
public Chunk(Layer layer, Vec2i c_pos, Random rand)
|
||||||
|
{
|
||||||
|
// Set some specified values
|
||||||
|
this.rand = rand;
|
||||||
|
this.layer = layer;
|
||||||
|
this.c_pos = c_pos;
|
||||||
|
|
||||||
|
// Loop over all the tiles in the chunk
|
||||||
|
for(int i=0;i<CHUNK_INDEX;i++)
|
||||||
|
{
|
||||||
|
// Make all these tiles void
|
||||||
|
tiles_back[i] = Tiles.VOID;
|
||||||
|
tiles_front[i] = Tiles.VOID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(Camera camera)
|
||||||
|
{
|
||||||
|
// Loop over all the tiles
|
||||||
|
for(int i=0;i<CHUNK_INDEX;i++)
|
||||||
|
{
|
||||||
|
// Get the tile pos
|
||||||
|
Vec2i t_pos = Vec2i.fromId(CHUNK_SIZE, i);
|
||||||
|
|
||||||
|
// Render the tiles
|
||||||
|
tiles_back[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera);
|
||||||
|
tiles_front[i].doRender(new Vec2d(t_pos.x + c_pos.x * 16, t_pos.y + c_pos.y * 16), camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render all the entities
|
||||||
|
for(int i=0;i<entities.size();i++) {
|
||||||
|
Entity e = entities.get(i);
|
||||||
|
e.doRender(e.pos, camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawnEntity(Entity e) {
|
||||||
|
entities.add(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tickEntities()
|
||||||
|
{
|
||||||
|
// Loop over every entitiy
|
||||||
|
for(int i=0;i<entities.size();i++)
|
||||||
|
{
|
||||||
|
// Get the entity and tick it
|
||||||
|
Entity e = entities.get(i);
|
||||||
|
e.tick(this, layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveEntities()
|
||||||
|
{
|
||||||
|
// Loop over every entity
|
||||||
|
for(int i=0;i<entities.size();i++)
|
||||||
|
{
|
||||||
|
// Get the entitiy
|
||||||
|
Entity e = entities.get(i);
|
||||||
|
|
||||||
|
// Has the entity left the chunk
|
||||||
|
int cx = c_pos.x;
|
||||||
|
int cy = c_pos.y;
|
||||||
|
if(((int)e.pos.x) / Chunk.CHUNK_SIZE.mx != cx && ((int)e.pos.y) / Chunk.CHUNK_SIZE.my != cy)
|
||||||
|
{
|
||||||
|
System.out.print("Moved entity, "+cx+", "+cy+", "+e.pos.x+", "+e.pos.y);
|
||||||
|
System.out.print(", "+(int)e.pos.x / Chunk.CHUNK_SIZE.mx+", "+(int)e.pos.y / Chunk.CHUNK_SIZE.my);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
// Process the entity by layer and remove the entity from the array
|
||||||
|
layer.spawnEntity(e);
|
||||||
|
entities.remove(i);
|
||||||
|
i -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackTile(Tile tile, Vec2i pos)
|
||||||
|
{
|
||||||
|
// Get the id
|
||||||
|
Vec2i cpos = new Vec2i(0, 0);
|
||||||
|
cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx);
|
||||||
|
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||||
|
int id = cpos.getId(CHUNK_SIZE);
|
||||||
|
|
||||||
|
// Set the back tile
|
||||||
|
this.tiles_back[id] = tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFrontTile(Tile tile, Vec2i pos)
|
||||||
|
{
|
||||||
|
// Get the id
|
||||||
|
Vec2i cpos = new Vec2i(0, 0);
|
||||||
|
cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx);
|
||||||
|
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||||
|
int id = cpos.getId(CHUNK_SIZE);
|
||||||
|
|
||||||
|
// Set the front tile
|
||||||
|
this.tiles_front[id] = tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tile getBackTile(Vec2i pos)
|
||||||
|
{
|
||||||
|
// Get the id
|
||||||
|
Vec2i cpos = new Vec2i(0, 0);
|
||||||
|
cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx);
|
||||||
|
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||||
|
int id = cpos.getId(CHUNK_SIZE);
|
||||||
|
|
||||||
|
// Send back the back tile
|
||||||
|
return this.tiles_back[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tile getFrontTile(Vec2i pos)
|
||||||
|
{
|
||||||
|
// Get the id
|
||||||
|
Vec2i cpos = new Vec2i(0, 0);
|
||||||
|
cpos.x = MathHelpers.mod(pos.x, CHUNK_SIZE.mx);
|
||||||
|
cpos.y = MathHelpers.mod(pos.y, CHUNK_SIZE.my);
|
||||||
|
int id = cpos.getId(CHUNK_SIZE);
|
||||||
|
|
||||||
|
// Send back the front tile
|
||||||
|
return this.tiles_front[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void killEntity(Entity e) {
|
||||||
|
entities.remove(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Entity> getNearbyEntities(Vec2d pos, double distance)
|
||||||
|
{
|
||||||
|
// Get the list of entities to send back
|
||||||
|
ArrayList<Entity> nearby_entities = new ArrayList<Entity>();
|
||||||
|
|
||||||
|
// Loop over the entities
|
||||||
|
for(Entity e : entities)
|
||||||
|
{
|
||||||
|
if(
|
||||||
|
e.pos.x + distance < pos.x &&
|
||||||
|
e.pos.x - distance > pos.x &&
|
||||||
|
e.pos.y + distance < pos.y &&
|
||||||
|
e.pos.y - distance > pos.y
|
||||||
|
) {
|
||||||
|
nearby_entities.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send back the entities
|
||||||
|
return nearby_entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package shootergame.world.chunk;
|
||||||
|
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.init.Tiles;
|
||||||
|
import shootergame.tiles.Tile;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
|
||||||
|
public class ChunkEmpty extends Chunk
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public ChunkEmpty() {
|
||||||
|
super(null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Camera camera) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tickEntities() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawnEntity(Entity e) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tile getBackTile(Vec2i pos) {
|
||||||
|
return Tiles.VOID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tile getFrontTile(Vec2i pos) {
|
||||||
|
return Tiles.VOID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBackTile(Tile tile, Vec2i pos) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFrontTile(Tile tile, Vec2i pos) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
package shootergame.world.chunk;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import mainloop.task.IMainloopTask;
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.util.math.map.Map2DElement;
|
||||||
|
import shootergame.util.math.random.RandomHelpers;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
public class ChunkEventHandler implements IMainloopTask
|
||||||
|
{
|
||||||
|
public static final ChunkEventHandler CHUNK_EVENT_HANDLER = new ChunkEventHandler();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopDelay(long millis) {
|
||||||
|
return millis > 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean MainLoopRepeat() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MainLoopUpdate()
|
||||||
|
{
|
||||||
|
// Get the layer
|
||||||
|
Layer layer = Main.world.getLayer();
|
||||||
|
|
||||||
|
// Loop over all the chunks in this layer
|
||||||
|
for(Map2DElement<Chunk> ce : layer.chunks)
|
||||||
|
{
|
||||||
|
// Convert the player pos to x and y
|
||||||
|
int px = (int)Main.player.pos.x / 16;
|
||||||
|
int py = (int)Main.player.pos.y / 16;
|
||||||
|
|
||||||
|
if(
|
||||||
|
// Is this chunk beyond the simulation distance
|
||||||
|
px > ce.pos.x + Chunk.SIMULATION_DISTANCE ||
|
||||||
|
px < ce.pos.x - Chunk.SIMULATION_DISTANCE ||
|
||||||
|
py > ce.pos.y + Chunk.SIMULATION_DISTANCE ||
|
||||||
|
py < ce.pos.y - Chunk.SIMULATION_DISTANCE
|
||||||
|
) {
|
||||||
|
// Unload the chunk
|
||||||
|
layer.unloadChunk(ce.pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop over the simulation distance
|
||||||
|
for(int x=-Chunk.SIMULATION_DISTANCE;x<Chunk.SIMULATION_DISTANCE;x++) {
|
||||||
|
for(int y=-Chunk.SIMULATION_DISTANCE;y<Chunk.SIMULATION_DISTANCE;y++)
|
||||||
|
{
|
||||||
|
// Get the chunk based on the player position
|
||||||
|
int cx = (int)Main.player.pos.x / 16 + x;
|
||||||
|
int cy = (int)Main.player.pos.y / 16 + y;
|
||||||
|
Vec2i c_pos = new Vec2i(cx, cy);
|
||||||
|
|
||||||
|
// Is this chunk not loaded
|
||||||
|
if(!layer.chunkLoaded(c_pos))
|
||||||
|
{
|
||||||
|
// Load the chunk
|
||||||
|
layer.loadChunk(c_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,143 @@
|
||||||
|
package shootergame.world.layer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.display.Camera;
|
||||||
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.tiles.Tile;
|
||||||
|
import shootergame.util.math.map.Map2D;
|
||||||
|
import shootergame.util.math.map.Map2DElement;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.world.World;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.layergen.LayerGen;
|
||||||
|
|
||||||
|
public class Layer
|
||||||
|
{
|
||||||
|
public Map2D<Chunk> chunks;
|
||||||
|
private LayerGen layergen;
|
||||||
|
private Random rand;
|
||||||
|
private long seed;
|
||||||
|
|
||||||
|
public Layer(Random rand, LayerGen layergen)
|
||||||
|
{
|
||||||
|
// Create the array of tiles
|
||||||
|
this.layergen = layergen;
|
||||||
|
this.seed = rand.nextLong();
|
||||||
|
this.rand = new Random();
|
||||||
|
this.chunks = new Map2D<Chunk>(layergen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(Camera camera)
|
||||||
|
{
|
||||||
|
// Render every chunk in the players render distance
|
||||||
|
for(int x=-camera.renderDistance;x<camera.renderDistance;x++) {
|
||||||
|
for(int y=-camera.renderDistance;y<camera.renderDistance;y++)
|
||||||
|
{
|
||||||
|
// Get the chunk x and y
|
||||||
|
int cx = ((int)Main.player.pos.x / 16) + x;
|
||||||
|
int cy = ((int)Main.player.pos.y / 16) + y;
|
||||||
|
|
||||||
|
// Render the chunk
|
||||||
|
chunks.get(new Vec2i(cx, cy)).render(camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tickEntities()
|
||||||
|
{
|
||||||
|
// Tick every entity in every loaded chunk
|
||||||
|
for(Map2DElement<Chunk> e : chunks) {
|
||||||
|
e.o.tickEntities();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move every entitiy in every loaded chunk
|
||||||
|
for(Map2DElement<Chunk> e : chunks) {
|
||||||
|
e.o.moveEntities();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawnRandomEntities() {
|
||||||
|
this.layergen.spawnEntities(this, rand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackTile(Tile tile, Vec2i pos)
|
||||||
|
{
|
||||||
|
// Get the chunk pos
|
||||||
|
Vec2i c_pos = new Vec2i(pos.x / Chunk.CHUNK_SIZE.my, pos.y / Chunk.CHUNK_SIZE.my);
|
||||||
|
|
||||||
|
// Set the chunks back tile
|
||||||
|
chunks.get(c_pos).setBackTile(tile, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFrontTile(Tile tile, Vec2i pos)
|
||||||
|
{
|
||||||
|
// Get the chunk pos
|
||||||
|
Vec2i c_pos = new Vec2i(pos.x / Chunk.CHUNK_SIZE.my, pos.y / Chunk.CHUNK_SIZE.my);
|
||||||
|
|
||||||
|
// Set the chunks front tile
|
||||||
|
chunks.get(c_pos).setFrontTile(tile, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tile getBackTile(Vec2i pos)
|
||||||
|
{
|
||||||
|
// Get the chunk pos
|
||||||
|
Vec2i c_pos = new Vec2i(pos.x / Chunk.CHUNK_SIZE.my, pos.y / Chunk.CHUNK_SIZE.my);
|
||||||
|
|
||||||
|
// Get the chunks back tile
|
||||||
|
return chunks.get(c_pos).getBackTile(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tile getFrontTile(Vec2i pos)
|
||||||
|
{
|
||||||
|
// Get the chunk pos
|
||||||
|
Vec2i c_pos = new Vec2i(pos.x / Chunk.CHUNK_SIZE.my, pos.y / Chunk.CHUNK_SIZE.my);
|
||||||
|
|
||||||
|
// Get the chunks front tile
|
||||||
|
return chunks.get(c_pos).getFrontTile(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawnEntity(Entity entity)
|
||||||
|
{
|
||||||
|
// Get the chunk pos
|
||||||
|
Vec2i c_pos = new Vec2i((int)entity.pos.x / Chunk.CHUNK_SIZE.mx, (int)entity.pos.y / Chunk.CHUNK_SIZE.my);
|
||||||
|
|
||||||
|
// Spawn the entity in the specified chunk
|
||||||
|
chunks.get(c_pos).spawnEntity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadChunk(Vec2i pos) {
|
||||||
|
chunks.set(pos, layergen.generateChunk(this, new Random(seed), pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unloadChunk(Vec2i pos) {
|
||||||
|
chunks.remove(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean chunkLoaded(Vec2i pos) {
|
||||||
|
return chunks.contains(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Entity> getNearbyEntities(Vec2d pos, double distance)
|
||||||
|
{
|
||||||
|
// Create the list of nearby entities
|
||||||
|
ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||||
|
|
||||||
|
Vec2i cpos = new Vec2i((int)pos.x / Chunk.CHUNK_SIZE.mx, (int)pos.y / Chunk.CHUNK_SIZE.my);
|
||||||
|
|
||||||
|
for(int x=-1;x<=1;x++) {
|
||||||
|
for(int y=-1;y<=1;y++)
|
||||||
|
{
|
||||||
|
for(Entity e : chunks.get(new Vec2i(x+cpos.x, y+cpos.y)).getNearbyEntities(pos, distance)) {
|
||||||
|
entities.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send back the list of nearby entities
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package shootergame.world.layer.layergen;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import shootergame.util.math.map.IMap2D;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
public abstract class LayerGen implements IMap2D<Chunk>
|
||||||
|
{
|
||||||
|
public abstract Chunk generateChunk(Layer layer, Random rand, Vec2i pos);
|
||||||
|
public abstract void spawnEntities(Layer layer, Random rand);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Chunk getEmpty(Vec2i pos) {
|
||||||
|
return Chunk.CHUNK_EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
package shootergame.world.layer.layergen;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
import shootergame.entity.Entity;
|
||||||
|
import shootergame.entity.EntityBullet;
|
||||||
|
import shootergame.entity.EntityZombie;
|
||||||
|
import shootergame.init.Tiles;
|
||||||
|
import shootergame.tiles.Tile;
|
||||||
|
import shootergame.util.math.random.OpenSimplexNoise;
|
||||||
|
import shootergame.util.math.random.RandomHelpers;
|
||||||
|
import shootergame.util.math.range.Range2i;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
import shootergame.util.math.vec.Vec2i;
|
||||||
|
import shootergame.world.chunk.Chunk;
|
||||||
|
import shootergame.world.layer.Layer;
|
||||||
|
|
||||||
|
public class LayerGenEarth extends LayerGen
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Chunk generateChunk(Layer layer, Random rand, Vec2i c_pos)
|
||||||
|
{
|
||||||
|
// Create the new chunk
|
||||||
|
Chunk chunk = new Chunk(layer, c_pos, rand);
|
||||||
|
|
||||||
|
// Get the noise generator
|
||||||
|
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
|
||||||
|
// Loop over the layer dimensions and create land
|
||||||
|
for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) {
|
||||||
|
for(int y=0;y<Chunk.CHUNK_SIZE.my;y++)
|
||||||
|
{
|
||||||
|
// Get the x and y in the world
|
||||||
|
int cx = x + c_pos.x * Chunk.CHUNK_SIZE.mx;
|
||||||
|
int cy = y + c_pos.y * Chunk.CHUNK_SIZE.my;
|
||||||
|
|
||||||
|
Entity e = new EntityBullet();
|
||||||
|
e.pos.x = cx;
|
||||||
|
e.pos.y = cy;
|
||||||
|
layer.spawnEntity(e);
|
||||||
|
|
||||||
|
// Get the noise value and the position vector
|
||||||
|
double noise_n = (noisegen_n.eval(cx/10.0, cy/10.0) + 1) * 50;
|
||||||
|
Vec2i pos = new Vec2i(x, y);
|
||||||
|
|
||||||
|
// Tree and rock generation
|
||||||
|
if(rand.nextDouble() > 0.9) chunk.setFrontTile(Tiles.TREE, pos);
|
||||||
|
else if(rand.nextDouble() > 0.99) chunk.setFrontTile(Tiles.ROCK, pos);
|
||||||
|
else chunk.setFrontTile(Tiles.VOID, pos);
|
||||||
|
|
||||||
|
// Terrain generation
|
||||||
|
if(noise_n < 20) {
|
||||||
|
chunk.setFrontTile(Tiles.WATER, pos);
|
||||||
|
chunk.setBackTile(Tiles.DIRT, pos);
|
||||||
|
}
|
||||||
|
else if(noise_n < 60) chunk.setBackTile(Tiles.GRASS, pos);
|
||||||
|
else if(noise_n < 80) chunk.setBackTile(Tiles.DIRT, pos);
|
||||||
|
else chunk.setBackTile(Tiles.STONE, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send back the new chunk
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawnEntities(Layer layer, Random rand)
|
||||||
|
{
|
||||||
|
if(rand.nextDouble() > 0.99)
|
||||||
|
{
|
||||||
|
Entity zombie = new EntityZombie();
|
||||||
|
zombie.pos = new Vec2d(
|
||||||
|
RandomHelpers.randrange(rand, (int)Main.player.pos.x - 100, (int)Main.player.pos.x + 100),
|
||||||
|
RandomHelpers.randrange(rand, (int)Main.player.pos.y - 100, (int)Main.player.pos.y + 100));
|
||||||
|
layer.spawnEntity(zombie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue