diff --git a/android/src/main/java/me/stringdotjar/funkin/android/AndroidLauncher.java b/android/src/main/java/me/stringdotjar/funkin/android/AndroidLauncher.java index 999621a..a1f2eb8 100644 --- a/android/src/main/java/me/stringdotjar/funkin/android/AndroidLauncher.java +++ b/android/src/main/java/me/stringdotjar/funkin/android/AndroidLauncher.java @@ -4,7 +4,7 @@ import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import me.stringdotjar.funkin.FunkinGame; -import me.stringdotjar.funkin.InitScreen; +import me.stringdotjar.funkin.InitState; import me.stringdotjar.funkin.util.FunkinConstants; /** Launches the Android application. */ @@ -17,7 +17,7 @@ protected void onCreate(Bundle savedInstanceState) { FunkinConstants.WINDOW_TITLE, FunkinConstants.WINDOW_WIDTH, FunkinConstants.WINDOW_HEIGHT, - new InitScreen() + new InitState() ); AndroidApplicationConfiguration configuration = new AndroidApplicationConfiguration(); configuration.useImmersiveMode = true; // Recommended, but not required. diff --git a/assets/another_test.groovy b/assets/another_test.groovy index 243bdcb..e7bed07 100644 --- a/assets/another_test.groovy +++ b/assets/another_test.groovy @@ -32,7 +32,7 @@ class AnotherTestClass extends Script { sprite.setPosition(randomPosX, randomPosY) - Flixel.screen.add(sprite) + Flixel.state.add(sprite) } } diff --git a/assets/test.groovy b/assets/test.groovy index ea4b33b..78e664b 100644 --- a/assets/test.groovy +++ b/assets/test.groovy @@ -2,7 +2,7 @@ import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.Color import me.stringdotjar.flixelgdx.Flixel -import me.stringdotjar.flixelgdx.graphics.FlixelScreen +import me.stringdotjar.flixelgdx.graphics.FlixelState import me.stringdotjar.flixelgdx.backend.FlixelPaths import me.stringdotjar.flixelgdx.graphics.sprite.FlixelSprite import me.stringdotjar.polyverse.script.type.SystemScript @@ -24,7 +24,7 @@ class TestScript extends SystemScript { super.onRender(delta) if (Gdx.input.isKeyJustPressed(Input.Keys.Q)) { - Flixel.setScreen(new TestScreen()) + Flixel.switchState(new TestState()) } } @@ -41,7 +41,7 @@ class TestScript extends SystemScript { } } -class TestScreen extends FlixelScreen { +class TestState extends FlixelState { private FlixelSprite test diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/Flixel.java b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/Flixel.java index bb89a0e..59c8328 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/Flixel.java +++ b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/Flixel.java @@ -9,14 +9,14 @@ import games.rednblack.miniaudio.MASound; import games.rednblack.miniaudio.MiniAudio; import games.rednblack.miniaudio.loader.MASoundLoader; -import me.stringdotjar.flixelgdx.graphics.FlixelScreen; +import me.stringdotjar.flixelgdx.graphics.FlixelState; import me.stringdotjar.flixelgdx.graphics.FlixelViewport; -import me.stringdotjar.flixelgdx.util.FlixelConstants; import me.stringdotjar.flixelgdx.signal.FlixelSignal; import me.stringdotjar.flixelgdx.signal.FlixelSignalData.MusicPlayedSignalData; -import me.stringdotjar.flixelgdx.signal.FlixelSignalData.RenderSignalData; -import me.stringdotjar.flixelgdx.signal.FlixelSignalData.ScreenSwitchSignalData; +import me.stringdotjar.flixelgdx.signal.FlixelSignalData.UpdateSignalData; +import me.stringdotjar.flixelgdx.signal.FlixelSignalData.StateSwitchSignalData; import me.stringdotjar.flixelgdx.signal.FlixelSignalData.SoundPlayedSignalData; +import me.stringdotjar.flixelgdx.util.FlixelConstants; import org.jetbrains.annotations.NotNull; import java.time.LocalDateTime; @@ -29,8 +29,8 @@ */ public final class Flixel { - /** The current {@code FlixelScreen} being displayed. */ - private static FlixelScreen screen; + /** The current {@code FlixelState} being displayed. */ + private static FlixelState state; /** The main audio object used to create, */ private static MiniAudio engine; @@ -63,7 +63,7 @@ public final class Flixel { */ public static void initialize(FlixelGame gameInstance) { if (initialized) { - throw new IllegalStateException("FNF:JE has already been initialized!"); + throw new IllegalStateException("FlixelGDX has already been initialized!"); } game = gameInstance; @@ -80,24 +80,24 @@ public static void initialize(FlixelGame gameInstance) { /** * Sets the current screen to the provided screen. * - * @param newScreen The new {@code FlixelScreen} to set as the current screen. + * @param newState The new {@code FlixelState} to set as the current screen. */ - public static void setScreen(FlixelScreen newScreen) { - Signals.preScreenSwitch.dispatch(new ScreenSwitchSignalData(newScreen)); + public static void switchState(FlixelState newState) { + Signals.preStateSwitch.dispatch(new StateSwitchSignalData(newState)); if (!initialized) { - throw new IllegalStateException("FNF:JE has not been initialized yet!"); + throw new IllegalStateException("Polyverse has not been initialized yet!"); } - if (newScreen == null) { - throw new IllegalArgumentException("Screen cannot be null!"); + if (newState == null) { + throw new IllegalArgumentException("New state cannot be null!"); } - if (screen != null) { - screen.hide(); - screen.dispose(); + if (state != null) { + state.hide(); + state.dispose(); } game.resetViewports(); - screen = newScreen; - screen.create(); - Signals.postScreenSwitch.dispatch(new ScreenSwitchSignalData(newScreen)); + state = newState; + state.create(); + Signals.postStateSwitch.dispatch(new StateSwitchSignalData(newState)); } /** @@ -112,8 +112,8 @@ public static void setScreen(FlixelScreen newScreen) { * } * * @param path The path to load the sound from. Note that if you're loading an external sound - * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a - * regular string (without {@code assets/} at the beginning). + * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a + * regular string (without {@code assets/} at the beginning). * @return The new sound instance. */ public static MASound playSound(String path) { @@ -131,9 +131,9 @@ public static MASound playSound(String path) { * Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1); * } * - * @param path The path to load the sound from. Note that if you're loading an external sound - * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a - * regular string (without {@code assets/} at the beginning). + * @param path The path to load the sound from. Note that if you're loading an external sound + * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a + * regular string (without {@code assets/} at the beginning). * @param volume The volume to play the new sound with. * @return The new sound instance. */ @@ -152,10 +152,10 @@ public static MASound playSound(String path, float volume) { * Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1, false); * } * - * @param path The path to load the sound from. Note that if you're loading an external sound - * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a - * regular string (without {@code assets/} at the beginning). - * @param volume The volume to play the new sound with. + * @param path The path to load the sound from. Note that if you're loading an external sound + * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a + * regular string (without {@code assets/} at the beginning). + * @param volume The volume to play the new sound with. * @param looping Should the new sound loop indefinitely? * @return The new sound instance. */ @@ -175,13 +175,13 @@ public static MASound playSound(String path, float volume, boolean looping) { * Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1, false, null); * } * - * @param path The path to load the sound from. Note that if you're loading an external sound - * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a - * regular string (without {@code assets/} at the beginning). - * @param volume The volume to play the new sound with. + * @param path The path to load the sound from. Note that if you're loading an external sound + * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a + * regular string (without {@code assets/} at the beginning). + * @param volume The volume to play the new sound with. * @param looping Should the new sound loop indefinitely? - * @param group The sound group to add the new sound to. If {@code null} is passed down, then the - * default sound group will be used. + * @param group The sound group to add the new sound to. If {@code null} is passed down, then the + * default sound group will be used. * @return The new sound instance. */ public static MASound playSound(String path, float volume, boolean looping, MAGroup group) { @@ -202,13 +202,13 @@ public static MASound playSound(String path, float volume, boolean looping, MAGr * Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1, false, null, true); * } * - * @param path The path to load the sound from. Note that if you're loading an external sound - * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a - * regular string (without {@code assets/} at the beginning). - * @param volume The volume to play the new sound with. - * @param looping Should the new sound loop indefinitely? - * @param group The sound group to add the new sound to. If {@code null} is passed down, then the - * default sound group will be used. + * @param path The path to load the sound from. Note that if you're loading an external sound + * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a + * regular string (without {@code assets/} at the beginning). + * @param volume The volume to play the new sound with. + * @param looping Should the new sound loop indefinitely? + * @param group The sound group to add the new sound to. If {@code null} is passed down, then the + * default sound group will be used. * @param external Should this sound be loaded externally? (This is only for mobile platforms!) * @return The new sound instance. */ @@ -234,8 +234,8 @@ public static MASound playSound(@NotNull String path, float volume, boolean loop * } * * @param path The path to load the music from. Note that if you're loading an external sound file - * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a - * regular string (without {@code assets/} at the beginning). + * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a + * regular string (without {@code assets/} at the beginning). */ public static void playMusic(String path) { playMusic(path, 1, true, false); @@ -252,9 +252,9 @@ public static void playMusic(String path) { * Flixel.playMusic(FlixelPaths.external("your/path/here").path(), 1); * } * - * @param path The path to load the music from. Note that if you're loading an external sound file - * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a - * regular string (without {@code assets/} at the beginning). + * @param path The path to load the music from. Note that if you're loading an external sound file + * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a + * regular string (without {@code assets/} at the beginning). * @param volume The volume to play the new music with. */ public static void playMusic(String path, float volume) { @@ -272,10 +272,10 @@ public static void playMusic(String path, float volume) { * Flixel.playMusic(FlixelPaths.external("your/path/here").path(), 1, false); * } * - * @param path The path to load the music from. Note that if you're loading an external sound file - * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a - * regular string (without {@code assets/} at the beginning). - * @param volume The volume to play the new music with. + * @param path The path to load the music from. Note that if you're loading an external sound file + * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a + * regular string (without {@code assets/} at the beginning). + * @param volume The volume to play the new music with. * @param looping Should the new music loop indefinitely? */ public static void playMusic(String path, float volume, boolean looping) { @@ -295,11 +295,11 @@ public static void playMusic(String path, float volume, boolean looping) { * Flixel.playMusic(FlixelPaths.external("your/path/here").path(), 1, false, true); * } * - * @param path The path to load the music from. Note that if you're loading an external sound file - * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a - * regular string (without {@code assets/} at the beginning). - * @param volume The volume to play the new music with. - * @param looping Should the new music loop indefinitely? + * @param path The path to load the music from. Note that if you're loading an external sound file + * outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a + * regular string (without {@code assets/} at the beginning). + * @param volume The volume to play the new music with. + * @param looping Should the new music loop indefinitely? * @param external Should this music be loaded externally? (This is only for mobile platforms!) */ public static void playMusic(String path, float volume, boolean looping, boolean external) { @@ -369,8 +369,8 @@ public static Stage getStage() { return game.stage; } - public static FlixelScreen getScreen() { - return screen; + public static FlixelState getState() { + return state; } public static MASound getMusic() { @@ -378,7 +378,7 @@ public static MASound getMusic() { } public static Vector2 getWindowSize() { - return game.windowSize; + return game.viewSize; } public static MiniAudio getAudioEngine() { @@ -397,7 +397,7 @@ public static MAGroup getSoundsGroup() { return soundsGroup; } - public static float getDelta() { + public static float getElapsed() { return Gdx.graphics.getDeltaTime(); } @@ -421,10 +421,12 @@ public static boolean isFullscreen() { */ public static final class Signals { - public static final FlixelSignal preRender = new FlixelSignal<>(); - public static final FlixelSignal postRender = new FlixelSignal<>(); - public static final FlixelSignal preScreenSwitch = new FlixelSignal<>(); - public static final FlixelSignal postScreenSwitch = new FlixelSignal<>(); + public static final FlixelSignal preUpdate = new FlixelSignal<>(); + public static final FlixelSignal postUpdate = new FlixelSignal<>(); + public static final FlixelSignal preDraw = new FlixelSignal<>(); + public static final FlixelSignal postDraw = new FlixelSignal<>(); + public static final FlixelSignal preStateSwitch = new FlixelSignal<>(); + public static final FlixelSignal postStateSwitch = new FlixelSignal<>(); public static final FlixelSignal preGameClose = new FlixelSignal<>(); public static final FlixelSignal postGameClose = new FlixelSignal<>(); public static final FlixelSignal windowFocused = new FlixelSignal<>(); diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java index faa04b5..5630cd8 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java +++ b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java @@ -12,13 +12,13 @@ import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.SnapshotArray; import me.stringdotjar.flixelgdx.graphics.FlixelObject; -import me.stringdotjar.flixelgdx.graphics.FlixelScreen; +import me.stringdotjar.flixelgdx.graphics.FlixelState; import me.stringdotjar.flixelgdx.graphics.FlixelViewport; import me.stringdotjar.flixelgdx.graphics.sprite.FlixelSprite; import me.stringdotjar.flixelgdx.tween.FlixelTween; import me.stringdotjar.flixelgdx.util.FlixelRuntimeUtil; -import static me.stringdotjar.flixelgdx.signal.FlixelSignalData.RenderSignalData; +import static me.stringdotjar.flixelgdx.signal.FlixelSignalData.UpdateSignalData; /** * Flixel's enhanced game object used for containing the main loop and core elements of Flixel. @@ -32,10 +32,13 @@ public abstract class FlixelGame implements ApplicationListener { protected String title; /** The size of the game's starting window position and its viewport. */ + protected Vector2 viewSize; + + /** The current window size stored in a vector object. */ protected Vector2 windowSize; /** The entry point screen the game starts in (which becomes null after the game is done setting up!). */ - protected FlixelScreen initialScreen; + protected FlixelState initialScreen; /** Is the game's window currently focused? */ private boolean isFocused = true; @@ -64,8 +67,9 @@ public abstract class FlixelGame implements ApplicationListener { * @param height The starting height of the game's window and how tall the viewport should be. * @param initialScreen The initial screen to load when the game starts. */ - public FlixelGame(String title, int width, int height, FlixelScreen initialScreen) { + public FlixelGame(String title, int width, int height, FlixelState initialScreen) { this.title = title; + this.viewSize = new Vector2(width, height); this.windowSize = new Vector2(width, height); this.initialScreen = initialScreen; } @@ -76,7 +80,7 @@ public void create() { batch = new SpriteBatch(); viewports = new SnapshotArray<>(FlixelViewport.class); - viewports.add(new FlixelViewport((int) windowSize.x, (int) windowSize.y)); + viewports.add(new FlixelViewport((int) viewSize.x, (int) viewSize.y)); stage = new Stage(getViewport(), batch); @@ -86,7 +90,7 @@ public void create() { bgTexture = new Texture(pixmap); pixmap.dispose(); - Flixel.setScreen(initialScreen); + Flixel.switchState(initialScreen); initialScreen = null; } @@ -102,68 +106,94 @@ public void resize(int width, int height) { viewports.end(); } - @Override - public void render() { - float delta = Gdx.graphics.getDeltaTime(); - FlixelScreen screen = Flixel.getScreen(); + /** + * Updates the logic of the game's loop. + * + * @param elapsed The amount of time that occurred in the last frame. + */ + public void update(float elapsed) { + Flixel.Signals.preUpdate.dispatch(new UpdateSignalData(elapsed)); - Flixel.Signals.preRender.dispatch(new RenderSignalData(delta)); + stage.act(elapsed); + FlixelTween.getGlobalManager().update(elapsed); - stage.act(delta); - FlixelTween.getGlobalManager().update(delta); + FlixelState state = Flixel.getState(); + state.update(elapsed); - // Update and render the current screen that's active. + // Update all members contained in the current state. + SnapshotArray members = state.getMembers(); + FlixelObject[] mbrs = members.begin(); + for (int i = 0; i < members.size; i++) { + mbrs[i].update(elapsed); + } + members.end(); + + Flixel.Signals.postUpdate.dispatch(new UpdateSignalData(elapsed)); + } + + /** + * Updates the graphics and display of the game. + */ + public void draw() { + Flixel.Signals.preDraw.dispatch(); ScreenUtils.clear(Color.BLACK); - if (screen != null) { - screen.update(delta); + // Loop through all viewports and draw the current state's members onto their set viewports. + FlixelViewport[] vps = viewports.begin(); + FlixelState state = Flixel.getState(); + SnapshotArray members = state.getMembers(); + FlixelObject[] mbrs = members.begin(); + for (int i = 0; i < viewports.size; i++) { + FlixelViewport viewport = vps[i]; + if (viewport == null) { + continue; + } - // Loop through all viewports and draw the current screen's members onto their set viewports. - FlixelViewport[] vps = viewports.begin(); - SnapshotArray members = screen.getMembers(); - for (int i = 0; i < viewports.size; i++) { - FlixelViewport viewport = vps[i]; - if (viewport == null) { + var camera = viewport.getCamera(); + viewport.apply(); + camera.update(); + batch.setProjectionMatrix(camera.combined); + batch.begin(); + + // Draw the background color first. + batch.setColor(state.getBgColor()); + batch.draw(bgTexture, 0, 0, getViewport().getWorldWidth(), getViewport().getWorldHeight()); + batch.setColor(Color.WHITE); // Set the batch color back to white so display objects aren't affected. + + // Draw all the current screens members. + for (int j = 0; j < members.size; j++) { + FlixelObject member = mbrs[j]; + if (member == null) { continue; } - - viewport.apply(); - var camera = viewport.getCamera(); - camera.update(); - batch.setProjectionMatrix(camera.combined); - batch.begin(); - - // Draw the background color first. - batch.setColor(screen.getBgColor()); - batch.draw(bgTexture, 0, 0, getViewport().getWorldWidth(), getViewport().getWorldHeight()); - batch.setColor(Color.WHITE); // Set the batch color back to white so display objects aren't affected. - // Draw all the current screens members. - FlixelObject[] mbrs = members.begin(); - for (int j = 0; j < members.size; j++) { - FlixelObject member = mbrs[j]; - if (member == null) { - continue; - } - member.update(delta); - if (member instanceof FlixelSprite s) { - // Check if the current sprite is in the visible part of the viewport. - // If it cannot be seen, then we don't draw the sprite to save performance. - if (camera.frustum.boundsInFrustum(s.getX(), s.getY(), 0, s.getWidth(), s.getHeight(), 0)) { - s.draw(batch); - } - } else { - member.draw(batch); + if (member instanceof FlixelSprite s) { + // Check if the current sprite is in the visible part of the viewport. + // If it cannot be seen, then we don't draw the sprite to save performance. + if (camera.frustum.boundsInFrustum(s.getX(), s.getY(), 0, s.getWidth(), s.getHeight(), 0)) { + s.draw(batch); } + } else { + member.draw(batch); } - batch.end(); - members.end(); } - viewports.end(); - screen.draw(batch); + batch.end(); } + viewports.end(); + members.end(); + state.draw(batch); stage.draw(); + Flixel.Signals.postDraw.dispatch(); + } + + @Override + public void render() { + float delta = Gdx.graphics.getDeltaTime(); - Flixel.Signals.postRender.dispatch(new RenderSignalData(delta)); + windowSize.x = Gdx.graphics.getWidth(); + windowSize.y = Gdx.graphics.getHeight(); + + update(delta); + draw(); } @Override @@ -212,13 +242,10 @@ public void onWindowMinimized(boolean iconified) { */ public void setFullscreen(boolean enabled) { if (enabled) { - if (!Flixel.isFullscreen()) { - windowSize.set(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); - } Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); Flixel.info("Entered fullscreen mode."); } else { - Gdx.graphics.setWindowedMode((int) windowSize.x, (int) windowSize.y); + Gdx.graphics.setWindowedMode((int) viewSize.x, (int) viewSize.y); Flixel.info("Exited fullscreen mode."); } } @@ -235,8 +262,8 @@ public void dispose() { Flixel.Signals.preGameClose.dispatch(); Flixel.info("Disposing the screen display..."); - Flixel.getScreen().hide(); - Flixel.getScreen().dispose(); + Flixel.getState().hide(); + Flixel.getState().dispose(); stage.dispose(); batch.dispose(); bgTexture.dispose(); @@ -272,6 +299,10 @@ public String getTitle() { return title; } + public Vector2 getViewSize() { + return viewSize; + } + public Vector2 getWindowSize() { return windowSize; } @@ -284,6 +315,12 @@ public Stage getStage() { return stage; } + /** + * Gets the first viewport that is part of the list. If the list is {@code null} or empty, then a new list (with a + * default viewport accordingly). + * + * @return The first viewport in the list. + */ public FlixelViewport getViewport() { Vector2 windowSize = Flixel.getWindowSize(); if (viewports == null) { @@ -298,8 +335,10 @@ public FlixelViewport getViewport() { } public void resetViewports() { + FlixelViewport viewport = new FlixelViewport((int) viewSize.x, (int) viewSize.y); + viewport.update((int) windowSize.x, (int) windowSize.y, true); viewports.clear(); - viewports.add(new FlixelViewport((int) windowSize.x, (int) windowSize.y)); + viewports.add(viewport); } public SnapshotArray getViewports() { @@ -318,9 +357,9 @@ public boolean isMinimized() { return isMinimized; } - public void setWindowSize(Vector2 windowSize) { - this.windowSize = windowSize; - Gdx.graphics.setWindowedMode((int) windowSize.x, (int) windowSize.y); - Flixel.info("Set window size. (WIDTH=" + windowSize.x + ", HEIGHT=" + windowSize.y + ")"); + public void setWindowSize(Vector2 newSize) { + viewSize = newSize; + Gdx.graphics.setWindowedMode((int) newSize.x, (int) newSize.y); + Flixel.info("Set window to new size. (WIDTH=" + newSize.x + ", HEIGHT=" + newSize.y + ")"); } } diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelObject.java b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelObject.java index 489ba9d..c806248 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelObject.java +++ b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelObject.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.graphics.g2d.Batch; -/** An interface which allows any class that implements it to be added to a {@link FlixelScreen}. */ +/** An interface which allows any class that implements it to be added to a {@link FlixelState}. */ public interface FlixelObject { void update(float delta); void draw(Batch batch); diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelScreen.java b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelState.java similarity index 89% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelScreen.java rename to flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelState.java index 6957ec6..d184750 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelScreen.java +++ b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelState.java @@ -10,7 +10,7 @@ * Base class for creating a better screen display with more functionality than the default {@link * com.badlogic.gdx.Screen} interface. */ -public abstract class FlixelScreen extends FlixelGroup implements Screen { +public abstract class FlixelState extends FlixelGroup implements Screen { /** Should {@code this} screen update its logic even when a substate is currently opened? */ public boolean persistentUpdate = false; @@ -21,7 +21,7 @@ public abstract class FlixelScreen extends FlixelGroup implements /** The background color of {@code this} current screen. */ protected Color bgColor; - public FlixelScreen() { + public FlixelState() { members = new SnapshotArray<>(FlixelObject.class); } @@ -46,16 +46,12 @@ public void update(float delta) { if (!persistentUpdate) { return; } - - forEachMember(object -> { - object.update(delta); - }); } /** * Draws its members onto the screen. * - * @param batch The batch that's used to draw the + * @param batch The batch that's used to draw {@code this} state's members. */ public void draw(Batch batch) { if (!persistentDraw) { diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java index 0da3e0d..0156008 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java +++ b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java @@ -1,7 +1,7 @@ package me.stringdotjar.flixelgdx.signal; import games.rednblack.miniaudio.MASound; -import me.stringdotjar.flixelgdx.graphics.FlixelScreen; +import me.stringdotjar.flixelgdx.graphics.FlixelState; import me.stringdotjar.flixelgdx.Flixel; /** @@ -10,9 +10,9 @@ */ public final class FlixelSignalData { - public record RenderSignalData(float delta) {} + public record UpdateSignalData(float delta) {} - public record ScreenSwitchSignalData(FlixelScreen screen) {} + public record StateSwitchSignalData(FlixelState screen) {} public record SoundPlayedSignalData(MASound sound) {} diff --git a/funkin/src/main/java/me/stringdotjar/funkin/FunkinGame.java b/funkin/src/main/java/me/stringdotjar/funkin/FunkinGame.java index 62e2258..866df71 100644 --- a/funkin/src/main/java/me/stringdotjar/funkin/FunkinGame.java +++ b/funkin/src/main/java/me/stringdotjar/funkin/FunkinGame.java @@ -4,7 +4,7 @@ import me.stringdotjar.flixelgdx.Flixel; import me.stringdotjar.flixelgdx.FlixelGame; import me.stringdotjar.flixelgdx.backend.FlixelPaths; -import me.stringdotjar.flixelgdx.graphics.FlixelScreen; +import me.stringdotjar.flixelgdx.graphics.FlixelState; import me.stringdotjar.polyverse.Polyverse; import me.stringdotjar.polyverse.script.type.Script; import me.stringdotjar.polyverse.script.type.SystemScript; @@ -16,7 +16,7 @@ public class FunkinGame extends FlixelGame { private float lastVolume = 1.0f; - public FunkinGame(String title, int width, int height, FlixelScreen initialScreen) { + public FunkinGame(String title, int width, int height, FlixelState initialScreen) { super(title, width, height, initialScreen); } @@ -34,7 +34,7 @@ public void render() { toggleFullscreen(); } - Polyverse.forAllScripts(script -> script.onRender(Flixel.getDelta())); + Polyverse.forAllScripts(script -> script.onRender(Flixel.getElapsed())); } @Override diff --git a/funkin/src/main/java/me/stringdotjar/funkin/InitScreen.java b/funkin/src/main/java/me/stringdotjar/funkin/InitScreen.java deleted file mode 100644 index a9ccf3f..0000000 --- a/funkin/src/main/java/me/stringdotjar/funkin/InitScreen.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.stringdotjar.funkin; - -import me.stringdotjar.flixelgdx.graphics.FlixelScreen; -import me.stringdotjar.flixelgdx.Flixel; -import me.stringdotjar.funkin.menus.TitleScreen; - -public class InitScreen extends FlixelScreen { - - @Override - public void create() { - super.create(); - Flixel.setScreen(new TitleScreen()); - } -} diff --git a/funkin/src/main/java/me/stringdotjar/funkin/InitState.java b/funkin/src/main/java/me/stringdotjar/funkin/InitState.java new file mode 100644 index 0000000..412adcc --- /dev/null +++ b/funkin/src/main/java/me/stringdotjar/funkin/InitState.java @@ -0,0 +1,14 @@ +package me.stringdotjar.funkin; + +import me.stringdotjar.flixelgdx.graphics.FlixelState; +import me.stringdotjar.flixelgdx.Flixel; +import me.stringdotjar.funkin.menus.TitleState; + +public class InitState extends FlixelState { + + @Override + public void create() { + super.create(); + Flixel.switchState(new TitleState()); + } +} diff --git a/funkin/src/main/java/me/stringdotjar/funkin/menus/TitleScreen.java b/funkin/src/main/java/me/stringdotjar/funkin/menus/TitleState.java similarity index 95% rename from funkin/src/main/java/me/stringdotjar/funkin/menus/TitleScreen.java rename to funkin/src/main/java/me/stringdotjar/funkin/menus/TitleState.java index 79fab0a..03e0778 100644 --- a/funkin/src/main/java/me/stringdotjar/funkin/menus/TitleScreen.java +++ b/funkin/src/main/java/me/stringdotjar/funkin/menus/TitleState.java @@ -3,7 +3,7 @@ import games.rednblack.miniaudio.MASound; import me.stringdotjar.flixelgdx.Flixel; import me.stringdotjar.flixelgdx.backend.FlixelPaths; -import me.stringdotjar.flixelgdx.graphics.FlixelScreen; +import me.stringdotjar.flixelgdx.graphics.FlixelState; import me.stringdotjar.flixelgdx.graphics.sprite.FlixelSprite; import me.stringdotjar.flixelgdx.input.FlixelKey; import me.stringdotjar.flixelgdx.tween.FlixelEase; @@ -11,7 +11,7 @@ import me.stringdotjar.flixelgdx.tween.settings.FlixelTweenSettings; import me.stringdotjar.flixelgdx.tween.settings.FlixelTweenType; -public class TitleScreen extends FlixelScreen { +public class TitleState extends FlixelState { private FlixelSprite logo; diff --git a/funkin/src/main/java/me/stringdotjar/funkin/util/FunkinConstants.java b/funkin/src/main/java/me/stringdotjar/funkin/util/FunkinConstants.java index 8fd5196..1981026 100644 --- a/funkin/src/main/java/me/stringdotjar/funkin/util/FunkinConstants.java +++ b/funkin/src/main/java/me/stringdotjar/funkin/util/FunkinConstants.java @@ -8,7 +8,7 @@ public final class FunkinConstants { /** * The default title for the game's window. */ - public static final String WINDOW_TITLE = "Friday Night Funkin': Java Edition"; + public static final String WINDOW_TITLE = "Polyverse Funkin'"; /** * How wide the window's viewport is in pixels. This also affects how wide the window is when diff --git a/lwjgl3/src/main/java/me/stringdotjar/funkin/lwjgl3/Lwjgl3Launcher.java b/lwjgl3/src/main/java/me/stringdotjar/funkin/lwjgl3/Lwjgl3Launcher.java index 7222c22..3ad634d 100644 --- a/lwjgl3/src/main/java/me/stringdotjar/funkin/lwjgl3/Lwjgl3Launcher.java +++ b/lwjgl3/src/main/java/me/stringdotjar/funkin/lwjgl3/Lwjgl3Launcher.java @@ -5,7 +5,7 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowAdapter; import me.stringdotjar.flixelgdx.Flixel; import me.stringdotjar.funkin.FunkinGame; -import me.stringdotjar.funkin.InitScreen; +import me.stringdotjar.funkin.InitState; import me.stringdotjar.funkin.util.FunkinConstants; /** Launches the desktop (LWJGL3) application. */ @@ -23,7 +23,7 @@ private static void createApplication() { FunkinConstants.WINDOW_TITLE, FunkinConstants.WINDOW_WIDTH, FunkinConstants.WINDOW_HEIGHT, - new InitScreen() + new InitState() ); Flixel.initialize(game); // This is VERY important to do before creating the application! var size = game.getWindowSize();