Separated animations in GameAnimations and added static
This commit is contained in:
@@ -7,6 +7,7 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.utils.viewport.StretchViewport;
|
import com.badlogic.gdx.utils.viewport.StretchViewport;
|
||||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||||
|
import io.github.eldek0.animation.GameAnimations;
|
||||||
import io.github.eldek0.asset.GameAssetManager;
|
import io.github.eldek0.asset.GameAssetManager;
|
||||||
import io.github.eldek0.screen.GameScene;
|
import io.github.eldek0.screen.GameScene;
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ public class App extends Game {
|
|||||||
public static final int SCREEN_WIDTH = 1024;
|
public static final int SCREEN_WIDTH = 1024;
|
||||||
public static final int SCREEN_HEIGHT = 768;
|
public static final int SCREEN_HEIGHT = 768;
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
|
public static boolean LOADED = false;
|
||||||
private GameScene gameScene;
|
private GameScene gameScene;
|
||||||
|
|
||||||
public static OrthographicCamera camera;
|
public static OrthographicCamera camera;
|
||||||
@@ -38,6 +40,9 @@ public class App extends Game {
|
|||||||
assets.loadMenuAssets();
|
assets.loadMenuAssets();
|
||||||
assets.finishLoading();
|
assets.finishLoading();
|
||||||
System.out.println("Assets Loaded");
|
System.out.println("Assets Loaded");
|
||||||
|
GameAnimations.load();
|
||||||
|
System.out.println("Animations Loaded");
|
||||||
|
App.LOADED = true;
|
||||||
this.setScreen(new GameScene(this));
|
this.setScreen(new GameScene(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +50,6 @@ public class App extends Game {
|
|||||||
public void render() {
|
public void render() {
|
||||||
super.render();
|
super.render();
|
||||||
Gdx.graphics.setTitle(Gdx.graphics.getFramesPerSecond() + " FPS");
|
Gdx.graphics.setTitle(Gdx.graphics.getFramesPerSecond() + " FPS");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package io.github.eldek0.animation;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Animation;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import io.github.eldek0.App;
|
||||||
|
|
||||||
|
public class FrameAnimation {
|
||||||
|
private final Animation<Texture> animation;
|
||||||
|
private float stateTime = 0f;
|
||||||
|
|
||||||
|
public FrameAnimation(float frameDuration, Texture[] frames) {
|
||||||
|
this.animation = new Animation<>(frameDuration, frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(float delta) {
|
||||||
|
stateTime += delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
stateTime = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayMode(Animation.PlayMode mode) {
|
||||||
|
animation.setPlayMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFinished() {
|
||||||
|
return animation.isAnimationFinished(stateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(SpriteBatch batch, float alpha) {
|
||||||
|
Color color = batch.getColor();
|
||||||
|
float oldAlpha = color.a;
|
||||||
|
Texture frame = animation.getKeyFrame(stateTime);
|
||||||
|
|
||||||
|
batch.setColor(color.r, color.g, color.b, alpha);
|
||||||
|
|
||||||
|
batch.draw(frame, 0, 0, App.SCREEN_WIDTH, App.SCREEN_HEIGHT);
|
||||||
|
|
||||||
|
batch.setColor(color.r, color.g, color.b, oldAlpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(SpriteBatch batch) {
|
||||||
|
this.draw(batch, 1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package io.github.eldek0.animation;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Animation;
|
||||||
|
import io.github.eldek0.App;
|
||||||
|
|
||||||
|
public class GameAnimations {
|
||||||
|
public static float FRAME_DURATION = 0.03f;
|
||||||
|
|
||||||
|
public static FrameAnimation monitorAnimation;
|
||||||
|
public static FrameAnimation maskInAnimation;
|
||||||
|
public static FrameAnimation bipAnimation;
|
||||||
|
public static FrameAnimation staticAnimation;
|
||||||
|
|
||||||
|
public static void load() {
|
||||||
|
monitorAnimation = new FrameAnimation(FRAME_DURATION, App.assets.monitor.sprites);
|
||||||
|
|
||||||
|
maskInAnimation = new FrameAnimation(FRAME_DURATION, App.assets.mask.sprites);
|
||||||
|
|
||||||
|
bipAnimation = new FrameAnimation(FRAME_DURATION, App.assets.cameras.staticB);
|
||||||
|
|
||||||
|
staticAnimation = new FrameAnimation(FRAME_DURATION, App.assets.cameras.staticA);
|
||||||
|
staticAnimation.setPlayMode(Animation.PlayMode.LOOP);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,12 +4,14 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Animation;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.Json;
|
import com.badlogic.gdx.utils.Json;
|
||||||
import io.github.eldek0.App;
|
import io.github.eldek0.App;
|
||||||
|
import io.github.eldek0.animation.GameAnimations;
|
||||||
import io.github.eldek0.config.RangeLong;
|
import io.github.eldek0.config.RangeLong;
|
||||||
import io.github.eldek0.config.SpriteConfig;
|
import io.github.eldek0.config.SpriteConfig;
|
||||||
import io.github.eldek0.config.animatronic.AnimState;
|
import io.github.eldek0.config.animatronic.AnimState;
|
||||||
@@ -120,6 +122,13 @@ public class Camera {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onTouchDown();
|
onTouchDown();
|
||||||
|
|
||||||
|
if (!GameAnimations.bipAnimation.isFinished()) {
|
||||||
|
GameAnimations.bipAnimation.update(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
GameAnimations.staticAnimation.update(delta);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderBackground(SpriteBatch batch) {
|
public void renderBackground(SpriteBatch batch) {
|
||||||
@@ -141,6 +150,8 @@ public class Camera {
|
|||||||
if (rect != null && rect.contains(position)) {
|
if (rect != null && rect.contains(position)) {
|
||||||
inCameraRoom = config.id;
|
inCameraRoom = config.id;
|
||||||
lightOn = false;
|
lightOn = false;
|
||||||
|
GameAnimations.bipAnimation.reset();
|
||||||
|
GameAnimations.bipAnimation.setPlayMode(Animation.PlayMode.NORMAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,6 +274,8 @@ public class Camera {
|
|||||||
public void renderUI(SpriteBatch batch) {
|
public void renderUI(SpriteBatch batch) {
|
||||||
if (!gameScene.hud.isInsideCamera()) return;
|
if (!gameScene.hud.isInsideCamera()) return;
|
||||||
|
|
||||||
|
GameAnimations.staticAnimation.draw(batch, 0.5f);
|
||||||
|
|
||||||
for (SpriteConfig config : layout.getSortedSprites()) {
|
for (SpriteConfig config : layout.getSortedSprites()) {
|
||||||
if (!config.active()) continue;
|
if (!config.active()) continue;
|
||||||
|
|
||||||
@@ -288,6 +301,10 @@ public class Camera {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drawCameraButtons(batch);
|
drawCameraButtons(batch);
|
||||||
|
|
||||||
|
if (!GameAnimations.bipAnimation.isFinished()) {
|
||||||
|
GameAnimations.bipAnimation.draw(batch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderHitboxes(ShapeRenderer shapeRenderer) {
|
public void renderHitboxes(ShapeRenderer shapeRenderer) {
|
||||||
|
|||||||
@@ -8,36 +8,32 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
|||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import io.github.eldek0.App;
|
import io.github.eldek0.App;
|
||||||
|
import io.github.eldek0.animation.FrameAnimation;
|
||||||
|
|
||||||
public class Button {
|
public class Button {
|
||||||
public static float FRAME_DURATION = 0.03f;
|
|
||||||
|
|
||||||
private boolean inside = false;
|
private boolean inside = false;
|
||||||
private boolean beingPressed = false;
|
private boolean beingPressed = false;
|
||||||
private boolean quitting = false;
|
private boolean quitting = false;
|
||||||
private boolean entering = false;
|
private boolean entering = false;
|
||||||
|
private boolean enable = true;
|
||||||
|
|
||||||
private final Texture buttonTexture;
|
private final Texture buttonTexture;
|
||||||
private final Rectangle bounds;
|
private final Rectangle bounds;
|
||||||
private final float x, y;
|
private final float x, y;
|
||||||
|
|
||||||
private final Animation<Texture> animation;
|
private final FrameAnimation transition;
|
||||||
private float stateTime;
|
|
||||||
|
|
||||||
private boolean enable = true;
|
public Button(Texture sprite, float x, float y, Rectangle bounds, FrameAnimation transition) {
|
||||||
|
|
||||||
public Button(Texture sprite, float x, float y, Rectangle bounds, Texture[] transitionFrames) {
|
|
||||||
this.buttonTexture = sprite;
|
this.buttonTexture = sprite;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
|
||||||
this.bounds = bounds;
|
this.bounds = bounds;
|
||||||
|
this.transition = transition;
|
||||||
animation = new Animation<>(FRAME_DURATION, transitionFrames);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(float delta) {
|
public void update(float delta) {
|
||||||
if (!enable){return;}
|
if (!enable) return;
|
||||||
|
|
||||||
Vector2 position = App.convertPosToWorldPos(new Vector2(Gdx.input.getX(), Gdx.input.getY()));
|
Vector2 position = App.convertPosToWorldPos(new Vector2(Gdx.input.getX(), Gdx.input.getY()));
|
||||||
|
|
||||||
if (bounds.contains(position)) {
|
if (bounds.contains(position)) {
|
||||||
@@ -49,57 +45,56 @@ public class Button {
|
|||||||
beingPressed = false;
|
beingPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInTransition()){
|
if (isInTransition()) {
|
||||||
stateTime += delta;
|
transition.update(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (animation.isAnimationFinished(stateTime)) {
|
if (transition.isFinished()) {
|
||||||
entering = false;
|
entering = false;
|
||||||
quitting = false;
|
quitting = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(SpriteBatch batch) {
|
public void render(SpriteBatch batch) {
|
||||||
if (!enable){return;}
|
if (!enable) return;
|
||||||
batch.draw(buttonTexture, x, y, buttonTexture.getWidth(), buttonTexture.getHeight());
|
batch.draw(buttonTexture, x, y, buttonTexture.getWidth(), buttonTexture.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderHitbox(ShapeRenderer shapeRenderer) {
|
public void renderHitbox(ShapeRenderer shapeRenderer) {
|
||||||
if (!enable){return;}
|
if (!enable) return;
|
||||||
shapeRenderer.rect(bounds.x, bounds.y, bounds.width, bounds.height);
|
shapeRenderer.rect(bounds.x, bounds.y, bounds.width, bounds.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderAnimation(SpriteBatch batch) {
|
public void renderAnimation(SpriteBatch batch) {
|
||||||
if (isInTransition()){
|
if (isInTransition()) {
|
||||||
Texture currentFrame = animation.getKeyFrame(stateTime);
|
transition.draw(batch);
|
||||||
batch.draw(currentFrame, 0, 0, App.SCREEN_WIDTH, App.SCREEN_HEIGHT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleButton() {
|
private void handleButton() {
|
||||||
if (isInTransition()) return;
|
if (isInTransition()) return;
|
||||||
|
|
||||||
if (!inside) {
|
if (!inside) {
|
||||||
entering = true;
|
entering = true;
|
||||||
quitting = false;
|
quitting = false;
|
||||||
inside = true;
|
inside = true;
|
||||||
animation.setPlayMode(Animation.PlayMode.NORMAL);
|
transition.setPlayMode(Animation.PlayMode.NORMAL);
|
||||||
} else {
|
} else {
|
||||||
quitting = true;
|
quitting = true;
|
||||||
entering = false;
|
entering = false;
|
||||||
inside = false;
|
inside = false;
|
||||||
animation.setPlayMode(Animation.PlayMode.REVERSED);
|
transition.setPlayMode(Animation.PlayMode.REVERSED);
|
||||||
}
|
}
|
||||||
stateTime = 0f;
|
|
||||||
|
|
||||||
|
|
||||||
|
transition.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnable() {return enable;}
|
public boolean isEnable() { return enable; }
|
||||||
public void enable() {this.enable = true;}
|
public void enable() { this.enable = true; }
|
||||||
public void disable() {this.enable = false;}
|
public void disable() { this.enable = false; }
|
||||||
public boolean isInTransition(){return entering || quitting;}
|
public boolean isInTransition() { return entering || quitting; }
|
||||||
public boolean isInside() { return inside; }
|
public boolean isInside() { return inside; }
|
||||||
public boolean isBeingPressed() { return beingPressed; }
|
public boolean isBeingPressed() { return beingPressed; }
|
||||||
public boolean isQuitting() { return quitting; }
|
public boolean isQuitting() { return quitting; }
|
||||||
public boolean isEntering() { return entering; }
|
public boolean isEntering() { return entering; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ package io.github.eldek0.ui;
|
|||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import io.github.eldek0.App;
|
import io.github.eldek0.App;
|
||||||
import io.github.eldek0.asset.GameAssetManager;
|
import io.github.eldek0.animation.GameAnimations;
|
||||||
|
|
||||||
public class CameraButton extends Button {
|
public class CameraButton extends Button {
|
||||||
public CameraButton(float x, float y) {
|
public CameraButton(float x, float y) {
|
||||||
super(getButtonTexture(), x, y, new Rectangle(x + 10, 0, 480, getButtonTexture().getHeight() + y),
|
super(getButtonTexture(), x, y,
|
||||||
App.assets.monitor.sprites);
|
new Rectangle(x + 10, 0, 480, getButtonTexture().getHeight() + y),
|
||||||
|
GameAnimations.monitorAnimation
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Texture getButtonTexture() {
|
private static Texture getButtonTexture() {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package io.github.eldek0.ui;
|
|||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import io.github.eldek0.App;
|
import io.github.eldek0.App;
|
||||||
|
import io.github.eldek0.animation.GameAnimations;
|
||||||
import io.github.eldek0.asset.GameAssetManager;
|
import io.github.eldek0.asset.GameAssetManager;
|
||||||
|
|
||||||
public class MaskButton extends Button {
|
public class MaskButton extends Button {
|
||||||
public MaskButton(float x, float y) {
|
public MaskButton(float x, float y) {
|
||||||
super(getButtonTexture(), x, y, new Rectangle(x + 10, 0, 480, getButtonTexture().getHeight() + y),
|
super(getButtonTexture(), x, y, new Rectangle(x + 10, 0, 480, getButtonTexture().getHeight() + y),
|
||||||
App.assets.mask.sprites);
|
GameAnimations.maskInAnimation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Texture getButtonTexture() {
|
private static Texture getButtonTexture() {
|
||||||
|
|||||||
Reference in New Issue
Block a user