Skip to content

Commit 207655c

Browse files
committed
Fixed merge conflicts for release v0.2.0
2 parents fc5b95a + 2b52451 commit 207655c

27 files changed

+822
-150
lines changed

duelinvaders/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.enstabretagne</groupId>
77
<artifactId>duelinvaders</artifactId>
8-
<version>0.1.0</version>
8+
<version>0.2.0</version>
99

1010
<properties>
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

duelinvaders/src/main/java/org/enstabretagne/Component/AlienComponent.java

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@
88
import com.almasb.fxgl.entity.Entity;
99
import com.almasb.fxgl.entity.component.Component;
1010

11-
import javafx.geometry.Point2D;
12-
1311
import static com.almasb.fxgl.dsl.FXGL.*;
1412

1513
/**
1614
* Cette classe représente le comportement des aliens
1715
* Elle permet de définir les données associées à l'alien et son comportement
1816
*
19-
* @author LBF38
17+
* @author LBF38, MathieuDFS
2018
* @since 0.1.0
2119
*/
2220
public class AlienComponent extends Component {
2321
private Double dx, dy;
24-
protected Direction movementDirection;
22+
private Direction movementDirection;
23+
private Direction globalDirection;
2524
private Double last_shot = 0.0;
25+
private double limit_right = Constant.GAME_WIDTH;
26+
private double limit_left = 0.0;
2627

2728
/**
2829
* Constructeur de la classe AlienComponent
@@ -49,6 +50,21 @@ public AlienComponent() {
4950
this(Direction.DOWN);
5051
}
5152

53+
/**
54+
* Initialise l'alien
55+
*
56+
*/
57+
public void initialize(Constant.Direction direction) {
58+
this.globalDirection = direction;
59+
if (direction == Constant.Direction.UP) {
60+
entity.rotateBy(180);
61+
this.movementDirection = Direction.RIGHT;
62+
} else if (direction == Constant.Direction.DOWN) {
63+
this.movementDirection = Direction.LEFT;
64+
}
65+
66+
}
67+
5268
/**
5369
* Méthode héritée de la classe Component.
5470
* Elle permet de définir comment se met à jour l'alien.
@@ -57,7 +73,7 @@ public AlienComponent() {
5773
@Override
5874
public void onUpdate(double tpf) {
5975
dx = tpf * Constant.SPEED_ALIEN;
60-
dy = 0.5 * Constant.SPEED_ALIEN;
76+
dy = entity.getHeight();
6177
this.move(dx);
6278
}
6379

@@ -68,12 +84,6 @@ public void onUpdate(double tpf) {
6884
* @param dx
6985
*/
7086
public void move(Double dx) {
71-
if (this.entity.getBottomY() >= Constant.GAME_HEIGHT) {
72-
// TODO: to remove if unnecessary
73-
System.out.println("Game Over");
74-
return;
75-
}
76-
7787
if (this.movementDirection == Direction.RIGHT)
7888
moveRight(dx);
7989
else if (this.movementDirection == Direction.LEFT)
@@ -86,10 +96,14 @@ else if (this.movementDirection == Direction.LEFT)
8696
* @param dx
8797
*/
8898
public void moveRight(Double dx) {
89-
if (this.entity.getRightX() + dx <= Constant.GAME_WIDTH) {
99+
if (this.entity.getRightX() + dx <= limit_right) {
90100
this.entity.translateX(dx);
91101
} else {
92-
this.entity.translateY(dy);
102+
if (this.globalDirection == Constant.Direction.DOWN) {
103+
this.entity.translateY(dy);
104+
} else if (this.globalDirection == Constant.Direction.UP) {
105+
this.entity.translateY(-dy);
106+
}
93107
this.movementDirection = Direction.LEFT;
94108
}
95109
}
@@ -100,14 +114,23 @@ public void moveRight(Double dx) {
100114
* @param dx
101115
*/
102116
public void moveLeft(Double dx) {
103-
if (this.entity.getX() - dx >= 0) {
117+
if (this.entity.getX() - dx >= limit_left) {
104118
this.entity.translateX(-dx);
105119
} else {
106-
this.entity.translateY(dy);
120+
if (this.globalDirection == Constant.Direction.DOWN) {
121+
this.entity.translateY(dy);
122+
} else if (this.globalDirection == Constant.Direction.UP) {
123+
this.entity.translateY(-dy);
124+
}
107125
this.movementDirection = Direction.RIGHT;
108126
}
109127
}
110128

129+
public void setAlienNumber(int AlienNumber) {
130+
limit_right = Constant.GAME_WIDTH - (Constant.ALIEN_WIDTH * (Constant.ALIENS_NUMBER - AlienNumber - 1));
131+
limit_left = 0.0 + (Constant.ALIEN_WIDTH * AlienNumber);
132+
}
133+
111134
/**
112135
* Tir aléatoire de l'alien.
113136
*
@@ -124,16 +147,19 @@ public void randomShoot(double chance) {
124147
*/
125148
public void shoot() {
126149
Boolean canShoot = getGameTimer().getNow() - last_shot.doubleValue() >= Constant.RATE_ALIEN_SHOOT.doubleValue();
127-
if (canShoot || last_shot == null) {
128-
double x = this.entity.getX() + this.entity.getWidth() / 2;
129-
double y = this.entity.getY() + this.entity.getHeight();
130-
spawn(entityNames.ECLAT,x,y);
131-
Entity bullet = spawn(entityNames.BULLET_ALIEN, x, y);
132-
BulletComponent bulletComponent = bullet.getComponent(BulletComponent.class);
133-
// TODO: rendre le shotDirection dépendant de la direction de l'alien
134-
bulletComponent.setDirection(new Point2D(0, 1));
135-
bulletComponent.initialize();
136-
last_shot = getGameTimer().getNow();
137-
}
150+
if (!canShoot)
151+
return;
152+
153+
double x = this.entity.getX() + this.entity.getWidth() / 2;
154+
double y = this.entity.getY();
155+
if (this.globalDirection == Constant.Direction.DOWN)
156+
y += this.entity.getHeight();
157+
158+
spawn(entityNames.ECLAT, x, y);
159+
Entity bullet = spawn(entityNames.BULLET_ALIEN, x, y);
160+
161+
bullet.getComponent(BulletComponent.class).initialize(this.globalDirection);
162+
bullet.rotateBy(90.0);
163+
last_shot = getGameTimer().getNow();
138164
}
139165
}

duelinvaders/src/main/java/org/enstabretagne/Component/BulletComponent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public BulletComponent() {
3232
* Ce sont des composants prédéfinis dans la librairie FXGL qui facilite la
3333
* création de projectiles
3434
*/
35-
public void initialize() {
35+
public void initialize(Constant.Direction UporDown) {
36+
this.direction= new Point2D(0, UporDown == Constant.Direction.UP ? -1 : 1);
3637
this.entity.addComponent(new ProjectileComponent(direction, speed));
3738
this.entity.addComponent(new ExpireCleanComponent(duration));
38-
this.entity.rotateBy(90);
3939
}
4040

4141
/**

duelinvaders/src/main/java/org/enstabretagne/Component/EntityType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/**
44
* Définition des types d'entités disponibles dans le jeu
55
*
6+
* @author jufch, LBF38, MathieuDFS
67
* @since 0.1.0
78
*/
89
public enum EntityType {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.enstabretagne.Component;
2+
3+
import org.enstabretagne.Core.Constant;
4+
5+
import com.almasb.fxgl.entity.component.Component;
6+
7+
/**
8+
* Cette classe représente l'affichage du nombre de vies restantes.
9+
*
10+
* @author MathieuDFS, jufch
11+
* @since 0.2.0
12+
*/
13+
public class LifeComponent extends Component {
14+
/**
15+
* Initialise le composant affichage de vie
16+
*/
17+
public void initialize(Constant.Direction direction) {
18+
if (direction == Constant.Direction.UP) {
19+
entity.setX(Constant.GAME_WIDTH - Constant.LIFE_DISPLAY_WIDTH);
20+
entity.setY(0);
21+
} else if (direction == Constant.Direction.DOWN) {
22+
entity.setX(Constant.GAME_WIDTH - Constant.LIFE_DISPLAY_WIDTH);
23+
entity.setY(Constant.GAME_HEIGHT - Constant.LIFE_DISPLAY_HEIGHT);
24+
}
25+
}
26+
27+
public void updateLife(boolean isActive) {
28+
entity.getViewComponent().setOpacity(isActive ? 1 : 0);
29+
}
30+
}

duelinvaders/src/main/java/org/enstabretagne/Component/PlayerComponent.java

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
package org.enstabretagne.Component;
22

3-
import static org.enstabretagne.Core.Constant.*;
3+
import static com.almasb.fxgl.dsl.FXGL.getGameTimer;
4+
import static com.almasb.fxgl.dsl.FXGL.runOnce;
5+
import static com.almasb.fxgl.dsl.FXGL.spawn;
6+
import static org.enstabretagne.Core.Constant.DELAY_BETWEEN_SHOOT;
7+
import static org.enstabretagne.Core.Constant.GAME_WIDTH;
8+
import static org.enstabretagne.Core.Constant.PLAYER_HEIGHT;
9+
import static org.enstabretagne.Core.Constant.SPEED_SPACESHIP;
410

11+
import org.enstabretagne.Core.Constant;
12+
import org.enstabretagne.Core.Constant.Direction;
513
import org.enstabretagne.Utils.entityNames;
614

715
import com.almasb.fxgl.entity.Entity;
816
import com.almasb.fxgl.entity.component.Component;
9-
import javafx.util.Duration;
1017

11-
import static com.almasb.fxgl.dsl.FXGL.*;
18+
import javafx.geometry.Point2D;
19+
import javafx.util.Duration;
1220

1321
/**
1422
* Définition du composant pour le joueur
@@ -19,7 +27,24 @@
1927
public class PlayerComponent extends Component {
2028
private Double dx;
2129
private Double last_shot = 0.0;
22-
private int side_shoot = 0;
30+
private Direction side_shoot = Direction.LEFT;
31+
private Constant.Direction direction = Constant.Direction.UP;
32+
33+
/**
34+
* Setter de la direction du joueur
35+
* Pour la rotation de l'image du joueur, on ne prend pas en compte les
36+
* directions LEFT et RIGHT
37+
*
38+
* @param direction
39+
*/
40+
public void setDirection(Constant.Direction direction) {
41+
if (direction == Constant.Direction.LEFT || direction == Constant.Direction.RIGHT)
42+
return;
43+
if (this.direction == direction)
44+
return;
45+
entity.rotateBy(180);
46+
this.direction = direction;
47+
}
2348

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

6185
if (!canShoot)
6286
return;
87+
Point2D bulletPosition = calculateShootPosition();
88+
createBullet(bulletPosition);
89+
createSmoke(bulletPosition);
90+
}
6391

64-
if (side_shoot == 0) {
65-
side_shoot = 1;
66-
decalage = 22;
92+
private Point2D calculateShootPosition() {
93+
double x = entity.getX() + (entity.getWidth() / 2);
94+
double y = entity.getY();
95+
int decalage = 20;
96+
int shift_x;
97+
int shift_y;
98+
if (this.direction == Constant.Direction.UP) {
99+
shift_y = -decalage;
67100
} else {
68-
side_shoot = 0;
69-
decalage = -18;
101+
shift_y = PLAYER_HEIGHT.intValue() + decalage;
70102
}
71-
double x = entity.getX() + (entity.getWidth() / 2) + decalage;
72-
double y = entity.getY() - 20;
73-
Entity bullet = spawn(entityNames.BULLET, x, y);
74-
bullet.getComponent(BulletComponent.class).initialize();
75-
last_shot = getGameTimer().getNow();
76103

104+
if (this.side_shoot == Direction.LEFT) {
105+
this.side_shoot = Direction.RIGHT;
106+
shift_x = -decalage;
107+
} else {
108+
this.side_shoot = Direction.LEFT;
109+
shift_x = decalage;
110+
}
111+
112+
x += shift_x;
113+
y += shift_y;
114+
return new Point2D(x, y);
115+
}
116+
117+
private void createBullet(Point2D position) {
118+
Entity bullet = spawn(entityNames.BULLET, position);
119+
bullet.getComponent(BulletComponent.class).initialize(this.direction);
120+
last_shot = getGameTimer().getNow();
77121
shootingRecoil();
78122
}
79123

80124
/**
81125
* Simule le recul du vaisseau lors du tir
82126
*/
83127
private void shootingRecoil() {
84-
entity.translateY(10);
85-
runOnce(() -> entity.translateY(-10), Duration.seconds(0.1));
128+
if (this.direction == Constant.Direction.DOWN) {
129+
this.entity.translateY(-10);
130+
runOnce(() -> this.entity.translateY(10), Duration.seconds(0.1));
131+
} else if (this.direction == Direction.UP) {
132+
this.entity.translateY(10);
133+
runOnce(() -> this.entity.translateY(-10), Duration.seconds(0.1));
134+
}
135+
}
136+
137+
private void createSmoke(Point2D position) {
138+
Entity shooting_start = spawn(entityNames.SHOOTING_START, position);
139+
shooting_start.getComponent(ShootingStartComponent.class).initialize(this.direction);
140+
runOnce(() -> {
141+
Entity shooting_smoke = spawn("shooting_smoke", position);
142+
shooting_smoke.getComponent(ShootingSmokeComponent.class).initialize(this.direction);
143+
}, Duration.seconds(0.2));
86144
}
87145
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.enstabretagne.Component;
2+
3+
import static org.enstabretagne.Core.Constant.SMOKE_DURATION;
4+
5+
import org.enstabretagne.Core.Constant;
6+
7+
import com.almasb.fxgl.dsl.components.ExpireCleanComponent;
8+
import com.almasb.fxgl.entity.component.Component;
9+
10+
/**
11+
* Cette classe représente la fumée lors d'un tir.
12+
*
13+
* @author MathieuDFS, jufch
14+
* @since 0.2.0
15+
*/
16+
public class ShootingSmokeComponent extends Component {
17+
/**
18+
* Initialise le composant fumée
19+
* Cette méthode ajoute le composant ExpireCleanComponent
20+
*
21+
* @param direction
22+
*/
23+
public void initialize(Constant.Direction direction) {
24+
this.entity.addComponent(new ExpireCleanComponent(SMOKE_DURATION));
25+
double dx = Constant.SHOOTING_SMOKE_WIDTH / 2;
26+
double dy = 30;
27+
if (direction == Constant.Direction.DOWN) {
28+
this.entity.rotateBy(180);
29+
this.entity.translate(dx, dy);
30+
}
31+
this.entity.translate(-dx, -dy);
32+
}
33+
}

0 commit comments

Comments
 (0)