Implemented animatronic.json
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package io.github.eldek0.config.animatronic;
|
||||
|
||||
public class AnimatronicConfig {
|
||||
public String id;
|
||||
public String displayName;
|
||||
public int inRoom;
|
||||
public int restRoom;
|
||||
public String color;
|
||||
public AnimatronicMovement movement;
|
||||
public AttackType attackType;
|
||||
public Jumpscare jumpscare;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package io.github.eldek0.config.animatronic;
|
||||
|
||||
public class AnimatronicManifest {
|
||||
public String[] animatronics;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.github.eldek0.config.animatronic;
|
||||
|
||||
public class AnimatronicMovement {
|
||||
public MovementType type;
|
||||
public int[] path;
|
||||
public int moveIntervalSeconds;
|
||||
public boolean aiSpeedMultiplier;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.github.eldek0.config.animatronic;
|
||||
|
||||
public enum AttackKind {
|
||||
LIGHT,
|
||||
MOVE_IN_OFFICE,
|
||||
IN_OFFICE,
|
||||
NORMAL
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.github.eldek0.config.animatronic;
|
||||
|
||||
public class AttackType {
|
||||
public AttackKind kind;
|
||||
|
||||
// If attack kind is IN_OFFICE
|
||||
public String officeSprite = null;
|
||||
public String inOfficeAnimatronicSprite = null;
|
||||
|
||||
// If attack kind is LIGHT
|
||||
public int lightLevel = 2;
|
||||
|
||||
// If attack type is MOVE_IN_OFFICE
|
||||
public int speed = 2;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.github.eldek0.config.animatronic;
|
||||
|
||||
public class Jumpscare {
|
||||
public String sprite;
|
||||
public String sound;
|
||||
public float durationSeconds;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package io.github.eldek0.config.animatronic;
|
||||
|
||||
public enum MovementType {
|
||||
SEQUENTIAL,
|
||||
RANDOM
|
||||
}
|
||||
40
core/src/main/java/io/github/eldek0/game/Animatronic.java
Normal file
40
core/src/main/java/io/github/eldek0/game/Animatronic.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package io.github.eldek0.game;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import io.github.eldek0.config.animatronic.AnimatronicConfig;
|
||||
import io.github.eldek0.config.animatronic.AnimatronicManifest;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Animatronic {
|
||||
private static final String MANIFEST = "data/config/animatronics.json";
|
||||
private static final String CONFIG = "data/config/animatronics/";
|
||||
|
||||
private String[] availableAnimatronics;
|
||||
|
||||
private HashMap<String, AnimatronicConfig> data = new HashMap<>();
|
||||
|
||||
public Animatronic(){
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
public Collection<AnimatronicConfig> getAnimatronicsData(){
|
||||
return data.values();
|
||||
}
|
||||
|
||||
private void loadConfig(){
|
||||
Json json = new Json();
|
||||
String raw = Gdx.files.internal(MANIFEST).readString();
|
||||
AnimatronicManifest manifest = json.fromJson(AnimatronicManifest.class, raw);
|
||||
availableAnimatronics = manifest.animatronics;
|
||||
|
||||
String rawAnim;
|
||||
for (String animatronic : availableAnimatronics){
|
||||
rawAnim = Gdx.files.internal(CONFIG + animatronic + ".json").readString();
|
||||
data.put(animatronic,
|
||||
json.fromJson(AnimatronicConfig.class, rawAnim));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.github.eldek0.game;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
@@ -10,6 +11,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import io.github.eldek0.App;
|
||||
import io.github.eldek0.config.*;
|
||||
import io.github.eldek0.config.animatronic.AnimatronicConfig;
|
||||
import io.github.eldek0.screen.GameScene;
|
||||
import io.github.eldek0.ui.SpriteLayout;
|
||||
|
||||
@@ -138,7 +140,7 @@ public class Camera {
|
||||
this.wideRandomMov = configFile.wideRandomMov;
|
||||
|
||||
this.layout = new SpriteLayout<>(
|
||||
configFile.sprites, // 👈 directo
|
||||
configFile.sprites,
|
||||
CameraSpriteType::valueOf
|
||||
);
|
||||
|
||||
@@ -198,8 +200,28 @@ public class Camera {
|
||||
|
||||
public void renderHitboxes(ShapeRenderer shapeRenderer) {
|
||||
shapeRenderer.setColor(1, 0, 0, 1);
|
||||
for (Rectangle rect : this.buttonScreenRects){
|
||||
CameraConfig config;
|
||||
Rectangle rect;
|
||||
for (int i = 0; i<this.buttonScreenRects.length; i++){
|
||||
rect = this.buttonScreenRects[i];
|
||||
config = this.cameraConfigs[i];
|
||||
|
||||
shapeRenderer.rect(rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
for (AnimatronicConfig animatronicConfig : gameScene.animatronic.getAnimatronicsData()) {
|
||||
|
||||
if (animatronicConfig.inRoom == config.id) {
|
||||
shapeRenderer.end();
|
||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
||||
|
||||
shapeRenderer.setColor(Color.valueOf(animatronicConfig.color));
|
||||
shapeRenderer.rect(rect.x, rect.y, 10, 30);
|
||||
|
||||
shapeRenderer.end();
|
||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
|
||||
shapeRenderer.setColor(1, 0, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import io.github.eldek0.App;
|
||||
import io.github.eldek0.game.Animatronic;
|
||||
import io.github.eldek0.game.Camera;
|
||||
import io.github.eldek0.game.Mask;
|
||||
import io.github.eldek0.game.Office;
|
||||
@@ -27,6 +28,7 @@ public class GameScene implements Screen {
|
||||
public final HUD hud;
|
||||
private final Mask mask;
|
||||
private final Camera camera;
|
||||
public final Animatronic animatronic;
|
||||
FrameBuffer frameBuffer;
|
||||
|
||||
public GameScene(App app) {
|
||||
@@ -39,6 +41,7 @@ public class GameScene implements Screen {
|
||||
|
||||
this.mask = new Mask(this.hud);
|
||||
this.camera = new Camera(this);
|
||||
this.animatronic = new Animatronic();
|
||||
|
||||
frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, App.SCREEN_WIDTH, App.SCREEN_HEIGHT, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user