diff --git a/.idea/misc.xml b/.idea/misc.xml
index dc377ec..9dc782b 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,5 +8,5 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.java b/src/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.java
index e9554cf..1951993 100644
--- a/src/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.java
+++ b/src/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.java
@@ -92,6 +92,7 @@ public void initGame() {
*/
public void initPhysics() {
onCollisionBegin(EntityType.PROJECTILE, EntityType.GREENDINO, (projectile, greendino) -> {
+ spawn("explosion", greendino.getX() - 25, greendino.getY() - 30);
FXGL.play(GameConstants.ENEMY_EXPLODE_SOUND);
projectile.removeFromWorld();
greendino.removeFromWorld();
diff --git a/src/main/java/com/dinosaur/dinosaurexploder/model/GameEntityFactory.java b/src/main/java/com/dinosaur/dinosaurexploder/model/GameEntityFactory.java
index 6c57eb7..9e171e8 100644
--- a/src/main/java/com/dinosaur/dinosaurexploder/model/GameEntityFactory.java
+++ b/src/main/java/com/dinosaur/dinosaurexploder/model/GameEntityFactory.java
@@ -2,6 +2,7 @@
import com.almasb.fxgl.dsl.EntityBuilder;
import com.almasb.fxgl.dsl.FXGL;
+import com.almasb.fxgl.dsl.components.ExpireCleanComponent;
import com.almasb.fxgl.dsl.components.OffscreenCleanComponent;
import com.almasb.fxgl.dsl.components.ProjectileComponent;
import com.almasb.fxgl.dsl.views.SelfScrollingBackgroundView;
@@ -11,12 +12,15 @@
import com.almasb.fxgl.entity.Spawns;
import com.almasb.fxgl.physics.BoundingShape;
import com.almasb.fxgl.physics.HitBox;
+import com.almasb.fxgl.texture.AnimatedTexture;
+import com.almasb.fxgl.texture.AnimationChannel;
import javafx.geometry.Orientation;
import javafx.geometry.Point2D;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
+import javafx.util.Duration;
import java.util.Objects;
@@ -24,7 +28,7 @@
/**
* Summary :
- * The Factory handles the creation of Background , Player , Score , Life , Dino
+ * The Factory handles the creation of Background , Player , Score , Life , Dino, Explosion
*/
public class GameEntityFactory implements EntityFactory {
/**
@@ -133,6 +137,26 @@ public Entity newLife(SpawnData data)
.with(new LifeComponent())
.with(new OffscreenCleanComponent()).build();
}
+
+ /**
+ * Summary :
+ * Animation of an explosion will be handled in below Entity
+ */
+ @Spawns("explosion")
+ public Entity newExplosion(SpawnData data)
+ {
+ Duration seconds = Duration.seconds(0.4);
+ AnimationChannel ac = new AnimationChannel(
+ FXGL.image("explosion.png"),
+ seconds, 16);
+
+ AnimatedTexture at = new AnimatedTexture(ac);
+ at.play();
+ return FXGL.entityBuilder(data)
+ .view(at)
+ .with(new ExpireCleanComponent(seconds))
+ .build();
+ }
/**
* Summary :
diff --git a/src/main/resources/assets/textures/explosion.png b/src/main/resources/assets/textures/explosion.png
new file mode 100644
index 0000000..5743585
Binary files /dev/null and b/src/main/resources/assets/textures/explosion.png differ