From ba15449dd518ba51a1a50d1607010f1918025ef2 Mon Sep 17 00:00:00 2001 From: josua Date: Fri, 23 Aug 2019 11:46:39 +1000 Subject: [PATCH] Got a working 3rd person camera, and fixed rendering opaque surfaces. Created entity renderers. --- src/shootergame/Main.java | 8 +- src/shootergame/display/Camera.java | 19 +++++ src/shootergame/display/DisplayRender.java | 79 +++++++++++++++++- src/shootergame/display/DisplayWindow.java | 5 +- .../transparent/ITransparentObject.java | 10 +++ .../transparent/TransparentObject.java | 18 ++++ .../transparent/TransparentObjects.java | 48 +++++++++++ src/shootergame/entity/Entity.java | 51 +++++++++++ .../entity/EntityEventHandler.java | 30 +++++++ src/shootergame/entity/EntityVertical.java | 26 ++++++ src/shootergame/entity/player/Player.java | 52 ++++++++++++ src/shootergame/init/Entities.java | 10 +++ src/shootergame/init/Textures.java | 40 ++++++++- src/shootergame/init/Tiles.java | 10 +++ src/shootergame/input/KeyCallback.java | 31 ++++++- src/shootergame/resources/texmap.png | Bin 672 -> 8234 bytes src/shootergame/tiles/Tile.java | 27 +++++- src/shootergame/tiles/TileDirt.java | 12 +++ src/shootergame/tiles/TileFire.java | 15 ++++ src/shootergame/tiles/TileFlat.java | 16 ++-- src/shootergame/tiles/TileSand.java | 12 +++ src/shootergame/tiles/TileStone.java | 12 +++ src/shootergame/tiles/TileTree.java | 15 ++++ src/shootergame/tiles/TileVertical.java | 31 +++++++ src/shootergame/util/gl/GlHelpers.java | 14 +++- src/shootergame/util/gl/VerticalRender.java | 37 ++++++++ .../gl/texture/AnimationEventHandler.java | 30 +++++++ .../util/gl/texture/AnimationReference.java | 46 ++++++++++ .../util/gl/texture/TextureMap.java | 4 +- .../gl/texture/TextureReferenceAnimation.java | 25 ------ src/shootergame/util/math/MathHelpers.java | 18 +++- src/shootergame/util/math/vec/Vec2d.java | 16 ++++ src/shootergame/util/math/vec/Vec2i.java | 16 ++++ src/shootergame/util/math/vec/Vec3d.java | 16 ++++ src/shootergame/util/math/vec/Vec3i.java | 16 ++++ 35 files changed, 765 insertions(+), 50 deletions(-) create mode 100644 src/shootergame/display/Camera.java create mode 100644 src/shootergame/display/transparent/ITransparentObject.java create mode 100644 src/shootergame/display/transparent/TransparentObject.java create mode 100644 src/shootergame/display/transparent/TransparentObjects.java create mode 100644 src/shootergame/entity/Entity.java create mode 100644 src/shootergame/entity/EntityEventHandler.java create mode 100644 src/shootergame/entity/EntityVertical.java create mode 100644 src/shootergame/entity/player/Player.java create mode 100644 src/shootergame/init/Entities.java create mode 100644 src/shootergame/tiles/TileDirt.java create mode 100644 src/shootergame/tiles/TileFire.java create mode 100644 src/shootergame/tiles/TileSand.java create mode 100644 src/shootergame/tiles/TileStone.java create mode 100644 src/shootergame/tiles/TileTree.java create mode 100644 src/shootergame/tiles/TileVertical.java create mode 100644 src/shootergame/util/gl/VerticalRender.java create mode 100644 src/shootergame/util/gl/texture/AnimationEventHandler.java create mode 100644 src/shootergame/util/gl/texture/AnimationReference.java delete mode 100644 src/shootergame/util/gl/texture/TextureReferenceAnimation.java diff --git a/src/shootergame/Main.java b/src/shootergame/Main.java index 9457f28..5de9ec0 100644 --- a/src/shootergame/Main.java +++ b/src/shootergame/Main.java @@ -2,6 +2,8 @@ package shootergame; import mainloop.manager.MainloopManager; import shootergame.display.DisplayWindow; +import shootergame.entity.EntityEventHandler; +import shootergame.entity.player.Player; import shootergame.init.Textures; import shootergame.mainloop.MainloopEventHandler; @@ -9,6 +11,7 @@ public class Main { public static MainloopManager mainloop; public static DisplayWindow window; + public static Player player = new Player(); public static void main(String[] args) { @@ -20,9 +23,12 @@ public class Main window = new DisplayWindow("ShooterGame"); window.init(); - // Initialize the textures + // Initialise the textures Textures.initTextures(window); + // Initialise the entities + mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER); + // Start the mainloop mainloop.start(); } diff --git a/src/shootergame/display/Camera.java b/src/shootergame/display/Camera.java new file mode 100644 index 0000000..2134b99 --- /dev/null +++ b/src/shootergame/display/Camera.java @@ -0,0 +1,19 @@ +package shootergame.display; + +import shootergame.util.math.MathHelpers; +import shootergame.util.math.vec.Vec2d; +import shootergame.util.math.vec.Vec3d; + +public class Camera +{ + public Vec3d pos; + public Vec2d angle; + + public Camera(Vec3d pos, Vec2d angle, double distance) + { + Vec3d p = new Vec3d(pos.x, pos.y+5, pos.z); + this.angle = new Vec2d(angle.x, -angle.y); + this.pos = pos.subtract(MathHelpers.moveTowards3( + 10, new Vec2d(Math.toRadians(angle.x), Math.toRadians(-angle.y)))); + } +} diff --git a/src/shootergame/display/DisplayRender.java b/src/shootergame/display/DisplayRender.java index f4a43f2..6b0de6c 100644 --- a/src/shootergame/display/DisplayRender.java +++ b/src/shootergame/display/DisplayRender.java @@ -2,12 +2,23 @@ package shootergame.display; import static org.lwjgl.opengl.GL11.*; +import org.joml.Matrix4f; import org.lwjgl.opengl.GL; +import org.lwjgl.system.MemoryStack; +import mainloop.task.MainloopTask; +import shootergame.Main; +import shootergame.display.transparent.TransparentObjects; +import shootergame.entity.Entity; +import shootergame.entity.player.Player; +import shootergame.init.Entities; import shootergame.init.Textures; import shootergame.init.Tiles; import shootergame.util.gl.GlHelpers; +import shootergame.util.math.MathHelpers; +import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; +import shootergame.util.math.vec.Vec3d; public class DisplayRender { @@ -15,11 +26,18 @@ public class DisplayRender { // Setup GL and clear the colour GL.createCapabilities(); - glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, w, h); + // Push the matrix + GlHelpers.pushMatrix(); + // Enable some stuff GlHelpers.enableTexture2d(); + GlHelpers.enableBlend(); + GlHelpers.enableAlpha(); + GlHelpers.enableDepthTest(); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Set the colour to white GlHelpers.color4(1, 1, 1, 1); @@ -27,9 +45,66 @@ public class DisplayRender // Bind the texmap Textures.texmap.bindTexture(); - Tiles.GRASS.render(new Vec2i(0, 0)); + GlHelpers.pushMatrix(); + + { + // Set matrix mode + glMatrixMode(GL_MODELVIEW); + + TransparentObjects.clear(); + + // Set the colour to white + GlHelpers.color4(1, 1, 1, 1); + + // Create a matrix + Matrix4f m = new Matrix4f(); + + // Set the perspective + m.setPerspective((float) Math.toRadians(45.0f), ((float)w)/((float)h), 0.01f, 100.0f); + try (MemoryStack stack = MemoryStack.stackPush()) { + glLoadMatrixf(m.get(stack.mallocFloat(16))); + } + + // Set the camera angle + m.setLookAt(0.0f, 0.0f, 10.0f, + 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f); + + Player player = Main.player; + Camera camera = new Camera(new Vec3d(player.pos.x, player.pos.y, 0), new Vec2d(player.angle, 45), 0); + + //GlHelpers.translate(0, 0, -5); + GlHelpers.rotate(camera.angle.y, 1, 0, 0); + GlHelpers.rotate(camera.angle.x, 0, 0, 1); + GlHelpers.translate(-camera.pos.x, -camera.pos.y, -camera.pos.z); + + int c = 20; + for(int x=-c;x objects = new ArrayList(); + + public static void clear() { + objects.clear(); + } + + public static void register(ITransparentObject object, Camera camera, Vec2d pos) + { + TransparentObject r_to = new TransparentObject(object, camera, pos); + ArrayList objects_n = new ArrayList(); + boolean added = false; + + // Loop over the transparent object items + for(TransparentObject to : objects) + { + if(r_to.distance > to.distance && !added) { + added = true; + objects_n.add(r_to); + } + + objects_n.add(to); + } + + if(!added) { + objects_n.add(r_to); + } + + objects = objects_n; + } + + public static void render(Camera camera) + { + // Loop over the objects and render all of them + for(TransparentObject to : objects) { + to.object.render(to.pos, camera); + } + } +} diff --git a/src/shootergame/entity/Entity.java b/src/shootergame/entity/Entity.java new file mode 100644 index 0000000..a981bc5 --- /dev/null +++ b/src/shootergame/entity/Entity.java @@ -0,0 +1,51 @@ +package shootergame.entity; + +import shootergame.display.Camera; +import shootergame.display.transparent.ITransparentObject; +import shootergame.display.transparent.TransparentObjects; +import shootergame.init.Entities; +import shootergame.util.math.vec.Vec2d; + +public class Entity implements ITransparentObject +{ + public Vec2d pos; + public double angle; + public boolean opaqueTile = true; + + public Entity(Vec2d pos, double angle) + { + // Add this entity to the list of entities + Entities.entities.add(this); + + // Store the specified values + this.angle = angle; + this.pos = pos; + } + + public Entity() { + this(new Vec2d(0, 0), 0); + } + + public void tick() { + } + + @Override + public void render(Vec2d pos, Camera camera) { + } + + public void doRender(Vec2d pos, Camera camera) + { + if(this.opaqueTile) { + TransparentObjects.register(this, camera, pos); + } + + else { + this.render(pos, camera); + } + } + + @Override + public boolean isOpaqueTile() { + return this.opaqueTile; + } +} diff --git a/src/shootergame/entity/EntityEventHandler.java b/src/shootergame/entity/EntityEventHandler.java new file mode 100644 index 0000000..3fc7e96 --- /dev/null +++ b/src/shootergame/entity/EntityEventHandler.java @@ -0,0 +1,30 @@ +package shootergame.entity; + +import java.util.ArrayList; + +import mainloop.task.IMainloopTask; +import shootergame.init.Entities; + +public class EntityEventHandler implements IMainloopTask +{ + public static final EntityEventHandler ENTITY_EVENT_HANDLER = new EntityEventHandler(); + + @Override + public boolean MainLoopDelay(long millis) { + return millis > 10; + } + + @Override + public boolean MainLoopRepeat() { + return true; + } + + @Override + public void MainLoopUpdate() + { + // Update each entity + for(Entity e : Entities.entities) { + e.tick(); + } + } +} diff --git a/src/shootergame/entity/EntityVertical.java b/src/shootergame/entity/EntityVertical.java new file mode 100644 index 0000000..1177aea --- /dev/null +++ b/src/shootergame/entity/EntityVertical.java @@ -0,0 +1,26 @@ +package shootergame.entity; + +import shootergame.Main; +import shootergame.display.Camera; +import shootergame.entity.player.Player; +import shootergame.util.gl.GlHelpers; +import shootergame.util.gl.VerticalRender; +import shootergame.util.gl.texture.TextureReference; +import shootergame.util.math.vec.Vec2d; + +public class EntityVertical extends Entity +{ + private TextureReference tex; + private double h; + + public EntityVertical(TextureReference tex, double height) { + this.tex = tex; + this.h = height; + } + + @Override + public void render(Vec2d pos, Camera camera) { + super.render(pos, camera); + VerticalRender.render(pos, camera, tex, h); + } +} diff --git a/src/shootergame/entity/player/Player.java b/src/shootergame/entity/player/Player.java new file mode 100644 index 0000000..4a2108f --- /dev/null +++ b/src/shootergame/entity/player/Player.java @@ -0,0 +1,52 @@ +package shootergame.entity.player; + +import shootergame.entity.Entity; +import shootergame.entity.EntityVertical; +import shootergame.init.Textures; +import shootergame.util.gl.texture.TextureReference; +import shootergame.util.math.MathHelpers; +import shootergame.util.math.vec.Vec2d; +import shootergame.util.math.vec.Vec2i; + +public class Player extends EntityVertical +{ + public Player() { + super(Textures.ENTITY_PLAYER, 1); + } + + public boolean MOVE_FORWARD = false; + public boolean MOVE_BACKWARD = false; + public boolean MOVE_LEFT = false; + public boolean MOVE_RIGHT = false; + + @Override + public void tick() + { + // Call super + super.tick(); + + // Rotate left + if(MOVE_LEFT) { + this.angle -= 1; + this.angle %= 360; + } + + // Rotate right + if(MOVE_RIGHT) { + this.angle += 1; + this.angle %= 360; + } + + // Move forward + if(MOVE_FORWARD) { + Vec2d t = MathHelpers.moveTowards2(0.1, Math.toRadians(angle)); + pos = new Vec2d(t.x+pos.x, t.y+pos.y); + } + + // Move backward + if(MOVE_BACKWARD) { + Vec2d t = MathHelpers.moveTowards2(-0.1, Math.toRadians(angle)); + pos = new Vec2d(t.x+pos.x, t.y+pos.y); + } + } +} diff --git a/src/shootergame/init/Entities.java b/src/shootergame/init/Entities.java new file mode 100644 index 0000000..68b11d4 --- /dev/null +++ b/src/shootergame/init/Entities.java @@ -0,0 +1,10 @@ +package shootergame.init; + +import java.util.ArrayList; + +import shootergame.entity.Entity; + +public class Entities +{ + public static final ArrayList entities = new ArrayList(); +} diff --git a/src/shootergame/init/Textures.java b/src/shootergame/init/Textures.java index cdeda90..70b21f6 100644 --- a/src/shootergame/init/Textures.java +++ b/src/shootergame/init/Textures.java @@ -7,7 +7,7 @@ import org.lwjgl.opengl.GL; import shootergame.display.DisplayWindow; import shootergame.util.gl.texture.TextureMap; import shootergame.util.gl.texture.TextureReference; -import shootergame.util.gl.texture.TextureReferenceAnimation; +import shootergame.util.gl.texture.AnimationReference; public class Textures { @@ -21,9 +21,41 @@ public class Textures texmap.init(); } - public static final ArrayList animations = new ArrayList(); + public static final ArrayList animations = new ArrayList(); + + public static final TextureMap texmap = new TextureMap( + "/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_SAND = texmap.getTextureReference(16, 32, 0, 16); + public static final TextureReference TILE_STONE = texmap.getTextureReference(32, 48, 0, 16); + public static final TextureReference TILE_DIRT = texmap.getTextureReference(48, 64, 0, 16); + public static final TextureReference TILE_TREE = texmap.getTextureReference(64, 80, 0, 64); + + // Fire + public static final TextureReference TILE_FIRE_0 = texmap.getTextureReference(0, 16, 16, 32); + public static final TextureReference TILE_FIRE_1 = texmap.getTextureReference(16, 32, 16, 32); + public static final TextureReference TILE_FIRE_2 = texmap.getTextureReference(32, 48, 16, 32); + public static final TextureReference TILE_FIRE_3 = texmap.getTextureReference(48, 64, 16, 32); + public static final TextureReference TILE_FIRE = new AnimationReference( + 8, TILE_FIRE_0, TILE_FIRE_1, TILE_FIRE_2, TILE_FIRE_3); + + // Player + public static final TextureReference ENTITY_PLAYER_0 = texmap.getTextureReference(0, 16, 32, 48); + public static final TextureReference ENTITY_PLAYER_1 = texmap.getTextureReference(16, 32, 32, 48); + public static final TextureReference ENTITY_PLAYER_2 = texmap.getTextureReference(32, 48, 32, 48); + public static final TextureReference ENTITY_PLAYER_3 = texmap.getTextureReference(48, 64, 32, 48); + public static final TextureReference ENTITY_PLAYER = new AnimationReference( + 10, ENTITY_PLAYER_0, ENTITY_PLAYER_1, ENTITY_PLAYER_2, ENTITY_PLAYER_3); + + // Zombie + public static final TextureReference ENTITY_ZOMBIE_0 = texmap.getTextureReference(0, 16, 48, 64); + public static final TextureReference ENTITY_ZOMBIE_1 = texmap.getTextureReference(16, 32, 48, 64); + public static final TextureReference ENTITY_ZOMBIE_2 = texmap.getTextureReference(32, 48, 48, 64); + public static final TextureReference ENTITY_ZOMBIE_3 = texmap.getTextureReference(48, 64, 48, 64); + public static final TextureReference ENTITY_ZOMBIE = new AnimationReference( + 10, ENTITY_ZOMBIE_0, ENTITY_ZOMBIE_1, ENTITY_ZOMBIE_2, ENTITY_ZOMBIE_3); + - public static final TextureMap texmap = new TextureMap("/home/josua/eclipse-workspace/ShooterGame/src/shootergame/resources/texmap.png"); - public static final TextureReference TILE_GRASS = texmap.getTextureReference(0, 0, 16, 16); } diff --git a/src/shootergame/init/Tiles.java b/src/shootergame/init/Tiles.java index 885c823..9cf53bd 100644 --- a/src/shootergame/init/Tiles.java +++ b/src/shootergame/init/Tiles.java @@ -1,9 +1,19 @@ package shootergame.init; import shootergame.tiles.Tile; +import shootergame.tiles.TileDirt; +import shootergame.tiles.TileFire; import shootergame.tiles.TileGrass; +import shootergame.tiles.TileSand; +import shootergame.tiles.TileStone; +import shootergame.tiles.TileTree; public class Tiles { public static final Tile GRASS = new TileGrass("grass"); + public static final Tile FIRE = new TileFire("fire"); + public static final Tile SAND = new TileSand("sand"); + public static final Tile STONE = new TileStone("stone"); + public static final Tile DIRT = new TileDirt("dirt"); + public static final Tile TREE = new TileTree("tree"); } diff --git a/src/shootergame/input/KeyCallback.java b/src/shootergame/input/KeyCallback.java index 2a864f1..0b8254c 100644 --- a/src/shootergame/input/KeyCallback.java +++ b/src/shootergame/input/KeyCallback.java @@ -1,14 +1,41 @@ package shootergame.input; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_A; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_D; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_SHIFT; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_S; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_W; +import static org.lwjgl.glfw.GLFW.GLFW_RELEASE; + import org.lwjgl.glfw.GLFWKeyCallbackI; +import shootergame.Main; + public class KeyCallback implements GLFWKeyCallbackI { @Override - public void invoke(long arg0, int arg1, int arg2, int arg3, int arg4) { - // TODO Auto-generated method stub + public void invoke(long window, int key, int scancode, int action, int mods) + { + boolean pressed = ! ( action == GLFW_RELEASE ); + + if(key == GLFW_KEY_W) { + Main.player.MOVE_FORWARD = pressed; + } + + if(key == GLFW_KEY_S) { + Main.player.MOVE_BACKWARD = pressed; + } + + if(key == GLFW_KEY_A) { + Main.player.MOVE_LEFT = pressed; + } + + if(key == GLFW_KEY_D) { + Main.player.MOVE_RIGHT = pressed; + } } } diff --git a/src/shootergame/resources/texmap.png b/src/shootergame/resources/texmap.png index d6973faa422cacec9ee45ab6464612179b427eb3..dcc3f83b1c8985fde59ad7b6bcd90f4ff55d1428 100644 GIT binary patch literal 8234 zcmeAS@N?(olHy`uVBq!ia0y~yU`SwKU~u4IV_;x-YEs0lb_G2ez$jjbm;x6eWCtWgZ)EeC+^JaTN%Du;P?cU2fH|y8f=xS zkW=BD>BP9!)NyCesT2Vx0e8W^*FtN43m$Xfc$ml`aDzdmP*zc;({ICD9)*s_R@0se zwUp+ZR_YX9xBs1?38z;COQZkNAl2y`4fEPo#3)~$a&(f|AqlTsRkQrNZQ7zgr>QO4 zbzV{bzpmQFA9X#so;Jr53l=mn9^&v?E2ivhsMfUYC+j1NgbnsfZp=#kzD{cXKKX;Q zH8#bqRG4z;+*5_ginGrrPhzp**Pq;IpwgH8$c>pX$ZJWEL~_R=siM0cEQ?%Gj}va2CFV{kSu1E1s>GM< zu$WcFv*mFL1G9_9%LGkn)!a!cN4Cl8Xg3FS#hAI<_MA+ged0;XmX3*DimfRtg4CYx z{POOdx|hvjC>R>e5$lSx1gvi=N_}B zMz~PaZJP-T8Yk|1;=9C7G;|Dya*mUEyEoX!@nEQCQ zF@F|&_VTrS+P9c)%iP?M)ppa;4UL{`PIzZ?XqDn?$0ep)i~jnm$~$!Bh&9yM^%uoX zc^r_D=htb@_HY-2%2cmghqJfZ&Rn}pO+n`EORmMjQ#N%jlD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/Tile.java b/src/shootergame/tiles/Tile.java index 9816529..85a76d2 100644 --- a/src/shootergame/tiles/Tile.java +++ b/src/shootergame/tiles/Tile.java @@ -1,10 +1,16 @@ package shootergame.tiles; +import shootergame.display.Camera; +import shootergame.display.transparent.ITransparentObject; +import shootergame.display.transparent.TransparentObjects; +import shootergame.entity.player.Player; +import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; -public class Tile +public class Tile implements ITransparentObject { private String id; + public boolean opaqueTile = false; public Tile(String id) { this.id = id; @@ -14,6 +20,23 @@ public class Tile return this.id; } - public void render(Vec2i pos) { + @Override + public void render(Vec2d pos, Camera camera) { + } + + public void doRender(Vec2d pos, Camera camera) + { + if(this.opaqueTile) { + TransparentObjects.register(this, camera, pos); + } + + else { + this.render(pos, camera); + } + } + + @Override + public boolean isOpaqueTile() { + return this.opaqueTile; } } diff --git a/src/shootergame/tiles/TileDirt.java b/src/shootergame/tiles/TileDirt.java new file mode 100644 index 0000000..af19f35 --- /dev/null +++ b/src/shootergame/tiles/TileDirt.java @@ -0,0 +1,12 @@ +package shootergame.tiles; + +import shootergame.init.Textures; + +public class TileDirt extends TileFlat +{ + + public TileDirt(String id) { + super(id, Textures.TILE_DIRT); + } + +} \ No newline at end of file diff --git a/src/shootergame/tiles/TileFire.java b/src/shootergame/tiles/TileFire.java new file mode 100644 index 0000000..5fd0b5e --- /dev/null +++ b/src/shootergame/tiles/TileFire.java @@ -0,0 +1,15 @@ +package shootergame.tiles; + +import shootergame.init.Textures; + +public class TileFire extends TileVertical +{ + + public TileFire(String id) { + super(id, Textures.TILE_FIRE, 6); + + // Set some settings + this.opaqueTile = true; + } + +} diff --git a/src/shootergame/tiles/TileFlat.java b/src/shootergame/tiles/TileFlat.java index 0427ace..ef2d26c 100644 --- a/src/shootergame/tiles/TileFlat.java +++ b/src/shootergame/tiles/TileFlat.java @@ -1,8 +1,12 @@ package shootergame.tiles; +import shootergame.display.Camera; +import shootergame.entity.player.Player; import shootergame.util.gl.GlHelpers; import shootergame.util.gl.texture.TextureReference; +import shootergame.util.math.vec.Vec2d; import shootergame.util.math.vec.Vec2i; +import shootergame.util.math.vec.Vec3d; public class TileFlat extends Tile { @@ -14,17 +18,17 @@ public class TileFlat extends Tile } @Override - public void render(Vec2i pos) + public void render(Vec2d pos, Camera camera) { // Call super - super.render(pos); + super.render(pos, camera); // Render the tile GlHelpers.begin(); - tex.texCoord(0, 0); GlHelpers.vertex2(pos.x+0, pos.y+0); - tex.texCoord(1, 0); GlHelpers.vertex2(pos.x+1, pos.y+0); - tex.texCoord(1, 1); GlHelpers.vertex2(pos.x+1, pos.y+1); - tex.texCoord(0, 1); GlHelpers.vertex2(pos.x+0, pos.y+1); + tex.texCoord(1, 1); GlHelpers.vertex3(pos.x+0, pos.y+0, 0); + tex.texCoord(0, 1); GlHelpers.vertex3(pos.x+1, pos.y+0, 0); + tex.texCoord(0, 0); GlHelpers.vertex3(pos.x+1, pos.y+1, 0); + tex.texCoord(1, 0); GlHelpers.vertex3(pos.x+0, pos.y+1, 0); GlHelpers.end(); } } diff --git a/src/shootergame/tiles/TileSand.java b/src/shootergame/tiles/TileSand.java new file mode 100644 index 0000000..7793604 --- /dev/null +++ b/src/shootergame/tiles/TileSand.java @@ -0,0 +1,12 @@ +package shootergame.tiles; + +import shootergame.init.Textures; + +public class TileSand extends TileFlat +{ + + public TileSand(String id) { + super(id, Textures.TILE_SAND); + } + +} \ No newline at end of file diff --git a/src/shootergame/tiles/TileStone.java b/src/shootergame/tiles/TileStone.java new file mode 100644 index 0000000..bd38935 --- /dev/null +++ b/src/shootergame/tiles/TileStone.java @@ -0,0 +1,12 @@ +package shootergame.tiles; + +import shootergame.init.Textures; + +public class TileStone extends TileFlat +{ + + public TileStone(String id) { + super(id, Textures.TILE_STONE); + } + +} diff --git a/src/shootergame/tiles/TileTree.java b/src/shootergame/tiles/TileTree.java new file mode 100644 index 0000000..862c04c --- /dev/null +++ b/src/shootergame/tiles/TileTree.java @@ -0,0 +1,15 @@ +package shootergame.tiles; + +import shootergame.init.Textures; + +public class TileTree extends TileVertical +{ + + public TileTree(String id) { + super(id, Textures.TILE_TREE, 4); + + // Set some settings + this.opaqueTile = true; + } + +} diff --git a/src/shootergame/tiles/TileVertical.java b/src/shootergame/tiles/TileVertical.java new file mode 100644 index 0000000..155203b --- /dev/null +++ b/src/shootergame/tiles/TileVertical.java @@ -0,0 +1,31 @@ +package shootergame.tiles; + +import shootergame.Main; +import shootergame.display.Camera; +import shootergame.entity.player.Player; +import shootergame.util.gl.GlHelpers; +import shootergame.util.gl.VerticalRender; +import shootergame.util.gl.texture.TextureReference; +import shootergame.util.math.vec.Vec2d; +import shootergame.util.math.vec.Vec2i; + +public class TileVertical extends Tile +{ + private TextureReference tex; + private int h; + + public TileVertical(String id, TextureReference tex, int height) { + super(id); + + // Store some variables + this.tex = tex; + this.h = height; + } + + @Override + public void render(Vec2d pos, Camera camera) { + super.render(pos, camera); + VerticalRender.render(pos, camera, tex, h); + } + +} diff --git a/src/shootergame/util/gl/GlHelpers.java b/src/shootergame/util/gl/GlHelpers.java index 565d477..bd6182c 100644 --- a/src/shootergame/util/gl/GlHelpers.java +++ b/src/shootergame/util/gl/GlHelpers.java @@ -25,11 +25,11 @@ public class GlHelpers } public static void vertex3(float x, float y, float z) { - glVertex3f(x, y, z); + glVertex3f(x/10, y/10, z/10); } public static void vertex2(float x, float y) { - glVertex2f(x/Main.window.getWidth()*100, y/Main.window.getHeight()*100); + glVertex2f(x/10, y/10); } public static void color3(float r, float g, float b) { @@ -45,7 +45,7 @@ public class GlHelpers } public static void translate(float x, float y, float z) { - glTranslatef(x, y, z); + glTranslatef(x/10, y/10, z/10); } public static void disableCullFace() { @@ -105,4 +105,12 @@ public class GlHelpers public static void rotate(double a, float x, float y, float z) { rotate((float)a, x, y, z); } + + public static void vertex3(double x, double y, double z) { + vertex3((float)x, (float)y, (float)z); + } + + public static void vertex2(double x, double y) { + vertex2((float)x, (float)y); + } } diff --git a/src/shootergame/util/gl/VerticalRender.java b/src/shootergame/util/gl/VerticalRender.java new file mode 100644 index 0000000..f2c7f50 --- /dev/null +++ b/src/shootergame/util/gl/VerticalRender.java @@ -0,0 +1,37 @@ +package shootergame.util.gl; + +import shootergame.display.Camera; +import shootergame.entity.player.Player; +import shootergame.util.gl.texture.TextureReference; +import shootergame.util.math.vec.Vec2d; + +public class VerticalRender +{ + public static void render(Vec2d pos, Camera camera, TextureReference tex, double height) + { + double h = height; + + // Push the matrix + GlHelpers.pushMatrix(); + + // Get the angle between the camera and the tile + double angle_r = Math.atan2(pos.y - camera.pos.y, pos.x - camera.pos.x); + + // Make the tile upright + GlHelpers.translate(0.5, 0, 0); + GlHelpers.translate(pos.x, pos.y, 0); + GlHelpers.rotate(Math.toDegrees(angle_r)+90, 0, 0, 1); + GlHelpers.translate(-0.5, 0, 0); + + // Render the tile + GlHelpers.begin(); + tex.texCoord(1, 1); GlHelpers.vertex3(0, 0, 0); + tex.texCoord(0, 1); GlHelpers.vertex3(1, 0, 0); + tex.texCoord(0, 0); GlHelpers.vertex3(1, 0, h); + tex.texCoord(1, 0); GlHelpers.vertex3(0, 0, h); + GlHelpers.end(); + + // Pop the matrix + GlHelpers.popMatrix(); + } +} diff --git a/src/shootergame/util/gl/texture/AnimationEventHandler.java b/src/shootergame/util/gl/texture/AnimationEventHandler.java new file mode 100644 index 0000000..c1894d8 --- /dev/null +++ b/src/shootergame/util/gl/texture/AnimationEventHandler.java @@ -0,0 +1,30 @@ +package shootergame.util.gl.texture; + +import mainloop.task.IMainloopTask; +import mainloop.task.MainloopTask; +import shootergame.init.Textures; + +public class AnimationEventHandler implements IMainloopTask +{ + public static final AnimationEventHandler ANIMATION_EVENT_HANDLER = new AnimationEventHandler(); + + @Override + public boolean MainLoopDelay(long millis) { + return millis > 10; + } + + @Override + public boolean MainLoopRepeat() { + return true; + } + + @Override + public void MainLoopUpdate() + { + // Loop over the animations and update them all + for(AnimationReference r : Textures.animations) { + r.tick(); + } + } + +} diff --git a/src/shootergame/util/gl/texture/AnimationReference.java b/src/shootergame/util/gl/texture/AnimationReference.java new file mode 100644 index 0000000..ab5d816 --- /dev/null +++ b/src/shootergame/util/gl/texture/AnimationReference.java @@ -0,0 +1,46 @@ +package shootergame.util.gl.texture; + +import shootergame.init.Textures; + +public class AnimationReference extends TextureReference +{ + private TextureReference[] references; + private int upto = 0; + private int speed; + private TextureReference c; + + public AnimationReference(int speed, TextureReference ... references) + { + // Store the texture references and the speed + this.references = references; + this.speed = speed; + + // Register the animation + Textures.animations.add(this); + c = references[0]; + } + + @Override + public void texCoord(float x, float y) { + c.texCoord(x, y); + } + + public void tick() + { + // Cycle through all the textures + upto += 1; + upto %= references.length * speed; + c = references[upto / speed]; + } + + @Override + public int getMaxX() { + return c.getMaxX(); + } + + @Override + public int getMaxY() { + return c.getMaxY(); + } + +} diff --git a/src/shootergame/util/gl/texture/TextureMap.java b/src/shootergame/util/gl/texture/TextureMap.java index de5ba0c..61982ee 100644 --- a/src/shootergame/util/gl/texture/TextureMap.java +++ b/src/shootergame/util/gl/texture/TextureMap.java @@ -37,8 +37,8 @@ public class TextureMap //texture.free(); } - public TextureReference getTextureReference(int start_x, int start_y, int end_x, int end_y) { - return new TextureReference(start_x, start_y, end_x, 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) { @Override diff --git a/src/shootergame/util/gl/texture/TextureReferenceAnimation.java b/src/shootergame/util/gl/texture/TextureReferenceAnimation.java deleted file mode 100644 index 9a3b0dc..0000000 --- a/src/shootergame/util/gl/texture/TextureReferenceAnimation.java +++ /dev/null @@ -1,25 +0,0 @@ -package shootergame.util.gl.texture; - -public abstract class TextureReferenceAnimation extends TextureReference -{ - private TextureReference[] references; - private int upto = 0; - - public TextureReferenceAnimation(TextureReference[] references) - { - this.references = references; - } - - @Override - public void texCoord(float x, float y) { - references[upto].texCoord(x, y); - } - - public void tick() - { - // Cycle through all the textures - upto += 1; - upto %= references.length; - } - -} diff --git a/src/shootergame/util/math/MathHelpers.java b/src/shootergame/util/math/MathHelpers.java index b6a9ca9..a409735 100644 --- a/src/shootergame/util/math/MathHelpers.java +++ b/src/shootergame/util/math/MathHelpers.java @@ -1,6 +1,7 @@ package shootergame.util.math; import shootergame.util.math.vec.Vec2d; +import shootergame.util.math.vec.Vec3d; public class MathHelpers { @@ -32,6 +33,21 @@ public class MathHelpers } public static Vec2d moveTowards2(double amount, double angle) { - return new Vec2d(Math.sin(angle), Math.cos(angle)); + return new Vec2d(Math.sin(angle)*amount, Math.cos(angle)*amount); + } + + public static Vec3d moveTowards3(double amount, Vec2d angles) + { + // Create some varibles + Vec3d points = new Vec3d(0, 0, 0); + double m; + + points.z = Math.sin(angles.y) * amount; + m = Math.cos(angles.y); + points.x = Math.sin(angles.x) * m * amount; + m = Math.cos(angles.x) * m; + points.y = m * amount; + + return points; } } diff --git a/src/shootergame/util/math/vec/Vec2d.java b/src/shootergame/util/math/vec/Vec2d.java index f87e7da..9ec875a 100644 --- a/src/shootergame/util/math/vec/Vec2d.java +++ b/src/shootergame/util/math/vec/Vec2d.java @@ -24,4 +24,20 @@ public class Vec2d public boolean equal(Vec2d other) { return x == other.x && y == other.y; } + + public Vec2d add(Vec2d other) { + return new Vec2d(this.x + other.x, this.y + other.y); + } + + public Vec2d subtract(Vec2d other) { + return new Vec2d(this.x - other.x, this.y - other.y); + } + + public Vec2d multiply(Vec2d other) { + return new Vec2d(this.x * other.x, this.y * other.y); + } + + public Vec2d divide(Vec2d other) { + return new Vec2d(this.x / other.x, this.y / other.y); + } } diff --git a/src/shootergame/util/math/vec/Vec2i.java b/src/shootergame/util/math/vec/Vec2i.java index beac2a2..c1bfeea 100644 --- a/src/shootergame/util/math/vec/Vec2i.java +++ b/src/shootergame/util/math/vec/Vec2i.java @@ -47,4 +47,20 @@ public class Vec2i public boolean equal(Vec2i other) { return x == other.x && y == other.y; } + + public Vec2i add(Vec2i other) { + return new Vec2i(this.x + other.x, this.y + other.y); + } + + public Vec2i subtract(Vec2i other) { + return new Vec2i(this.x - other.x, this.y - other.y); + } + + public Vec2i multiply(Vec2i other) { + return new Vec2i(this.x * other.x, this.y * other.y); + } + + public Vec2i divide(Vec2i other) { + return new Vec2i(this.x / other.x, this.y / other.y); + } } diff --git a/src/shootergame/util/math/vec/Vec3d.java b/src/shootergame/util/math/vec/Vec3d.java index 42bb4f9..29c3936 100644 --- a/src/shootergame/util/math/vec/Vec3d.java +++ b/src/shootergame/util/math/vec/Vec3d.java @@ -26,4 +26,20 @@ public class Vec3d public boolean equal(Vec3d other) { return x == other.x && y == other.y && z == other.z; } + + public Vec3d add(Vec3d other) { + return new Vec3d(this.x + other.x, this.y + other.y, this.z + other.z); + } + + public Vec3d subtract(Vec3d other) { + return new Vec3d(this.x - other.x, this.y - other.y, this.z - other.z); + } + + public Vec3d multiply(Vec3d other) { + return new Vec3d(this.x * other.x, this.y * other.y, this.z * other.z); + } + + public Vec3d divide(Vec3d other) { + return new Vec3d(this.x / other.x, this.y / other.y, this.z / other.z); + } } diff --git a/src/shootergame/util/math/vec/Vec3i.java b/src/shootergame/util/math/vec/Vec3i.java index 4c99fbf..c87e414 100644 --- a/src/shootergame/util/math/vec/Vec3i.java +++ b/src/shootergame/util/math/vec/Vec3i.java @@ -54,4 +54,20 @@ public class Vec3i public boolean equal(Vec3i other) { return x == other.x && y == other.y && z == other.z; } + + public Vec3i add(Vec3i other) { + return new Vec3i(this.x + other.x, this.y + other.y, this.z + other.z); + } + + public Vec3i subtract(Vec3i other) { + return new Vec3i(this.x - other.x, this.y - other.y, this.z - other.z); + } + + public Vec3i multiply(Vec3i other) { + return new Vec3i(this.x * other.x, this.y * other.y, this.z * other.z); + } + + public Vec3i divide(Vec3i other) { + return new Vec3i(this.x / other.x, this.y / other.y, this.z / other.z); + } }