diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ebdeac336..7d9c46915 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ Please see the list below on how you can contribute to the project. Once you've decided what you would like to do, let me know about it first. This is just to make sure that the issue you want hasn't already been implemented, fixed or being worked on in newer versions. -Any new API or changes to existing API should be discussed first to avoid inconsistency. +Any new API or changes to existing API should be discussed to avoid inconsistency. * Proof read public documentation for errors, ambiguities and typos. * Crash test features for bugs or write a unit test for one. @@ -24,13 +24,12 @@ You can build FXGL from sources using [Maven](https://maven.apache.org/): mvn clean package ``` -This will compile and package all FXGL modules, as well as -create FXGL-x.y.z.jar, including sources, javadoc and uber-jar in the "fxgl/target/" directory. +This will create FXGL-x.y.z.jar, sources.jar, javadoc.jar and uber-jar in the "fxgl/target/" directory. ## Workflow Typically there are 2 branches: `master` and `x.y.z`. -The `master` branch is always *clean* and deployable, i.e. only for releases. +The `master` branch is for releases only. All the work goes to and stems from the `x.y.z` branch. Hence, after cloning you should always branch away from `x.y.z` and once your work is complete, pull a request back to `x.y.z`. @@ -56,10 +55,9 @@ The project uses the following guidelines (the list is likely to grow over time) * Tabs set to 4 spaces & consistent indentation. * Consistent naming conventions (no [Hungarian notation](https://en.wikipedia.org/wiki/Hungarian_notation)). -* Javadoc on all public and protected API. +* Javadoc on public and protected API (where appropriate). * Keep access to fields and methods as restricted as you can. -* [License](LICENSE) header in each new file. +* Short license header in each new file and `@author`. Code quality reports are available from [Codacy](https://www.codacy.com/app/AlmasB/FXGL/dashboard). If in doubt, skim through the existing source code to get a feel for it. -If a pull request violates too many guidelines it is unlikely to be merged. diff --git a/README.md b/README.md index 956808094..d0a082375 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![promo](https://raw.githubusercontent.com/AlmasB/git-server/master/storage/images/fxgl_promo.jpg) + ## What? JavaFX Game Development Framework @@ -30,8 +32,6 @@ JavaFX Game Development Framework * The list of features can be found in the [Wiki](https://github.com/AlmasB/FXGL/wiki/Core-Features) * [Showcase](http://almasb.github.io/FXGLGames/) -![promo](https://raw.githubusercontent.com/AlmasB/git-server/master/storage/images/fxgl_promo.jpg) - ## Minimal Example ```java @@ -52,11 +52,11 @@ public class BasicGameApp extends GameApplication { ## Getting Started -* Written tutorials - [Wiki](https://github.com/AlmasB/FXGL/wiki) -* Video tutorials - [YouTube](https://www.youtube.com/playlist?list=PL4h6ypqTi3RTiTuAQFKE6xwflnPKyFuPp) -* The [Samples](fxgl-samples) module is constantly updated with feature demos -* Advanced examples - [FXGLGames](https://github.com/AlmasB/FXGLGames) -* Pre-built game demos (standalone .jar) - [Games](https://github.com/AlmasB/FXGLGames/tree/master/binaries) +* [Wiki & Written tutorials](https://github.com/AlmasB/FXGL/wiki) +* [YouTube tutorials](https://www.youtube.com/playlist?list=PL4h6ypqTi3RTiTuAQFKE6xwflnPKyFuPp) +* [Feature demos](fxgl-samples) +* [Game demos](https://github.com/AlmasB/FXGLGames) (src) +* [Game demos](https://github.com/AlmasB/FXGLGames/tree/master/binaries) (.jar) ## Maven @@ -69,7 +69,7 @@ Already have `pom.xml`? Then add: com.github.almasb fxgl - 0.3.5 + 0.3.6 ``` @@ -86,7 +86,7 @@ repositories { } dependencies { - compile 'com.github.almasb:fxgl:0.3.5' + compile 'com.github.almasb:fxgl:0.3.6' } ``` diff --git a/fxgl-games/pom.xml b/fxgl-extra/pom.xml similarity index 95% rename from fxgl-games/pom.xml rename to fxgl-extra/pom.xml index ad6bdf3d7..ec3a58d79 100644 --- a/fxgl-games/pom.xml +++ b/fxgl-extra/pom.xml @@ -6,11 +6,11 @@ fxgl-framework com.github.almasb - 0.3.5 + 0.3.6 4.0.0 - fxgl-games + fxgl-extra diff --git a/fxgl/src/main/java/com/almasb/fxgl/scene/menu/CCTRMenu.java b/fxgl-extra/src/main/java/com/almasb/fxgl/scene/menu/CCTRMenu.java similarity index 100% rename from fxgl/src/main/java/com/almasb/fxgl/scene/menu/CCTRMenu.java rename to fxgl-extra/src/main/java/com/almasb/fxgl/scene/menu/CCTRMenu.java diff --git a/fxgl/src/main/java/com/almasb/fxgl/scene/menu/GTAVMenu.java b/fxgl-extra/src/main/java/com/almasb/fxgl/scene/menu/GTAVMenu.java similarity index 100% rename from fxgl/src/main/java/com/almasb/fxgl/scene/menu/GTAVMenu.java rename to fxgl-extra/src/main/java/com/almasb/fxgl/scene/menu/GTAVMenu.java diff --git a/fxgl-games/README.md b/fxgl-games/README.md deleted file mode 100644 index 84072db62..000000000 --- a/fxgl-games/README.md +++ /dev/null @@ -1,3 +0,0 @@ -**Note** that this module is **READ ONLY** and exists for quick testing. -This module should **NOT** be modified. -The actual repo containing game demos is [FXGLGames](https://github.com/AlmasB/FXGLGames). \ No newline at end of file diff --git a/fxgl-games/src/main/resources/assets/properties/system.properties b/fxgl-games/src/main/resources/assets/properties/system.properties deleted file mode 100644 index 08a924bf5..000000000 --- a/fxgl-games/src/main/resources/assets/properties/system.properties +++ /dev/null @@ -1,7 +0,0 @@ -# -# FXGL - JavaFX Game Library. The MIT License (MIT). -# Copyright (c) AlmasB (almaslvl@gmail.com). -# See LICENSE for details. -# - -ui.font = kenvector_future_thin.ttf \ No newline at end of file diff --git a/fxgl-games/src/main/resources/assets/textures/Bullet.png b/fxgl-games/src/main/resources/assets/textures/Bullet.png deleted file mode 100644 index 8ff1eef7b..000000000 Binary files a/fxgl-games/src/main/resources/assets/textures/Bullet.png and /dev/null differ diff --git a/fxgl-games/src/main/resources/assets/textures/Player.png b/fxgl-games/src/main/resources/assets/textures/Player.png deleted file mode 100644 index 7bbc93d4a..000000000 Binary files a/fxgl-games/src/main/resources/assets/textures/Player.png and /dev/null differ diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/explosion.png b/fxgl-games/src/main/resources/assets/textures/spaceinvaders/explosion.png deleted file mode 100644 index 96b0f94ed..000000000 Binary files a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/explosion.png and /dev/null differ diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/life.png b/fxgl-games/src/main/resources/assets/textures/spaceinvaders/life.png deleted file mode 100644 index 1b435b31d..000000000 Binary files a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/life.png and /dev/null differ diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/player2.png b/fxgl-games/src/main/resources/assets/textures/spaceinvaders/player2.png deleted file mode 100644 index f34faf066..000000000 Binary files a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/player2.png and /dev/null differ diff --git a/fxgl-games/src/main/resources/assets/textures/tank_bullet.png b/fxgl-games/src/main/resources/assets/textures/tank_bullet.png deleted file mode 100644 index 1e5914f53..000000000 Binary files a/fxgl-games/src/main/resources/assets/textures/tank_bullet.png and /dev/null differ diff --git a/fxgl-samples/pom.xml b/fxgl-samples/pom.xml index a9881298e..07be27733 100644 --- a/fxgl-samples/pom.xml +++ b/fxgl-samples/pom.xml @@ -6,7 +6,7 @@ fxgl-framework com.github.almasb - 0.3.5 + 0.3.6 4.0.0 @@ -15,7 +15,7 @@ com.github.almasb - fxgl + fxgl-extra ${fxgl.version} diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/breakout/BreakoutApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/BreakoutApp.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/breakout/BreakoutApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/BreakoutApp.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/breakout/BreakoutFactory.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/BreakoutFactory.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/breakout/BreakoutFactory.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/BreakoutFactory.java index 617f12894..8a2812b09 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/breakout/BreakoutFactory.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/BreakoutFactory.java @@ -16,11 +16,11 @@ import com.almasb.fxgl.physics.BoundingShape; import com.almasb.fxgl.physics.HitBox; import com.almasb.fxgl.physics.PhysicsComponent; +import com.almasb.fxgl.physics.box2d.dynamics.BodyType; +import com.almasb.fxgl.physics.box2d.dynamics.FixtureDef; import com.almasb.fxglgames.breakout.control.BallControl; import com.almasb.fxglgames.breakout.control.BatControl; import com.almasb.fxglgames.breakout.control.BrickControl; -import com.almasb.fxgl.physics.box2d.dynamics.BodyType; -import com.almasb.fxgl.physics.box2d.dynamics.FixtureDef; /** * @author Almas Baimagambetov (almaslvl@gmail.com) diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/breakout/BreakoutType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/BreakoutType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/breakout/BreakoutType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/BreakoutType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/breakout/control/BallControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/control/BallControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/breakout/control/BallControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/control/BallControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/breakout/control/BatControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/control/BatControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/breakout/control/BatControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/control/BatControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/breakout/control/BrickControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/control/BrickControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/breakout/control/BrickControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/breakout/control/BrickControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/drop/BucketControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/drop/BucketControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/drop/BucketControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/drop/BucketControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/drop/DropApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/drop/DropApp.java similarity index 75% rename from fxgl-games/src/main/java/com/almasb/fxglgames/drop/DropApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/drop/DropApp.java index 4dc213335..867504989 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/drop/DropApp.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/drop/DropApp.java @@ -7,16 +7,21 @@ package com.almasb.fxglgames.drop; import com.almasb.fxgl.app.ApplicationMode; +import com.almasb.fxgl.app.DSLKt; import com.almasb.fxgl.app.GameApplication; import com.almasb.fxgl.ecs.Entity; +import com.almasb.fxgl.input.Input; import com.almasb.fxgl.input.UserAction; import com.almasb.fxgl.physics.CollisionHandler; import com.almasb.fxgl.physics.PhysicsWorld; -import com.almasb.fxgl.input.Input; import com.almasb.fxgl.settings.GameSettings; import javafx.scene.input.KeyCode; import javafx.util.Duration; +import static com.almasb.fxgl.app.DSLKt.onCollision; +import static com.almasb.fxgl.app.DSLKt.onCollisionBegin; +import static com.almasb.fxgl.app.DSLKt.play; + /** * This is an FXGL version of the libGDX simple game tutorial which can be found * here - https://github.com/libgdx/libgdx/wiki/A-simple-game @@ -72,16 +77,21 @@ protected void initGame() { @Override protected void initPhysics() { - PhysicsWorld physicsWorld = getPhysicsWorld(); - - physicsWorld.addCollisionHandler(new CollisionHandler(DropType.DROPLET, DropType.BUCKET) { - @Override - protected void onCollisionBegin(Entity droplet, Entity bucket) { - droplet.removeFromWorld(); - - getAudioPlayer().playSound("drop/drop.wav"); - } + onCollisionBegin(DropType.DROPLET, DropType.BUCKET, (droplet, bucket) -> { + droplet.removeFromWorld(); + play("drop/drop.wav"); }); + +// PhysicsWorld physicsWorld = getPhysicsWorld(); +// +// physicsWorld.addCollisionHandler(new CollisionHandler(DropType.DROPLET, DropType.BUCKET) { +// @Override +// protected void onCollisionBegin(Entity droplet, Entity bucket) { +// droplet.removeFromWorld(); +// +// getAudioPlayer().playSound("drop/drop.wav"); +// } +// }); } public static void main(String[] args) { diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/drop/DropFactory.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/drop/DropFactory.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/drop/DropFactory.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/drop/DropFactory.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/drop/DropType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/drop/DropType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/drop/DropType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/drop/DropType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/drop/DropletControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/drop/DropletControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/drop/DropletControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/drop/DropletControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/flappy/ColorChangingControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/ColorChangingControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/flappy/ColorChangingControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/ColorChangingControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/flappy/EntityType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/EntityType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/flappy/EntityType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/EntityType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/flappy/FlappyBirdApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/FlappyBirdApp.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/flappy/FlappyBirdApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/FlappyBirdApp.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/flappy/PlayerControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/PlayerControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/flappy/PlayerControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/PlayerControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/flappy/WallBuildingControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/WallBuildingControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/flappy/WallBuildingControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/flappy/WallBuildingControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsApp.java similarity index 94% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsApp.java index 72b098534..bb4bd705e 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsApp.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsApp.java @@ -7,14 +7,15 @@ import com.almasb.fxgl.app.ApplicationMode; import com.almasb.fxgl.app.GameApplication; +import com.almasb.fxgl.audio.Music; import com.almasb.fxgl.ecs.Entity; import com.almasb.fxgl.entity.Entities; import com.almasb.fxgl.entity.EntityView; import com.almasb.fxgl.entity.GameEntity; +import com.almasb.fxgl.input.Input; import com.almasb.fxgl.input.UserAction; import com.almasb.fxgl.physics.CollisionHandler; import com.almasb.fxgl.physics.PhysicsWorld; -import com.almasb.fxgl.input.Input; import com.almasb.fxgl.settings.GameSettings; import com.almasb.fxgl.ui.WheelMenu; import com.almasb.fxglgames.geowars.component.GraphicsComponent; @@ -37,6 +38,9 @@ import java.util.Map; +import static com.almasb.fxgl.app.DSLKt.getd; +import static com.almasb.fxgl.app.DSLKt.set; + /** * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) */ @@ -120,6 +124,13 @@ protected void onActionBegin() { openWeaponMenu(); } }, MouseButton.SECONDARY); + + input.addAction(new UserAction("Time") { + @Override + protected void onActionBegin() { + set("timeRatio", getd("timeRatio") == 1.0 ? 0.05 : 1.0); + } + }, KeyCode.G); } @Override @@ -128,9 +139,12 @@ protected void initGameVars(Map vars) { vars.put("multiplier", 1); vars.put("kills", 0); vars.put("time", 180); + vars.put("timeRatio", 1.0); vars.put("weaponType", WeaponType.NORMAL); } + private Music music; + @Override protected void initGame() { getAudioPlayer().setGlobalSoundVolume(0.2); @@ -145,7 +159,16 @@ protected void initGame() { getMasterTimer().runAtInterval(() -> getGameWorld().spawn("Crystal", getRandomPoint()), Duration.seconds(4)); getMasterTimer().runAtInterval(() -> getGameState().increment("time", -1), Duration.seconds(1)); - getAudioPlayer().playMusic("bgm.mp3"); + music = getAssetLoader().loadMusic("bgm.mp3"); + + getGameState().addListener("timeRatio", (prev, now) -> { + if (now != 1.0) { + now = 0.85; + } + music.setRate(now); + }); + + getAudioPlayer().playMusic(music); } @Override diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsConfig.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsConfig.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsConfig.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsConfig.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsFactory.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsFactory.java similarity index 89% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsFactory.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsFactory.java index b763f61f9..caf6e5312 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsFactory.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsFactory.java @@ -10,6 +10,7 @@ import com.almasb.fxgl.annotation.Spawns; import com.almasb.fxgl.app.FXGL; import com.almasb.fxgl.core.math.FXGLMath; +import com.almasb.fxgl.ecs.component.TimeComponent; import com.almasb.fxgl.entity.Entities; import com.almasb.fxgl.entity.EntityFactory; import com.almasb.fxgl.entity.GameEntity; @@ -77,11 +78,14 @@ public GameEntity spawnPlayer(SpawnData data) { public GameEntity spawnBullet(SpawnData data) { FXGL.getAudioPlayer().playSound("shoot" + (int) (Math.random() * 8 + 1) + ".wav"); + TimeComponent time = new TimeComponent(); + time.valueProperty().bind(FXGL.getApp().getGameState().doubleProperty("timeRatio")); + return Entities.builder() .type(GeoWarsType.BULLET) .from(data) .viewFromTextureWithBBox("Bullet.png") - .with(new CollidableComponent(true)) + .with(new CollidableComponent(true), time) .with(new ProjectileControl(data.get("direction"), 600), new BulletControl(FXGL.getAppCast().getGrid()), new OffscreenCleanControl()) @@ -95,12 +99,15 @@ public GameEntity spawnWanderer(SpawnData data) { int moveSpeed = red ? config.getRedEnemyMoveSpeed() : FXGLMath.random(100, config.getWandererMaxMoveSpeed()); + TimeComponent time = new TimeComponent(); + time.valueProperty().bind(FXGL.getApp().getGameState().doubleProperty("timeRatio")); + return Entities.builder() .type(GeoWarsType.WANDERER) .at(getRandomSpawnPoint()) .viewFromTextureWithBBox(red ? "RedWanderer.png" : "Wanderer.png") .with(new HPComponent(red ? config.getRedEnemyHealth() : config.getEnemyHealth()), - new CollidableComponent(true)) + new CollidableComponent(true), time) .with(new WandererControl(moveSpeed)) .build(); } @@ -112,12 +119,15 @@ public GameEntity spawnSeeker(SpawnData data) { int moveSpeed = red ? config.getRedEnemyMoveSpeed() : FXGLMath.random(150, config.getSeekerMaxMoveSpeed()); + TimeComponent time = new TimeComponent(); + time.valueProperty().bind(FXGL.getApp().getGameState().doubleProperty("timeRatio")); + return Entities.builder() .type(GeoWarsType.SEEKER) .at(getRandomSpawnPoint()) .viewFromTextureWithBBox(red ? "RedSeeker.png" : "Seeker.png") .with(new HPComponent(red ? config.getRedEnemyHealth() : config.getEnemyHealth()), - new CollidableComponent(true)) + new CollidableComponent(true), time) .with(new SeekerControl(FXGL.getAppCast().getPlayer(), moveSpeed)) .build(); } diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/GeoWarsType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/GeoWarsType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/WeaponType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/WeaponType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/WeaponType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/WeaponType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/collision/PlayerCrystalHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/collision/PlayerCrystalHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/collision/PlayerCrystalHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/collision/PlayerCrystalHandler.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/component/GraphicsComponent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/component/GraphicsComponent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/component/GraphicsComponent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/component/GraphicsComponent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/component/HPComponent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/component/HPComponent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/component/HPComponent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/component/HPComponent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/component/OldPositionComponent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/component/OldPositionComponent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/component/OldPositionComponent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/component/OldPositionComponent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/BulletControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/BulletControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/BulletControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/BulletControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/ExhaustParticleControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/ExhaustParticleControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/ExhaustParticleControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/ExhaustParticleControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/GraphicsUpdateControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/GraphicsUpdateControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/GraphicsUpdateControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/GraphicsUpdateControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/KeepOnScreenControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/KeepOnScreenControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/KeepOnScreenControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/KeepOnScreenControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/ParticleControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/ParticleControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/ParticleControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/ParticleControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/PlayerControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/PlayerControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/PlayerControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/PlayerControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/RicochetControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/RicochetControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/RicochetControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/RicochetControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/SeekerControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/SeekerControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/SeekerControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/SeekerControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/WandererControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/WandererControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/control/WandererControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/control/WandererControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/AdditionalLineControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/AdditionalLineControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/AdditionalLineControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/AdditionalLineControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/Grid.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/Grid.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/Grid.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/Grid.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/GridControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/GridControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/GridControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/GridControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/LineControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/LineControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/LineControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/LineControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/PointMass.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/PointMass.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/PointMass.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/PointMass.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/Spring.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/Spring.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/geowars/grid/Spring.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/geowars/grid/Spring.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/PacmanApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/PacmanApp.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/PacmanApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/PacmanApp.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/PacmanFactory.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/PacmanFactory.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/PacmanFactory.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/PacmanFactory.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/PacmanType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/PacmanType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/PacmanType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/PacmanType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/PacmanUIController.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/PacmanUIController.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/PacmanUIController.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/PacmanUIController.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/ai/MoveAction.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/ai/MoveAction.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/ai/MoveAction.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/ai/MoveAction.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/ai/PlayerCloseCondition.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/ai/PlayerCloseCondition.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/ai/PlayerCloseCondition.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/ai/PlayerCloseCondition.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/ai/RandomMoveAction.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/ai/RandomMoveAction.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/ai/RandomMoveAction.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/ai/RandomMoveAction.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/collision/PlayerCoinHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/collision/PlayerCoinHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/collision/PlayerCoinHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/collision/PlayerCoinHandler.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/collision/PlayerEnemyHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/collision/PlayerEnemyHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/collision/PlayerEnemyHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/collision/PlayerEnemyHandler.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/AStarEnemyControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/AStarEnemyControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/AStarEnemyControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/AStarEnemyControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/DiffEnemyControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/DiffEnemyControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/DiffEnemyControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/DiffEnemyControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/EnemyControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/EnemyControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/EnemyControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/EnemyControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/MoveDirection.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/MoveDirection.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/MoveDirection.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/MoveDirection.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/PaletteChangingControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/PaletteChangingControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/PaletteChangingControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/PaletteChangingControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/PlayerControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/PlayerControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pacman/control/PlayerControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pacman/control/PlayerControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/AppController.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/AppController.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/AppController.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/AppController.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/BallControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/BallControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/BallControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/BallControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/BatControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/BatControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/BatControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/BatControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/ClientMessage.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/ClientMessage.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/ClientMessage.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/ClientMessage.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/EnemyBatControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/EnemyBatControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/EnemyBatControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/EnemyBatControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/EntityType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/EntityType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/EntityType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/EntityType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/GameMode.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/GameMode.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/GameMode.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/GameMode.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/PongApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/PongApp.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/PongApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/PongApp.java index dadbaf691..8af72db90 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/PongApp.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/PongApp.java @@ -17,11 +17,11 @@ import com.almasb.fxgl.entity.component.CollidableComponent; import com.almasb.fxgl.entity.component.TypeComponent; import com.almasb.fxgl.input.ActionType; +import com.almasb.fxgl.input.Input; import com.almasb.fxgl.input.InputMapping; import com.almasb.fxgl.net.Server; import com.almasb.fxgl.physics.CollisionHandler; import com.almasb.fxgl.physics.HitBox; -import com.almasb.fxgl.input.Input; import com.almasb.fxgl.settings.GameSettings; import com.almasb.fxgl.settings.MenuItem; import com.almasb.fxgl.ui.UI; diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/PongFactory.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/PongFactory.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/PongFactory.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/PongFactory.java index b1439dad1..a6e107965 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/PongFactory.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/PongFactory.java @@ -12,11 +12,11 @@ import com.almasb.fxgl.physics.BoundingShape; import com.almasb.fxgl.physics.HitBox; import com.almasb.fxgl.physics.PhysicsComponent; +import com.almasb.fxgl.physics.box2d.dynamics.BodyType; +import com.almasb.fxgl.physics.box2d.dynamics.FixtureDef; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.shape.Rectangle; -import com.almasb.fxgl.physics.box2d.dynamics.BodyType; -import com.almasb.fxgl.physics.box2d.dynamics.FixtureDef; /** * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/pong/ServerMessage.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/pong/ServerMessage.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/pong/ServerMessage.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/pong/ServerMessage.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/BonusType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/BonusType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/BonusType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/BonusType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/Config.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/Config.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/Config.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/Config.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/ExplosionEmitter.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/ExplosionEmitter.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/ExplosionEmitter.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/ExplosionEmitter.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/GameController.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/GameController.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/GameController.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/GameController.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SaveData.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SaveData.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SaveData.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SaveData.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersApp.java similarity index 96% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersApp.java index aeea124c8..9c875874c 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersApp.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersApp.java @@ -9,6 +9,7 @@ import com.almasb.fxgl.annotation.Handles; import com.almasb.fxgl.annotation.OnUserAction; import com.almasb.fxgl.app.ApplicationMode; +import com.almasb.fxgl.app.DSLKt; import com.almasb.fxgl.app.FXGL; import com.almasb.fxgl.app.GameApplication; import com.almasb.fxgl.core.logging.Logger; @@ -17,9 +18,9 @@ import com.almasb.fxgl.entity.SpawnData; import com.almasb.fxgl.gameplay.Achievement; import com.almasb.fxgl.gameplay.AchievementManager; +import com.almasb.fxgl.input.Input; import com.almasb.fxgl.input.InputMapping; import com.almasb.fxgl.io.FS; -import com.almasb.fxgl.input.Input; import com.almasb.fxgl.settings.GameSettings; import com.almasb.fxgl.ui.UI; import com.almasb.fxglgames.spaceinvaders.control.PlayerControl; @@ -36,6 +37,7 @@ import java.util.Map; import java.util.stream.IntStream; +import static com.almasb.fxgl.app.DSLKt.*; import static com.almasb.fxglgames.spaceinvaders.Config.*; /** @@ -291,6 +293,8 @@ private void playTutorial() { @Handles(eventType = "PLAYER_GOT_HIT") public void onPlayerGotHit(GameEvent event) { + getGameScene().getViewport().shake(12); + getGameState().increment("lives", -1); uiController.loseLife(); @@ -340,6 +344,19 @@ public void onEnemyReachedEnd(GameEvent event) { nextLevel(); } + public void onEnemyReachedEndDSL(GameEvent event) { + inc("enemiesKilled", +1); + + inc("lives", -1); + uiController.loseLife(); + + if (geti("lives") == 0) + showGameOver(); + + if (geti("enemiesKilled") == ENEMIES_PER_LEVEL) + nextLevel(); + } + @Handles(eventType = "ANY") public void onBonusPickup(BonusPickupEvent event) { switch (event.getType()) { diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersFactory.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersFactory.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersFactory.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersFactory.java index c891821e2..79dde439e 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersFactory.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersFactory.java @@ -18,6 +18,8 @@ import com.almasb.fxgl.physics.BoundingShape; import com.almasb.fxgl.physics.HitBox; import com.almasb.fxgl.physics.PhysicsComponent; +import com.almasb.fxgl.physics.box2d.dynamics.BodyType; +import com.almasb.fxgl.physics.box2d.dynamics.FixtureDef; import com.almasb.fxgl.service.AssetLoader; import com.almasb.fxgl.texture.Texture; import com.almasb.fxglgames.spaceinvaders.component.HPComponent; @@ -33,8 +35,6 @@ import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.util.Duration; -import com.almasb.fxgl.physics.box2d.dynamics.BodyType; -import com.almasb.fxgl.physics.box2d.dynamics.FixtureDef; import java.util.Random; diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/SpaceInvadersType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BonusPlayerHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BonusPlayerHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BonusPlayerHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BonusPlayerHandler.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletEnemyHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletEnemyHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletEnemyHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletEnemyHandler.java index ebe866065..980f1ff66 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletEnemyHandler.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletEnemyHandler.java @@ -9,9 +9,9 @@ import com.almasb.fxgl.annotation.AddCollisionHandler; import com.almasb.fxgl.app.FXGL; import com.almasb.fxgl.ecs.Entity; +import com.almasb.fxgl.ecs.GameWorld; import com.almasb.fxgl.effect.ParticleControl; import com.almasb.fxgl.entity.Entities; -import com.almasb.fxgl.ecs.GameWorld; import com.almasb.fxgl.entity.component.PositionComponent; import com.almasb.fxgl.entity.component.ViewComponent; import com.almasb.fxgl.entity.control.ExpireCleanControl; diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletPlayerHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletPlayerHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletPlayerHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletPlayerHandler.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletWallHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletWallHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletWallHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/collision/BulletWallHandler.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/component/HPComponent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/component/HPComponent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/component/HPComponent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/component/HPComponent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/component/InvincibleComponent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/component/InvincibleComponent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/component/InvincibleComponent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/component/InvincibleComponent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/component/OwnerComponent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/component/OwnerComponent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/component/OwnerComponent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/component/OwnerComponent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/component/SubTypeComponent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/component/SubTypeComponent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/component/SubTypeComponent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/component/SubTypeComponent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/BonusControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/BonusControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/BonusControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/BonusControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/BulletControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/BulletControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/BulletControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/BulletControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/EnemyControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/EnemyControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/EnemyControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/EnemyControl.java index b3e859945..27e41843f 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/EnemyControl.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/EnemyControl.java @@ -10,8 +10,8 @@ import com.almasb.fxgl.core.math.FXGLMath; import com.almasb.fxgl.ecs.Control; import com.almasb.fxgl.ecs.Entity; -import com.almasb.fxgl.entity.Entities; import com.almasb.fxgl.ecs.GameWorld; +import com.almasb.fxgl.entity.Entities; import com.almasb.fxgl.entity.SpawnData; import com.almasb.fxgl.entity.component.BoundingBoxComponent; import com.almasb.fxgl.entity.component.PositionComponent; diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/LaserHitControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/LaserHitControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/LaserHitControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/LaserHitControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/MeteorControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/MeteorControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/MeteorControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/MeteorControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/PlayerControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/PlayerControl.java similarity index 96% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/PlayerControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/PlayerControl.java index c7e791c00..9d8890d06 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/control/PlayerControl.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/control/PlayerControl.java @@ -11,7 +11,10 @@ import com.almasb.fxgl.ecs.Entity; import com.almasb.fxgl.ecs.GameWorld; import com.almasb.fxgl.ecs.component.Required; -import com.almasb.fxgl.entity.*; +import com.almasb.fxgl.entity.Entities; +import com.almasb.fxgl.entity.EntityView; +import com.almasb.fxgl.entity.RenderLayer; +import com.almasb.fxgl.entity.SpawnData; import com.almasb.fxgl.entity.component.BoundingBoxComponent; import com.almasb.fxgl.entity.component.PositionComponent; import com.almasb.fxgl.entity.component.ViewComponent; diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/event/BonusPickupEvent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/event/BonusPickupEvent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/event/BonusPickupEvent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/event/BonusPickupEvent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/event/GameEvent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/event/GameEvent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/event/GameEvent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/event/GameEvent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/tutorial/Tutorial.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/tutorial/Tutorial.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/tutorial/Tutorial.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/tutorial/Tutorial.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/tutorial/TutorialStep.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/tutorial/TutorialStep.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spaceinvaders/tutorial/TutorialStep.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spaceinvaders/tutorial/TutorialStep.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerApp.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerApp.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerFactory.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerFactory.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerFactory.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerFactory.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/SpaceRunnerType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/collision/BulletEnemyHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/collision/BulletEnemyHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/collision/BulletEnemyHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/collision/BulletEnemyHandler.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/control/EnemyControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/control/EnemyControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/control/EnemyControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/control/EnemyControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/control/KeepOnScreenControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/control/KeepOnScreenControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/control/KeepOnScreenControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/control/KeepOnScreenControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/control/PlayerControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/control/PlayerControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/spacerunner/control/PlayerControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/spacerunner/control/PlayerControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TicTacToeApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TicTacToeApp.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TicTacToeApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TicTacToeApp.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileCombo.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileCombo.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileCombo.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileCombo.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileEntity.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileEntity.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileEntity.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileEntity.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileValue.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileValue.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileValue.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileValue.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileValueComponent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileValueComponent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileValueComponent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileValueComponent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileView.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileView.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/TileView.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/TileView.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/control/TileControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/control/TileControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/control/TileControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/control/TileControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/EnemyControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/EnemyControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/EnemyControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/EnemyControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/MinimaxControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/MinimaxControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/MinimaxControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/MinimaxControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/RuleBasedControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/RuleBasedControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/RuleBasedControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/control/enemy/RuleBasedControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/event/AIEvent.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/event/AIEvent.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/tictactoe/event/AIEvent.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/tictactoe/event/AIEvent.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/ArrowControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/ArrowControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/ArrowControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/ArrowControl.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/CharacterControl.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/CharacterControl.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/CharacterControl.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/CharacterControl.java index e7b01973c..b0cd142f0 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/CharacterControl.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/CharacterControl.java @@ -8,8 +8,8 @@ import com.almasb.fxgl.ecs.Control; import com.almasb.fxgl.ecs.Entity; -import com.almasb.fxgl.entity.Entities; import com.almasb.fxgl.ecs.GameWorld; +import com.almasb.fxgl.entity.Entities; import com.almasb.fxgl.entity.SpawnData; import com.almasb.fxgl.entity.component.PositionComponent; import com.almasb.fxgl.physics.PhysicsComponent; diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/EntityType.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/EntityType.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/EntityType.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/EntityType.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/TowerfallApp.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/TowerfallApp.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/TowerfallApp.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/TowerfallApp.java index 46ac97604..9d8fc952f 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/TowerfallApp.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/TowerfallApp.java @@ -14,9 +14,9 @@ import com.almasb.fxgl.gameplay.rpg.quest.QuestObjective; import com.almasb.fxgl.gameplay.rpg.quest.QuestPane; import com.almasb.fxgl.gameplay.rpg.quest.QuestWindow; +import com.almasb.fxgl.input.Input; import com.almasb.fxgl.input.UserAction; import com.almasb.fxgl.parser.text.TextLevelParser; -import com.almasb.fxgl.input.Input; import com.almasb.fxgl.settings.GameSettings; import javafx.scene.input.KeyCode; import javafx.util.Duration; diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/TowerfallFactory.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/TowerfallFactory.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/TowerfallFactory.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/TowerfallFactory.java index 68d7dcab2..e041f2446 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/TowerfallFactory.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/TowerfallFactory.java @@ -20,6 +20,7 @@ import com.almasb.fxgl.physics.BoundingShape; import com.almasb.fxgl.physics.HitBox; import com.almasb.fxgl.physics.PhysicsComponent; +import com.almasb.fxgl.physics.box2d.dynamics.BodyType; import javafx.geometry.Point2D; import javafx.scene.paint.Color; import javafx.scene.paint.CycleMethod; @@ -27,7 +28,6 @@ import javafx.scene.paint.Stop; import javafx.scene.shape.Rectangle; import javafx.util.Duration; -import com.almasb.fxgl.physics.box2d.dynamics.BodyType; /** * Arrow sprite from https://www.spriters-resource.com/game_boy_advance/justiceleagueheroestheflash/sheet/18563/ diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/ai/AttackTask.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/ai/AttackTask.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/ai/AttackTask.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/ai/AttackTask.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/ai/MoveTask.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/ai/MoveTask.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/ai/MoveTask.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/ai/MoveTask.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/ai/TargetFarCondition.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/ai/TargetFarCondition.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/ai/TargetFarCondition.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/ai/TargetFarCondition.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowEnemyHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowEnemyHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowEnemyHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowEnemyHandler.java diff --git a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowPlatformHandler.java b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowPlatformHandler.java similarity index 100% rename from fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowPlatformHandler.java rename to fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowPlatformHandler.java index c7f81afef..3b4609d5e 100644 --- a/fxgl-games/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowPlatformHandler.java +++ b/fxgl-samples/src/main/java/com/almasb/fxglgames/towerfall/collision/ArrowPlatformHandler.java @@ -17,14 +17,14 @@ import com.almasb.fxgl.entity.component.CollidableComponent; import com.almasb.fxgl.physics.CollisionHandler; import com.almasb.fxgl.physics.PhysicsComponent; +import com.almasb.fxgl.physics.box2d.dynamics.BodyType; +import com.almasb.fxgl.physics.box2d.dynamics.FixtureDef; import com.almasb.fxglgames.towerfall.ArrowControl; import com.almasb.fxglgames.towerfall.EntityType; import javafx.geometry.Rectangle2D; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.image.WritableImage; -import com.almasb.fxgl.physics.box2d.dynamics.BodyType; -import com.almasb.fxgl.physics.box2d.dynamics.FixtureDef; /** * @author Almas Baimagambetov (almaslvl@gmail.com) diff --git a/fxgl-samples/src/main/java/s03entities/AnimColorSample.java b/fxgl-samples/src/main/java/s03entities/AnimColorSample.java new file mode 100644 index 000000000..8a4d3adad --- /dev/null +++ b/fxgl-samples/src/main/java/s03entities/AnimColorSample.java @@ -0,0 +1,61 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package s03entities; + +import com.almasb.fxgl.app.GameApplication; +import com.almasb.fxgl.entity.Entities; +import com.almasb.fxgl.entity.GameEntity; +import com.almasb.fxgl.entity.component.ColorComponent; +import com.almasb.fxgl.settings.GameSettings; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; +import javafx.util.Duration; + +/** + * This is an example of a minimalistic FXGL game application. + * + * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) + */ +public class AnimColorSample extends GameApplication { + + @Override + protected void initSettings(GameSettings settings) { + settings.setWidth(800); + settings.setHeight(600); + settings.setTitle("AnimColorSample"); + settings.setVersion("0.1"); + settings.setIntroEnabled(false); + settings.setMenuEnabled(false); + settings.setCloseConfirmation(false); + settings.setProfilingEnabled(false); + } + + @Override + protected void initGame() { + Rectangle playerView = new Rectangle(40, 40); + + GameEntity player = Entities.builder() + .at(100, 100) + .viewFromNode(playerView) + .with(new ColorComponent()) + .buildAndAttach(); + + playerView.fillProperty().bind(player.getComponent(ColorComponent.class).valueProperty()); + + Entities.animationBuilder() + .duration(Duration.seconds(2)) + .repeat(4) + .color(player) + .fromColor(Color.AQUA) + .toColor(Color.BURLYWOOD) + .buildAndPlay(); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/fxgl-samples/src/main/java/s03entities/AnimationSample4.java b/fxgl-samples/src/main/java/s03entities/AnimationSample4.java new file mode 100644 index 000000000..ca1dc7ca3 --- /dev/null +++ b/fxgl-samples/src/main/java/s03entities/AnimationSample4.java @@ -0,0 +1,81 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package s03entities; + +import com.almasb.fxgl.animation.Animation; +import com.almasb.fxgl.animation.ParallelAnimation; +import com.almasb.fxgl.animation.SequentialAnimation; +import com.almasb.fxgl.app.ApplicationMode; +import com.almasb.fxgl.app.GameApplication; +import com.almasb.fxgl.entity.Entities; +import com.almasb.fxgl.entity.GameEntity; +import com.almasb.fxgl.settings.GameSettings; +import javafx.geometry.Point2D; +import javafx.scene.shape.Rectangle; +import javafx.scene.text.Text; +import javafx.util.Duration; + +/** + * Shows how to init a basic game object and attach it to the world + * using fluent API. + * + * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) + */ +public class AnimationSample4 extends GameApplication { + + // 1. define types of entities in the game using Enum + private enum Type { + PLAYER + } + + // make the field instance level + // but do NOT init here for properly functioning save-load system + private GameEntity player; + + @Override + protected void initSettings(GameSettings settings) { + settings.setWidth(800); + settings.setHeight(600); + settings.setTitle("AnimationSample4"); + settings.setVersion("0.1"); + settings.setFullScreen(false); + settings.setIntroEnabled(false); + settings.setMenuEnabled(false); + settings.setProfilingEnabled(false); + settings.setCloseConfirmation(false); + settings.setApplicationMode(ApplicationMode.DEVELOPER); + } + + @Override + protected void initGame() { + Rectangle rect1 = new Rectangle(40, 40); + rect1.setTranslateY(50); + + Rectangle rect2 = new Rectangle(40, 40); + rect2.setTranslateY(100); + + Rectangle rect3 = new Rectangle(40, 40); + rect3.setTranslateY(150); + + getGameScene().addUINodes(rect1, rect2, rect3); + + Animation anim1 = getUIFactory().translate(rect1, new Point2D(100, 50), Duration.seconds(1)); + Animation anim2 = getUIFactory().translate(rect2, new Point2D(100, 100), Duration.seconds(1.5)); + Animation anim3 = getUIFactory().translate(rect3, new Point2D(100, 150), Duration.seconds(0.4)); + + ParallelAnimation anim = new ParallelAnimation(anim1, anim2, anim3); + //SequentialAnimation anim = new SequentialAnimation(anim1, anim2, anim3); + anim.setCycleCount(2); + anim.setAutoReverse(true); + anim.setOnFinished(() -> System.out.println("finished")); + anim.start(getStateMachine().getPlayState()); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/fxgl-samples/src/main/java/s03entities/InterpolatorSample.java b/fxgl-samples/src/main/java/s03entities/InterpolatorSample.java new file mode 100644 index 000000000..b34a50cec --- /dev/null +++ b/fxgl-samples/src/main/java/s03entities/InterpolatorSample.java @@ -0,0 +1,128 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package s03entities; + +import com.almasb.fxgl.animation.EasingInterpolator; +import com.almasb.fxgl.animation.Interpolators; +import com.almasb.fxgl.app.ApplicationMode; +import com.almasb.fxgl.app.GameApplication; +import com.almasb.fxgl.entity.Entities; +import com.almasb.fxgl.entity.GameEntity; +import com.almasb.fxgl.input.UserAction; +import com.almasb.fxgl.settings.GameSettings; +import com.almasb.fxgl.ui.LevelText; +import javafx.animation.Interpolator; +import javafx.geometry.Point2D; +import javafx.scene.control.Button; +import javafx.scene.control.RadioButton; +import javafx.scene.control.Toggle; +import javafx.scene.control.ToggleGroup; +import javafx.scene.input.KeyCode; +import javafx.scene.layout.VBox; +import javafx.util.Duration; + +import java.util.*; + +import static com.almasb.fxgl.app.DSLKt.set; + +/** + * + * + * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) + */ +public class InterpolatorSample extends GameApplication { + + private GameEntity player; + + @Override + protected void initSettings(GameSettings settings) { + settings.setWidth(800); + settings.setHeight(600); + settings.setTitle("InterpolatorSample"); + settings.setVersion("0.1"); + settings.setFullScreen(false); + settings.setIntroEnabled(false); + settings.setMenuEnabled(false); + settings.setProfilingEnabled(false); + settings.setCloseConfirmation(false); + settings.setApplicationMode(ApplicationMode.DEVELOPER); + } + + @Override + protected void initGameVars(Map vars) { + vars.put("canPlay", true); + } + + @Override + protected void initGame() { + LevelText text = new LevelText("Level 1"); + text.animateIn(); + + player = Entities.builder() + .viewFromNode(text) + .buildAndAttach(getGameWorld()); + } + + private ToggleGroup group = new ToggleGroup(); + + @Override + protected void initUI() { + VBox vbox = new VBox(5); + + for (EasingInterpolator interpolator : Interpolators.values()) { + Button btn = new Button(interpolator.toString()); + btn.disableProperty().bind(getGameState().booleanProperty("canPlay").not()); + btn.setOnAction(e -> playAnimation(interpolator)); + + vbox.getChildren().add(btn); + } + + RadioButton btn1 = new RadioButton("Ease In"); + RadioButton btn2 = new RadioButton("Ease Out"); + RadioButton btn3 = new RadioButton("Ease In Out"); + btn1.setToggleGroup(group); + btn2.setToggleGroup(group); + btn3.setToggleGroup(group); + btn2.setSelected(true); + + vbox.getChildren().addAll(btn1, btn2, btn3); + + vbox.setTranslateX(650); + getGameScene().addUINode(vbox); + } + + private void playAnimation(EasingInterpolator interpolator) { + set("canPlay", false); + + Interpolator ease = getEase(interpolator); + + Entities.animationBuilder() + .interpolator(ease) + .duration(Duration.seconds(2.3)) + .onFinished(() -> set("canPlay", true)) + .translate(player) + .from(new Point2D(0, -150)) + .to(new Point2D(0, 300)) + .buildAndPlay(); + } + + private Interpolator getEase(EasingInterpolator interpolator) { + String name = ((RadioButton) group.getSelectedToggle()).getText(); + + if (name.equals("Ease In")) { + return interpolator.EASE_IN(); + } else if (name.equals("Ease Out")) { + return interpolator.EASE_OUT(); + } else { + return interpolator.EASE_IN_OUT(); + } + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/fxgl-samples/src/main/java/s05uimenus/MenuStyleSample.java b/fxgl-samples/src/main/java/s05uimenus/MenuStyleSample.java index b8d122265..78c32b799 100644 --- a/fxgl-samples/src/main/java/s05uimenus/MenuStyleSample.java +++ b/fxgl-samples/src/main/java/s05uimenus/MenuStyleSample.java @@ -8,15 +8,19 @@ import com.almasb.fxgl.app.ApplicationMode; import com.almasb.fxgl.app.GameApplication; -import com.almasb.fxgl.scene.menu.MenuStyle; +import com.almasb.fxgl.scene.FXGLMenu; +import com.almasb.fxgl.scene.SceneFactory; +import com.almasb.fxgl.scene.menu.GTAVMenu; +import com.almasb.fxgl.scene.menu.MenuType; +import com.almasb.fxgl.service.ServiceType; import com.almasb.fxgl.settings.GameSettings; +import org.jetbrains.annotations.NotNull; /** * Shows how to set different menu styles. */ public class MenuStyleSample extends GameApplication { - @Override protected void initSettings(GameSettings settings) { settings.setWidth(800); settings.setHeight(600); @@ -24,16 +28,36 @@ protected void initSettings(GameSettings settings) { settings.setVersion("0.1"); settings.setFullScreen(false); settings.setIntroEnabled(false); - - // 1. set menu enabled to true settings.setMenuEnabled(true); + settings.setProfilingEnabled(true); + settings.setApplicationMode(ApplicationMode.DEVELOPER); - // 2. set menu style - settings.setMenuStyle(MenuStyle.GTA5); + settings.addServiceType(new ServiceType() { + @Override + public Class service() { + return SceneFactory.class; + } - settings.setProfilingEnabled(false); - settings.setCloseConfirmation(false); - settings.setApplicationMode(ApplicationMode.DEVELOPER); + @Override + public Class serviceProvider() { + return MySceneFactory.class; + } + }); + } + + public static class MySceneFactory extends SceneFactory { + + @NotNull + @Override + public FXGLMenu newMainMenu(@NotNull GameApplication app) { + return new GTAVMenu(app, MenuType.MAIN_MENU); + } + + @NotNull + @Override + public FXGLMenu newGameMenu(@NotNull GameApplication app) { + return new GTAVMenu(app, MenuType.GAME_MENU); + } } public static void main(String[] args) { diff --git a/fxgl-samples/src/main/java/sandbox/HighlightSample.java b/fxgl-samples/src/main/java/sandbox/HighlightSample.java new file mode 100644 index 000000000..a9e983140 --- /dev/null +++ b/fxgl-samples/src/main/java/sandbox/HighlightSample.java @@ -0,0 +1,90 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package sandbox; + +import com.almasb.fxgl.animation.Animation; +import com.almasb.fxgl.app.ApplicationMode; +import com.almasb.fxgl.app.FXGL; +import com.almasb.fxgl.app.GameApplication; +import com.almasb.fxgl.entity.Entities; +import com.almasb.fxgl.entity.GameEntity; +import com.almasb.fxgl.entity.component.HighlightableComponent; +import com.almasb.fxgl.settings.GameSettings; +import javafx.geometry.Point2D; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.effect.DropShadow; +import javafx.scene.paint.*; +import javafx.scene.shape.Rectangle; +import javafx.scene.text.Text; +import javafx.util.Duration; + +/** + * Shows how to init a basic game object and attach it to the world + * using fluent API. + * + * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) + */ +public class HighlightSample extends GameApplication { + + // 1. define types of entities in the game using Enum + private enum Type { + PLAYER + } + + // make the field instance level + // but do NOT init here for properly functioning save-load system + private GameEntity player; + + @Override + protected void initSettings(GameSettings settings) { + settings.setWidth(800); + settings.setHeight(600); + settings.setTitle("HighlightSample"); + settings.setVersion("0.1"); + settings.setFullScreen(false); + settings.setIntroEnabled(false); + settings.setMenuEnabled(false); + settings.setProfilingEnabled(false); + settings.setCloseConfirmation(false); + settings.setApplicationMode(ApplicationMode.DEVELOPER); + } + + @Override + protected void initGame() { + // 2. create entity and attach to world using fluent API + player = Entities.builder() + .type(Type.PLAYER) + .at(100, 100) + .viewFromNode(new Rectangle(40, 40)) + .with(new HighlightableComponent()) + .buildAndAttach(getGameWorld()); + + Entities.builder() + .at(300, 100) + .viewFromNode(new Rectangle(200, 40, Color.BLUE)) + .with(new HighlightableComponent()) + .buildAndAttach(getGameWorld()); + } + + @Override + protected void initUI() { + Text text = getUIFactory().newText("Level 1", Color.WHITESMOKE, 46.0); + + DropShadow ds = new DropShadow(25, 0, 0, Color.BLACK); + + text.setEffect(ds); + + getUIFactory().centerText(text); + + getGameScene().addUINode(text); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/fxgl-samples/src/main/java/sandbox/ResetSample.java b/fxgl-samples/src/main/java/sandbox/ResetSample.java new file mode 100644 index 000000000..da2fba5da --- /dev/null +++ b/fxgl-samples/src/main/java/sandbox/ResetSample.java @@ -0,0 +1,66 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package sandbox; + +import com.almasb.fxgl.app.ApplicationMode; +import com.almasb.fxgl.app.GameApplication; +import com.almasb.fxgl.ecs.component.IrremovableComponent; +import com.almasb.fxgl.entity.Entities; +import com.almasb.fxgl.entity.GameEntity; +import com.almasb.fxgl.settings.GameSettings; +import javafx.scene.shape.Rectangle; + +/** + * Shows how to init a basic game object and attach it to the world + * using fluent API. + * + * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) + */ +public class ResetSample extends GameApplication { + + // 1. define types of entities in the game using Enum + private enum Type { + PLAYER + } + + // make the field instance level + // but do NOT init here for properly functioning save-load system + private GameEntity player; + + @Override + protected void initSettings(GameSettings settings) { + settings.setWidth(800); + settings.setHeight(600); + settings.setTitle("ResetSample"); + settings.setVersion("0.1"); + settings.setFullScreen(false); + settings.setIntroEnabled(false); + settings.setMenuEnabled(false); + settings.setProfilingEnabled(false); + settings.setCloseConfirmation(false); + settings.setApplicationMode(ApplicationMode.DEVELOPER); + } + + @Override + protected void initGame() { + // 2. create entity and attach to world using fluent API + player = Entities.builder() + .type(Type.PLAYER) + .at(100, 100) + .viewFromNode(new Rectangle(40, 40)) + .with(new IrremovableComponent()) + .buildAndAttach(getGameWorld()); + + getGameWorld().clear(); + + System.out.println(getGameWorld().getEntities().size()); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/fxgl-samples/src/main/java/sandbox/scifi/ScifiSample.java b/fxgl-samples/src/main/java/sandbox/scifi/ScifiSample.java index ae1cfdc8e..489e36314 100644 --- a/fxgl-samples/src/main/java/sandbox/scifi/ScifiSample.java +++ b/fxgl-samples/src/main/java/sandbox/scifi/ScifiSample.java @@ -6,19 +6,43 @@ package sandbox.scifi; +import com.almasb.fxgl.animation.Animation; import com.almasb.fxgl.app.ApplicationMode; +import com.almasb.fxgl.app.DSLKt; import com.almasb.fxgl.app.GameApplication; import com.almasb.fxgl.ecs.Entity; +import com.almasb.fxgl.effect.ParticleControl; +import com.almasb.fxgl.effect.ParticleEmitter; +import com.almasb.fxgl.effect.ParticleEmitters; import com.almasb.fxgl.entity.*; +import com.almasb.fxgl.entity.component.PositionComponent; +import com.almasb.fxgl.gameplay.Achievement; +import com.almasb.fxgl.gameplay.qte.QTE; import com.almasb.fxgl.input.UserAction; +import com.almasb.fxgl.physics.BoundingShape; import com.almasb.fxgl.physics.CollisionHandler; import com.almasb.fxgl.physics.HitBox; +import com.almasb.fxgl.physics.PhysicsParticleComponent; +import com.almasb.fxgl.physics.box2d.particle.ParticleGroupDef; +import com.almasb.fxgl.physics.box2d.particle.ParticleType; import com.almasb.fxgl.physics.handler.CollectibleHandler; import com.almasb.fxgl.settings.GameSettings; +import com.almasb.fxgl.texture.AnimatedTexture; +import com.almasb.fxgl.ui.InGamePanel; +import com.almasb.fxgl.ui.LevelText; import javafx.geometry.Orientation; +import javafx.scene.effect.DropShadow; import javafx.scene.input.KeyCode; +import javafx.scene.paint.Color; +import javafx.scene.text.Text; +import javafx.util.Duration; import java.util.Arrays; +import java.util.EnumSet; +import java.util.Map; + +import static com.almasb.fxgl.app.DSLKt.geti; +import static com.almasb.fxgl.app.DSLKt.set; /** * @@ -29,19 +53,25 @@ public class ScifiSample extends GameApplication { @Override protected void initSettings(GameSettings settings) { - settings.setWidth(1280); - settings.setHeight(768); - settings.setTitle("ScifiSample"); + settings.setWidth(1920); + settings.setHeight(1080); + settings.setTitle("Feature Showcase"); settings.setVersion("0.1"); - settings.setIntroEnabled(false); - settings.setMenuEnabled(false); + settings.setFullScreen(true); + settings.setIntroEnabled(true); + settings.setMenuEnabled(true); settings.setProfilingEnabled(false); - settings.setCloseConfirmation(false); + settings.setCloseConfirmation(true); settings.setApplicationMode(ApplicationMode.DEVELOPER); } private PlayerControl playerControl; + @Override + protected void initAchievements() { + getGameplay().getAchievementManager().registerAchievement(new Achievement("Collector", "Collect 10 coins")); + } + @Override protected void initInput() { getInput().addAction(new UserAction("Left") { @@ -74,11 +104,60 @@ protected void onActionBegin() { playerControl.jump(); } }, KeyCode.W); + + getInput().addAction(new UserAction("Animate Level Text") { + @Override + protected void onActionBegin() { + levelText.animateIn(); + } + + @Override + protected void onActionEnd() { + levelText.animateOut(); + } + }, KeyCode.G); + + getInput().addAction(new UserAction("Open/Close Panel") { + @Override + protected void onActionBegin() { + if (panel.isOpen()) + panel.close(); + else + panel.open(); + } + }, KeyCode.TAB); + } + + @Override + protected void initGameVars(Map vars) { + vars.put("coins", 0); } @Override protected void initGame() { + + // assets from https://raventale.itch.io/parallax-background + getGameScene().addGameView(new ParallaxBackgroundView(Arrays.asList( + new ParallaxTexture(getAssetLoader().loadTexture("bg_10.png", getWidth(), getHeight()), 1.0), + new ParallaxTexture(getAssetLoader().loadTexture("bg_9.png", getWidth(), getHeight()), 0.05), + new ParallaxTexture(getAssetLoader().loadTexture("bg_8.png", getWidth(), getHeight()), 0.1), + new ParallaxTexture(getAssetLoader().loadTexture("bg_7.png", getWidth(), getHeight()), 0.3), + new ParallaxTexture(getAssetLoader().loadTexture("bg_6.png", getWidth(), getHeight()), 0.45), + //new ParallaxTexture(getAssetLoader().loadTexture("bg_5.png", getWidth(), getHeight()), 0.45), + //new ParallaxTexture(getAssetLoader().loadTexture("bg_4.png", getWidth(), getHeight()), 0.6), + new ParallaxTexture(getAssetLoader().loadTexture("bg_3.png", getWidth(), getHeight()), 0.5), + new ParallaxTexture(getAssetLoader().loadTexture("bg_2.png", getWidth(), getHeight()), 0.7), + new ParallaxTexture(getAssetLoader().loadTexture("bg_1.png", getWidth(), getHeight()), 0.8), + new ParallaxTexture(getAssetLoader().loadTexture("bg_0.png", getWidth(), getHeight()), 0.9) + ), Orientation.HORIZONTAL, BG)); + nextLevel(); + + getGameplay().getAchievementManager() + .getAchievementByName("Collector") + .bind(getGameState().intProperty("coins"), 10); + + //getMasterTimer().runOnceAfter(this::seerCutscene, Duration.seconds(7)); } private int level = 1; @@ -101,27 +180,58 @@ private void nextLevel() { Entity player = getGameWorld().getEntitiesByType(ScifiType.PLAYER).get(0); playerControl = player.getControl(PlayerControl.class); - getGameScene().getViewport().setBounds(0, 0, 3000, 768); + getGameScene().getViewport().setBounds(0, 0, 3000, getHeight()); getGameScene().getViewport().bindToEntity(player, 500, 0); - // assets from https://raventale.itch.io/parallax-background - getGameScene().addGameView(new ParallaxBackgroundView(Arrays.asList( - new ParallaxTexture(getAssetLoader().loadTexture("bg_10.png", 1280, 768), 1.0), - new ParallaxTexture(getAssetLoader().loadTexture("bg_9.png", 1280, 768), 0.05), - new ParallaxTexture(getAssetLoader().loadTexture("bg_8.png", 1280, 768), 0.1), - new ParallaxTexture(getAssetLoader().loadTexture("bg_7.png", 1280, 768), 0.3), - new ParallaxTexture(getAssetLoader().loadTexture("bg_6.png", 1280, 768), 0.45), - //new ParallaxTexture(getAssetLoader().loadTexture("bg_5.png", 1280, 768), 0.45), - //new ParallaxTexture(getAssetLoader().loadTexture("bg_4.png", 1280, 768), 0.6), - new ParallaxTexture(getAssetLoader().loadTexture("bg_3.png", 1280, 768), 0.5), - new ParallaxTexture(getAssetLoader().loadTexture("bg_2.png", 1280, 768), 0.7), - new ParallaxTexture(getAssetLoader().loadTexture("bg_1.png", 1280, 768), 0.8), - new ParallaxTexture(getAssetLoader().loadTexture("bg_0.png", 1280, 768), 0.9) - ), Orientation.HORIZONTAL, BG)); - level++; if (level == 4) level = 1; + + initUI(); + } + + private void seerCutscene() { + // TODO: on cutscene end() + // TODO: also why does player keep moving, input not cleared? + getGameplay().getCutsceneManager().startCutscene("seer.txt"); + + AnimatedTexture anim = getAssetLoader().loadTexture("player.png").toAnimatedTexture(3, Duration.seconds(0.5)); + + // TODO: wrong behavior? + anim.start(getStateMachine().getCurrentState()); + anim.setScaleX(-3); + anim.setScaleY(3); + anim.setTranslateX(getWidth() / 2); + anim.setTranslateY(getHeight() / 2); + + getGameScene().addUINode(anim); + + Animation anim2 = getUIFactory().fadeOut(anim, Duration.seconds(1.75)); + anim2.setOnFinished(() -> { + getGameScene().removeUINode(anim); + + QTE qte = getGameplay().getQTE(); + + qte.start(yes -> { + + }, Duration.seconds(3), KeyCode.W, KeyCode.W, KeyCode.D, KeyCode.A); + }); + anim2.startInPlayState(); + + addRain(); + initLiquid(); + } + + private void addRain() { + ParticleEmitter emitter = ParticleEmitters.newRainEmitter(getWidth()); + emitter.setSourceImage(getAssetLoader().loadTexture("rain.png").multiplyColor(Color.LIGHTBLUE).getImage()); + + GameEntity rain = Entities.builder() + .with(new ParticleControl(emitter)) + .buildAndAttach(getGameWorld()); + + rain.getPositionComponent().xProperty().bind(getGameScene().getViewport().xProperty()); + rain.getPositionComponent().yProperty().bind(getGameScene().getViewport().yProperty()); } @Override @@ -142,7 +252,45 @@ protected void onCollisionBegin(Entity a, Entity b) { } }); - getPhysicsWorld().addCollisionHandler(new CollectibleHandler(ScifiType.PLAYER, ScifiType.COIN, "drop.wav")); + getPhysicsWorld().addCollisionHandler(new CollectibleHandler(ScifiType.PLAYER, ScifiType.COIN, "drop.wav", + (c) -> set("coins", geti("coins") + 1))); + } + + private LevelText levelText; + private InGamePanel panel; + + @Override + protected void initUI() { + getGameScene().removeUINode(levelText); + getGameScene().removeUINode(panel); + + levelText = new LevelText("Level " + (level-1)); + getGameScene().addUINode(levelText); + + panel = new InGamePanel(); + + Text text = getUIFactory().newText("No Network Connection", Color.BLACK, 24.0); + text.setTranslateX(getWidth() / 3 / 2 - text.getLayoutBounds().getWidth() / 2); + text.setTranslateY(getHeight() / 2); + panel.getChildren().add(text); + + getGameScene().addUINode(panel); + } + + private void initLiquid() { + ParticleGroupDef groupDef = new ParticleGroupDef(); + groupDef.setTypes(EnumSet.of(ParticleType.WATER)); + + PhysicsParticleComponent ppComponent = new PhysicsParticleComponent(); + ppComponent.setDefinition(groupDef); + ppComponent.setColor(Color.BLUE.brighter()); + + GameEntity liquid = new GameEntity(); + liquid.setPosition(playerControl.getEntity().getComponent(PositionComponent.class).getValue().subtract(0, 650)); + liquid.getBoundingBoxComponent().addHitBox(new HitBox("MAIN", BoundingShape.circle(55))); + liquid.addComponent(ppComponent); + + getGameWorld().addEntities(liquid); } public static void main(String[] args) { diff --git a/fxgl-games/src/main/resources/assets/ai/pacman/pacman_enemy1.tree b/fxgl-samples/src/main/resources/assets/ai/pacman/pacman_enemy1.tree similarity index 100% rename from fxgl-games/src/main/resources/assets/ai/pacman/pacman_enemy1.tree rename to fxgl-samples/src/main/resources/assets/ai/pacman/pacman_enemy1.tree diff --git a/fxgl-games/src/main/resources/assets/ai/towerfall/enemy_easy.tree b/fxgl-samples/src/main/resources/assets/ai/towerfall/enemy_easy.tree similarity index 100% rename from fxgl-games/src/main/resources/assets/ai/towerfall/enemy_easy.tree rename to fxgl-samples/src/main/resources/assets/ai/towerfall/enemy_easy.tree diff --git a/fxgl-games/src/main/resources/assets/kv/config.kv b/fxgl-samples/src/main/resources/assets/kv/config.kv similarity index 100% rename from fxgl-games/src/main/resources/assets/kv/config.kv rename to fxgl-samples/src/main/resources/assets/kv/config.kv diff --git a/fxgl-games/src/main/resources/assets/music/bgm.mp3 b/fxgl-samples/src/main/resources/assets/music/bgm.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/bgm.mp3 rename to fxgl-samples/src/main/resources/assets/music/bgm.mp3 diff --git a/fxgl-games/src/main/resources/assets/music/breakout/BGM01.wav b/fxgl-samples/src/main/resources/assets/music/breakout/BGM01.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/music/breakout/BGM01.wav rename to fxgl-samples/src/main/resources/assets/music/breakout/BGM01.wav diff --git a/fxgl-games/src/main/resources/assets/music/dialogs/move_left.mp3 b/fxgl-samples/src/main/resources/assets/music/dialogs/move_left.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/dialogs/move_left.mp3 rename to fxgl-samples/src/main/resources/assets/music/dialogs/move_left.mp3 diff --git a/fxgl-games/src/main/resources/assets/music/dialogs/move_right.mp3 b/fxgl-samples/src/main/resources/assets/music/dialogs/move_right.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/dialogs/move_right.mp3 rename to fxgl-samples/src/main/resources/assets/music/dialogs/move_right.mp3 diff --git a/fxgl-games/src/main/resources/assets/music/dialogs/shoot.mp3 b/fxgl-samples/src/main/resources/assets/music/dialogs/shoot.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/dialogs/shoot.mp3 rename to fxgl-samples/src/main/resources/assets/music/dialogs/shoot.mp3 diff --git a/fxgl-games/src/main/resources/assets/music/move_left.mp3 b/fxgl-samples/src/main/resources/assets/music/move_left.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/move_left.mp3 rename to fxgl-samples/src/main/resources/assets/music/move_left.mp3 diff --git a/fxgl-games/src/main/resources/assets/music/move_right.mp3 b/fxgl-samples/src/main/resources/assets/music/move_right.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/move_right.mp3 rename to fxgl-samples/src/main/resources/assets/music/move_right.mp3 diff --git a/fxgl-games/src/main/resources/assets/music/shoot.mp3 b/fxgl-samples/src/main/resources/assets/music/shoot.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/shoot.mp3 rename to fxgl-samples/src/main/resources/assets/music/shoot.mp3 diff --git a/fxgl-games/src/main/resources/assets/music/spaceinvaders/move_left.mp3 b/fxgl-samples/src/main/resources/assets/music/spaceinvaders/move_left.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/spaceinvaders/move_left.mp3 rename to fxgl-samples/src/main/resources/assets/music/spaceinvaders/move_left.mp3 diff --git a/fxgl-games/src/main/resources/assets/music/spaceinvaders/move_right.mp3 b/fxgl-samples/src/main/resources/assets/music/spaceinvaders/move_right.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/spaceinvaders/move_right.mp3 rename to fxgl-samples/src/main/resources/assets/music/spaceinvaders/move_right.mp3 diff --git a/fxgl-games/src/main/resources/assets/music/spaceinvaders/shoot.mp3 b/fxgl-samples/src/main/resources/assets/music/spaceinvaders/shoot.mp3 similarity index 100% rename from fxgl-games/src/main/resources/assets/music/spaceinvaders/shoot.mp3 rename to fxgl-samples/src/main/resources/assets/music/spaceinvaders/shoot.mp3 diff --git a/fxgl-samples/src/main/resources/assets/properties/system.properties b/fxgl-samples/src/main/resources/assets/properties/system.properties index 3709315ef..08a924bf5 100644 --- a/fxgl-samples/src/main/resources/assets/properties/system.properties +++ b/fxgl-samples/src/main/resources/assets/properties/system.properties @@ -4,4 +4,4 @@ # See LICENSE for details. # -physics.ppm = 45.0 \ No newline at end of file +ui.font = kenvector_future_thin.ttf \ No newline at end of file diff --git a/fxgl-games/src/main/resources/assets/sounds/beam.wav b/fxgl-samples/src/main/resources/assets/sounds/beam.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/beam.wav rename to fxgl-samples/src/main/resources/assets/sounds/beam.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/breakout/bonus.wav b/fxgl-samples/src/main/resources/assets/sounds/breakout/bonus.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/breakout/bonus.wav rename to fxgl-samples/src/main/resources/assets/sounds/breakout/bonus.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/breakout/brick_hit.wav b/fxgl-samples/src/main/resources/assets/sounds/breakout/brick_hit.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/breakout/brick_hit.wav rename to fxgl-samples/src/main/resources/assets/sounds/breakout/brick_hit.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/breakout/btn_press.wav b/fxgl-samples/src/main/resources/assets/sounds/breakout/btn_press.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/breakout/btn_press.wav rename to fxgl-samples/src/main/resources/assets/sounds/breakout/btn_press.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/breakout/lose.wav b/fxgl-samples/src/main/resources/assets/sounds/breakout/lose.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/breakout/lose.wav rename to fxgl-samples/src/main/resources/assets/sounds/breakout/lose.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/breakout/win.wav b/fxgl-samples/src/main/resources/assets/sounds/breakout/win.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/breakout/win.wav rename to fxgl-samples/src/main/resources/assets/sounds/breakout/win.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/drop/drop.wav b/fxgl-samples/src/main/resources/assets/sounds/drop/drop.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/drop/drop.wav rename to fxgl-samples/src/main/resources/assets/sounds/drop/drop.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/explosion-01.wav b/fxgl-samples/src/main/resources/assets/sounds/explosion-01.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/explosion-01.wav rename to fxgl-samples/src/main/resources/assets/sounds/explosion-01.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/explosion-02.wav b/fxgl-samples/src/main/resources/assets/sounds/explosion-02.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/explosion-02.wav rename to fxgl-samples/src/main/resources/assets/sounds/explosion-02.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/explosion-03.wav b/fxgl-samples/src/main/resources/assets/sounds/explosion-03.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/explosion-03.wav rename to fxgl-samples/src/main/resources/assets/sounds/explosion-03.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/explosion-04.wav b/fxgl-samples/src/main/resources/assets/sounds/explosion-04.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/explosion-04.wav rename to fxgl-samples/src/main/resources/assets/sounds/explosion-04.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/explosion-05.wav b/fxgl-samples/src/main/resources/assets/sounds/explosion-05.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/explosion-05.wav rename to fxgl-samples/src/main/resources/assets/sounds/explosion-05.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/explosion-06.wav b/fxgl-samples/src/main/resources/assets/sounds/explosion-06.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/explosion-06.wav rename to fxgl-samples/src/main/resources/assets/sounds/explosion-06.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/explosion-07.wav b/fxgl-samples/src/main/resources/assets/sounds/explosion-07.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/explosion-07.wav rename to fxgl-samples/src/main/resources/assets/sounds/explosion-07.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/explosion-08.wav b/fxgl-samples/src/main/resources/assets/sounds/explosion-08.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/explosion-08.wav rename to fxgl-samples/src/main/resources/assets/sounds/explosion-08.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/explosion.wav b/fxgl-samples/src/main/resources/assets/sounds/explosion.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/explosion.wav rename to fxgl-samples/src/main/resources/assets/sounds/explosion.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/jump.wav b/fxgl-samples/src/main/resources/assets/sounds/jump.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/jump.wav rename to fxgl-samples/src/main/resources/assets/sounds/jump.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/level.wav b/fxgl-samples/src/main/resources/assets/sounds/level.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/level.wav rename to fxgl-samples/src/main/resources/assets/sounds/level.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/lose_life.wav b/fxgl-samples/src/main/resources/assets/sounds/lose_life.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/lose_life.wav rename to fxgl-samples/src/main/resources/assets/sounds/lose_life.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/normal.wav b/fxgl-samples/src/main/resources/assets/sounds/normal.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/normal.wav rename to fxgl-samples/src/main/resources/assets/sounds/normal.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/ricochet.wav b/fxgl-samples/src/main/resources/assets/sounds/ricochet.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/ricochet.wav rename to fxgl-samples/src/main/resources/assets/sounds/ricochet.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/shoot1.wav b/fxgl-samples/src/main/resources/assets/sounds/shoot1.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/shoot1.wav rename to fxgl-samples/src/main/resources/assets/sounds/shoot1.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/shoot2.wav b/fxgl-samples/src/main/resources/assets/sounds/shoot2.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/shoot2.wav rename to fxgl-samples/src/main/resources/assets/sounds/shoot2.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/shoot3.wav b/fxgl-samples/src/main/resources/assets/sounds/shoot3.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/shoot3.wav rename to fxgl-samples/src/main/resources/assets/sounds/shoot3.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/shoot4.wav b/fxgl-samples/src/main/resources/assets/sounds/shoot4.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/shoot4.wav rename to fxgl-samples/src/main/resources/assets/sounds/shoot4.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/shoot5.wav b/fxgl-samples/src/main/resources/assets/sounds/shoot5.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/shoot5.wav rename to fxgl-samples/src/main/resources/assets/sounds/shoot5.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/shoot6.wav b/fxgl-samples/src/main/resources/assets/sounds/shoot6.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/shoot6.wav rename to fxgl-samples/src/main/resources/assets/sounds/shoot6.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/shoot7.wav b/fxgl-samples/src/main/resources/assets/sounds/shoot7.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/shoot7.wav rename to fxgl-samples/src/main/resources/assets/sounds/shoot7.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/shoot8.wav b/fxgl-samples/src/main/resources/assets/sounds/shoot8.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/shoot8.wav rename to fxgl-samples/src/main/resources/assets/sounds/shoot8.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spaceinvaders/explosion.wav b/fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/explosion.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spaceinvaders/explosion.wav rename to fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/explosion.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spaceinvaders/level.wav b/fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/level.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spaceinvaders/level.wav rename to fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/level.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spaceinvaders/lose_life.wav b/fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/lose_life.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spaceinvaders/lose_life.wav rename to fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/lose_life.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spaceinvaders/shoot1.wav b/fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/shoot1.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spaceinvaders/shoot1.wav rename to fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/shoot1.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spaceinvaders/shoot2.wav b/fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/shoot2.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spaceinvaders/shoot2.wav rename to fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/shoot2.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spaceinvaders/shoot3.wav b/fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/shoot3.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spaceinvaders/shoot3.wav rename to fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/shoot3.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spaceinvaders/shoot4.wav b/fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/shoot4.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spaceinvaders/shoot4.wav rename to fxgl-samples/src/main/resources/assets/sounds/spaceinvaders/shoot4.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spawn-01.wav b/fxgl-samples/src/main/resources/assets/sounds/spawn-01.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spawn-01.wav rename to fxgl-samples/src/main/resources/assets/sounds/spawn-01.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spawn-02.wav b/fxgl-samples/src/main/resources/assets/sounds/spawn-02.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spawn-02.wav rename to fxgl-samples/src/main/resources/assets/sounds/spawn-02.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spawn-03.wav b/fxgl-samples/src/main/resources/assets/sounds/spawn-03.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spawn-03.wav rename to fxgl-samples/src/main/resources/assets/sounds/spawn-03.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spawn-04.wav b/fxgl-samples/src/main/resources/assets/sounds/spawn-04.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spawn-04.wav rename to fxgl-samples/src/main/resources/assets/sounds/spawn-04.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spawn-05.wav b/fxgl-samples/src/main/resources/assets/sounds/spawn-05.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spawn-05.wav rename to fxgl-samples/src/main/resources/assets/sounds/spawn-05.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spawn-06.wav b/fxgl-samples/src/main/resources/assets/sounds/spawn-06.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spawn-06.wav rename to fxgl-samples/src/main/resources/assets/sounds/spawn-06.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spawn-07.wav b/fxgl-samples/src/main/resources/assets/sounds/spawn-07.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spawn-07.wav rename to fxgl-samples/src/main/resources/assets/sounds/spawn-07.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/spawn-08.wav b/fxgl-samples/src/main/resources/assets/sounds/spawn-08.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/spawn-08.wav rename to fxgl-samples/src/main/resources/assets/sounds/spawn-08.wav diff --git a/fxgl-games/src/main/resources/assets/sounds/wave.wav b/fxgl-samples/src/main/resources/assets/sounds/wave.wav similarity index 100% rename from fxgl-games/src/main/resources/assets/sounds/wave.wav rename to fxgl-samples/src/main/resources/assets/sounds/wave.wav diff --git a/fxgl-games/src/main/resources/assets/text/breakout/levels/level1.txt b/fxgl-samples/src/main/resources/assets/text/breakout/levels/level1.txt similarity index 100% rename from fxgl-games/src/main/resources/assets/text/breakout/levels/level1.txt rename to fxgl-samples/src/main/resources/assets/text/breakout/levels/level1.txt diff --git a/fxgl-games/src/main/resources/assets/text/pacman/levels/pacman_level0.txt b/fxgl-samples/src/main/resources/assets/text/pacman/levels/pacman_level0.txt similarity index 100% rename from fxgl-games/src/main/resources/assets/text/pacman/levels/pacman_level0.txt rename to fxgl-samples/src/main/resources/assets/text/pacman/levels/pacman_level0.txt diff --git a/fxgl-samples/src/main/resources/assets/text/seer.txt b/fxgl-samples/src/main/resources/assets/text/seer.txt new file mode 100644 index 000000000..d27fb1b5d --- /dev/null +++ b/fxgl-samples/src/main/resources/assets/text/seer.txt @@ -0,0 +1,8 @@ +Player: Oh... Hi! +Seer: I'm a seer! I can see... +Player: I see. +Seer: No, you don't! +Player: I didn't mean... Nevermind. +Seer: It's starting to rain. +Player: Don't need to be a seer to see that. +Seer: Watch your tongue! Cool off with that diff --git a/fxgl-games/src/main/resources/assets/text/towerfall/levels/level1.txt b/fxgl-samples/src/main/resources/assets/text/towerfall/levels/level1.txt similarity index 100% rename from fxgl-games/src/main/resources/assets/text/towerfall/levels/level1.txt rename to fxgl-samples/src/main/resources/assets/text/towerfall/levels/level1.txt diff --git a/fxgl-games/src/main/resources/assets/textures/Black Hole.png b/fxgl-samples/src/main/resources/assets/textures/Black Hole.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/Black Hole.png rename to fxgl-samples/src/main/resources/assets/textures/Black Hole.png diff --git a/fxgl-games/src/main/resources/assets/textures/Glow.png b/fxgl-samples/src/main/resources/assets/textures/Glow.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/Glow.png rename to fxgl-samples/src/main/resources/assets/textures/Glow.png diff --git a/fxgl-games/src/main/resources/assets/textures/Laser.png b/fxgl-samples/src/main/resources/assets/textures/Laser.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/Laser.png rename to fxgl-samples/src/main/resources/assets/textures/Laser.png diff --git a/fxgl-games/src/main/resources/assets/textures/Pointer.png b/fxgl-samples/src/main/resources/assets/textures/Pointer.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/Pointer.png rename to fxgl-samples/src/main/resources/assets/textures/Pointer.png diff --git a/fxgl-games/src/main/resources/assets/textures/RedSeeker.png b/fxgl-samples/src/main/resources/assets/textures/RedSeeker.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/RedSeeker.png rename to fxgl-samples/src/main/resources/assets/textures/RedSeeker.png diff --git a/fxgl-games/src/main/resources/assets/textures/RedWanderer.png b/fxgl-samples/src/main/resources/assets/textures/RedWanderer.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/RedWanderer.png rename to fxgl-samples/src/main/resources/assets/textures/RedWanderer.png diff --git a/fxgl-games/src/main/resources/assets/textures/Seeker.png b/fxgl-samples/src/main/resources/assets/textures/Seeker.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/Seeker.png rename to fxgl-samples/src/main/resources/assets/textures/Seeker.png diff --git a/fxgl-games/src/main/resources/assets/textures/Wanderer.png b/fxgl-samples/src/main/resources/assets/textures/Wanderer.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/Wanderer.png rename to fxgl-samples/src/main/resources/assets/textures/Wanderer.png diff --git a/fxgl-games/src/main/resources/assets/textures/YellowCrystal.png b/fxgl-samples/src/main/resources/assets/textures/YellowCrystal.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/YellowCrystal.png rename to fxgl-samples/src/main/resources/assets/textures/YellowCrystal.png diff --git a/fxgl-games/src/main/resources/assets/textures/background.png b/fxgl-samples/src/main/resources/assets/textures/background.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/background.png rename to fxgl-samples/src/main/resources/assets/textures/background.png diff --git a/fxgl-games/src/main/resources/assets/textures/background/background.png b/fxgl-samples/src/main/resources/assets/textures/background/background.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/background/background.png rename to fxgl-samples/src/main/resources/assets/textures/background/background.png diff --git a/fxgl-games/src/main/resources/assets/textures/background/meteor1.png b/fxgl-samples/src/main/resources/assets/textures/background/meteor1.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/background/meteor1.png rename to fxgl-samples/src/main/resources/assets/textures/background/meteor1.png diff --git a/fxgl-games/src/main/resources/assets/textures/background/meteor2.png b/fxgl-samples/src/main/resources/assets/textures/background/meteor2.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/background/meteor2.png rename to fxgl-samples/src/main/resources/assets/textures/background/meteor2.png diff --git a/fxgl-games/src/main/resources/assets/textures/background/meteor3.png b/fxgl-samples/src/main/resources/assets/textures/background/meteor3.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/background/meteor3.png rename to fxgl-samples/src/main/resources/assets/textures/background/meteor3.png diff --git a/fxgl-games/src/main/resources/assets/textures/background/meteor4.png b/fxgl-samples/src/main/resources/assets/textures/background/meteor4.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/background/meteor4.png rename to fxgl-samples/src/main/resources/assets/textures/background/meteor4.png diff --git a/fxgl-games/src/main/resources/assets/textures/bird.png b/fxgl-samples/src/main/resources/assets/textures/bird.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/bird.png rename to fxgl-samples/src/main/resources/assets/textures/bird.png diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/back.gif b/fxgl-samples/src/main/resources/assets/textures/breakout/back.gif similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/back.gif rename to fxgl-samples/src/main/resources/assets/textures/breakout/back.gif diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/ball.png b/fxgl-samples/src/main/resources/assets/textures/breakout/ball.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/ball.png rename to fxgl-samples/src/main/resources/assets/textures/breakout/ball.png diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/bat.png b/fxgl-samples/src/main/resources/assets/textures/breakout/bat.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/bat.png rename to fxgl-samples/src/main/resources/assets/textures/breakout/bat.png diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/bonus.png b/fxgl-samples/src/main/resources/assets/textures/breakout/bonus.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/bonus.png rename to fxgl-samples/src/main/resources/assets/textures/breakout/bonus.png diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/brick_blue.png b/fxgl-samples/src/main/resources/assets/textures/breakout/brick_blue.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/brick_blue.png rename to fxgl-samples/src/main/resources/assets/textures/breakout/brick_blue.png diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/brick_blue_cracked.png b/fxgl-samples/src/main/resources/assets/textures/breakout/brick_blue_cracked.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/brick_blue_cracked.png rename to fxgl-samples/src/main/resources/assets/textures/breakout/brick_blue_cracked.png diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/bubble.png b/fxgl-samples/src/main/resources/assets/textures/breakout/bubble.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/bubble.png rename to fxgl-samples/src/main/resources/assets/textures/breakout/bubble.png diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/lives.png b/fxgl-samples/src/main/resources/assets/textures/breakout/lives.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/lives.png rename to fxgl-samples/src/main/resources/assets/textures/breakout/lives.png diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/logo.png b/fxgl-samples/src/main/resources/assets/textures/breakout/logo.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/logo.png rename to fxgl-samples/src/main/resources/assets/textures/breakout/logo.png diff --git a/fxgl-games/src/main/resources/assets/textures/breakout/menu_back.jpg b/fxgl-samples/src/main/resources/assets/textures/breakout/menu_back.jpg similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/breakout/menu_back.jpg rename to fxgl-samples/src/main/resources/assets/textures/breakout/menu_back.jpg diff --git a/fxgl-samples/src/main/resources/assets/textures/bullet.png b/fxgl-samples/src/main/resources/assets/textures/bullet.png index d557f592c..8ff1eef7b 100644 Binary files a/fxgl-samples/src/main/resources/assets/textures/bullet.png and b/fxgl-samples/src/main/resources/assets/textures/bullet.png differ diff --git a/fxgl-games/src/main/resources/assets/textures/drop/bucket.png b/fxgl-samples/src/main/resources/assets/textures/drop/bucket.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/drop/bucket.png rename to fxgl-samples/src/main/resources/assets/textures/drop/bucket.png diff --git a/fxgl-games/src/main/resources/assets/textures/drop/droplet.png b/fxgl-samples/src/main/resources/assets/textures/drop/droplet.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/drop/droplet.png rename to fxgl-samples/src/main/resources/assets/textures/drop/droplet.png diff --git a/fxgl-games/src/main/resources/assets/textures/enemy1.png b/fxgl-samples/src/main/resources/assets/textures/enemy1.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/enemy1.png rename to fxgl-samples/src/main/resources/assets/textures/enemy1.png diff --git a/fxgl-games/src/main/resources/assets/textures/enemy2.png b/fxgl-samples/src/main/resources/assets/textures/enemy2.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/enemy2.png rename to fxgl-samples/src/main/resources/assets/textures/enemy2.png diff --git a/fxgl-games/src/main/resources/assets/textures/enemy3.png b/fxgl-samples/src/main/resources/assets/textures/enemy3.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/enemy3.png rename to fxgl-samples/src/main/resources/assets/textures/enemy3.png diff --git a/fxgl-samples/src/main/resources/assets/textures/explosion.png b/fxgl-samples/src/main/resources/assets/textures/explosion.png index 3297bbc02..96b0f94ed 100644 Binary files a/fxgl-samples/src/main/resources/assets/textures/explosion.png and b/fxgl-samples/src/main/resources/assets/textures/explosion.png differ diff --git a/fxgl-games/src/main/resources/assets/textures/laser1.png b/fxgl-samples/src/main/resources/assets/textures/laser1.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/laser1.png rename to fxgl-samples/src/main/resources/assets/textures/laser1.png diff --git a/fxgl-games/src/main/resources/assets/textures/laser2.png b/fxgl-samples/src/main/resources/assets/textures/laser2.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/laser2.png rename to fxgl-samples/src/main/resources/assets/textures/laser2.png diff --git a/fxgl-games/src/main/resources/assets/textures/laser_end.png b/fxgl-samples/src/main/resources/assets/textures/laser_end.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/laser_end.png rename to fxgl-samples/src/main/resources/assets/textures/laser_end.png diff --git a/fxgl-games/src/main/resources/assets/textures/laser_hit.png b/fxgl-samples/src/main/resources/assets/textures/laser_hit.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/laser_hit.png rename to fxgl-samples/src/main/resources/assets/textures/laser_hit.png diff --git a/fxgl-games/src/main/resources/assets/textures/pacman/coin.png b/fxgl-samples/src/main/resources/assets/textures/pacman/coin.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/pacman/coin.png rename to fxgl-samples/src/main/resources/assets/textures/pacman/coin.png diff --git a/fxgl-games/src/main/resources/assets/textures/pacman/player.png b/fxgl-samples/src/main/resources/assets/textures/pacman/player.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/pacman/player.png rename to fxgl-samples/src/main/resources/assets/textures/pacman/player.png diff --git a/fxgl-games/src/main/resources/assets/textures/pacman/spritesheet.png b/fxgl-samples/src/main/resources/assets/textures/pacman/spritesheet.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/pacman/spritesheet.png rename to fxgl-samples/src/main/resources/assets/textures/pacman/spritesheet.png diff --git a/fxgl-samples/src/main/resources/assets/textures/player.png b/fxgl-samples/src/main/resources/assets/textures/player.png index 2b928abf2..7bbc93d4a 100644 Binary files a/fxgl-samples/src/main/resources/assets/textures/player.png and b/fxgl-samples/src/main/resources/assets/textures/player.png differ diff --git a/fxgl-samples/src/main/resources/assets/textures/player2.png b/fxgl-samples/src/main/resources/assets/textures/player2.png index 04c10cddb..f34faf066 100644 Binary files a/fxgl-samples/src/main/resources/assets/textures/player2.png and b/fxgl-samples/src/main/resources/assets/textures/player2.png differ diff --git a/fxgl-games/src/main/resources/assets/textures/powerup_atk_rate.png b/fxgl-samples/src/main/resources/assets/textures/powerup_atk_rate.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/powerup_atk_rate.png rename to fxgl-samples/src/main/resources/assets/textures/powerup_atk_rate.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/background.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/background.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/background.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/background.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/meteor1.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/meteor1.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/meteor1.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/meteor1.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/meteor2.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/meteor2.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/meteor2.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/meteor2.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/meteor3.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/meteor3.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/meteor3.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/meteor3.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/meteor4.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/meteor4.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/background/meteor4.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/background/meteor4.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/enemy1.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/enemy1.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/enemy1.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/enemy1.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/enemy2.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/enemy2.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/enemy2.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/enemy2.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/enemy3.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/enemy3.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/enemy3.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/enemy3.png diff --git a/fxgl-games/src/main/resources/assets/textures/explosion.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/explosion.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/explosion.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/explosion.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/laser1.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/laser1.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/laser1.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/laser1.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/laser2.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/laser2.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/laser2.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/laser2.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/laser_end.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/laser_end.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/laser_end.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/laser_end.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/laser_hit.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/laser_hit.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/laser_hit.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/laser_hit.png diff --git a/fxgl-games/src/main/resources/assets/textures/life.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/life.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/life.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/life.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/player.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/player.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/player.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/player.png diff --git a/fxgl-games/src/main/resources/assets/textures/player2.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/player2.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/player2.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/player2.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/powerup_atk_rate.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/powerup_atk_rate.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/powerup_atk_rate.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/powerup_atk_rate.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/tank_bullet.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/tank_bullet.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/tank_bullet.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/tank_bullet.png diff --git a/fxgl-games/src/main/resources/assets/textures/spaceinvaders/wall.png b/fxgl-samples/src/main/resources/assets/textures/spaceinvaders/wall.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spaceinvaders/wall.png rename to fxgl-samples/src/main/resources/assets/textures/spaceinvaders/wall.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/bg_0.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/bg_0.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/bg_0.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/bg_0.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/bg_1.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/bg_1.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/bg_1.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/bg_1.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/bg_2.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/bg_2.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/bg_2.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/bg_2.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_bullet.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_bullet.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_bullet.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_bullet.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_1.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_1.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_1.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_1.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_10.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_10.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_10.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_10.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_2.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_2.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_2.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_2.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_3.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_3.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_3.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_3.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_4.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_4.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_4.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_4.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_5.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_5.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_5.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_5.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_6.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_6.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_6.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_6.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_7.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_7.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_7.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_7.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_8.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_8.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_8.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_8.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_9.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_9.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_enemy_9.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_enemy_9.png diff --git a/fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_player.png b/fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_player.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/spacerunner/sprite_player.png rename to fxgl-samples/src/main/resources/assets/textures/spacerunner/sprite_player.png diff --git a/fxgl-games/src/main/resources/assets/textures/towerfall/arrow.png b/fxgl-samples/src/main/resources/assets/textures/towerfall/arrow.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/towerfall/arrow.png rename to fxgl-samples/src/main/resources/assets/textures/towerfall/arrow.png diff --git a/fxgl-games/src/main/resources/assets/textures/towerfall/brick.png b/fxgl-samples/src/main/resources/assets/textures/towerfall/brick.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/towerfall/brick.png rename to fxgl-samples/src/main/resources/assets/textures/towerfall/brick.png diff --git a/fxgl-games/src/main/resources/assets/textures/wall.png b/fxgl-samples/src/main/resources/assets/textures/wall.png similarity index 100% rename from fxgl-games/src/main/resources/assets/textures/wall.png rename to fxgl-samples/src/main/resources/assets/textures/wall.png diff --git a/fxgl-games/src/main/resources/assets/ui/fonts/kenvector_future_thin.ttf b/fxgl-samples/src/main/resources/assets/ui/fonts/kenvector_future_thin.ttf similarity index 100% rename from fxgl-games/src/main/resources/assets/ui/fonts/kenvector_future_thin.ttf rename to fxgl-samples/src/main/resources/assets/ui/fonts/kenvector_future_thin.ttf diff --git a/fxgl-games/src/main/resources/assets/ui/fonts/sf_atarian_system.ttf b/fxgl-samples/src/main/resources/assets/ui/fonts/sf_atarian_system.ttf similarity index 100% rename from fxgl-games/src/main/resources/assets/ui/fonts/sf_atarian_system.ttf rename to fxgl-samples/src/main/resources/assets/ui/fonts/sf_atarian_system.ttf diff --git a/fxgl-games/src/main/resources/assets/ui/main.fxml b/fxgl-samples/src/main/resources/assets/ui/main.fxml similarity index 100% rename from fxgl-games/src/main/resources/assets/ui/main.fxml rename to fxgl-samples/src/main/resources/assets/ui/main.fxml diff --git a/fxgl-games/src/main/resources/assets/ui/pacman/pacman_ui.fxml b/fxgl-samples/src/main/resources/assets/ui/pacman/pacman_ui.fxml similarity index 100% rename from fxgl-games/src/main/resources/assets/ui/pacman/pacman_ui.fxml rename to fxgl-samples/src/main/resources/assets/ui/pacman/pacman_ui.fxml diff --git a/fxgl-games/src/main/resources/assets/ui/pong/main.fxml b/fxgl-samples/src/main/resources/assets/ui/pong/main.fxml similarity index 100% rename from fxgl-games/src/main/resources/assets/ui/pong/main.fxml rename to fxgl-samples/src/main/resources/assets/ui/pong/main.fxml diff --git a/fxgl-games/src/main/resources/assets/ui/spaceinvaders/fonts/kenvector_future_thin.ttf b/fxgl-samples/src/main/resources/assets/ui/spaceinvaders/fonts/kenvector_future_thin.ttf similarity index 100% rename from fxgl-games/src/main/resources/assets/ui/spaceinvaders/fonts/kenvector_future_thin.ttf rename to fxgl-samples/src/main/resources/assets/ui/spaceinvaders/fonts/kenvector_future_thin.ttf diff --git a/fxgl-games/src/main/resources/assets/ui/spaceinvaders/main.fxml b/fxgl-samples/src/main/resources/assets/ui/spaceinvaders/main.fxml similarity index 100% rename from fxgl-games/src/main/resources/assets/ui/spaceinvaders/main.fxml rename to fxgl-samples/src/main/resources/assets/ui/spaceinvaders/main.fxml diff --git a/fxgl-games/src/main/resources/assets/ui/ui.fxml b/fxgl-samples/src/main/resources/assets/ui/ui.fxml similarity index 100% rename from fxgl-games/src/main/resources/assets/ui/ui.fxml rename to fxgl-samples/src/main/resources/assets/ui/ui.fxml diff --git a/fxgl/pom.xml b/fxgl/pom.xml index 16479710f..f181e8a4e 100644 --- a/fxgl/pom.xml +++ b/fxgl/pom.xml @@ -7,7 +7,7 @@ fxgl-framework com.github.almasb - 0.3.5 + 0.3.6 fxgl diff --git a/fxgl/src/main/java/com/almasb/fxgl/ecs/Entity.java b/fxgl/src/main/java/com/almasb/fxgl/ecs/Entity.java index 9287ff527..1560877af 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/ecs/Entity.java +++ b/fxgl/src/main/java/com/almasb/fxgl/ecs/Entity.java @@ -41,11 +41,11 @@ public class Entity { private ReadOnlyBooleanWrapper active = new ReadOnlyBooleanWrapper(false); - private boolean updating = false; - private boolean delayedRemove = false; private boolean cleaning = false; private boolean controlsEnabled = true; + private boolean isMarkedForRemoval = false; + private Runnable onActive = null; private Runnable onNotActive = null; @@ -71,11 +71,7 @@ void init(GameWorld world) { public final void removeFromWorld() { checkValid(); - if (updating) { - delayedRemove = true; - } else { - world.removeEntity(this); - } + world.removeEntity(this); } /** @@ -125,6 +121,14 @@ public final void setOnNotActive(Runnable action) { onNotActive = action; } + boolean isMarkedForRemoval() { + return isMarkedForRemoval; + } + + void markForRemoval() { + isMarkedForRemoval = true; + } + /** * Setting this to false will disable each control's update until this has * been set back to true. @@ -141,8 +145,6 @@ public final void setControlsEnabled(boolean b) { * @param tpf time per frame */ void update(double tpf) { - updating = true; - if (controlsEnabled) { for (Control c : controls.values()) { if (!c.isPaused()) { @@ -150,11 +152,6 @@ void update(double tpf) { } } } - - updating = false; - - if (delayedRemove) - removeFromWorld(); } /** diff --git a/fxgl/src/main/java/com/almasb/fxgl/ecs/EntityWorldListener.java b/fxgl/src/main/java/com/almasb/fxgl/ecs/EntityWorldListener.java index 9052d5701..6561dcd51 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/ecs/EntityWorldListener.java +++ b/fxgl/src/main/java/com/almasb/fxgl/ecs/EntityWorldListener.java @@ -36,9 +36,4 @@ public interface EntityWorldListener { * @param tpf time per frame */ void onWorldUpdate(double tpf); - - /** - * Called after the world has been reset. - */ - void onWorldReset(); } diff --git a/fxgl/src/main/java/com/almasb/fxgl/ecs/GameWorld.java b/fxgl/src/main/java/com/almasb/fxgl/ecs/GameWorld.java index ba177ea4a..0d84d5351 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/ecs/GameWorld.java +++ b/fxgl/src/main/java/com/almasb/fxgl/ecs/GameWorld.java @@ -14,6 +14,8 @@ import com.almasb.fxgl.core.logging.FXGLLogger; import com.almasb.fxgl.core.logging.Logger; import com.almasb.fxgl.core.reflect.ReflectionUtils; +import com.almasb.fxgl.ecs.component.IrremovableComponent; +import com.almasb.fxgl.ecs.component.TimeComponent; import com.almasb.fxgl.entity.*; import com.almasb.fxgl.entity.component.*; import com.almasb.fxgl.event.EventTrigger; @@ -40,7 +42,7 @@ * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) */ @Singleton -public class GameWorld { +public final class GameWorld { private static Logger log = FXGLLogger.get("FXGL.GameWorld"); @@ -93,8 +95,7 @@ public void addEntity(Entity entity) { waitingList.add(entity); entities.add(entity); - entity.init(this); - notifyEntityAdded(entity); + add(entity); } public void addEntities(Entity... entitiesToAdd) { @@ -104,13 +105,15 @@ public void addEntities(Entity... entitiesToAdd) { } public void removeEntity(Entity entity) { + if (!canRemove(entity)) + return; + if (entity.getWorld() != this) throw new IllegalArgumentException("Attempted to remove entity not attached to this world"); entities.remove(entity); - notifyEntityRemoved(entity); - entity.clean(); + entity.markForRemoval(); } public void removeEntities(Entity... entitiesToRemove) { @@ -131,10 +134,15 @@ private void update(double tpf) { for (Iterator it = updateList.iterator(); it.hasNext(); ) { Entity e = it.next(); - if (e.isActive()) { - e.update(tpf); - } else { + if (e.isMarkedForRemoval()) { + remove(e); it.remove(); + } else { + TimeComponent time = e.getComponent(TimeComponent.class); + + double tpfRatio = time == null ? 1.0 : time.getValue(); + + e.update(tpf * tpfRatio); } } @@ -142,29 +150,44 @@ private void update(double tpf) { } /** - * Resets the world to its initial state. * Does NOT clear state listeners. */ - public void reset() { - log.debug("Resetting game world"); + public void clear() { + log.debug("Clearing game world"); + + for (Iterator it = updateList.iterator(); it.hasNext(); ) { + Entity e = it.next(); - for (Entity e : updateList) { - if (e.isActive()) { - notifyEntityRemoved(e); - e.clean(); + if (canRemove(e)) { + remove(e); + it.remove(); } } - for (Entity e : waitingList) { - notifyEntityRemoved(e); - e.clean(); + for (Iterator it = waitingList.iterator(); it.hasNext(); ) { + Entity e = it.next(); + + if (canRemove(e)) { + remove(e); + it.remove(); + } } - waitingList.clear(); - updateList.clear(); - entities.clear(); + entities.removeIf(this::canRemove); + } + + private void add(Entity entity) { + entity.init(this); + notifyEntityAdded(entity); + } - notifyWorldReset(); + private void remove(Entity entity) { + notifyEntityRemoved(entity); + entity.clean(); + } + + private boolean canRemove(Entity entity) { + return !entity.hasComponent(IrremovableComponent.class); } private Array worldListeners = new Array<>(); @@ -195,12 +218,6 @@ private void notifyWorldUpdated(double tpf) { } } - private void notifyWorldReset() { - for (int i = 0; i < worldListeners.size(); i++) { - worldListeners.get(i).onWorldReset(); - } - } - /** * @return direct list of entities in the world (do NOT modify) */ @@ -264,7 +281,7 @@ public ObjectProperty selectedEntityProperty() { * @param level the level */ public void setLevel(Level level) { - reset(); + clear(); log.debug("Setting level: " + level); level.getEntities().forEach(this::addEntity); @@ -278,7 +295,7 @@ public void setLevelFromMap(String mapFileName) { } public void setLevelFromMap(TiledMap map) { - reset(); + clear(); log.debug("Setting level from map"); diff --git a/fxgl/src/main/java/com/almasb/fxgl/entity/Entities.java b/fxgl/src/main/java/com/almasb/fxgl/entity/Entities.java index bdda7e59b..4a386819a 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/entity/Entities.java +++ b/fxgl/src/main/java/com/almasb/fxgl/entity/Entities.java @@ -292,6 +292,15 @@ public GameEntity build() { return entity; } + /** + * Finishes building the entity and attaches it to default game world. + * + * @return entity + */ + public GameEntity buildAndAttach() { + return buildAndAttach(FXGL.getApp().getGameWorld()); + } + /** * Finishes building the entity and attaches it to given world. * diff --git a/fxgl/src/main/java/com/almasb/fxgl/entity/animation/AnimationBuilder.java b/fxgl/src/main/java/com/almasb/fxgl/entity/animation/AnimationBuilder.java index ad6d9f0e6..bdd1c0ed5 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/entity/animation/AnimationBuilder.java +++ b/fxgl/src/main/java/com/almasb/fxgl/entity/animation/AnimationBuilder.java @@ -7,12 +7,12 @@ package com.almasb.fxgl.entity.animation; import com.almasb.fxgl.entity.GameEntity; +import com.almasb.fxgl.entity.component.ColorComponent; +import com.almasb.fxgl.util.EmptyRunnable; import javafx.animation.Interpolator; import javafx.util.Duration; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; /** @@ -20,30 +20,43 @@ * * @author Almas Baimagambetov (almaslvl@gmail.com) */ -public class AnimationBuilder { +public final class AnimationBuilder { private Duration duration = Duration.seconds(1); private Duration delay = Duration.ZERO; private Interpolator interpolator = Interpolator.LINEAR; private int times = 1; - private List entities = new ArrayList<>(); + private Runnable onFinished = EmptyRunnable.INSTANCE; + private boolean autoReverse = false; - Duration getDelay() { + // guaranteed to be initialized before access by specific animation builder + // see rotate(), scale(), translate(), etc. below + private List entities; + + public Duration getDelay() { return delay; } - Duration getDuration() { + public Duration getDuration() { return duration; } - int getTimes() { + public int getTimes() { return times; } - Interpolator getInterpolator() { + public Interpolator getInterpolator() { return interpolator; } + public Runnable getOnFinished() { + return onFinished; + } + + public boolean isAutoReverse() { + return autoReverse; + } + List getEntities() { return entities; } @@ -63,29 +76,61 @@ public AnimationBuilder repeat(int times) { return this; } + public AnimationBuilder onFinished(Runnable onFinished) { + this.onFinished = onFinished; + return this; + } + public AnimationBuilder interpolator(Interpolator interpolator) { this.interpolator = interpolator; return this; } + public AnimationBuilder autoReverse(boolean autoReverse) { + this.autoReverse = autoReverse; + return this; + } + public RotationAnimationBuilder rotate(GameEntity... entities) { return rotate(Arrays.asList(entities)); } public RotationAnimationBuilder rotate(List entities) { - this.entities.addAll(entities); + this.entities = entities; return new RotationAnimationBuilder(this); } public TranslationAnimationBuilder translate(GameEntity... entities) { - Collections.addAll(this.entities, entities); + return translate(Arrays.asList(entities)); + } + public TranslationAnimationBuilder translate(List entities) { + this.entities = entities; return new TranslationAnimationBuilder(this); } public ScaleAnimationBuilder scale(GameEntity... entities) { - Collections.addAll(this.entities, entities); + return scale(Arrays.asList(entities)); + } + public ScaleAnimationBuilder scale(List entities) { + this.entities = entities; return new ScaleAnimationBuilder(this); } + + public ColorAnimationBuilder color(GameEntity... entities) { + return color(Arrays.asList(entities)); + } + + public ColorAnimationBuilder color(List entities) { + this.entities = entities; + + boolean dontHaveColor = this.entities.stream().anyMatch(e -> !e.hasComponent(ColorComponent.class)); + + if (dontHaveColor) { + throw new IllegalArgumentException("All entities must have ColorComponent"); + } + + return new ColorAnimationBuilder(this); + } } \ No newline at end of file diff --git a/fxgl/src/main/java/com/almasb/fxgl/net/MultiServer.java b/fxgl/src/main/java/com/almasb/fxgl/net/MultiServer.java deleted file mode 100644 index 1e0a33ae2..000000000 --- a/fxgl/src/main/java/com/almasb/fxgl/net/MultiServer.java +++ /dev/null @@ -1,313 +0,0 @@ -/* - * FXGL - JavaFX Game Library. The MIT License (MIT). - * Copyright (c) AlmasB (almaslvl@gmail.com). - * See LICENSE for details. - */ - -package com.almasb.fxgl.net;///* -// * The MIT License (MIT) -// * -// * FXGL - JavaFX Game Library -// * -// * Copyright (c) 2015-2017 AlmasB (almaslvl@gmail.com) -// * -// * Permission is hereby granted, free of charge, to any person obtaining a copy -// * of this software and associated documentation files (the "Software"), to deal -// * in the Software without restriction, including without limitation the rights -// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// * copies of the Software, and to permit persons to whom the Software is -// * furnished to do so, subject to the following conditions: -// * -// * The above copyright notice and this permission notice shall be included in -// * all copies or substantial portions of the Software. -// * -// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// * SOFTWARE. -// */ -// -//package com.almasb.fxgl.net; -// -//import org.apache.logging.log4j.LogManager; -//import org.apache.logging.log4j.Logger; -// -//import java.io.*; -//import java.net.*; -//import java.util.ArrayList; -//import java.util.Collections; -//import java.util.List; -// -///** -// * MultiServer for multiple concurrent network connections (clients) -// *

-// * Since there isn't a 1 to 1 connection, {@link #stop()} must be explicitly -// * called to attempt a clean shutdown of the server -// * -// * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) -// */ -//public final class MultiServer extends NetworkConnection { -// -// private static final Logger log = LogManager.getLogger(MultiServer.class); -// -// private TCPConnectionThread tcpThread = new TCPConnectionThread(); -// private UDPConnectionThread udpThread = new UDPConnectionThread(); -// -// private final List tcpThreads = Collections.synchronizedList(new ArrayList<>()); -// -// private final List addresses = Collections.synchronizedList(new ArrayList<>()); -// private int tcpPort, udpPort; -// -// /** -// * Constructs and configures a multi server with default ports -// * No network operation is done at this point. -// */ -// public MultiServer() { -// this(NetworkConfig.DEFAULT_TCP_PORT, NetworkConfig.DEFAULT_UDP_PORT); -// } -// -// /** -// * Constructs and configures a multi server with specified ports -// * No network operation is done at this point. -// * -// * @param tcpPort tcp port to use -// * @param udpPort udp port to use -// */ -// public MultiServer(int tcpPort, int udpPort) { -// this.tcpPort = tcpPort; -// this.udpPort = udpPort; -// -// tcpThread.setDaemon(true); -// udpThread.setDaemon(true); -// } -// -// /** -// * Starts the server. This performs an actual network operation -// * of binding to ports and listening for incoming connections. -// */ -// public void start() { -// tcpThread.start(); -// udpThread.start(); -// } -// -// /** -// * Sends a message to all connected clients that -// * the server is about to shut down. Then stops the server -// * and the connection threads. -// *

-// * Further calls to {@link #send(Serializable)} will -// * throw IllegalStateException -// */ -// public void stop() { -// sendClosingMessage(); -// -// tcpThread.running = false; -// try { -// tcpThread.server.close(); -// } catch (IOException ignored) { -// } -// -// tcpThreads.forEach(t -> t.running = false); -// udpThread.running = false; -// } -// -// @Override -// public void close() { -// stop(); -// } -// -// @Override -// protected void sendUDP(Serializable data) throws Exception { -// if (udpThread.running) { -// byte[] buf = toByteArray(data); -// synchronized (addresses) { -// for (FullInetAddress addr : addresses) { -// try { -// udpThread.outSocket.send(new DatagramPacket(buf, buf.length, addr.address, addr.port)); -// } catch (Exception e) { -// log.warn("Failed to send UDP message: " + e.getMessage()); -// } -// } -// } -// } else { -// throw new IllegalStateException("UDP connection not active"); -// } -// } -// -// @Override -// protected void sendTCP(Serializable data) throws Exception { -// synchronized (tcpThreads) { -// tcpThreads.stream().filter(tcpThread -> tcpThread.running).forEach(tcpThread -> { -// try { -// tcpThread.outputStream.writeObject(data); -// } catch (Exception e) { -// log.warn("Failed to send TCP message: " + e.getMessage()); -// } -// }); -// } -// } -// -// private class TCPConnectionThread extends Thread { -// private boolean running = true; -// private ServerSocket server; -// -// @Override -// public void run() { -// try { -// server = new ServerSocket(tcpPort); -// } catch (Exception e) { -// log.warn("Exception during TCP connection creation: " + e.getMessage()); -// running = false; -// return; -// } -// -// while (running) { -// try { -// Socket socket = server.accept(); -// socket.setTcpNoDelay(true); -// -// TCPThread t = new TCPThread(socket); -// t.setDaemon(true); -// tcpThreads.add(t); -// t.start(); -// } catch (Exception e) { -// log.warn("Exception during TCP connection execution: " + e.getMessage()); -// } -// } -// -// try { -// server.close(); -// } catch (Exception ignored) { -// } -// log.debug("TCP connection closed normally"); -// } -// } -// -// private class TCPThread extends Thread { -// private boolean running = false; -// private ObjectOutputStream outputStream; -// private Socket socket; -// -// public TCPThread(Socket socket) { -// this.socket = socket; -// } -// -// @Override -// public void run() { -// try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); -// ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) { -// outputStream = out; -// socket.setTcpNoDelay(true); -// running = true; -// -// while (running) { -// Object data = in.readObject(); -// if (data == ConnectionMessage.CLOSE) { -// running = false; -// break; -// } -// if (data == ConnectionMessage.CLOSING) { -// outputStream.writeObject(ConnectionMessage.CLOSE); -// running = false; -// break; -// } -// -// parsers.getOrDefault(data.getClass(), d -> { -// }).parse((Serializable) data); -// } -// } catch (Exception e) { -// log.warn("Exception during TCP connection execution: " + e.getMessage()); -// running = false; -// tcpThreads.remove(this); -// try { -// socket.close(); -// } catch (IOException ignored) { -// } -// return; -// } -// -// tcpThreads.remove(this); -// try { -// socket.close(); -// } catch (IOException ignored) { -// } -// log.debug("TCP connection closed normally"); -// } -// } -// -// private class UDPConnectionThread extends Thread { -// private DatagramSocket outSocket; -// private boolean running = false; -// -// @Override -// public void run() { -// try (DatagramSocket socket = new DatagramSocket(udpPort)) { -// outSocket = socket; -// running = true; -// -// while (running) { -// try { -// byte[] buf = new byte[16384]; -// DatagramPacket datagramPacket = new DatagramPacket(buf, buf.length); -// socket.receive(datagramPacket); -// -// try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(datagramPacket.getData()))) { -// Object data = in.readObject(); -// FullInetAddress addr = new FullInetAddress(datagramPacket.getAddress(), datagramPacket.getPort()); -// -// if (data == ConnectionMessage.OPEN) { -// if (!addresses.contains(addr)) { -// addresses.add(addr); -// } -// } -// if (data == ConnectionMessage.CLOSE) { -// addresses.remove(addr); -// continue; -// } -// if (data == ConnectionMessage.CLOSING) { -// byte[] sendBuf = toByteArray(ConnectionMessage.CLOSE); -// udpThread.outSocket.send(new DatagramPacket(sendBuf, sendBuf.length, addr.address, addr.port)); -// continue; -// } -// -// parsers.getOrDefault(data.getClass(), d -> { -// }).parse((Serializable) data); -// } -// } catch (Exception e) { -// log.warn("Exception during UDP connection execution: " + e.getMessage()); -// } -// } -// } catch (Exception e) { -// log.warn("Exception during UDP connection execution: " + e.getMessage()); -// running = false; -// return; -// } -// -// log.debug("UDP connection closed normally"); -// } -// } -// -// private static class FullInetAddress { -// private InetAddress address; -// private int port; -// -// public FullInetAddress(InetAddress address, int port) { -// this.address = address; -// this.port = port; -// } -// -// @Override -// public boolean equals(Object obj) { -// if (obj instanceof FullInetAddress) { -// FullInetAddress other = (FullInetAddress) obj; -// return this.address.getHostAddress().equals( -// other.address.getHostAddress()) -// && this.port == other.port; -// } -// return false; -// } -// } -//} diff --git a/fxgl/src/main/java/com/almasb/fxgl/physics/PhysicsWorld.java b/fxgl/src/main/java/com/almasb/fxgl/physics/PhysicsWorld.java index dd048a811..43d1147dd 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/physics/PhysicsWorld.java +++ b/fxgl/src/main/java/com/almasb/fxgl/physics/PhysicsWorld.java @@ -261,12 +261,11 @@ private void postStep() { } /** - * Resets physics world. + * Clears collidable entities and active collisions. * Does not clear collision handlers. */ - @Override - public void onWorldReset() { - log.debug("Resetting physics world"); + public void clear() { + log.debug("Clearing physics world"); entities.clear(); collisions.clear(); diff --git a/fxgl/src/main/java/com/almasb/fxgl/scene/GameScene.java b/fxgl/src/main/java/com/almasb/fxgl/scene/GameScene.java index 1669eaaf8..89fb12ac0 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/scene/GameScene.java +++ b/fxgl/src/main/java/com/almasb/fxgl/scene/GameScene.java @@ -38,7 +38,7 @@ * Represents the scene that shows game objects on the screen during "play" mode. * Contains 3 layers. From bottom to top: *

    - *
  1. Entities and their render layers
  2. + *
  3. Entities and their render layers (game view)
  4. *
  5. Particles
  6. *
  7. UI Overlay
  8. *
@@ -202,6 +202,20 @@ public void removeGameView(EntityView view) { getRenderGroup(view.getRenderLayer()).getChildren().remove(view); } + /** + * Removes all nodes from the game view layer. + */ + public void clearGameViews() { + gameRoot.getChildren().clear(); + } + + /** + * Removes all nodes from the UI overlay. + */ + public void clearUINodes() { + uiRoot.getChildren().clear(); + } + /** * Set true if UI elements should forward mouse events * to the game layer. @@ -260,6 +274,8 @@ private Group getRenderGroup(RenderLayer layer) { @Override public void onWorldUpdate(double tpf) { + getViewport().onUpdate(tpf); + particlesGC.setGlobalAlpha(1); particlesGC.setGlobalBlendMode(BlendMode.SRC_OVER); particlesGC.clearRect(0, 0, getWidth(), getHeight()); @@ -277,9 +293,8 @@ public void onWorldUpdate(double tpf) { } } - @Override - public void onWorldReset() { - log.debug("Resetting game scene"); + public void clear() { + log.debug("Clearing game scene"); getViewport().unbind(); drawables.clear(); diff --git a/fxgl/src/main/java/com/almasb/fxgl/scene/menu/FXGLDefaultMenu.java b/fxgl/src/main/java/com/almasb/fxgl/scene/menu/FXGLDefaultMenu.java index c131bd535..f54a33f24 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/scene/menu/FXGLDefaultMenu.java +++ b/fxgl/src/main/java/com/almasb/fxgl/scene/menu/FXGLDefaultMenu.java @@ -114,10 +114,6 @@ protected MenuBox createMenuBodyMainMenu() { box.add(itemContinue); itemContinue.disableProperty().bind(listener.hasSavesProperty().not()); - -// app.getEventBus().addEventHandler(ProfileSelectedEvent.ANY, event -> { -// itemContinue.setDisable(!event.hasSaves()); -// }); } MenuButton itemNewGame = new MenuButton("NEW GAME"); diff --git a/fxgl/src/main/java/com/almasb/fxgl/scene/menu/MenuStyle.java b/fxgl/src/main/java/com/almasb/fxgl/scene/menu/MenuStyle.java deleted file mode 100644 index 91b3a9c95..000000000 --- a/fxgl/src/main/java/com/almasb/fxgl/scene/menu/MenuStyle.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * FXGL - JavaFX Game Library. The MIT License (MIT). - * Copyright (c) AlmasB (almaslvl@gmail.com). - * See LICENSE for details. - */ -package com.almasb.fxgl.scene.menu; - -/** - * FXGL built-in menu styles. NOT COMPLETED YET. - * - * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) - */ -public enum MenuStyle { - FXGL_DEFAULT("fxgl_dark.css"), - - GTA5("fxgl_gta5.css"), - - CCTR("fxgl_cctr.css"), - - WARCRAFT3("fxgl_war3.css"); - - private String css; - - public String getCSSFileName() { - return css; - } - - MenuStyle(String css) { - this.css = css; - } -} diff --git a/fxgl/src/main/java/com/almasb/fxgl/service/AudioPlayer.java b/fxgl/src/main/java/com/almasb/fxgl/service/AudioPlayer.java index 0d801112c..beb0b9a48 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/service/AudioPlayer.java +++ b/fxgl/src/main/java/com/almasb/fxgl/service/AudioPlayer.java @@ -103,6 +103,15 @@ default void playPositionalSound(String assetName, Point2D soundPosition, Point2 */ void playPositionalSound(Sound sound, Point2D soundPosition, Point2D earPosition, double maxDistance); + /** + * @param bgmName name of the background music file to loop + */ + default void loopBGM(String bgmName) { + Music music = FXGL.getAssetLoader().loadMusic(bgmName); + music.setCycleCount(Integer.MAX_VALUE); + playMusic(music); + } + /** * Convenience method to play the music given its filename. * diff --git a/fxgl/src/main/java/com/almasb/fxgl/settings/GameSettings.java b/fxgl/src/main/java/com/almasb/fxgl/settings/GameSettings.java index 063b9fe1c..66bb09224 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/settings/GameSettings.java +++ b/fxgl/src/main/java/com/almasb/fxgl/settings/GameSettings.java @@ -6,7 +6,6 @@ package com.almasb.fxgl.settings; import com.almasb.fxgl.app.ApplicationMode; -import com.almasb.fxgl.scene.menu.MenuStyle; import com.almasb.fxgl.service.ServiceType; import com.almasb.fxgl.util.Credits; import javafx.scene.input.KeyCode; @@ -137,15 +136,6 @@ public void setApplicationMode(ApplicationMode mode) { this.appMode = mode; } - /** - * Set the menu style to use. - * - * @param style menu style - */ - public void setMenuStyle(MenuStyle style) { - this.menuStyle = style; - } - /** * Set the key that will trigger in-game menu. * diff --git a/fxgl/src/main/java/com/almasb/fxgl/settings/ReadOnlyGameSettings.java b/fxgl/src/main/java/com/almasb/fxgl/settings/ReadOnlyGameSettings.java index 026d4e755..6c9d74d61 100644 --- a/fxgl/src/main/java/com/almasb/fxgl/settings/ReadOnlyGameSettings.java +++ b/fxgl/src/main/java/com/almasb/fxgl/settings/ReadOnlyGameSettings.java @@ -6,7 +6,6 @@ package com.almasb.fxgl.settings; import com.almasb.fxgl.app.ApplicationMode; -import com.almasb.fxgl.scene.menu.MenuStyle; import com.almasb.fxgl.service.ServiceType; import com.almasb.fxgl.util.Credits; import javafx.scene.input.KeyCode; @@ -33,7 +32,6 @@ public class ReadOnlyGameSettings { protected boolean profilingEnabled = true; protected boolean closeConfirmation = true; protected ApplicationMode appMode = ApplicationMode.DEVELOPER; - protected MenuStyle menuStyle = MenuStyle.FXGL_DEFAULT; protected KeyCode menuKey = KeyCode.ESCAPE; protected Credits credits = new Credits(Collections.emptyList()); protected List > services = new ArrayList<>(); @@ -64,7 +62,6 @@ public class ReadOnlyGameSettings { this.profilingEnabled = copy.profilingEnabled; this.closeConfirmation = copy.closeConfirmation; this.appMode = copy.appMode; - this.menuStyle = copy.menuStyle; this.menuKey = copy.menuKey; this.credits = new Credits(copy.credits); this.services = copy.services; @@ -111,10 +108,6 @@ public final ApplicationMode getApplicationMode() { return appMode; } - public final MenuStyle getMenuStyle() { - return menuStyle; - } - public final KeyCode getMenuKey() { return menuKey; } @@ -142,7 +135,6 @@ public String toString() { "Menus: " + menuEnabled + '\n' + "Profiling: " + profilingEnabled + '\n' + "App Mode: " + appMode + '\n' + - "Menu Style: " + menuStyle + '\n' + "Menu Key: " + menuKey + '\n' + "Services: " + services; } diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/animation/AnimatedValue.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/AnimatedValue.kt index 850297a21..a621e3e74 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/animation/AnimatedValue.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/AnimatedValue.kt @@ -9,6 +9,7 @@ package com.almasb.fxgl.animation import com.almasb.fxgl.core.math.FXGLMath import javafx.animation.Interpolator import javafx.geometry.Point2D +import javafx.scene.paint.Color import javafx.scene.shape.CubicCurve import javafx.scene.shape.QuadCurve @@ -19,7 +20,7 @@ import javafx.scene.shape.QuadCurve * @author Almas Baimagambetov (almaslvl@gmail.com) */ open class AnimatedValue -@JvmOverloads constructor(val from: T, val to: T, val interpolator: Interpolator = Interpolator.LINEAR) { +@JvmOverloads constructor(val from: T, val to: T, var interpolator: Interpolator = Interpolator.LINEAR) { fun getValue(progress: Double): T { return animate(from, to, progress, interpolator) @@ -65,4 +66,18 @@ class AnimatedCubicBezierPoint2D progress ) } +} + +class AnimatedColor +@JvmOverloads constructor(from: Color, to: Color, interpolator: Interpolator = Interpolator.LINEAR) + : AnimatedValue(from, to, interpolator) { + + override fun animate(val1: Color, val2: Color, progress: Double, interpolator: Interpolator): Color { + return Color.color( + FXGLMath.interpolate(val1.red, val2.red, progress, interpolator), + FXGLMath.interpolate(val1.green, val2.green, progress, interpolator), + FXGLMath.interpolate(val1.blue, val2.blue, progress, interpolator), + FXGLMath.interpolate(val1.opacity, val2.opacity, progress, interpolator) + ) + } } \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/animation/Animation.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/Animation.kt index ee74836f2..abeb84be7 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/animation/Animation.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/Animation.kt @@ -9,6 +9,7 @@ package com.almasb.fxgl.animation import com.almasb.fxgl.app.FXGL import com.almasb.fxgl.app.State import com.almasb.fxgl.app.listener.StateListener +import com.almasb.fxgl.entity.animation.AnimationBuilder import com.almasb.fxgl.util.EmptyRunnable import javafx.util.Duration @@ -23,6 +24,14 @@ abstract class Animation var cycleCount: Int = 1, val animatedValue: AnimatedValue): StateListener { + constructor(animationBuilder: AnimationBuilder, animatedValue: AnimatedValue) : this(animationBuilder.delay, + animationBuilder.duration, + animationBuilder.times, + animatedValue) { + onFinished = animationBuilder.onFinished + isAutoReverse = animationBuilder.isAutoReverse + } + var isAutoReverse = false var onFinished: Runnable = EmptyRunnable @@ -38,6 +47,10 @@ abstract class Animation var isPaused = false private set + /** + * True between start and stop. + * Pauses have no effect on this flag. + */ var isAnimating = false private set diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/animation/Interpolators.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/Interpolators.kt new file mode 100644 index 000000000..d8aa4594a --- /dev/null +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/Interpolators.kt @@ -0,0 +1,293 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.animation + +import javafx.animation.Interpolator + +/** + * Adapted from https://github.com/grapefrukt/juicy-breakout/tree/master/lib/com/gskinner/motion/easing + * + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +enum class Interpolators : EasingInterpolator { + + LINEAR { + override fun easeIn(ratio: Double): Double { + return ratio + } + + override fun easeOut(ratio: Double): Double { + return ratio + } + + override fun easeInOut(ratio: Double): Double { + return ratio + } + }, + + QUADRATIC { + override fun easeIn(ratio: Double): Double { + return ratio*ratio + } + + override fun easeOut(ratio: Double): Double { + return -ratio*(ratio-2) + } + + override fun easeInOut(ratio: Double): Double { + return if (ratio < 0.5) + 2*ratio*ratio + else + -2*ratio*(ratio-2)-1 + } + }, + + CUBIC { + override fun easeIn(ratio: Double): Double { + return ratio*ratio*ratio + } + + override fun easeOut(ratio: Double): Double { + val r = ratio - 1 + return r*r*r+1 + } + + override fun easeInOut(ratio: Double): Double { + val r = ratio - 1 + + return if (ratio < 0.5) + 4*ratio*ratio*ratio + else + 4*r*r*r+1 + } + }, + + QUARTIC { + override fun easeIn(ratio: Double): Double { + return ratio*ratio*ratio*ratio + } + + override fun easeOut(ratio: Double): Double { + val r = ratio - 1 + + return 1-r*r*r*r + } + + override fun easeInOut(ratio: Double): Double { + val r = ratio - 1 + + return if (ratio < 0.5) + 8*ratio*ratio*ratio*ratio + else + -8*r*r*r*r+1 + } + }, + + QUINTIC { + override fun easeIn(ratio: Double): Double { + return ratio*ratio*ratio*ratio*ratio + } + + override fun easeOut(ratio: Double): Double { + val r = ratio - 1 + + return 1 + r*r*r*r*r + } + + override fun easeInOut(ratio: Double): Double { + val r = ratio - 1 + + return if (ratio < 0.5) + 16*ratio*ratio*ratio*ratio*ratio + else + 16 * r*r*r*r*r + 1 + } + }, + + EXPONENTIAL { + override fun easeIn(ratio: Double): Double { + return if (ratio == 0.0) 0.0 else Math.pow(2.0, 10 * (ratio - 1)) + } + + override fun easeOut(ratio: Double): Double { + return if (ratio == 1.0) 1.0 else 1 - Math.pow(2.0, -10 * ratio) + } + + override fun easeInOut(ratio: Double): Double { + if (ratio == 0.0 || ratio == 1.0) + return ratio + + val r = ratio * 2 - 1 + if (r < 0) + return 0.5*Math.pow(2.0, 10*r) + + return 1 - 0.5*Math.pow(2.0, -10*r) + } + }, + + SINE { + override fun easeIn(ratio: Double): Double { + return 1 - Math.cos(ratio * (Math.PI / 2)) + } + + override fun easeOut(ratio: Double): Double { + return Math.sin(ratio * (Math.PI / 2)) + } + + override fun easeInOut(ratio: Double): Double { + return -0.5 * (Math.cos(ratio * Math.PI) - 1) + } + }, + + CIRCULAR { + override fun easeIn(ratio: Double): Double { + return -(Math.sqrt(1 - ratio*ratio) - 1) + } + + override fun easeOut(ratio: Double): Double { + return Math.sqrt(1 - (ratio - 1) * (ratio - 1)) + } + + override fun easeInOut(ratio: Double): Double { + val r = ratio * 2 + val r2 = r - 2 + + return if (r < 1) + -0.5 * (Math.sqrt(1 - r * r) - 1) + else + 0.5 * (Math.sqrt(1 - r2 * r2) + 1) + } + }, + + SMOOTH { + override fun easeIn(ratio: Double): Double { + return Interpolator.EASE_IN.interpolate(0.0, 1.0, ratio) + } + + override fun easeOut(ratio: Double): Double { + return Interpolator.EASE_OUT.interpolate(0.0, 1.0, ratio) + } + + override fun easeInOut(ratio: Double): Double { + return Interpolator.EASE_BOTH.interpolate(0.0, 1.0, ratio) + } + }, + + BOUNCE { + override fun easeIn(ratio: Double): Double { + return 1 - easeOut(1 - ratio) + } + + override fun easeOut(ratio: Double): Double { + if (ratio < 1/2.75) { + return 7.5625*ratio*ratio + } else if (ratio < 2/2.75) { + val r = ratio - 1.5/2.75 + return 7.5625*r*r+0.75 + } else if (ratio < 2.5/2.75) { + val r = ratio-2.25/2.75 + return 7.5625*r*r+0.9375 + } else { + val r = ratio - 2.625/2.75 + return 7.5625*r*r+0.984375 + } + } + + override fun easeInOut(ratio: Double): Double { + val r = ratio * 2 + + return if (r < 1) + 0.5 * easeIn(r) + else + 0.5 * easeOut(r - 1) + 0.5 + } + }, + + ELASTIC { + private val a = 1 + private val p = 0.3 + private val s = p / 4 + + override fun easeIn(ratio: Double): Double { + if (ratio == 0.0 || ratio == 1.0) + return ratio + + val r = ratio - 1 + + return -(a * Math.pow(2.0, 10 * r) * Math.sin((r - s) * (2 * Math.PI) / p)) + } + + override fun easeOut(ratio: Double): Double { + if (ratio == 0.0 || ratio == 1.0) + return ratio + + return a * Math.pow(2.0, -10 * ratio) * Math.sin((ratio - s) * (2 * Math.PI) / p) + 1 + } + + override fun easeInOut(ratio: Double): Double { + if (ratio == 0.0 || ratio == 1.0) + return ratio + + val r = ratio*2 - 1 + + if (r < 0) { + return -0.5 * (a * Math.pow(2.0, 10 * r) * Math.sin((r - s*1.5) * (2 * Math.PI) /(p*1.5))) + } + + return 0.5 * a * Math.pow(2.0, -10 * r) * Math.sin((r - s*1.5) * (2 * Math.PI) / (p*1.5)) + 1 + } + }, + + BACK { + private val s = 1.70158 + + override fun easeIn(ratio: Double): Double { + return ratio * ratio * ((s+1) * ratio - s) + } + + override fun easeOut(ratio: Double): Double { + val r = ratio - 1 + + return r * r * ((s+1) * r + s) + 1 + } + + override fun easeInOut(ratio: Double): Double { + val r = ratio * 2 + val r2 = r - 2 + + return if (r < 1) + 0.5*(r*r*((s*1.525+1)*r-s*1.525)) + else + 0.5*(r2 * r2 * ((s*1.525 + 1) * r2 + s*1.525)+2) + } + } +} + +interface EasingInterpolator { + + fun EASE_IN(): Interpolator = object : Interpolator() { + override fun curve(t: Double): Double { + return easeIn(t) + } + } + + fun EASE_OUT(): Interpolator = object : Interpolator() { + override fun curve(t: Double): Double { + return easeOut(t) + } + } + + fun EASE_IN_OUT(): Interpolator = object : Interpolator() { + override fun curve(t: Double): Double { + return easeInOut(t) + } + } + + fun easeIn(ratio: Double): Double + fun easeOut(ratio: Double): Double + fun easeInOut(ratio: Double): Double +} \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/animation/ParallelAnimation.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/ParallelAnimation.kt new file mode 100644 index 000000000..720a12451 --- /dev/null +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/ParallelAnimation.kt @@ -0,0 +1,136 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.animation + +import com.almasb.fxgl.app.FXGL +import com.almasb.fxgl.app.State +import com.almasb.fxgl.app.listener.StateListener +import com.almasb.fxgl.util.EmptyRunnable + +/** + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class ParallelAnimation(var cycleCount: Int = 1, vararg animations: Animation<*>) : StateListener { + + constructor(vararg animations: Animation<*>) : this(1, *animations) + + private val animations: List> = animations.toList() + + var isAutoReverse = false + var onFinished: Runnable = EmptyRunnable + + private var count = 0 + + var isReverse = false + private set + + var isPaused = false + private set + + /** + * True between start and stop. + * Pauses have no effect on this flag. + */ + var isAnimating = false + private set + + private var checkDelay = true + + init { + if (animations.isEmpty()) + throw IllegalArgumentException("Animation list is empty!") + } + + /** + * State in which we are animating. + */ + private lateinit var state: State + + fun startInPlayState() { + start(FXGL.getApp().stateMachine.playState) + } + + fun startReverse(state: State) { + if (!isAnimating) { + isReverse = true + start(state) + } + } + + fun start(state: State) { + if (!isAnimating) { + this.state = state + isAnimating = true + state.addStateListener(this) + + // reset animations, then start + if (isReverse) { + animations.forEach { + (it as Animation).onProgress(it.animatedValue.getValue(1.0)) + it.startReverse(state) + } + } else { + animations.forEach { + (it as Animation).onProgress(it.animatedValue.getValue(0.0)) + it.start(state) + } + } + } + } + + fun stop() { + if (isAnimating) { + isAnimating = false + state.removeStateListener(this) + count = 0 + isReverse = false + checkDelay = true + } + } + + fun pause() { + isPaused = true + } + + fun resume() { + isPaused = false + } + + override fun onUpdate(tpf: Double) { + if (isPaused) + return + + val isFinished = animations.none { it.isAnimating } + + if (isFinished) { + count++ + + if (count >= cycleCount) { + onFinished.run() + stop() + return + } else { + if (isAutoReverse) { + isReverse = !isReverse + + // reset animations, then start + if (isReverse) { + animations.forEach { + (it as Animation).onProgress(it.animatedValue.getValue(1.0)) + it.startReverse(state) + } + } else { + animations.forEach { + (it as Animation).onProgress(it.animatedValue.getValue(0.0)) + it.start(state) + } + } + } + } + } + } +} \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/animation/SequentialAnimation.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/SequentialAnimation.kt new file mode 100644 index 000000000..c33c7a664 --- /dev/null +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/animation/SequentialAnimation.kt @@ -0,0 +1,141 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.animation + +import com.almasb.fxgl.app.FXGL +import com.almasb.fxgl.app.State +import com.almasb.fxgl.app.listener.StateListener +import com.almasb.fxgl.util.EmptyRunnable + +/** + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class SequentialAnimation +@JvmOverloads constructor(var cycleCount: Int = 1, vararg animations: Animation<*>) : StateListener { + + private val animations: List> = animations.toList() + + var isAutoReverse = false + var onFinished: Runnable = EmptyRunnable + + private var count = 0 + + var isReverse = false + private set + + var isPaused = false + private set + + /** + * True between start and stop. + * Pauses have no effect on this flag. + */ + var isAnimating = false + private set + + private var checkDelay = true + + private var animationIndex = 0 + + init { + if (animations.isEmpty()) + throw IllegalArgumentException("Animation list is empty!") + } + + /** + * State in which we are animating. + */ + private lateinit var state: State + + fun startInPlayState() { + start(FXGL.getApp().stateMachine.playState) + } + + fun startReverse(state: State) { + if (!isAnimating) { + isReverse = true + start(state) + } + } + + fun start(state: State) { + if (!isAnimating) { + this.state = state + isAnimating = true + state.addStateListener(this) + + animationIndex = if (isReverse) animations.size-1 else 0 + + // reset animations, then start + if (isReverse) { + animations.forEach { (it as Animation).onProgress(it.animatedValue.getValue(1.0)) } + animations[animationIndex].startReverse(state) + } else { + animations.forEach { (it as Animation).onProgress(it.animatedValue.getValue(0.0)) } + animations[animationIndex].start(state) + } + } + } + + fun stop() { + if (isAnimating) { + isAnimating = false + state.removeStateListener(this) + count = 0 + isReverse = false + checkDelay = true + } + } + + fun pause() { + isPaused = true + } + + fun resume() { + isPaused = false + } + + override fun onUpdate(tpf: Double) { + if (isPaused) + return + + val anim = animations[animationIndex] + + if (!anim.isAnimating) { + animationIndex += if (isReverse) -1 else 1 + + if ((!isReverse && animationIndex == animations.size) || (isReverse && animationIndex == -1)) { + + count++ + + if (count >= cycleCount) { + onFinished.run() + stop() + return + } else { + if (isAutoReverse) { + isReverse = !isReverse + } + } + + animationIndex = if (isReverse) animations.size-1 else 0 + + if (isReverse) { + animations.forEach { (it as Animation).onProgress(it.animatedValue.getValue(1.0)) } + } else { + animations.forEach { (it as Animation).onProgress(it.animatedValue.getValue(0.0)) } + } + } + + if (isReverse) { + animations[animationIndex].startReverse(state) + } else { + animations[animationIndex].start(state) + } + } + } +} \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/app/DSL.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/app/DSL.kt index ec8bace3a..9d0e3c03c 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/app/DSL.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/app/DSL.kt @@ -6,22 +6,143 @@ package com.almasb.fxgl.app +import com.almasb.fxgl.texture.Texture + +import com.almasb.fxgl.app.FXGL.Companion.getApp +import com.almasb.fxgl.app.FXGL.Companion.getAssetLoader +import com.almasb.fxgl.app.FXGL.Companion.getAudioPlayer +import com.almasb.fxgl.app.FXGL.Companion.getInput +import com.almasb.fxgl.core.math.FXGLMath.* +import com.almasb.fxgl.ecs.Entity +import com.almasb.fxgl.input.UserAction +import com.almasb.fxgl.physics.CollisionHandler +import javafx.beans.property.* +import javafx.geometry.Point2D +import javafx.scene.input.KeyCode +import java.util.function.BiConsumer + /** * This API is experimental. + * Using this API results in more concise but less readable code. + * Use with care. * * @author Almas Baimagambetov (almaslvl@gmail.com) */ -fun set(varName: String, value: Any) { - FXGL.getApp().gameState.setValue(varName, value) +/* VARS */ + +fun set(varName: String, value: Any) = getApp().gameState.setValue(varName, value) + +fun geti(varName: String): Int = getApp().gameState.getInt(varName) + +fun getd(varName: String): Double = getApp().gameState.getDouble(varName) + +fun getb(varName: String): Boolean = getApp().gameState.getBoolean(varName) + +fun gets(varName: String): String = getApp().gameState.getString(varName) + +fun geto(varName: String): T = getApp().gameState.getObject(varName) + +fun getip(varName: String): IntegerProperty = getApp().gameState.intProperty(varName) + +fun getdp(varName: String): DoubleProperty = getApp().gameState.doubleProperty(varName) + +fun getbp(varName: String): BooleanProperty = getApp().gameState.booleanProperty(varName) + +fun getsp(varName: String): StringProperty = getApp().gameState.stringProperty(varName) + +fun getop(varName: String): ObjectProperty = getApp().gameState.objectProperty(varName) + +fun inc(varName: String, value: Int) = getApp().gameState.increment(varName, value) + +fun inc(varName: String, value: Double) = getApp().gameState.increment(varName, value) + +/* ASSET LOADING */ + +fun texture(assetName: String): Texture = getAssetLoader().loadTexture(assetName) + +fun texture(assetName: String, width: Double, height: Double): Texture = getAssetLoader().loadTexture(assetName, width, height) + +fun text(assetName: String) = getAssetLoader().loadText(assetName) + +fun jsonAs(name: String, type: Class): T = getAssetLoader().loadJSON(name, type) + +/* AUDIO */ + +fun loopBGM(assetName: String) = getAudioPlayer().loopBGM(assetName) + +fun play(assetName: String) { + if (assetName.endsWith(".wav")) { + getAudioPlayer().playSound(assetName) + } else if (assetName.endsWith(".mp3")) { + getAudioPlayer().playMusic(assetName) + } else { + throw IllegalArgumentException("Unsupported audio format: $assetName") + } +} + +/* INPUT */ + +fun onKeyDown(key: KeyCode, actionName: String, action: Runnable) { + getInput().addAction(object : UserAction(actionName) { + override fun onActionBegin() { + action.run() + } + }, key) +} + +fun onKey(key: KeyCode, actionName: String, action: Runnable) { + getInput().addAction(object : UserAction(actionName) { + override fun onAction() { + action.run() + } + }, key) +} + +fun onKeyUp(key: KeyCode, actionName: String, action: Runnable) { + getInput().addAction(object : UserAction(actionName) { + override fun onActionEnd() { + action.run() + } + }, key) } -fun geti(varName: String): Int = FXGL.getApp().gameState.getInt(varName) +/* GAME WORLD */ -fun getd(varName: String): Double = FXGL.getApp().gameState.getDouble(varName) +fun spawn(entityName: String): Entity = getApp().gameWorld.spawn(entityName) + +fun spawn(entityName: String, x: Double, y: Double): Entity = getApp().gameWorld.spawn(entityName, x, y) + +fun spawn(entityName: String, position: Point2D): Entity = getApp().gameWorld.spawn(entityName, position) + +/* PHYSICS */ + +fun onCollisionBegin(typeA: Enum<*>, typeB: Enum<*>, action: BiConsumer) { + getApp().physicsWorld.addCollisionHandler(object : CollisionHandler(typeA, typeB) { + override fun onCollisionBegin(a: Entity, b: Entity) { + action.accept(a, b) + } + }) +} + +fun onCollision(typeA: Enum<*>, typeB: Enum<*>, action: BiConsumer) { + getApp().physicsWorld.addCollisionHandler(object : CollisionHandler(typeA, typeB) { + override fun onCollision(a: Entity, b: Entity) { + action.accept(a, b) + } + }) +} + +fun onCollisionEnd(typeA: Enum<*>, typeB: Enum<*>, action: BiConsumer) { + getApp().physicsWorld.addCollisionHandler(object : CollisionHandler(typeA, typeB) { + override fun onCollisionEnd(a: Entity, b: Entity) { + action.accept(a, b) + } + }) +} -fun getb(varName: String): Boolean = FXGL.getApp().gameState.getBoolean(varName) +/* MATH */ -fun gets(varName: String): String = FXGL.getApp().gameState.getString(varName) +fun rand() = random() -fun geto(varName: String): T = FXGL.getApp().gameState.getObject(varName) \ No newline at end of file +fun rand(min: Int, max: Int) = random(min, max) \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/app/LoadingState.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/app/LoadingState.kt index 36d7d316b..6f96d3699 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/app/LoadingState.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/app/LoadingState.kt @@ -99,9 +99,11 @@ internal class LoadingState private fun clearPreviousGame() { log.debug("Clearing previous game") - app.gameWorld.reset() - app.gameState.clear() + app.gameWorld.clear() + app.physicsWorld.clear() app.physicsWorld.clearCollisionHandlers() + app.gameScene.clear() + app.gameState.clear() app.masterTimer.clear() } diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/app/MenuEventHandler.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/app/MenuEventHandler.kt index 7c3661c02..531b814b6 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/app/MenuEventHandler.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/app/MenuEventHandler.kt @@ -87,6 +87,7 @@ internal class MenuEventHandler(private val app: GameApplication) : MenuEventLis saveLoadManager .saveTask(dataFile, saveFile) + .onSuccessKt { hasSaves.value = true } .executeAsyncWithDialogFX(ProgressDialog("Saving data: $saveFileName")) } diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/app/PauseMenuSubState.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/app/PauseMenuSubState.kt index f66345b41..ddc385f8e 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/app/PauseMenuSubState.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/app/PauseMenuSubState.kt @@ -7,6 +7,7 @@ package com.almasb.fxgl.app import com.almasb.fxgl.animation.Animation +import com.almasb.fxgl.animation.Interpolators import com.almasb.fxgl.input.UserAction import com.almasb.fxgl.texture.Texture import com.almasb.fxgl.util.EmptyRunnable @@ -60,7 +61,8 @@ internal object PauseMenuSubState : SubState() { animation = FXGL.getUIFactory().translate(content, Point2D(FXGL.getAppWidth() / 2.0 - 125, -400.0), Point2D(FXGL.getAppWidth() / 2.0 - 125, FXGL.getAppHeight() / 2.0 - 200), - Duration.seconds(0.33)) + Duration.seconds(0.5)) + animation.animatedValue.interpolator = Interpolators.BACK.EASE_OUT() } override fun onEnter(prevState: State) { diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/asset/FXGLAssets.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/asset/FXGLAssets.kt index 94d453faf..39abbaf5a 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/asset/FXGLAssets.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/asset/FXGLAssets.kt @@ -44,22 +44,9 @@ class FXGLAssets { UI_FONT = loader.loadFont(getString("ui.font")) UI_MONO_FONT = loader.loadFont(getString("ui.mono.font")) - UI_CSS = loadCSS() + UI_CSS = loader.loadCSS(getString("ui.css")) UI_ICON_NAME = getString("ui.icon.name") UI_ICON = loader.loadAppIcon(UI_ICON_NAME) } - - private fun loadCSS(): CSS { - val cssExternalForm = getString("ui.css") - - return FXGL.getAssetLoader().loadCSS( - - // if default css, then use menu style css - if (cssExternalForm.endsWith("fxgl.css")) - FXGL.getSettings().menuStyle.cssFileName - else - cssExternalForm - ) - } } } \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/devtools/DeveloperPane.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/devtools/DeveloperPane.kt index f48432e74..ebd2abded 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/devtools/DeveloperPane.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/devtools/DeveloperPane.kt @@ -98,6 +98,4 @@ class DeveloperPane : VBox(25.0), EntityWorldListener { } override fun onWorldUpdate(tpf: Double) { } - - override fun onWorldReset() { } } \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/ecs/component/IrremovableComponent.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/ecs/component/IrremovableComponent.kt new file mode 100644 index 000000000..876085a08 --- /dev/null +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/ecs/component/IrremovableComponent.kt @@ -0,0 +1,12 @@ +package com.almasb.fxgl.ecs.component + +import com.almasb.fxgl.ecs.Component + +/** + * Marks an entity that cannot be removed from the game world. + * To remove such entity, this component must be removed first. + * + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class IrremovableComponent : Component() { +} \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/ecs/component/TimeComponent.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/ecs/component/TimeComponent.kt new file mode 100644 index 000000000..4a6c9a19e --- /dev/null +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/ecs/component/TimeComponent.kt @@ -0,0 +1,9 @@ +package com.almasb.fxgl.ecs.component + +/** + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class TimeComponent +@JvmOverloads constructor(value: Double = 1.0) : DoubleComponent(value) { + +} \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/ColorAnimationBuilder.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/ColorAnimationBuilder.kt new file mode 100644 index 000000000..2f8f7e065 --- /dev/null +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/ColorAnimationBuilder.kt @@ -0,0 +1,48 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.entity.animation + +import com.almasb.fxgl.animation.AnimatedColor +import com.almasb.fxgl.animation.Animation +import com.almasb.fxgl.entity.component.ColorComponent +import javafx.scene.paint.Color + +/** + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class ColorAnimationBuilder(private val animationBuilder: AnimationBuilder) { + + private var startColor = Color.TRANSPARENT + private var endColor = Color.TRANSPARENT + + fun fromColor(startColor: Color): ColorAnimationBuilder { + this.startColor = startColor + return this + } + + fun toColor(endColor: Color): ColorAnimationBuilder { + this.endColor = endColor + return this + } + + fun build(): Animation<*> { + return object : Animation(animationBuilder, AnimatedColor(startColor, endColor, animationBuilder.interpolator)) { + + override fun onProgress(value: Color) { + animationBuilder.entities + .map { it.getComponent(ColorComponent::class.java) } + .forEach { it.value = value } + } + } + } + + fun buildAndPlay(): Animation<*> { + val anim = build() + anim.startInPlayState() + return anim + } +} \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/RotationAnimationBuilder.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/RotationAnimationBuilder.kt index ace481e35..6bb85af74 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/RotationAnimationBuilder.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/RotationAnimationBuilder.kt @@ -30,8 +30,7 @@ class RotationAnimationBuilder(private val animationBuilder: AnimationBuilder) { } fun build(): Animation<*> { - return object : Animation(animationBuilder.delay, animationBuilder.duration, animationBuilder.times, - AnimatedValue(startAngle, endAngle, animationBuilder.interpolator)) { + return object : Animation(animationBuilder, AnimatedValue(startAngle, endAngle, animationBuilder.interpolator)) { override fun onProgress(value: Double) { animationBuilder.entities.forEach { it.rotation = value } diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/ScaleAnimationBuilder.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/ScaleAnimationBuilder.kt index 59167d880..daf6d4fb9 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/ScaleAnimationBuilder.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/ScaleAnimationBuilder.kt @@ -31,8 +31,7 @@ class ScaleAnimationBuilder(private val animationBuilder: AnimationBuilder) { } fun build(): Animation<*> { - return object : Animation(animationBuilder.delay, animationBuilder.duration, animationBuilder.times, - AnimatedPoint2D(startScale, endScale, animationBuilder.interpolator)) { + return object : Animation(animationBuilder, AnimatedPoint2D(startScale, endScale, animationBuilder.interpolator)) { override fun onProgress(value: Point2D) { animationBuilder.entities.forEach { diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/TranslationAnimationBuilder.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/TranslationAnimationBuilder.kt index a1191a29e..aff1db93a 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/TranslationAnimationBuilder.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/animation/TranslationAnimationBuilder.kt @@ -52,8 +52,7 @@ class TranslationAnimationBuilder(private val animationBuilder: AnimationBuilder } private fun makeAnim(animValue: AnimatedValue): Animation { - return object : Animation(animationBuilder.delay, animationBuilder.duration, animationBuilder.times, - animValue) { + return object : Animation(animationBuilder, animValue) { override fun onProgress(value: Point2D) { animationBuilder.entities.forEach { it.position = value } diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/entity/component/ColorComponent.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/component/ColorComponent.kt new file mode 100644 index 000000000..3cb181501 --- /dev/null +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/component/ColorComponent.kt @@ -0,0 +1,16 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.entity.component + +import com.almasb.fxgl.ecs.component.ObjectComponent +import javafx.scene.paint.Color + +/** + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class ColorComponent : ObjectComponent(Color.TRANSPARENT) { +} \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/entity/component/HighlightableComponent.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/component/HighlightableComponent.kt new file mode 100644 index 000000000..5f93a2e7a --- /dev/null +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/entity/component/HighlightableComponent.kt @@ -0,0 +1,117 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.entity.component + +import com.almasb.fxgl.animation.Animation +import com.almasb.fxgl.animation.SequentialAnimation +import com.almasb.fxgl.app.FXGL +import com.almasb.fxgl.ecs.Component +import com.almasb.fxgl.ecs.Entity +import com.almasb.fxgl.ecs.component.Required +import com.almasb.fxgl.entity.Entities +import javafx.geometry.Point2D +import javafx.scene.Node +import javafx.scene.Parent +import javafx.scene.paint.Color +import javafx.scene.shape.Rectangle +import javafx.util.Duration +import jfxtras.util.NodeUtil + +/** + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +@Required(ViewComponent::class) +class HighlightableComponent : Component() { + + companion object { + private val SIZE = 2.0 + + private class HighlightView : Parent() { + + private val animations = arrayListOf>() + + fun startForView(view: Node) { + children.clear() + + val light = Rectangle(view.layoutBounds.maxX, view.layoutBounds.maxY, null) + with(light) { + translateX = -1.0 + translateY = -1.0 + stroke = Color.YELLOW + strokeWidth = 2.0 + } + + val particle = makeParticle(0.0, 0.0) + + children.addAll(light, particle) + + val speed = 240.0 + + val dist1 = Point2D(-SIZE, -SIZE).distance(Point2D(view.layoutBounds.maxX, (-SIZE))) + val dist2 = Point2D(view.layoutBounds.maxX, (-SIZE)).distance(Point2D(view.layoutBounds.maxX, view.layoutBounds.maxY)) + val dist3 = Point2D(view.layoutBounds.maxX, view.layoutBounds.maxY).distance(Point2D((-SIZE), view.layoutBounds.maxY)) + val dist4 = Point2D((-SIZE), view.layoutBounds.maxY).distance(Point2D(-SIZE, -SIZE)) + + SequentialAnimation(1, + FXGL.getUIFactory().translate(particle, Point2D(-SIZE, -SIZE), Point2D(view.layoutBounds.maxX, (-SIZE)), Duration.seconds(dist1 / speed)), + FXGL.getUIFactory().translate(particle, Point2D(view.layoutBounds.maxX, (-SIZE)), Point2D(view.layoutBounds.maxX, view.layoutBounds.maxY), Duration.seconds(dist2 / speed)), + FXGL.getUIFactory().translate(particle, Point2D(view.layoutBounds.maxX, view.layoutBounds.maxY), Point2D((-SIZE), view.layoutBounds.maxY), Duration.seconds(dist3 / speed)), + FXGL.getUIFactory().translate(particle, Point2D((-SIZE), view.layoutBounds.maxY), Point2D(-SIZE, -SIZE), Duration.seconds(dist4 / speed)) + + ).startInPlayState() + +// animations.forEach { it.stop() } +// animations.clear() +// +// children.addAll( +// makeParticle((-SIZE), (-SIZE)), +// makeParticle(view.layoutBounds.maxX, (-SIZE)), +// makeParticle(view.layoutBounds.maxX, view.layoutBounds.maxY), +// makeParticle((-SIZE), view.layoutBounds.maxY) +// ) +// +// for (i in 0..children.size-1) { +// val animation = FXGL.getUIFactory() +// .translate(children[i], +// Point2D(children[if (i == children.size-1) 0 else i + 1].translateX, children[if (i == children.size-1) 0 else i + 1].translateY), +// Duration.seconds(1.0)) +// +// animation.cycleCount = Integer.MAX_VALUE +// animations.add(animation) +// animation.startInPlayState() +// } + } + + private fun makeParticle(x: Double, y: Double): Node { + //val particle = FXGL.getAssetLoader().loadTexture("highlight_particle.png", SIZE, SIZE).multiplyColor(Color.DARKRED) + val particle = Rectangle(SIZE, SIZE, Color.color(0.7, 0.5, 0.3, 0.75)) + particle.translateX = x + particle.translateY = y + return particle + } + } + + private val HIGHLIGHT = HighlightView() + } + + override fun onAdded(entity: Entity) { + val view = Entities.getView(entity) + + view.view.setOnMouseEntered { + if (HIGHLIGHT.scene != null) { + NodeUtil.removeFromParent(HIGHLIGHT) + } + + HIGHLIGHT.startForView(view.view) + view.view.addNode(HIGHLIGHT) + } + + view.view.setOnMouseExited { + view.view.removeNode(HIGHLIGHT) + } + } +} \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/io/FS.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/io/FS.kt index 840910916..3ac7e105b 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/io/FS.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/io/FS.kt @@ -6,7 +6,7 @@ package com.almasb.fxgl.io -import org.apache.logging.log4j.LogManager +import com.almasb.fxgl.core.logging.FXGLLogger import java.io.* import java.nio.file.* import java.nio.file.attribute.BasicFileAttributes @@ -17,15 +17,15 @@ import java.util.stream.Collectors * * @author Almas Baimagambetov (almaslvl@gmail.com) */ -class FS { +class FS +private constructor() { companion object { - private val log = LogManager.getLogger(FS::class.java) + private val log = FXGLLogger.get(FS::class.java) private fun errorIfAbsent(path: Path) { if (!Files.exists(path)) { - log.warn ( "Path $path does not exist" ) throw FileNotFoundException("Path $path does not exist") } } @@ -43,12 +43,12 @@ class FS { // if file.parent is null we will use current dir, which exists if (file.parent != null && !Files.exists(file.parent)) { - log.debug ( "Creating directories to: ${file.parent}" ) + log.debug("Creating directories to: ${file.parent}") Files.createDirectories(file.parent) } ObjectOutputStream(Files.newOutputStream(file)).use { - log.debug ( "Writing to: $file" ) + log.debug("Writing to: $file") it.writeObject(data) } }) @@ -68,7 +68,7 @@ class FS { errorIfAbsent(file) ObjectInputStream(Files.newInputStream(file)).use { - log.debug ( "Reading from: $file" ) + log.debug("Reading from: $file") return@taskOf it.readObject() as T } } @@ -172,7 +172,7 @@ class FS { errorIfAbsent(file) - log.debug ( "Deleting file: $file" ) + log.debug("Deleting file: $file") Files.delete(file) } @@ -191,17 +191,17 @@ class FS { Files.walkFileTree(dir, object : SimpleFileVisitor() { override fun visitFile(file: Path, p1: BasicFileAttributes): FileVisitResult { - log.debug ( "Deleting file: $file" ) + log.debug("Deleting file: $file") Files.delete(file) return FileVisitResult.CONTINUE } - override fun postVisitDirectory(dir: Path, e: IOException?): FileVisitResult { + override fun postVisitDirectory(directory: Path, e: IOException?): FileVisitResult { if (e == null) { - log.debug ( "Deleting directory: $dir" ) + log.debug("Deleting directory: $directory") - Files.delete(dir) + Files.delete(directory) return FileVisitResult.CONTINUE } else { throw e diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/scene/SceneFactory.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/scene/SceneFactory.kt index 6d4da9ea2..7ad656b02 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/scene/SceneFactory.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/scene/SceneFactory.kt @@ -47,12 +47,7 @@ open class SceneFactory { * @return main menu */ open fun newMainMenu(app: GameApplication): FXGLMenu { - when (app.settings.menuStyle) { - MenuStyle.GTA5 -> return GTAVMenu(app, MenuType.MAIN_MENU) - MenuStyle.CCTR -> return CCTRMenu(app, MenuType.MAIN_MENU) - MenuStyle.WARCRAFT3 -> return Warcraft3Menu(app, MenuType.MAIN_MENU) - else -> return FXGLDefaultMenu(app, MenuType.MAIN_MENU) - } + return FXGLDefaultMenu(app, MenuType.MAIN_MENU) } /** @@ -63,11 +58,6 @@ open class SceneFactory { * @return game menu */ open fun newGameMenu(app: GameApplication): FXGLMenu { - when (app.settings.menuStyle) { - MenuStyle.GTA5 -> return GTAVMenu(app, MenuType.GAME_MENU) - MenuStyle.CCTR -> return CCTRMenu(app, MenuType.GAME_MENU) - MenuStyle.WARCRAFT3 -> return Warcraft3Menu(app, MenuType.GAME_MENU) - else -> return FXGLDefaultMenu(app, MenuType.GAME_MENU) - } + return FXGLDefaultMenu(app, MenuType.GAME_MENU) } } \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/scene/Viewport.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/scene/Viewport.kt index e34bd8968..39bffaae1 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/scene/Viewport.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/scene/Viewport.kt @@ -6,6 +6,8 @@ package com.almasb.fxgl.scene +import com.almasb.fxgl.core.math.FXGLMath +import com.almasb.fxgl.core.math.Vec2 import com.almasb.fxgl.ecs.Entity import com.almasb.fxgl.entity.component.BoundingBoxComponent import com.almasb.fxgl.entity.component.PositionComponent @@ -16,7 +18,7 @@ import javafx.geometry.Point2D import javafx.geometry.Rectangle2D /** - * Game scene viewport. + * Scene viewport. * * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com) */ @@ -170,4 +172,40 @@ class Viewport this.maxX.set(maxX) this.maxY.set(maxY) } + + // adapted from https://gamedev.stackexchange.com/questions/1828/realistic-camera-screen-shake-from-explosion + private var shakePower = 0.0f + private var shakeAngle = 0.0f + private val originBeforeShake = Vec2() + private val offset = Vec2() + private var shake = false + + fun shake(power: Double) { + shakePower = power.toFloat() + shakeAngle = FXGLMath.random() * FXGLMath.PI2 + + // only record origin if not shaking, so that we don't record 'false' origin + if (!shake) + originBeforeShake.set(x.floatValue(), y.floatValue()) + + shake = true + } + + fun onUpdate(tpf: Double) { + if (!shake) + return + + shakePower *= 0.9f * 60 * tpf.toFloat() + shakeAngle += 180 + FXGLMath.random() * FXGLMath.PI2 / 6 + offset.set(shakePower * FXGLMath.cos(shakeAngle), shakePower * FXGLMath.sin(shakeAngle)) + + setX(offset.x + originBeforeShake.x.toDouble()) + setY(offset.y + originBeforeShake.y.toDouble()) + + if (FXGLMath.abs(offset.x) < 0.5 && FXGLMath.abs(offset.y) < 0.5) { + setX(originBeforeShake.x.toDouble()) + setY(originBeforeShake.y.toDouble()) + shake = false + } + } } \ No newline at end of file diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/ui/LevelText.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/ui/LevelText.kt new file mode 100644 index 000000000..bfa161da8 --- /dev/null +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/ui/LevelText.kt @@ -0,0 +1,61 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.ui + +import com.almasb.fxgl.animation.ParallelAnimation +import com.almasb.fxgl.app.FXGL +import javafx.geometry.Point2D +import javafx.scene.layout.StackPane +import javafx.scene.paint.Color +import javafx.scene.paint.CycleMethod +import javafx.scene.paint.LinearGradient +import javafx.scene.paint.Stop +import javafx.scene.shape.Rectangle +import javafx.scene.text.Text +import javafx.util.Duration + +/** + * By default level text is invisible and [animateIn] is used to reveal the text + * via an animation. + * Then [animateOut] can be used to make this node invisible again. + * + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class LevelText(levelName: String) : StackPane() { + + private val text: Text = FXGL.getUIFactory().newText(levelName, Color.WHITESMOKE, 46.0) + private val bg = Rectangle(text.layoutBounds.width + 100, text.layoutBounds.height + 20) + + init { + translateX = FXGL.getAppWidth() / 2 - text.layoutBounds.width / 2 + translateY = FXGL.getAppHeight() / 3.0 + opacity = 0.0 + + with(bg) { + arcWidth = 35.0 + arcHeight = 35.0 + fill = LinearGradient(0.0, 0.0, 1.0, 0.0, true, CycleMethod.NO_CYCLE, + Stop(0.0, Color.TRANSPARENT), + Stop(0.5, Color.color(0.0, 0.0, 0.0, 0.85)), + Stop(1.0, Color.TRANSPARENT) + ) + } + + children.addAll(bg, text) + } + + fun animateIn() { + ParallelAnimation( + FXGL.getUIFactory().fadeIn(this@LevelText, Duration.seconds(1.0)), + FXGL.getUIFactory().translate(text, Point2D(-20.0, 0.0), Point2D.ZERO, Duration.seconds(1.0)) + ).startInPlayState() + } + + fun animateOut() { + FXGL.getUIFactory().fadeOut(this, Duration.seconds(1.0)).startInPlayState() + } +} \ No newline at end of file diff --git a/fxgl/src/main/resources/com/almasb/fxgl/app/system.properties b/fxgl/src/main/resources/com/almasb/fxgl/app/system.properties index 48e31d868..70f78af4a 100644 --- a/fxgl/src/main/resources/com/almasb/fxgl/app/system.properties +++ b/fxgl/src/main/resources/com/almasb/fxgl/app/system.properties @@ -6,6 +6,7 @@ # # FXGL System Properties +# Mostly used to change things that don't require recompilation, e.g. sounds / css / fonts # # Supported value types: @@ -51,8 +52,8 @@ sound.menu.press = menu/press.wav ui.font = Copperplate_Gothic_Light_Regular.ttf ui.mono.font = lucida_console.ttf -# default CSS loaded from ui/css, empty -ui.css = fxgl.css +# default CSS loaded from ui/css +ui.css = fxgl_dark.css # default icon loaded from ui/icons, this is displayed in task bar and window title ui.icon.name = fxgl_icon.png diff --git a/fxgl/src/test/java/com/almasb/fxgl/app/MockGameApplication.java b/fxgl/src/test/java/com/almasb/fxgl/app/MockGameApplication.java index cb5bf6e04..76d1eb9d1 100644 --- a/fxgl/src/test/java/com/almasb/fxgl/app/MockGameApplication.java +++ b/fxgl/src/test/java/com/almasb/fxgl/app/MockGameApplication.java @@ -5,7 +5,6 @@ */ package com.almasb.fxgl.app; -import com.almasb.fxgl.scene.menu.MenuStyle; import com.almasb.fxgl.service.ServiceType; import com.almasb.fxgl.settings.GameSettings; import com.almasb.fxgl.util.Credits; @@ -41,7 +40,6 @@ protected void initSettings(GameSettings settings) { settings.setProfilingEnabled(false); settings.setCloseConfirmation(false); settings.setMenuKey(KeyCode.ENTER); - settings.setMenuStyle(MenuStyle.CCTR); settings.setCredits(new Credits(Arrays.asList("TestCredit1", "TestCredit2"))); settings.addServiceType(new ServiceType() { @Override diff --git a/fxgl/src/test/java/com/almasb/fxgl/ecs/EntityTest.java b/fxgl/src/test/java/com/almasb/fxgl/ecs/EntityTest.java index 51e5623a7..fb2f62dc4 100644 --- a/fxgl/src/test/java/com/almasb/fxgl/ecs/EntityTest.java +++ b/fxgl/src/test/java/com/almasb/fxgl/ecs/EntityTest.java @@ -389,6 +389,7 @@ public void testActiveCallbacks() { assertThat(hp.value, is(30.0)); world.removeEntity(entity); + world.onUpdate(0); assertThat(hp.value, is(-50.0)); assertFalse(entity.activeProperty().get()); @@ -413,6 +414,7 @@ public void testIntegrity() { world.addEntity(entity); world.removeEntity(entity); + world.onUpdate(0); try { entity.addComponent(new HPComponent(23)); diff --git a/fxgl/src/test/kotlin/com/almasb/fxgl/animation/AnimatedValueTest.kt b/fxgl/src/test/kotlin/com/almasb/fxgl/animation/AnimatedValueTest.kt new file mode 100644 index 000000000..8e782545e --- /dev/null +++ b/fxgl/src/test/kotlin/com/almasb/fxgl/animation/AnimatedValueTest.kt @@ -0,0 +1,36 @@ +/* + * FXGL - JavaFX Game Library. The MIT License (MIT). + * Copyright (c) AlmasB (almaslvl@gmail.com). + * See LICENSE for details. + */ + +package com.almasb.fxgl.animation + +import javafx.geometry.Point2D +import org.hamcrest.CoreMatchers.`is` +import org.junit.Assert.assertThat +import org.junit.Test + +/** + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class AnimatedValueTest { + + @Test + fun `Point2D`() { + val anim = AnimatedPoint2D(Point2D(0.0, 0.0), Point2D(100.0, 100.0)) + + assertThat(anim.getValue(0.0), `is`(Point2D(0.0, 0.0))) + assertThat(anim.getValue(1.0), `is`(Point2D(100.0, 100.0))) + assertThat(anim.getValue(0.5), `is`(Point2D(50.0, 50.0))) + } + + @Test + fun `Double`() { + val anim = AnimatedValue(100.0, 200.0) + + assertThat(anim.getValue(0.0), `is`(100.0)) + assertThat(anim.getValue(1.0), `is`(200.0)) + assertThat(anim.getValue(0.5), `is`(150.0)) + } +} \ No newline at end of file diff --git a/fxgl/src/test/kotlin/com/almasb/fxgl/ecs/GameWorldTest.kt b/fxgl/src/test/kotlin/com/almasb/fxgl/ecs/GameWorldTest.kt index e554d2090..096f82fad 100644 --- a/fxgl/src/test/kotlin/com/almasb/fxgl/ecs/GameWorldTest.kt +++ b/fxgl/src/test/kotlin/com/almasb/fxgl/ecs/GameWorldTest.kt @@ -10,6 +10,7 @@ import com.almasb.fxgl.annotation.Spawns import com.almasb.fxgl.app.FXGL import com.almasb.fxgl.app.MockApplicationModule import com.almasb.fxgl.core.collection.Array +import com.almasb.fxgl.ecs.component.IrremovableComponent import com.almasb.fxgl.entity.* import com.almasb.fxgl.entity.component.IDComponent import com.almasb.fxgl.entity.component.PositionComponent @@ -292,6 +293,17 @@ class GameWorldTest { gameWorld.removeEntity(e) } + @Test + fun `Do not remove if entity has IrremovableComponent`() { + val e = Entity() + e.addComponent(IrremovableComponent()) + + gameWorld.addEntity(e) + gameWorld.removeEntity(e) + + assertThat(gameWorld.entities, hasItems(e)) + } + @Test fun `Remove multiple entities`() { assertThat(gameWorld.entities, hasItems(e1, e2)) @@ -304,11 +316,22 @@ class GameWorldTest { fun `Reset`() { assertThat(gameWorld.entities.size, `is`(not(0))) - gameWorld.reset() + gameWorld.clear() assertThat(gameWorld.entities.size, `is`(0)) } + @Test + fun `Reset does not remove if entity has IrremovableComponent`() { + val e = Entity() + e.addComponent(IrremovableComponent()) + + gameWorld.addEntity(e) + gameWorld.clear() + + assertThat(gameWorld.entities, hasItems(e)) + } + @Test fun `Set level`() { val e = Entity() diff --git a/fxgl/src/test/kotlin/com/almasb/fxgl/io/FSTest.kt b/fxgl/src/test/kotlin/com/almasb/fxgl/io/FSTest.kt new file mode 100644 index 000000000..31daf2098 --- /dev/null +++ b/fxgl/src/test/kotlin/com/almasb/fxgl/io/FSTest.kt @@ -0,0 +1,70 @@ +package com.almasb.fxgl.io + +import com.almasb.fxgl.app.FXGL +import com.almasb.fxgl.app.MockApplicationModule +import org.hamcrest.CoreMatchers +import org.hamcrest.CoreMatchers.hasItems +import org.junit.AfterClass +import org.junit.Assert +import org.junit.Assert.* +import org.junit.BeforeClass +import org.junit.Test +import java.nio.file.Files +import java.nio.file.Paths + +/** + * @author Almas Baimagambetov (almaslvl@gmail.com) + */ +class FSTest { + + companion object { + @BeforeClass + @JvmStatic fun before() { + cleanUp() + + Files.createDirectories(Paths.get("testdir")) + Files.createDirectories(Paths.get("testdir/testsubdir")) + + Files.createFile(Paths.get("testdir/testfile.txt")) + Files.createFile(Paths.get("testdir/testfile.json")) + + assertTrue("test file is not present before", Files.exists(Paths.get("testdir/testfile.txt"))) + assertTrue("test file is not present before", Files.exists(Paths.get("testdir/testfile.json"))) + } + + @AfterClass + @JvmStatic fun cleanUp() { + // ensure previous tests have been cleared + Files.deleteIfExists(Paths.get("testdir/testfile.txt")) + Files.deleteIfExists(Paths.get("testdir/testfile.json")) + Files.deleteIfExists(Paths.get("testdir/testsubdir")) + Files.deleteIfExists(Paths.get("testdir/somefile")) + Files.deleteIfExists(Paths.get("testdir")) + + assertTrue("test dir is present before", !Files.exists(Paths.get("testdir"))) + } + } + + @Test + fun `Load file names from a dir`() { + val fileNames = FS.loadFileNamesTask("testdir", false).execute() + + assertThat(fileNames, hasItems("testfile.txt", "testfile.json")) + } + + @Test + fun `Load dir names from a dir`() { + val dirNames = FS.loadDirectoryNamesTask("testdir", false).execute() + + assertThat(dirNames, hasItems("testsubdir")) + } + + @Test + fun `File not present after delete`() { + Files.createFile(Paths.get("testdir/somefile")) + assertTrue(Files.exists(Paths.get("testdir/somefile"))) + + FS.deleteFileTask("testdir/somefile").execute() + assertFalse(Files.exists(Paths.get("testdir/somefile"))) + } +} \ No newline at end of file diff --git a/fxgl/src/test/kotlin/com/almasb/fxgl/settings/GameSettingsTest.kt b/fxgl/src/test/kotlin/com/almasb/fxgl/settings/GameSettingsTest.kt index c53cebd5c..33b65082e 100644 --- a/fxgl/src/test/kotlin/com/almasb/fxgl/settings/GameSettingsTest.kt +++ b/fxgl/src/test/kotlin/com/almasb/fxgl/settings/GameSettingsTest.kt @@ -70,7 +70,6 @@ class GameSettingsTest { assertThat(settings.profilingEnabled, `is`(false)) assertThat(settings.closeConfirmation, `is`(false)) assertThat(settings.menuKey, `is`(KeyCode.ENTER)) - assertThat(settings.menuStyle, `is`(com.almasb.fxgl.scene.menu.MenuStyle.CCTR)) assertThat(settings.credits.list, hasItems("TestCredit1", "TestCredit2")) assertThat(settings.appMode, `is`(ApplicationMode.RELEASE)) } diff --git a/pom.xml b/pom.xml index 68e3e0ed0..09097bed0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.github.almasb fxgl-framework - 0.3.5 + 0.3.6 pom ${project.groupId}:${project.artifactId} @@ -12,11 +12,14 @@ http://almasb.github.io/FXGL/ + fxgl - + + fxgl-extra + + fxgl-samples - fxgl-games @@ -72,8 +75,8 @@ 4.5.3 - 1.1.2-2 - 0.14.1 + 1.1.3-2 + 0.16 4.1.0 8.0-r5 8.40.12