100 lines
2.6 KiB
Java
100 lines
2.6 KiB
Java
package shootergame.tiles;
|
|
|
|
import mainloop.task.IMainloopTask;
|
|
import shootergame.Main;
|
|
import shootergame.entity.Entity;
|
|
import shootergame.entity.player.EntityPlayer;
|
|
import shootergame.init.Textures;
|
|
import shootergame.init.Tiles;
|
|
import shootergame.util.gl.texture.TextureReference;
|
|
import shootergame.util.math.vec.Vec2d;
|
|
import shootergame.util.math.vec.Vec2i;
|
|
import shootergame.world.chunk.Chunk;
|
|
import shootergame.world.layer.Layer;
|
|
|
|
public class TilePortalDown extends TileFlat
|
|
{
|
|
|
|
public TilePortalDown(String id) {
|
|
super(id, Textures.TILE_PORTAL);
|
|
|
|
this.unbreakable = true;
|
|
}
|
|
|
|
@Override
|
|
public void onActivated(Chunk chunk, Layer layer, Vec2i pos, Entity entity, short meta)
|
|
{
|
|
// Call super
|
|
super.onWalkedOn(chunk, layer, pos, entity, meta);
|
|
|
|
// Is the entity the player
|
|
if(entity == Main.player)
|
|
{
|
|
// Cast to player
|
|
EntityPlayer player = (EntityPlayer)entity;
|
|
double playerAngle = player.angle;
|
|
Vec2d playerPos = player.pos.copy();
|
|
player.height = 0;
|
|
|
|
// Register the animation
|
|
Main.mainloop.register(new IMainloopTask() {
|
|
|
|
int movingPlayer = 0;
|
|
|
|
@Override
|
|
public void MainLoopUpdate()
|
|
{
|
|
player.angle = playerAngle;
|
|
player.pos = playerPos.copy();
|
|
player.moving = true;
|
|
|
|
if(movingPlayer == 0) {
|
|
player.height -= 0.02;
|
|
}
|
|
|
|
if(movingPlayer == 1) {
|
|
player.height -= 0.04;
|
|
}
|
|
|
|
if(player.height < -1 && movingPlayer == 0)
|
|
{
|
|
movingPlayer = 1;
|
|
Main.world.setLayerID(meta);
|
|
player.height = 6;
|
|
}
|
|
|
|
if(player.height < 0 && movingPlayer == 1)
|
|
{
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean MainLoopRepeat() {
|
|
return movingPlayer != 2;
|
|
}
|
|
|
|
@Override
|
|
public boolean MainLoopDelay(long arg0) {
|
|
return arg0 > 10;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|