Skip to content

Commit

Permalink
PR #16 - release v0.3.0
Browse files Browse the repository at this point in the history
v0.3.0 - New Main menu and added Players infos UI

Bypassed branch protections for final release before evaluation.
  • Loading branch information
LBF38 authored Jan 4, 2023
2 parents 8de4b56 + 21362d4 commit 16a64db
Show file tree
Hide file tree
Showing 18 changed files with 479 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven
name: Verify Maven build and javadoc for Java project

on:
push:
Expand All @@ -29,4 +29,4 @@ jobs:
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file duelinvaders/pom.xml
run: mvn clean javadoc:jar -B package --file duelinvaders/pom.xml
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ mvn clean package
> **Note**
> Vous devez exécuter cette commande dans le dossier du projet contenant le fichier `pom.xml`. Ici, le dossier racine du projet est `duelinvaders`.
Vous pouvez également compiler la javadoc du projet en exécutant la commande suivante :

```bash
mvn javadoc:javadoc
```

La javadoc sera générée dans le dossier `target/site/apidocs` du projet. (par défaut)

> **Note**
> Les releases fournissent la javadoc du projet en archive `.jar`. Ils sont builds avec la commande `mvn clean package javadoc:jar` et sont disponibles dans la section [Releases](https://github.com/LBF38/Duel-invaders/releases) du projet.
### Exécution

> **Warning**
Expand Down
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.2.0</version>
<version>0.3.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 @@ -20,6 +20,15 @@ public class BulletComponent extends Component {
private Double speed = Constant.SPEED_SHOOT;
private Duration duration = Constant.BULLET_DURATION;
private Point2D direction = new Point2D(0, -1);
private int playerId;

public int getPlayerId() {
return playerId;
}

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

public BulletComponent() {
super();
Expand All @@ -33,7 +42,7 @@ public BulletComponent() {
* création de projectiles
*/
public void initialize(Constant.Direction UporDown) {
this.direction= new Point2D(0, UporDown == Constant.Direction.UP ? -1 : 1);
this.direction = new Point2D(0, UporDown == Constant.Direction.UP ? -1 : 1);
this.entity.addComponent(new ProjectileComponent(direction, speed));
this.entity.addComponent(new ExpireCleanComponent(duration));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* @author MathieuDFS, jufch
* @since 0.2.0
* @deprecated since 0.3.0
*/
public class LifeComponent extends Component {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.enstabretagne.Component;

import static com.almasb.fxgl.dsl.FXGL.getGameTimer;
import static com.almasb.fxgl.dsl.FXGL.geti;
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 static org.enstabretagne.Core.Constant.DELAY_BETWEEN_SHOOT;
import static org.enstabretagne.Core.Constant.GAME_WIDTH;
Expand All @@ -10,6 +12,7 @@

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

import com.almasb.fxgl.entity.Entity;
Expand All @@ -29,6 +32,17 @@ public class PlayerComponent extends Component {
private Double last_shot = 0.0;
private Direction side_shoot = Direction.LEFT;
private Constant.Direction direction = Constant.Direction.UP;
private int id;
private static int counter;

public int getId() {
return id;
}

public PlayerComponent() {
super();
this.id = counter++;
}

/**
* Setter de la direction du joueur
Expand Down Expand Up @@ -117,6 +131,7 @@ private Point2D calculateShootPosition() {
private void createBullet(Point2D position) {
Entity bullet = spawn(entityNames.BULLET, position);
bullet.getComponent(BulletComponent.class).initialize(this.direction);
bullet.getComponent(BulletComponent.class).setPlayerId(this.getId());
last_shot = getGameTimer().getNow();
shootingRecoil();
}
Expand All @@ -142,4 +157,109 @@ private void createSmoke(Point2D position) {
shooting_smoke.getComponent(ShootingSmokeComponent.class).initialize(this.direction);
}, Duration.seconds(0.2));
}

/**
* Incrémente le score du joueur
*/
public void incrementScore() {
if (isPlayer1())
set(GameVariableNames.PLAYER1_SCORE, geti(GameVariableNames.PLAYER1_SCORE) + 1);
else
set(GameVariableNames.PLAYER2_SCORE, geti(GameVariableNames.PLAYER2_SCORE) + 1);
}

/**
* @return boolean
*/
private boolean isPlayer1() {
return id % 2 == 1;
}

/**
* Initialisation du score du joueur
*/
public void initializeScore() {
if (isPlayer1())
set(GameVariableNames.PLAYER1_SCORE, 0);
else
set(GameVariableNames.PLAYER2_SCORE, 0);
}

/**
* @return int
*/
public int getScore() {
if (isPlayer1())
return geti(GameVariableNames.PLAYER1_SCORE);
else
return geti(GameVariableNames.PLAYER2_SCORE);
}

/**
* @param score
*/
public void setScore(int score) {
if (isPlayer1())
set(GameVariableNames.PLAYER1_SCORE, score);
else
set(GameVariableNames.PLAYER2_SCORE, score);
}

public void decrementScore() {
if (isPlayer1())
set(GameVariableNames.PLAYER1_SCORE, geti(GameVariableNames.PLAYER1_SCORE) - 1);
else
set(GameVariableNames.PLAYER2_SCORE, geti(GameVariableNames.PLAYER2_SCORE) - 1);
}

/**
* Incrémente le nombre de vie du joueur
*/
public void incrementLife() {
if (isPlayer1())
set(GameVariableNames.PLAYER1_LIFE, geti(GameVariableNames.PLAYER1_LIFE) + 1);
else
set(GameVariableNames.PLAYER2_LIFE, geti(GameVariableNames.PLAYER2_LIFE) + 1);
}

/**
* Initialise le nombre de vie du joueur
*/
public void initializeLife() {
int life = 5;
if (isPlayer1())
set(GameVariableNames.PLAYER1_LIFE, life);
else
set(GameVariableNames.PLAYER2_LIFE, life);
}

/**
* @return int
*/
public int getLife() {
if (isPlayer1())
return geti(GameVariableNames.PLAYER1_LIFE);
else
return geti(GameVariableNames.PLAYER2_LIFE);
}

/**
* @param life
*/
public void setLife(int life) {
if (isPlayer1())
set(GameVariableNames.PLAYER1_LIFE, life);
else
set(GameVariableNames.PLAYER2_LIFE, life);
}

/**
* Décrémente le nombre de vie du joueur
*/
public void decrementLife() {
if (isPlayer1())
set(GameVariableNames.PLAYER1_LIFE, geti(GameVariableNames.PLAYER1_LIFE) - 1);
else
set(GameVariableNames.PLAYER2_LIFE, geti(GameVariableNames.PLAYER2_LIFE) - 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Entity newEclat(SpawnData data) {
public Entity newBackground(SpawnData data) {
return entityBuilder()
.at(-10, -10)
.view(texture(assetNames.textures.BACKGROUND, Constant.GAME_WIDTH + 20, Constant.GAME_HEIGHT + 20))
.view(texture(assetNames.textures.GAME_BACKGROUND, Constant.GAME_WIDTH + 20, Constant.GAME_HEIGHT + 20))
.zIndex(-500)
.build();
}
Expand Down Expand Up @@ -266,6 +266,7 @@ public Entity explosion_player_death(SpawnData data) {
*
* @param data
* @return Entity
* @deprecated
*/
@Spawns(entityNames.LIFE)
public Entity life(SpawnData data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.enstabretagne.Core;

import static com.almasb.fxgl.dsl.FXGL.getGameWorld;
import static com.almasb.fxgl.dsl.FXGL.inc;
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.assetNames;
import org.enstabretagne.Utils.entityNames;

Expand Down Expand Up @@ -42,7 +43,11 @@ public AlienBulletCollision() {
protected void onCollisionBegin(Entity bullet, Entity alien) {
bullet.removeFromWorld();
alien.removeFromWorld();
inc(GameVariableNames.PLAYERS_SCORE, +1);
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();

spawn(entityNames.EXPLOSION_ALIEN, alien.getPosition());
play(assetNames.sounds.EXPLOSION_ALIEN);
set(GameVariableNames.isGameWon, getGameWorld().getEntitiesByType(EntityType.ALIEN).isEmpty());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

package org.enstabretagne.Core;

import static com.almasb.fxgl.dsl.FXGL.geti;
import static com.almasb.fxgl.dsl.FXGL.inc;
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.assetNames;
import org.enstabretagne.Utils.entityNames;

Expand Down Expand Up @@ -38,13 +37,16 @@ public BulletPlayerCollision() {
@Override
protected void onCollisionBegin(Entity bullet, Entity player) {
bullet.removeFromWorld();

inc(GameVariableNames.PLAYERS_LIVES, -1);
if (geti(GameVariableNames.PLAYERS_LIVES) == 0) {
PlayerComponent playerComponent = player.getComponent(PlayerComponent.class);
playerComponent.decrementLife();
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(1));
runOnce(() -> set(GameVariableNames.isGameOver, true), Duration.seconds(2));
} else {
spawn(entityNames.EXPLOSION_PLAYER_BULLET, bullet.getPosition());
play(assetNames.sounds.EXPLOSION_PLAYER_LIFE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public class Constant {
public static final Duration FIRE_DURATION = Duration.seconds(0.2);
public static final Duration SMOKE_DURATION = Duration.seconds(0.2);

public static final Double START_LIVES = 3.0;

public enum Direction {
UP, DOWN, LEFT, RIGHT
}
Expand All @@ -53,7 +51,7 @@ public enum AlienColor {
RED, GREEN, BLUE, YELLOW, PURPLE, ORANGE
}

public enum Music {
public enum Music_List {
MUSIC_ACROSS_THE_UNIVERSE, MUSIC_BEYOND_CONSCIOUSNESS, MUSIC_DARK_MATTER, MUSIC_DEGREE_OF_FREEDOM,
MUSIC_STELLAR_REMEBER
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

package org.enstabretagne.Core;

import static com.almasb.fxgl.dsl.FXGL.geti;
import static com.almasb.fxgl.dsl.FXGL.inc;
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.assetNames;
import org.enstabretagne.Utils.entityNames;

Expand Down Expand Up @@ -35,9 +34,9 @@ public EnemyShootPlayerCollision() {
@Override
protected void onCollisionBegin(Entity enemy_shoot, Entity player) {
enemy_shoot.removeFromWorld();

inc(GameVariableNames.PLAYERS_LIVES, -1);
if (geti(GameVariableNames.PLAYERS_LIVES) == 0) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
* @since 0.1.0
*/
public class GameVariableNames {
public static final String PLAYERS_SCORE = "Players_score";
public static final String PLAYERS_LIVES = "Players_lives";
public static final String PLAYER1_SCORE = "Player1_score";
public static final String PLAYER2_SCORE = "Player2_score";
public static final String PLAYER1_LIFE = "Player1_lives";
public static final String PLAYER2_LIFE = "Player2_lives";
public static final String isGameOver = "isGameOver";
public static final String isGameWon = "isGameWon";
}
Loading

0 comments on commit 16a64db

Please sign in to comment.