forked from kailielexx/Space-Shooter-Game
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kailielexx#2 from hoangsonww/main
Added JavaFX GUI files for the game
- Loading branch information
Showing
21 changed files
with
1,022 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created | ||
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path | ||
|
||
name: Maven Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml | ||
settings-path: ${{ github.workspace }} # location for the settings.xml file | ||
|
||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml | ||
|
||
- name: Publish to GitHub Packages Apache Maven | ||
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
name: Java CI with Maven | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: maven | ||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml | ||
|
||
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive | ||
- name: Update dependency graph | ||
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar |
69 changes: 69 additions & 0 deletions
69
src/main/java/com/example/spaceshooterproject/BossEnemy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.example.spaceshooterproject; | ||
|
||
import javafx.scene.canvas.GraphicsContext; | ||
import javafx.scene.paint.Color; | ||
|
||
import java.util.List; | ||
|
||
public class BossEnemy extends Enemy { | ||
|
||
private int health = 5; | ||
|
||
private int WIDTH; | ||
|
||
private int HEIGHT; | ||
|
||
private int numHits = 5; | ||
|
||
public BossEnemy(double x, double y) { | ||
super(x, y); | ||
SPEED = 1.0; | ||
WIDTH = 50; | ||
HEIGHT = 50; | ||
health = 5; | ||
} | ||
|
||
|
||
@Override | ||
public void update() { | ||
// BossEnemy stays at the top of the screen | ||
if (y < 40) { | ||
y += SPEED; | ||
} | ||
} | ||
|
||
public void takeDamage() { | ||
health--; | ||
if (health <= 0) { | ||
setDead(true); | ||
} | ||
} | ||
|
||
public void shoot(List<GameObject> newObjects) { | ||
if (Math.random() < 0.015) { | ||
newObjects.add(new EnemyBullet(x, y + HEIGHT / 2)); | ||
} | ||
} | ||
|
||
public void decreaseHealth() { | ||
health--; | ||
} | ||
|
||
public boolean isDead() { | ||
return health <= 0; | ||
} | ||
|
||
@Override | ||
public void render(GraphicsContext gc) { | ||
gc.setFill(Color.BLUE); | ||
gc.fillRect(x - WIDTH / 2, y - HEIGHT / 2, WIDTH * 2, HEIGHT * 2); | ||
} | ||
|
||
public void hit() { | ||
health--; | ||
if (health <= 0) { | ||
setDead(true); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.example.spaceshooterproject; | ||
|
||
import javafx.scene.canvas.GraphicsContext; | ||
import javafx.scene.paint.Color; | ||
|
||
public class Bullet extends GameObject { | ||
|
||
public static final int WIDTH = 4; | ||
public static final int HEIGHT = 20; | ||
private static final double SPEED = 7; | ||
|
||
public Bullet(double x, double y) { | ||
super(x, y, WIDTH, HEIGHT); // Pass the WIDTH and HEIGHT constants | ||
} | ||
|
||
@Override | ||
public void update() { | ||
y -= SPEED; | ||
} | ||
|
||
@Override | ||
public void render(GraphicsContext gc) { | ||
gc.setFill(Color.YELLOW); | ||
gc.fillRect(x - WIDTH / 2, y - HEIGHT / 2, WIDTH, HEIGHT); | ||
} | ||
|
||
// In Bullet class | ||
@Override | ||
public double getWidth() { | ||
return WIDTH; | ||
} | ||
|
||
@Override | ||
public double getHeight() { | ||
return HEIGHT; | ||
} | ||
|
||
private boolean dead = false; | ||
|
||
public void setDead(boolean dead) { | ||
this.dead = dead; | ||
} | ||
|
||
@Override | ||
public boolean isDead() { | ||
return dead; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.example.spaceshooterproject; | ||
|
||
import javafx.scene.canvas.GraphicsContext; | ||
import javafx.scene.paint.Color; | ||
import javafx.scene.shape.Rectangle; | ||
|
||
public class Enemy extends GameObject { | ||
|
||
protected static final int WIDTH = 30; | ||
protected static final int HEIGHT = 30; | ||
public static double SPEED = 2; | ||
|
||
public Enemy(double x, double y) { | ||
super(x, y, WIDTH, HEIGHT); | ||
} | ||
|
||
@Override | ||
public void update() { | ||
y += SPEED; | ||
} | ||
|
||
@Override | ||
public void render(GraphicsContext gc) { | ||
gc.setFill(Color.RED); | ||
gc.fillRect(x - WIDTH / 2, y - HEIGHT / 2, WIDTH, HEIGHT); | ||
} | ||
|
||
@Override | ||
public double getWidth() { | ||
return WIDTH; | ||
} | ||
|
||
@Override | ||
public double getHeight() { | ||
return HEIGHT; | ||
} | ||
|
||
private boolean dead = false; | ||
|
||
public void setDead(boolean dead) { | ||
this.dead = dead; | ||
} | ||
|
||
@Override | ||
public boolean isDead() { | ||
return dead; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/example/spaceshooterproject/EnemyBullet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.example.spaceshooterproject; | ||
|
||
import javafx.scene.canvas.GraphicsContext; | ||
import javafx.scene.paint.Color; | ||
|
||
public class EnemyBullet extends GameObject { | ||
|
||
public static final int WIDTH = 4; | ||
public static final int HEIGHT = 20; | ||
private static final double SPEED = 3; | ||
|
||
public EnemyBullet(double x, double y) { | ||
super(x, y, WIDTH, HEIGHT); | ||
} | ||
|
||
@Override | ||
public void update() { | ||
y += SPEED; | ||
} | ||
|
||
@Override | ||
public void render(GraphicsContext gc) { | ||
gc.setFill(Color.RED); | ||
gc.fillRect(x - WIDTH / 2, y - HEIGHT / 2, WIDTH, HEIGHT); | ||
} | ||
|
||
@Override | ||
public double getWidth() { | ||
return WIDTH; | ||
} | ||
|
||
@Override | ||
public double getHeight() { | ||
return HEIGHT; | ||
} | ||
|
||
private boolean dead = false; | ||
|
||
public void setDead(boolean dead) { | ||
this.dead = dead; | ||
} | ||
|
||
@Override | ||
public boolean isDead() { | ||
return dead; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/example/spaceshooterproject/GameObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.spaceshooterproject; | ||
|
||
import javafx.scene.canvas.GraphicsContext; | ||
import javafx.geometry.Bounds; | ||
import javafx.scene.shape.Rectangle; | ||
|
||
|
||
public abstract class GameObject { | ||
|
||
protected double x; | ||
protected double y; | ||
protected double width; | ||
protected double height; | ||
|
||
public GameObject(double x, double y, double width, double height) { | ||
this.x = x; | ||
this.y = y; | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public abstract void update(); | ||
|
||
public abstract void render(GraphicsContext gc); | ||
|
||
public abstract boolean isDead(); | ||
|
||
public double getX() { | ||
return x; | ||
} | ||
|
||
public double getY() { | ||
return y; | ||
} | ||
|
||
public Bounds getBounds() { | ||
return new Rectangle(x - getWidth() / 2, y - getHeight() / 2, getWidth(), getHeight()).getBoundsInLocal(); | ||
} | ||
|
||
public abstract double getWidth(); | ||
|
||
public abstract double getHeight(); | ||
} |
Oops, something went wrong.