Fixed the sound, added a health bar
This commit is contained in:
parent
341261f346
commit
cad3cc198c
|
|
@ -93,6 +93,7 @@ public class AudioObject
|
|||
|
||||
// Play the sound with a new source
|
||||
int source = AudioSources.getSource();
|
||||
alSourceStop(source);
|
||||
alSourcei(source, AL_BUFFER, bufferPointer);
|
||||
alSourcef(source, AL_GAIN, (float)volume);
|
||||
alSource3f(source, AL_POSITION, (float)x, (float)y, (float)z);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import static org.lwjgl.openal.AL11.*;
|
|||
public class AudioSources
|
||||
{
|
||||
static ArrayList<Integer> sources = new ArrayList<Integer>();
|
||||
private static int upto = 0;
|
||||
public static int upto = 0;
|
||||
private static int max = 0;
|
||||
|
||||
public static void init()
|
||||
|
|
@ -26,7 +26,7 @@ public class AudioSources
|
|||
}
|
||||
}
|
||||
|
||||
public static int getSource()
|
||||
static int getSource()
|
||||
{
|
||||
// Get the next source
|
||||
int source = sources.get(upto);
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ import shootergame.util.math.vec.Vec3d;
|
|||
|
||||
public class DisplayRender
|
||||
{
|
||||
public static int fps = 0;
|
||||
|
||||
public static void render(int w, int h)
|
||||
{
|
||||
// Setup GL and clear the colour
|
||||
|
|
@ -86,14 +84,8 @@ public class DisplayRender
|
|||
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();
|
||||
// Render the user interface
|
||||
DisplayRenderUI.render();
|
||||
|
||||
// Unbind the texmap
|
||||
Textures.texmap.unbindTexture();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
package shootergame.display;
|
||||
|
||||
import shootergame.Main;
|
||||
import shootergame.audio.AudioSources;
|
||||
import shootergame.entity.player.EntityPlayer;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.text.Text;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
|
||||
public class DisplayRenderUI
|
||||
{
|
||||
|
||||
|
||||
public static void render()
|
||||
{
|
||||
// Get the player
|
||||
EntityPlayer player = Main.player;
|
||||
|
||||
// Disable some opengl options
|
||||
GlHelpers.disableDepthTest();
|
||||
|
||||
// Render the fps and the position
|
||||
GlHelpers.pushMatrix();
|
||||
GlHelpers.translate(-9.5, 9.5, 0);
|
||||
GlHelpers.color3(1, 1, 0);
|
||||
Text.render("FPS: " + DisplayStatsEventHandler.fps, new Vec2d(0.5, 0.2));
|
||||
GlHelpers.translate(0, -0.5, 0);
|
||||
Text.render("x: " + (int) player.pos.x + ", y: " + (int) player.pos.y, new Vec2d(0.5, 0.2));
|
||||
GlHelpers.translate(0, -0.5, 0);
|
||||
Text.render("AL Sound Source: "+AudioSources.upto, new Vec2d(0.5, 0.2));
|
||||
GlHelpers.color3(1, 1, 1);
|
||||
GlHelpers.popMatrix();
|
||||
|
||||
// Render the healthbar
|
||||
double max_health = player.maxHealth();
|
||||
double a = 1 - (player.getHealth() / max_health);
|
||||
TextureReference health_fg = Textures.UI_HEALTH_FG;
|
||||
TextureReference health_bg = Textures.UI_HEALTH_BG;
|
||||
GlHelpers.begin();
|
||||
|
||||
health_bg.texCoord(0, 0); GlHelpers.vertex2(-2.5, -9.0);
|
||||
health_bg.texCoord(0, 1); GlHelpers.vertex2(-2.5, -9.5);
|
||||
health_bg.texCoord(1, 1); GlHelpers.vertex2(2.5, -9.5);
|
||||
health_bg.texCoord(1, 0); GlHelpers.vertex2(2.5, -9.0);
|
||||
|
||||
health_fg.texCoord(0, 0); GlHelpers.vertex2(-2.5, -9.0);
|
||||
health_fg.texCoord(0, 1); GlHelpers.vertex2(-2.5, -9.5);
|
||||
health_fg.texCoord(1-a, 1); GlHelpers.vertex2(2.5-a*5, -9.5);
|
||||
health_fg.texCoord(1-a, 0); GlHelpers.vertex2(2.5-a*5, -9.0);
|
||||
|
||||
GlHelpers.end();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ public class DisplayStatsEventHandler implements IMainloopTask
|
|||
{
|
||||
public static final DisplayStatsEventHandler DISPLAY_STATS_EVENT_HANDLER = new DisplayStatsEventHandler();
|
||||
|
||||
public static int fps = 0;
|
||||
|
||||
@Override
|
||||
public boolean MainLoopDelay(long millis) {
|
||||
return millis > 1000;
|
||||
|
|
@ -22,7 +24,7 @@ public class DisplayStatsEventHandler implements IMainloopTask
|
|||
{
|
||||
// Set the fps from mspf every second
|
||||
long mspf = MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf;
|
||||
DisplayRender.fps = (int)(1000 / mspf);
|
||||
fps = (int)(1000 / mspf);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import shootergame.Main;
|
|||
import shootergame.display.Camera;
|
||||
import shootergame.entity.particle.ParticleBlood;
|
||||
import shootergame.entity.particle.ParticleSpark;
|
||||
import shootergame.init.Sounds;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.init.Tiles;
|
||||
import shootergame.tiles.TileBlackened;
|
||||
|
|
@ -83,16 +84,19 @@ public class EntityTnt extends EntityVertical
|
|||
// Calculate the blackened gradient
|
||||
short blackened_gradient = (short)( Short.MAX_VALUE - distance/explode_radius*Short.MAX_VALUE );
|
||||
|
||||
// Get the front tile
|
||||
// Get the front and back tile
|
||||
Vec2i tpos = new Vec2i(MathHelpers.floor(px), MathHelpers.floor(py));
|
||||
TileState bts = l.getBackTile(tpos);
|
||||
TileState fts = l.getFrontTile(tpos);
|
||||
if(bts.tile instanceof TileStone) {
|
||||
|
||||
// Is this tile the same as the "empty" tile
|
||||
TileState ets = l.layergen.getTileDestroyed();
|
||||
if(bts.tile == ets.tile) {
|
||||
if(bts.meta > blackened_gradient) blackened_gradient = bts.meta;
|
||||
}
|
||||
|
||||
// Set the tiles
|
||||
if(!bts.tile.unbreakable) l.setBackTile(new TileState(Tiles.STONE,
|
||||
if(!bts.tile.unbreakable) l.setBackTile(new TileState(ets.tile,
|
||||
(short)blackened_gradient), tpos);
|
||||
if(!fts.tile.unbreakable) l.setFrontTile(Tiles.VOID.getDefaultState(), tpos);
|
||||
|
||||
|
|
@ -117,6 +121,9 @@ public class EntityTnt extends EntityVertical
|
|||
}
|
||||
}
|
||||
|
||||
// Play the explosion sound
|
||||
Sounds.EXPLOSION.play(new Vec3d(pos.x, pos.y, height), 1);
|
||||
|
||||
// Delete the entity
|
||||
kill();
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -58,11 +58,17 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
|
|||
}
|
||||
|
||||
// Don't tick if the player is dead
|
||||
else if(health < 0) {
|
||||
dead = true;
|
||||
health = 0;
|
||||
}
|
||||
if(dead) return;
|
||||
|
||||
// Call super
|
||||
super.tick(chunk, layer);
|
||||
|
||||
this.addHealth(0.1);
|
||||
|
||||
// Rotate left
|
||||
if(MOVE_LEFT) {
|
||||
this.angle -= 1;
|
||||
|
|
@ -158,7 +164,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
|
|||
|
||||
@Override
|
||||
public void addHealth(double amount) {
|
||||
health += amount;
|
||||
if(health < health_max) health += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ public class Resources
|
|||
HIT_OGG_0.load();
|
||||
HIT_OGG_1.load();
|
||||
HIT_OGG_2.load();
|
||||
|
||||
EXPLOSION_OGG.load();
|
||||
}
|
||||
|
||||
public static final Resource TEXMAP_PNG = new Resource("texmap.png");
|
||||
|
|
@ -40,4 +42,6 @@ public class Resources
|
|||
public static final Resource HIT_OGG_0 = new Resource("sound/hit0.ogg");
|
||||
public static final Resource HIT_OGG_1 = new Resource("sound/hit1.ogg");
|
||||
public static final Resource HIT_OGG_2 = new Resource("sound/hit2.ogg");
|
||||
|
||||
public static final Resource EXPLOSION_OGG = new Resource("sound/explosion.ogg");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ public class Sounds
|
|||
HIT_0.init();
|
||||
HIT_1.init();
|
||||
HIT_2.init();
|
||||
|
||||
EXPLOSION.init();
|
||||
}
|
||||
|
||||
public static final AudioObject GUN_0 = new AudioObject(Resources.GUN_OGG_0);
|
||||
|
|
@ -44,4 +46,6 @@ public class Sounds
|
|||
|
||||
public static final AudioObject HIT = new AudioRandom(
|
||||
HIT_0, HIT_1, HIT_2);
|
||||
|
||||
public static final AudioObject EXPLOSION = new AudioObject(Resources.EXPLOSION_OGG);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ public class Textures
|
|||
public static final TextureReference TILE_WALL = texmap.getTextureReference(2, 3, 5, 6);
|
||||
public static final TextureReference TILE_LADDER_UP = texmap.getTextureReference(16, 17, 0, 16);
|
||||
|
||||
public static final TextureReference UI_HEALTH_FG = texmap.getTextureReference(0, 16, 11, 12);
|
||||
public static final TextureReference UI_HEALTH_BG = texmap.getTextureReference(0, 16, 12, 13);
|
||||
|
||||
// Fire
|
||||
public static final TextureReference TILE_FIRE_0 = texmap.getTextureReference(0, 1, 1, 2);
|
||||
public static final TextureReference TILE_FIRE_1 = texmap.getTextureReference(1, 2, 1, 2);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package shootergame.tiles;
|
||||
|
||||
import shootergame.display.Camera;
|
||||
import shootergame.init.Textures;
|
||||
import shootergame.util.gl.GlHelpers;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
|
||||
public class TileDirt extends TileFlat
|
||||
{
|
||||
|
|
@ -9,4 +12,11 @@ public class TileDirt extends TileFlat
|
|||
super(id, Textures.TILE_DIRT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Vec2d pos, Camera camera, short meta) {
|
||||
GlHelpers.color4(1, 1, 1, (Short.MAX_VALUE - (double)meta) / Short.MAX_VALUE);
|
||||
super.render(pos, camera, meta);
|
||||
GlHelpers.color4(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import shootergame.entity.player.EntityPlayer;
|
|||
import shootergame.init.Textures;
|
||||
import shootergame.init.Tiles;
|
||||
import shootergame.util.gl.texture.TextureReference;
|
||||
import shootergame.util.math.TileState;
|
||||
import shootergame.util.math.vec.Vec2d;
|
||||
import shootergame.util.math.vec.Vec2i;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
|
|
@ -61,6 +62,26 @@ public class TilePortalDown extends TileFlat
|
|||
movingPlayer = 1;
|
||||
Main.world.setLayerID(meta);
|
||||
player.height = 6;
|
||||
|
||||
Vec2i check_poses[] = {
|
||||
new Vec2i( 1, 0),
|
||||
new Vec2i(-1, 0),
|
||||
new Vec2i( 0, 1),
|
||||
new Vec2i( 0, -1),
|
||||
};
|
||||
|
||||
Layer layer = Main.world.getLayer();
|
||||
for(int i=0;i<=16;i++)
|
||||
{
|
||||
for(Vec2i check_m_pos : check_poses)
|
||||
{
|
||||
Vec2i check_pos = check_m_pos.multiply(new Vec2i(i, i));
|
||||
TileState ets = layer.layergen.getTileDestroyed();
|
||||
|
||||
if(layer.getBackTile(check_pos).tile != ets.tile)
|
||||
layer.setBackTile(new TileState(ets.tile, (short)0), check_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(player.height < 0 && movingPlayer == 1)
|
||||
|
|
@ -68,18 +89,6 @@ public class TilePortalDown extends TileFlat
|
|||
movingPlayer = 2;
|
||||
player.height = 0;
|
||||
player.moving = false;
|
||||
|
||||
Layer layer = Main.world.getLayer();
|
||||
for(int i=0;i<=16;i++) {
|
||||
if(layer.getBackTile(new Vec2i(pos.x+i, pos.y)).tile != Tiles.STONE)
|
||||
layer.setBackTile(Tiles.STONE.getDefaultState(), new Vec2i(pos.x+i, pos.y));
|
||||
if(layer.getBackTile(new Vec2i(pos.x-i, pos.y)).tile != Tiles.STONE)
|
||||
layer.setBackTile(Tiles.STONE.getDefaultState(), new Vec2i(pos.x-i, pos.y));
|
||||
if(layer.getBackTile(new Vec2i(pos.x, pos.y+i)).tile != Tiles.STONE)
|
||||
layer.setBackTile(Tiles.STONE.getDefaultState(), new Vec2i(pos.x, pos.y+i));
|
||||
if(layer.getBackTile(new Vec2i(pos.x, pos.y-i)).tile != Tiles.STONE)
|
||||
layer.setBackTile(Tiles.STONE.getDefaultState(), new Vec2i(pos.x, pos.y-i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import shootergame.world.layer.layergen.LayerGen;
|
|||
public class Layer
|
||||
{
|
||||
public Map2D<Chunk> chunks;
|
||||
private LayerGen layergen;
|
||||
public LayerGen layergen;
|
||||
private Random rand;
|
||||
private long seed;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package shootergame.world.layer.layergen;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import shootergame.util.math.TileState;
|
||||
import shootergame.util.math.map.IMap2D;
|
||||
import shootergame.util.math.vec.Vec2i;
|
||||
import shootergame.world.chunk.Chunk;
|
||||
|
|
@ -11,6 +12,7 @@ public abstract class LayerGen implements IMap2D<Chunk>
|
|||
{
|
||||
public abstract void generateChunk(Chunk chunk, Layer layer, long seed, Random rand, Vec2i pos);
|
||||
public abstract void spawnEntities(Layer layer, Random rand);
|
||||
public abstract TileState getTileDestroyed();
|
||||
|
||||
@Override
|
||||
public Chunk getEmpty(Vec2i pos) {
|
||||
|
|
|
|||
|
|
@ -62,4 +62,9 @@ public class LayerGenCaves extends LayerGen
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileState getTileDestroyed() {
|
||||
return Tiles.STONE.getDefaultState();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,4 +79,9 @@ public class LayerGenEarth extends LayerGen
|
|||
layer.spawnEntity(zombie);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileState getTileDestroyed() {
|
||||
return Tiles.DIRT.getDefaultState();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue