Made the ladder branching into the caves not happen if there is a free

space under the player, removed some println functions.
This commit is contained in:
josua 2019-08-29 09:03:16 +10:00
parent 52779665c8
commit a30a3f0566
9 changed files with 44 additions and 33 deletions

View File

@ -37,6 +37,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
private double health_max = 1000;
private double health = health_max;
public boolean dead = false;
public boolean in_animation = false;
public EntityPlayer() {
this.angle = 45;
@ -62,11 +63,14 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
dead = true;
health = 0;
}
if(dead) return;
// Is the player dead or in an animation
if(dead || in_animation) return;
// Call super
super.tick(chunk, layer);
// Regen some of the players health
this.addHealth(0.1);
// Rotate left
@ -108,7 +112,8 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
@Override
public void moveTowards(double angle, double speed) {
if(!dead) super.moveTowards(angle, speed);
if(dead || in_animation) return;
super.moveTowards(angle, speed);
}
@Override
@ -144,7 +149,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
public void fireBullet(double angle)
{
if(dead) return;
if(dead || in_animation) return;
bullet_frequency += 1;
bullet_frequency %= 10;
@ -158,7 +163,7 @@ public class EntityPlayer extends EntityVertical implements EntityAlive
}
public void throwTnt(double angle) {
if(dead) return;
if(dead || in_animation) return;
Main.world.getLayer().spawnEntity(new EntityTnt(pos.copy(), angle + this.angle, 10));
}

View File

@ -159,7 +159,6 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
// Is the right x axis stick moved into a position (camera stick)
if(right_x > 0.3 || right_x < -0.3) {
System.out.println("Angle changed");
Main.player.angle += right_x;
}

View File

@ -135,7 +135,6 @@ public class Resource
public ByteBuffer getByteBuffer()
{
System.out.println(data.length);
ByteBuffer buffer = ByteBuffer.allocateDirect(data.length);
for(int i=0;i<data.length;i++) {

View File

@ -23,16 +23,16 @@ public class ResourceDownload
InputStream stream = con.getInputStream();
// Get 1 kb packets from the server
for(int i = 0; i < fileSize; i += 1024)
for(int i = 0; i < fileSize; i ++)
{
// Load the stream contents to the buffer
byte buffer[] = new byte[1024];
byte buffer[] = new byte[1];
stream.read(buffer);
// Send a status update
DecimalFormat decim = new DecimalFormat("#.##");
System.out.println(decim.format(i/1024.0) + " kb / " +
decim.format(fileSize/1024.0) + " kb - " +
if(i % 1048576 == 0) System.out.println(decim.format(i / 1048576) + " MB / " +
decim.format(fileSize / 1048576) + " MB - " +
decim.format((double)i / (double)fileSize) + "%");
// Store the bytes downloaded to the data variable

View File

@ -16,8 +16,6 @@ public class TileBlackened extends Tile
@Override
public void render(Vec2d pos, Camera camera, short meta)
{
//System.out.println("META: "+ (int)meta);
// Call super
super.render(pos, camera, meta);

View File

@ -33,9 +33,9 @@ public class TileLadderUp extends TileVertical
{
// Cast to player
EntityPlayer player = (EntityPlayer)entity;
double playerAngle = player.angle;
Vec2d playerPos = player.pos.copy();
if(player.in_animation) return;
player.height = 0;
player.in_animation = true;
// Register the animation
Main.mainloop.register(new IMainloopTask() {
@ -45,8 +45,6 @@ public class TileLadderUp extends TileVertical
@Override
public void MainLoopUpdate()
{
player.angle = playerAngle;
player.pos = playerPos.copy();
player.moving = true;
if(movingPlayer == 0) {
@ -69,6 +67,7 @@ public class TileLadderUp extends TileVertical
movingPlayer = 2;
player.height = 0;
player.moving = false;
player.in_animation = false;
}
}

View File

@ -33,8 +33,8 @@ public class TilePortalDown extends TileFlat
{
// Cast to player
EntityPlayer player = (EntityPlayer)entity;
double playerAngle = player.angle;
Vec2d playerPos = player.pos.copy();
if(player.in_animation) return;
player.in_animation = true;
player.height = 0;
// Register the animation
@ -45,8 +45,6 @@ public class TilePortalDown extends TileFlat
@Override
public void MainLoopUpdate()
{
player.angle = playerAngle;
player.pos = playerPos.copy();
player.moving = true;
if(movingPlayer == 0) {
@ -62,6 +60,14 @@ public class TilePortalDown extends TileFlat
movingPlayer = 1;
Main.world.setLayerID(meta);
player.height = 6;
}
if(player.height < 0 && movingPlayer == 1)
{
movingPlayer = 2;
player.height = 0;
player.moving = false;
player.in_animation = false;
Vec2i check_poses[] = {
new Vec2i( 1, 0),
@ -70,26 +76,33 @@ public class TilePortalDown extends TileFlat
new Vec2i( 0, -1),
};
// Set the first back tile to the tile the ladder is on
Layer layer = Main.world.getLayer();
for(int i=0;i<=16;i++)
TileState ets = layer.layergen.getTileDestroyed();
if(layer.getBackTile(pos).tile != ets.tile) {
layer.setBackTile(new TileState(ets.tile, (short)0), pos);
}
// Exit out of this function if there is an empty space under the player
else return;
boolean found_exit = false;
for(int i=1;!found_exit;i++)
{
for(Vec2i check_m_pos : check_poses)
{
Vec2i check_pos = check_m_pos.multiply(new Vec2i(i, i));
TileState ets = layer.layergen.getTileDestroyed();
Vec2i check_pos = check_m_pos.multiply(new Vec2i(i, i)).add(pos);
if(layer.getBackTile(check_pos).tile != ets.tile)
if(layer.getBackTile(check_pos).tile == ets.tile) {
found_exit = true;
}
else {
layer.setBackTile(new TileState(ets.tile, (short)0), check_pos);
}
}
}
}
if(player.height < 0 && movingPlayer == 1)
{
movingPlayer = 2;
player.height = 0;
player.moving = false;
}
}
@Override

View File

@ -41,7 +41,6 @@ public class Map2D<T> implements Iterable<Map2DElement<T>>
{
// Send back the object if these positions are the same
if(e.pos.equal(pos)) {
//System.out.println(1);
return e.o;
}
}

View File

@ -150,7 +150,6 @@ public class Layer
for(int x=-scan_distance;x<=scan_distance;x++) {
for(int y=-scan_distance;y<=scan_distance;y++)
{
//System.out.println("x: "+x+", y: "+y);
for(Entity e : chunks.get(new Vec2i(x+cpos.x, y+cpos.y)).getNearbyEntities(pos, distance)) {
entities.add(e);
}