feat: Burning
Added Burning state so player will be burning even after he is out of lava. Also added texture for fire that is added on top of steve texture
This commit is contained in:
@ -388,7 +388,8 @@ public class Game extends AutoTransientSupport {
|
||||
|
||||
CustomPlaceHandler placeHandler = gameStates.dependencies.placeHandler.get(item.getId());
|
||||
|
||||
var blocksRemove = blocks.stream().filter(block -> block.getClass().isAnnotationPresent(BreaksByPlace.class)).toList();
|
||||
var blocksRemove = blocks.stream().filter(block -> block.getClass().isAnnotationPresent(BreaksByPlace.class))
|
||||
.toList();
|
||||
|
||||
if (placeHandler.place(this, x, y)) {
|
||||
blocks.removeAll(blocksRemove);
|
||||
|
12
src/main/java/cz/jzitnik/game/annotations/Burning.java
Normal file
12
src/main/java/cz/jzitnik/game/annotations/Burning.java
Normal file
@ -0,0 +1,12 @@
|
||||
package cz.jzitnik.game.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@RequireAnnotation(BlockRegistry.class)
|
||||
public @interface Burning {
|
||||
}
|
@ -13,6 +13,9 @@ public class Player implements Serializable {
|
||||
private int fallDistance = 0;
|
||||
private Block playerBlock1;
|
||||
private Block playerBlock2;
|
||||
private boolean burning = false;
|
||||
private int burningTimeout;
|
||||
private boolean burningState = false;
|
||||
|
||||
public synchronized void heal() {
|
||||
if (hunger > 3 && health < 10) {
|
||||
|
@ -2,10 +2,12 @@ package cz.jzitnik.game.entities.items.registry.blocks.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.annotations.Burning;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.logic.services.flowing.FlowingData;
|
||||
import cz.jzitnik.game.sprites.Water;
|
||||
|
||||
@Burning
|
||||
@BlockRegistry(value = "lava", drops = "lava_bucket")
|
||||
public class LavaBlock extends Block {
|
||||
public LavaBlock() {
|
||||
|
@ -34,7 +34,7 @@ public class Generation {
|
||||
world[terrainHeight[256] - 1][256].add(steveBlock2);
|
||||
world[terrainHeight[256] - 2][256].add(steveBlock);
|
||||
|
||||
game.getInventory().addItem(ItemBlockSupplier.getItem("bucket"));
|
||||
game.getInventory().addItem(ItemBlockSupplier.getItem("lava_bucket"));
|
||||
}
|
||||
|
||||
private static void initializeWorld(List<Block>[][] world) {
|
||||
|
@ -0,0 +1,40 @@
|
||||
package cz.jzitnik.game.logic.services.burning;
|
||||
|
||||
import cz.jzitnik.game.Game;
|
||||
import cz.jzitnik.game.annotations.CustomLogic;
|
||||
import cz.jzitnik.game.entities.Player;
|
||||
import cz.jzitnik.game.logic.CustomLogicInterface;
|
||||
|
||||
@CustomLogic
|
||||
public class Burning implements CustomLogicInterface {
|
||||
@Override
|
||||
public void nextIteration(Game game) {
|
||||
var world = game.getWorld();
|
||||
int[] data = game.getPlayerCords();
|
||||
int x = data[0];
|
||||
int y = data[1];
|
||||
Player player = game.getPlayer();
|
||||
|
||||
var blocks = world[y][x];
|
||||
|
||||
if (blocks.stream().anyMatch(i -> i.getClass().isAnnotationPresent(cz.jzitnik.game.annotations.Burning.class))) {
|
||||
player.setBurning(true);
|
||||
player.setBurningTimeout(0);
|
||||
} else {
|
||||
boolean prev = player.isBurning();
|
||||
if (prev) {
|
||||
player.setBurning(false);
|
||||
player.setBurningTimeout(5);
|
||||
} else if (player.getBurningTimeout() != 0) {
|
||||
player.setBurningTimeout(player.getBurningTimeout() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (player.isBurning() || player.getBurningTimeout() != 0) {
|
||||
player.dealDamage();
|
||||
player.setBurningState(true);
|
||||
} else {
|
||||
player.setBurningState(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package cz.jzitnik.tui;
|
||||
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.Game;
|
||||
import cz.jzitnik.game.sprites.SimpleSprite;
|
||||
import cz.jzitnik.game.sprites.Steve;
|
||||
import cz.jzitnik.game.blocks.Chest;
|
||||
import cz.jzitnik.game.blocks.Furnace;
|
||||
@ -111,6 +112,12 @@ public class ScreenRenderer {
|
||||
sprites.add(stringBuilder.toString());
|
||||
}
|
||||
|
||||
if (blocks.stream().anyMatch(block -> block.getBlockId().equals("steve") && block.getSpriteState().get() == Steve.SteveState.SECOND) && game.getPlayer().isBurningState()) {
|
||||
SimpleSprite fire = new SimpleSprite("fire.ans");
|
||||
|
||||
sprites.add(fire.getSprite());
|
||||
}
|
||||
|
||||
String sprite = SpriteCombiner.combineSprites(sprites.toArray(String[]::new));
|
||||
|
||||
String[] spriteLines = sprite.split("\n");
|
||||
|
Reference in New Issue
Block a user