Skip to content

Commit

Permalink
Merge pull request #34 from LBF38/development
Browse files Browse the repository at this point in the history
🚀 release v1.0.0
  • Loading branch information
LBF38 authored Mar 12, 2023
2 parents 2a795aa + 2e5f449 commit dce3256
Show file tree
Hide file tree
Showing 37 changed files with 1,295 additions and 710 deletions.
2 changes: 1 addition & 1 deletion duelinvaders/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.enstabretagne</groupId>
<artifactId>duelinvaders</artifactId>
<version>0.3.1</version>
<version>1.0.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.enstabretagne.Core;
package org.enstabretagne.Collision;

import static com.almasb.fxgl.dsl.FXGL.getGameWorld;
import static com.almasb.fxgl.dsl.FXGL.play;
import static com.almasb.fxgl.dsl.FXGL.set;
import static com.almasb.fxgl.dsl.FXGL.spawn;

import org.enstabretagne.Component.BulletComponent;
import org.enstabretagne.Component.EntityType;
import org.enstabretagne.Component.PlayerComponent;
import org.enstabretagne.Utils.EntityType;
import org.enstabretagne.Utils.GameVariableNames;
import org.enstabretagne.Utils.assetNames;
import org.enstabretagne.Utils.entityNames;

Expand Down Expand Up @@ -43,10 +44,8 @@ public AlienBulletCollision() {
protected void onCollisionBegin(Entity bullet, Entity alien) {
bullet.removeFromWorld();
alien.removeFromWorld();
int playerId = bullet.getComponent(BulletComponent.class).getPlayerId();
Entity player = getGameWorld().getEntitiesByType(EntityType.PLAYER).stream()
.filter(p -> p.getComponent(PlayerComponent.class).getId() == playerId).findFirst().get();
player.getComponent(PlayerComponent.class).incrementScore();
PlayerComponent playerComponent = bullet.getComponent(BulletComponent.class).getPlayerComponent();
playerComponent.incrementScore();

spawn(entityNames.EXPLOSION_ALIEN, alien.getPosition());
play(assetNames.sounds.EXPLOSION_ALIEN);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.enstabretagne.Core;
package org.enstabretagne.Collision;

import static com.almasb.fxgl.dsl.FXGL.play;
import static com.almasb.fxgl.dsl.FXGL.set;
import static com.almasb.fxgl.dsl.FXGL.spawn;

import org.enstabretagne.Component.EntityType;
import org.enstabretagne.Utils.EntityType;
import org.enstabretagne.Utils.GameVariableNames;
import org.enstabretagne.Utils.assetNames;
import org.enstabretagne.Utils.entityNames;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.enstabretagne.Core;
package org.enstabretagne.Collision;

import static com.almasb.fxgl.dsl.FXGL.play;
import static com.almasb.fxgl.dsl.FXGL.spawn;

import org.enstabretagne.Component.EntityType;
import org.enstabretagne.Utils.EntityType;
import org.enstabretagne.Utils.assetNames;
import org.enstabretagne.Utils.entityNames;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

package org.enstabretagne.Core;
package org.enstabretagne.Collision;

import static com.almasb.fxgl.dsl.FXGL.play;
import static com.almasb.fxgl.dsl.FXGL.runOnce;
import static com.almasb.fxgl.dsl.FXGL.set;
import static com.almasb.fxgl.dsl.FXGL.spawn;

import org.enstabretagne.Component.EntityType;
import org.enstabretagne.Component.PlayerComponent;
import org.enstabretagne.Utils.EntityType;
import org.enstabretagne.Utils.GameVariableNames;
import org.enstabretagne.Utils.assetNames;
import org.enstabretagne.Utils.entityNames;

Expand Down Expand Up @@ -42,14 +43,14 @@ protected void onCollisionBegin(Entity bullet, Entity player) {
if (bullet.hasComponent(PlayerComponent.class)) {
bullet.getComponent(PlayerComponent.class).incrementScore();
}
if (playerComponent.getLife() == 0) {
spawn(entityNames.EXPLOSION_PLAYER_DEATH, player.getPosition());
player.removeFromWorld();
play(assetNames.sounds.EXPLOSION_PLAYER_DEATH);
runOnce(() -> set(GameVariableNames.isGameOver, true), Duration.seconds(2));
} else {
if (playerComponent.getLife() != 0) {
spawn(entityNames.EXPLOSION_PLAYER_BULLET, bullet.getPosition());
play(assetNames.sounds.EXPLOSION_PLAYER_LIFE);
return;
}
spawn(entityNames.EXPLOSION_PLAYER_DEATH, player.getPosition());
player.removeFromWorld();
play(assetNames.sounds.EXPLOSION_PLAYER_DEATH);
runOnce(() -> set(GameVariableNames.isGameOver, true), Duration.seconds(2));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.enstabretagne.Core;
package org.enstabretagne.Collision;

import static com.almasb.fxgl.dsl.FXGL.play;
import static com.almasb.fxgl.dsl.FXGL.spawn;

import org.enstabretagne.Component.EntityType;
import org.enstabretagne.Utils.EntityType;
import org.enstabretagne.Utils.assetNames;
import org.enstabretagne.Utils.entityNames;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

package org.enstabretagne.Core;
package org.enstabretagne.Collision;

import static com.almasb.fxgl.dsl.FXGL.play;
import static com.almasb.fxgl.dsl.FXGL.set;
import static com.almasb.fxgl.dsl.FXGL.spawn;

import org.enstabretagne.Component.EntityType;
import org.enstabretagne.Component.PlayerComponent;
import org.enstabretagne.Utils.EntityType;
import org.enstabretagne.Utils.GameVariableNames;
import org.enstabretagne.Utils.assetNames;
import org.enstabretagne.Utils.entityNames;

Expand Down Expand Up @@ -36,14 +37,14 @@ protected void onCollisionBegin(Entity enemy_shoot, Entity player) {
enemy_shoot.removeFromWorld();
PlayerComponent playerComponent = player.getComponent(PlayerComponent.class);
playerComponent.decrementLife();
if (playerComponent.getLife() == 0) {
spawn(entityNames.EXPLOSION_PLAYER_DEATH, player.getPosition());
play(assetNames.sounds.EXPLOSION_PLAYER_DEATH);
set(GameVariableNames.isGameOver, true);
player.removeFromWorld();
} else {
if (playerComponent.getLife() != 0) {
spawn(entityNames.EXPLOSION_PLAYER_BULLET, enemy_shoot.getPosition());
play(assetNames.sounds.EXPLOSION_PLAYER_LIFE);
return;
}
spawn(entityNames.EXPLOSION_PLAYER_DEATH, player.getPosition());
play(assetNames.sounds.EXPLOSION_PLAYER_DEATH);
set(GameVariableNames.isGameOver, true);
player.removeFromWorld();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.enstabretagne.Component;

import org.enstabretagne.Core.Constant;
import org.enstabretagne.Core.Constant.Direction;
import org.enstabretagne.Utils.Settings;
import org.enstabretagne.Utils.entityNames;
import org.enstabretagne.Utils.Settings.Direction;

import com.almasb.fxgl.core.math.FXGLMath;
import com.almasb.fxgl.entity.Entity;
Expand All @@ -22,7 +22,7 @@ public class AlienComponent extends Component {
private Direction movementDirection;
private Direction globalDirection;
private Double last_shot = 0.0;
private double limit_right = Constant.GAME_WIDTH;
private double limit_right = Settings.GAME_WIDTH;
private double limit_left = 0.0;

/**
Expand Down Expand Up @@ -54,12 +54,12 @@ public AlienComponent() {
* Initialise l'alien
*
*/
public void initialize(Constant.Direction direction) {
public void initialize(Settings.Direction direction) {
this.globalDirection = direction;
if (direction == Constant.Direction.UP) {
if (direction == Settings.Direction.UP) {
entity.rotateBy(180);
this.movementDirection = Direction.RIGHT;
} else if (direction == Constant.Direction.DOWN) {
} else if (direction == Settings.Direction.DOWN) {
this.movementDirection = Direction.LEFT;
}

Expand All @@ -72,11 +72,15 @@ public void initialize(Constant.Direction direction) {
*/
@Override
public void onUpdate(double tpf) {
dx = tpf * Constant.SPEED_ALIEN;
dx = tpf * Settings.SPEED_ALIEN;
dy = entity.getHeight();
this.move(dx);
}

public Direction getDirection() {
return globalDirection;
}

/**
* Déplacement de l'alien selon la direction et les limites du jeu.
* L'alien se déplace de dx pixels.
Expand All @@ -98,14 +102,15 @@ else if (this.movementDirection == Direction.LEFT)
public void moveRight(Double dx) {
if (this.entity.getRightX() + dx <= limit_right) {
this.entity.translateX(dx);
} else {
if (this.globalDirection == Constant.Direction.DOWN) {
this.entity.translateY(dy);
} else if (this.globalDirection == Constant.Direction.UP) {
this.entity.translateY(-dy);
}
this.movementDirection = Direction.LEFT;
return;
}

if (this.globalDirection == Settings.Direction.DOWN) {
this.entity.translateY(dy);
} else if (this.globalDirection == Settings.Direction.UP) {
this.entity.translateY(-dy);
}
this.movementDirection = Direction.LEFT;
}

/**
Expand All @@ -116,19 +121,20 @@ public void moveRight(Double dx) {
public void moveLeft(Double dx) {
if (this.entity.getX() - dx >= limit_left) {
this.entity.translateX(-dx);
} else {
if (this.globalDirection == Constant.Direction.DOWN) {
this.entity.translateY(dy);
} else if (this.globalDirection == Constant.Direction.UP) {
this.entity.translateY(-dy);
}
this.movementDirection = Direction.RIGHT;
return;
}

if (this.globalDirection == Settings.Direction.DOWN) {
this.entity.translateY(dy);
} else if (this.globalDirection == Settings.Direction.UP) {
this.entity.translateY(-dy);
}
this.movementDirection = Direction.RIGHT;
}

public void setAlienNumber(int AlienNumber) {
limit_right = Constant.GAME_WIDTH - (Constant.ALIEN_WIDTH * (Constant.ALIENS_NUMBER - AlienNumber - 1));
limit_left = 0.0 + (Constant.ALIEN_WIDTH * AlienNumber);
limit_right = Settings.GAME_WIDTH - (Settings.ALIEN_WIDTH * (Settings.ALIENS_NUMBER - AlienNumber - 1));
limit_left = 0.0 + (Settings.ALIEN_WIDTH * AlienNumber);
}

/**
Expand All @@ -146,13 +152,13 @@ public void randomShoot(double chance) {
* L'alien tire un projectile à une cadence définie dans {@code}Constant{@code}.
*/
public void shoot() {
Boolean canShoot = getGameTimer().getNow() - last_shot.doubleValue() >= Constant.RATE_ALIEN_SHOOT.doubleValue();
Boolean canShoot = getGameTimer().getNow() - last_shot.doubleValue() >= Settings.RATE_ALIEN_SHOOT.doubleValue();
if (!canShoot)
return;

double x = this.entity.getX() + this.entity.getWidth() / 2;
double y = this.entity.getY();
if (this.globalDirection == Constant.Direction.DOWN)
if (this.globalDirection == Settings.Direction.DOWN)
y += this.entity.getHeight();

spawn(entityNames.ECLAT, x, y);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.enstabretagne.Component;

import org.enstabretagne.Core.Constant;
import org.enstabretagne.Utils.Settings;

import com.almasb.fxgl.dsl.components.ExpireCleanComponent;
import com.almasb.fxgl.dsl.components.ProjectileComponent;
Expand All @@ -17,17 +17,17 @@
* @since 0.1.0
*/
public class BulletComponent extends Component {
private Double speed = Constant.SPEED_SHOOT;
private Duration duration = Constant.BULLET_DURATION;
private Double speed = Settings.SPEED_SHOOT;
private Duration duration = Settings.BULLET_DURATION;
private Point2D direction = new Point2D(0, -1);
private int playerId;
private PlayerComponent playerComponent;

public int getPlayerId() {
return playerId;
public PlayerComponent getPlayerComponent() {
return playerComponent;
}

public void setPlayerId(int player_id) {
this.playerId = player_id;
public void setPlayer(PlayerComponent playerComponent) {
this.playerComponent = playerComponent;
}

public BulletComponent() {
Expand All @@ -41,8 +41,8 @@ public BulletComponent() {
* Ce sont des composants prédéfinis dans la librairie FXGL qui facilite la
* création de projectiles
*/
public void initialize(Constant.Direction UporDown) {
this.direction = new Point2D(0, UporDown == Constant.Direction.UP ? -1 : 1);
public void initialize(Settings.Direction UporDown) {
this.direction = new Point2D(0, UporDown == Settings.Direction.UP ? -1 : 1);
this.entity.addComponent(new ProjectileComponent(direction, speed));
this.entity.addComponent(new ExpireCleanComponent(duration));
}
Expand Down

This file was deleted.

Loading

0 comments on commit dce3256

Please sign in to comment.