Implemented animatronic.json

This commit is contained in:
2026-04-01 00:51:49 -03:00
parent ffa3dc076b
commit f40831c3c2
13 changed files with 173 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
{
"animatronics": [
"freddy"
]
}

View File

@@ -0,0 +1,27 @@
{
"id": "freddy",
"displayName": "Freddy Fazbear",
"inRoom": 9,
"restRoom": 9,
"color": "#FF5733",
"movement": {
"type": "SEQUENTIAL",
"path": [9],
"moveIntervalSeconds": 30,
"aiSpeedMultiplier": true
},
"attackType": {
"kind": "LIGHT",
"lightLevel": 3
},
"jumpscare": {
"sprite": "freddy_jumpscare",
"sound": "freddy_scream",
"durationSeconds": 2.5
}
}

View File

@@ -0,0 +1,12 @@
{
"nights": [
{
"night": 1,
"hours": [
{ "hour": 0, "ai": { "freddy": 10 } },
{ "hour": 1, "ai": { "freddy": 11 } },
{ "hour": 2, "ai": { "freddy": 20 } }
]
}
]
}

View File

@@ -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;
}

View File

@@ -0,0 +1,5 @@
package io.github.eldek0.config.animatronic;
public class AnimatronicManifest {
public String[] animatronics;
}

View File

@@ -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;
}

View File

@@ -0,0 +1,8 @@
package io.github.eldek0.config.animatronic;
public enum AttackKind {
LIGHT,
MOVE_IN_OFFICE,
IN_OFFICE,
NORMAL
}

View File

@@ -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;
}

View File

@@ -0,0 +1,7 @@
package io.github.eldek0.config.animatronic;
public class Jumpscare {
public String sprite;
public String sound;
public float durationSeconds;
}

View File

@@ -0,0 +1,6 @@
package io.github.eldek0.config.animatronic;
public enum MovementType {
SEQUENTIAL,
RANDOM
}

View 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));
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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);