Skip to content

Commit

Permalink
Fixed merge conflicts for release v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LBF38 committed Jan 3, 2023
2 parents fc5b95a + 2b52451 commit 207655c
Show file tree
Hide file tree
Showing 27 changed files with 822 additions and 150 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.1.0</version>
<version>0.2.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.component.Component;

import javafx.geometry.Point2D;

import static com.almasb.fxgl.dsl.FXGL.*;

/**
* Cette classe représente le comportement des aliens
* Elle permet de définir les données associées à l'alien et son comportement
*
* @author LBF38
* @author LBF38, MathieuDFS
* @since 0.1.0
*/
public class AlienComponent extends Component {
private Double dx, dy;
protected Direction movementDirection;
private Direction movementDirection;
private Direction globalDirection;
private Double last_shot = 0.0;
private double limit_right = Constant.GAME_WIDTH;
private double limit_left = 0.0;

/**
* Constructeur de la classe AlienComponent
Expand All @@ -49,6 +50,21 @@ public AlienComponent() {
this(Direction.DOWN);
}

/**
* Initialise l'alien
*
*/
public void initialize(Constant.Direction direction) {
this.globalDirection = direction;
if (direction == Constant.Direction.UP) {
entity.rotateBy(180);
this.movementDirection = Direction.RIGHT;
} else if (direction == Constant.Direction.DOWN) {
this.movementDirection = Direction.LEFT;
}

}

/**
* Méthode héritée de la classe Component.
* Elle permet de définir comment se met à jour l'alien.
Expand All @@ -57,7 +73,7 @@ public AlienComponent() {
@Override
public void onUpdate(double tpf) {
dx = tpf * Constant.SPEED_ALIEN;
dy = 0.5 * Constant.SPEED_ALIEN;
dy = entity.getHeight();
this.move(dx);
}

Expand All @@ -68,12 +84,6 @@ public void onUpdate(double tpf) {
* @param dx
*/
public void move(Double dx) {
if (this.entity.getBottomY() >= Constant.GAME_HEIGHT) {
// TODO: to remove if unnecessary
System.out.println("Game Over");
return;
}

if (this.movementDirection == Direction.RIGHT)
moveRight(dx);
else if (this.movementDirection == Direction.LEFT)
Expand All @@ -86,10 +96,14 @@ else if (this.movementDirection == Direction.LEFT)
* @param dx
*/
public void moveRight(Double dx) {
if (this.entity.getRightX() + dx <= Constant.GAME_WIDTH) {
if (this.entity.getRightX() + dx <= limit_right) {
this.entity.translateX(dx);
} else {
this.entity.translateY(dy);
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;
}
}
Expand All @@ -100,14 +114,23 @@ public void moveRight(Double dx) {
* @param dx
*/
public void moveLeft(Double dx) {
if (this.entity.getX() - dx >= 0) {
if (this.entity.getX() - dx >= limit_left) {
this.entity.translateX(-dx);
} else {
this.entity.translateY(dy);
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;
}
}

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);
}

/**
* Tir aléatoire de l'alien.
*
Expand All @@ -124,16 +147,19 @@ public void randomShoot(double chance) {
*/
public void shoot() {
Boolean canShoot = getGameTimer().getNow() - last_shot.doubleValue() >= Constant.RATE_ALIEN_SHOOT.doubleValue();
if (canShoot || last_shot == null) {
double x = this.entity.getX() + this.entity.getWidth() / 2;
double y = this.entity.getY() + this.entity.getHeight();
spawn(entityNames.ECLAT,x,y);
Entity bullet = spawn(entityNames.BULLET_ALIEN, x, y);
BulletComponent bulletComponent = bullet.getComponent(BulletComponent.class);
// TODO: rendre le shotDirection dépendant de la direction de l'alien
bulletComponent.setDirection(new Point2D(0, 1));
bulletComponent.initialize();
last_shot = getGameTimer().getNow();
}
if (!canShoot)
return;

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

spawn(entityNames.ECLAT, x, y);
Entity bullet = spawn(entityNames.BULLET_ALIEN, x, y);

bullet.getComponent(BulletComponent.class).initialize(this.globalDirection);
bullet.rotateBy(90.0);
last_shot = getGameTimer().getNow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public BulletComponent() {
* Ce sont des composants prédéfinis dans la librairie FXGL qui facilite la
* création de projectiles
*/
public void initialize() {
public void initialize(Constant.Direction UporDown) {
this.direction= new Point2D(0, UporDown == Constant.Direction.UP ? -1 : 1);
this.entity.addComponent(new ProjectileComponent(direction, speed));
this.entity.addComponent(new ExpireCleanComponent(duration));
this.entity.rotateBy(90);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* Définition des types d'entités disponibles dans le jeu
*
* @author jufch, LBF38, MathieuDFS
* @since 0.1.0
*/
public enum EntityType {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.enstabretagne.Component;

import org.enstabretagne.Core.Constant;

import com.almasb.fxgl.entity.component.Component;

/**
* Cette classe représente l'affichage du nombre de vies restantes.
*
* @author MathieuDFS, jufch
* @since 0.2.0
*/
public class LifeComponent extends Component {
/**
* Initialise le composant affichage de vie
*/
public void initialize(Constant.Direction direction) {
if (direction == Constant.Direction.UP) {
entity.setX(Constant.GAME_WIDTH - Constant.LIFE_DISPLAY_WIDTH);
entity.setY(0);
} else if (direction == Constant.Direction.DOWN) {
entity.setX(Constant.GAME_WIDTH - Constant.LIFE_DISPLAY_WIDTH);
entity.setY(Constant.GAME_HEIGHT - Constant.LIFE_DISPLAY_HEIGHT);
}
}

public void updateLife(boolean isActive) {
entity.getViewComponent().setOpacity(isActive ? 1 : 0);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package org.enstabretagne.Component;

import static org.enstabretagne.Core.Constant.*;
import static com.almasb.fxgl.dsl.FXGL.getGameTimer;
import static com.almasb.fxgl.dsl.FXGL.runOnce;
import static com.almasb.fxgl.dsl.FXGL.spawn;
import static org.enstabretagne.Core.Constant.DELAY_BETWEEN_SHOOT;
import static org.enstabretagne.Core.Constant.GAME_WIDTH;
import static org.enstabretagne.Core.Constant.PLAYER_HEIGHT;
import static org.enstabretagne.Core.Constant.SPEED_SPACESHIP;

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

import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.component.Component;
import javafx.util.Duration;

import static com.almasb.fxgl.dsl.FXGL.*;
import javafx.geometry.Point2D;
import javafx.util.Duration;

/**
* Définition du composant pour le joueur
Expand All @@ -19,7 +27,24 @@
public class PlayerComponent extends Component {
private Double dx;
private Double last_shot = 0.0;
private int side_shoot = 0;
private Direction side_shoot = Direction.LEFT;
private Constant.Direction direction = Constant.Direction.UP;

/**
* Setter de la direction du joueur
* Pour la rotation de l'image du joueur, on ne prend pas en compte les
* directions LEFT et RIGHT
*
* @param direction
*/
public void setDirection(Constant.Direction direction) {
if (direction == Constant.Direction.LEFT || direction == Constant.Direction.RIGHT)
return;
if (this.direction == direction)
return;
entity.rotateBy(180);
this.direction = direction;
}

/**
* Mise à jour de la vitesse du joueur à chaque frame.
Expand Down Expand Up @@ -56,32 +81,65 @@ public void moveLeft() {
*/
public void shoot() {
Boolean canShoot = getGameTimer().getNow() - last_shot.doubleValue() >= DELAY_BETWEEN_SHOOT.toSeconds();
int decalage = 0;

if (!canShoot)
return;
Point2D bulletPosition = calculateShootPosition();
createBullet(bulletPosition);
createSmoke(bulletPosition);
}

if (side_shoot == 0) {
side_shoot = 1;
decalage = 22;
private Point2D calculateShootPosition() {
double x = entity.getX() + (entity.getWidth() / 2);
double y = entity.getY();
int decalage = 20;
int shift_x;
int shift_y;
if (this.direction == Constant.Direction.UP) {
shift_y = -decalage;
} else {
side_shoot = 0;
decalage = -18;
shift_y = PLAYER_HEIGHT.intValue() + decalage;
}
double x = entity.getX() + (entity.getWidth() / 2) + decalage;
double y = entity.getY() - 20;
Entity bullet = spawn(entityNames.BULLET, x, y);
bullet.getComponent(BulletComponent.class).initialize();
last_shot = getGameTimer().getNow();

if (this.side_shoot == Direction.LEFT) {
this.side_shoot = Direction.RIGHT;
shift_x = -decalage;
} else {
this.side_shoot = Direction.LEFT;
shift_x = decalage;
}

x += shift_x;
y += shift_y;
return new Point2D(x, y);
}

private void createBullet(Point2D position) {
Entity bullet = spawn(entityNames.BULLET, position);
bullet.getComponent(BulletComponent.class).initialize(this.direction);
last_shot = getGameTimer().getNow();
shootingRecoil();
}

/**
* Simule le recul du vaisseau lors du tir
*/
private void shootingRecoil() {
entity.translateY(10);
runOnce(() -> entity.translateY(-10), Duration.seconds(0.1));
if (this.direction == Constant.Direction.DOWN) {
this.entity.translateY(-10);
runOnce(() -> this.entity.translateY(10), Duration.seconds(0.1));
} else if (this.direction == Direction.UP) {
this.entity.translateY(10);
runOnce(() -> this.entity.translateY(-10), Duration.seconds(0.1));
}
}

private void createSmoke(Point2D position) {
Entity shooting_start = spawn(entityNames.SHOOTING_START, position);
shooting_start.getComponent(ShootingStartComponent.class).initialize(this.direction);
runOnce(() -> {
Entity shooting_smoke = spawn("shooting_smoke", position);
shooting_smoke.getComponent(ShootingSmokeComponent.class).initialize(this.direction);
}, Duration.seconds(0.2));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.enstabretagne.Component;

import static org.enstabretagne.Core.Constant.SMOKE_DURATION;

import org.enstabretagne.Core.Constant;

import com.almasb.fxgl.dsl.components.ExpireCleanComponent;
import com.almasb.fxgl.entity.component.Component;

/**
* Cette classe représente la fumée lors d'un tir.
*
* @author MathieuDFS, jufch
* @since 0.2.0
*/
public class ShootingSmokeComponent extends Component {
/**
* Initialise le composant fumée
* Cette méthode ajoute le composant ExpireCleanComponent
*
* @param direction
*/
public void initialize(Constant.Direction direction) {
this.entity.addComponent(new ExpireCleanComponent(SMOKE_DURATION));
double dx = Constant.SHOOTING_SMOKE_WIDTH / 2;
double dy = 30;
if (direction == Constant.Direction.DOWN) {
this.entity.rotateBy(180);
this.entity.translate(dx, dy);
}
this.entity.translate(-dx, -dy);
}
}
Loading

0 comments on commit 207655c

Please sign in to comment.