Skip to content

Commit

Permalink
Merge pull request #117 from QwitherY/main
Browse files Browse the repository at this point in the history
Add animation of an explosion when the dinosaurs are killed
  • Loading branch information
jvondermarck authored Dec 24, 2024
2 parents 3fd8a57 + 73b638f commit 1553d78
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,20 +12,23 @@
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;

import static com.almasb.fxgl.dsl.FXGLForKtKt.texture;

/**
* 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 {
/**
Expand Down Expand Up @@ -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 :
Expand Down
Binary file added src/main/resources/assets/textures/explosion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1553d78

Please sign in to comment.