diff --git a/.gradle/7.5.1/executionHistory/executionHistory.bin b/.gradle/7.5.1/executionHistory/executionHistory.bin
index 095b464..6c3fa1b 100644
Binary files a/.gradle/7.5.1/executionHistory/executionHistory.bin and b/.gradle/7.5.1/executionHistory/executionHistory.bin differ
diff --git a/.gradle/7.5.1/executionHistory/executionHistory.lock b/.gradle/7.5.1/executionHistory/executionHistory.lock
index f2176e5..8da2413 100644
Binary files a/.gradle/7.5.1/executionHistory/executionHistory.lock and b/.gradle/7.5.1/executionHistory/executionHistory.lock differ
diff --git a/.gradle/7.5.1/fileHashes/fileHashes.bin b/.gradle/7.5.1/fileHashes/fileHashes.bin
index b73c3cc..658f29f 100644
Binary files a/.gradle/7.5.1/fileHashes/fileHashes.bin and b/.gradle/7.5.1/fileHashes/fileHashes.bin differ
diff --git a/.gradle/7.5.1/fileHashes/fileHashes.lock b/.gradle/7.5.1/fileHashes/fileHashes.lock
index 7c1f31e..f42a244 100644
Binary files a/.gradle/7.5.1/fileHashes/fileHashes.lock and b/.gradle/7.5.1/fileHashes/fileHashes.lock differ
diff --git a/.gradle/7.5.1/fileHashes/resourceHashesCache.bin b/.gradle/7.5.1/fileHashes/resourceHashesCache.bin
index 8527445..50bfc86 100644
Binary files a/.gradle/7.5.1/fileHashes/resourceHashesCache.bin and b/.gradle/7.5.1/fileHashes/resourceHashesCache.bin differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
index 1b344b4..a428af2 100644
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin
index 3ad0a9a..925e47f 100644
Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ
diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe
index 2df1116..a8faf55 100644
Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ
diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml
new file mode 100644
index 0000000..2aa056d
--- /dev/null
+++ b/.idea/google-java-format.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__junit_junit_4_13_1.xml b/.idea/libraries/Gradle__junit_junit_4_13_1.xml
new file mode 100644
index 0000000..f28cdec
--- /dev/null
+++ b/.idea/libraries/Gradle__junit_junit_4_13_1.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_1_2.xml b/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_1_2.xml
new file mode 100644
index 0000000..ec7423e
--- /dev/null
+++ b/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_1_2.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
new file mode 100644
index 0000000..8262f72
--- /dev/null
+++ b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_8_1.xml b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_8_1.xml
new file mode 100644
index 0000000..e4ec376
--- /dev/null
+++ b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_8_1.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml
new file mode 100644
index 0000000..4da4781
--- /dev/null
+++ b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_8_1.xml b/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_8_1.xml
new file mode 100644
index 0000000..ec1b37e
--- /dev/null
+++ b/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_8_1.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_8_1.xml b/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_8_1.xml
new file mode 100644
index 0000000..2940fd5
--- /dev/null
+++ b/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_8_1.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_mongodb_bson_4_9_0.xml b/.idea/libraries/Gradle__org_mongodb_bson_4_9_0.xml
new file mode 100644
index 0000000..2292b49
--- /dev/null
+++ b/.idea/libraries/Gradle__org_mongodb_bson_4_9_0.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_mongodb_bson_record_codec_4_9_0.xml b/.idea/libraries/Gradle__org_mongodb_bson_record_codec_4_9_0.xml
new file mode 100644
index 0000000..9e50e0b
--- /dev/null
+++ b/.idea/libraries/Gradle__org_mongodb_bson_record_codec_4_9_0.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_mongodb_mongodb_driver_core_4_9_0.xml b/.idea/libraries/Gradle__org_mongodb_mongodb_driver_core_4_9_0.xml
new file mode 100644
index 0000000..f31d4e4
--- /dev/null
+++ b/.idea/libraries/Gradle__org_mongodb_mongodb_driver_core_4_9_0.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_mongodb_mongodb_driver_sync_4_9_0.xml b/.idea/libraries/Gradle__org_mongodb_mongodb_driver_sync_4_9_0.xml
new file mode 100644
index 0000000..f15f570
--- /dev/null
+++ b/.idea/libraries/Gradle__org_mongodb_mongodb_driver_sync_4_9_0.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_2_0.xml b/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_2_0.xml
new file mode 100644
index 0000000..c0ad60c
--- /dev/null
+++ b/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_2_0.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 51bcb2b..0d32c34 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,5 @@
-
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..206e6ce
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/bcit.comp2522.project-team-a.project-team-a.iml b/.idea/modules/bcit.comp2522.project-team-a.project-team-a.iml
new file mode 100644
index 0000000..511d5da
--- /dev/null
+++ b/.idea/modules/bcit.comp2522.project-team-a.project-team-a.iml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/bcit.comp2522.project-team-a.project-team-a.main.iml b/.idea/modules/bcit.comp2522.project-team-a.project-team-a.main.iml
new file mode 100644
index 0000000..027a653
--- /dev/null
+++ b/.idea/modules/bcit.comp2522.project-team-a.project-team-a.main.iml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/bcit.comp2522.project-team-a.project-team-a.test.iml b/.idea/modules/bcit.comp2522.project-team-a.project-team-a.test.iml
new file mode 100644
index 0000000..7be8385
--- /dev/null
+++ b/.idea/modules/bcit.comp2522.project-team-a.project-team-a.test.iml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/project-team-a.main.iml b/.idea/modules/project-team-a.main.iml
index 9e3449c..22fc826 100644
--- a/.idea/modules/project-team-a.main.iml
+++ b/.idea/modules/project-team-a.main.iml
@@ -1,6 +1,47 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/project-team-a.test.iml b/.idea/modules/project-team-a.test.iml
new file mode 100644
index 0000000..3ba1a8a
--- /dev/null
+++ b/.idea/modules/project-team-a.test.iml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/src/project-team-a.src.iml b/.idea/modules/src/project-team-a.src.iml
new file mode 100644
index 0000000..aa47021
--- /dev/null
+++ b/.idea/modules/src/project-team-a.src.iml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/project-team-a.iml b/.idea/project-team-a.iml
index 9e3449c..6f5ad5a 100644
--- a/.idea/project-team-a.iml
+++ b/.idea/project-team-a.iml
@@ -1,6 +1,15 @@
-
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/A_UML.pdf b/A_UML.pdf
new file mode 100644
index 0000000..c7ac1e7
Binary files /dev/null and b/A_UML.pdf differ
diff --git a/CODEOWNERS b/CODEOWNERS
new file mode 100644
index 0000000..56eab55
--- /dev/null
+++ b/CODEOWNERS
@@ -0,0 +1,15 @@
+# Lines starting with '#' are comments.
+# Each line is a file pattern followed by one or more owners.
+
+# More details are here: https://help.github.com/articles/about-codeowners/
+
+# The '*' pattern is global owners.
+
+# Order is important. The last matching pattern has the most precedence.
+# The folders are ordered as follows:
+
+# In each subsection folders are ordered first by depth, then alphabetically.
+# This should make it easy to add new rules without breaking existing ones.
+
+# Global rule:
+* @dlau72
diff --git a/Pitch.md b/Pitch.md
new file mode 100644
index 0000000..c090de1
--- /dev/null
+++ b/Pitch.md
@@ -0,0 +1,38 @@
+Project pitch
+
+- small game
+- pacman
+- shooting plane game
+- snake.io
+- agar.io
+-
+
+Pitch - A top down interactive space shooter game that player object shoots
+bullet towards the enemy to gain score.
+
+Outline - 1. We will use the processing.org library to incorporate the player and the enemy, and all the other objectives will be conducted via this interface.
+
+2. We will commit, push, and pull regularly to let the teammates to know the process that is happening and let them know what to do
+
+3. We will use a database to save data of enemy structure and number of scores.
+
+4. We will have a collection of enemies and when the enemies are hit by a ‘bullet ’of the player, we will delete the enemy from the collection. We will also keep adding enemies in the collection continuously.
+
+5. We will try our best to make the project and finish it with the best result.
+
+
+Communication policies - Using discord to communicate and have time set up for meeting in-person.
+
+Roles and responsibilities -
+
+Architect: you are in charge of the high-level code structuring and organizing.
+
+Test maker: you are in charge of test coverage that supports other group members.
+UI/UX lead: you design and implement the user interface.
+
+Backend: you design and implement the data structures.
+
+Every member of the team will be included in every role and work through it together.
+
+
+Milestone - Estimated until week 15
diff --git a/build.gradle b/build.gradle
index c9941fa..45d480a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -13,6 +13,7 @@ dependencies {
implementation fileTree(dir: 'library', include: ['*.jar'])
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
+ implementation 'org.mongodb:mongodb-driver-sync:4.9.0'
}
test {
diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin
index b83a18f..82885e7 100644
Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ
diff --git a/images/GameOver.png b/images/GameOver.png
new file mode 100644
index 0000000..9b2cdd9
Binary files /dev/null and b/images/GameOver.png differ
diff --git a/images/background.png b/images/background.png
new file mode 100644
index 0000000..e52ddbd
Binary files /dev/null and b/images/background.png differ
diff --git a/images/backgroundI.png b/images/backgroundI.png
new file mode 100644
index 0000000..202d29d
Binary files /dev/null and b/images/backgroundI.png differ
diff --git a/images/titleImage.png b/images/titleImage.png
new file mode 100644
index 0000000..eb669a7
Binary files /dev/null and b/images/titleImage.png differ
diff --git a/src/main/java/bcit/comp2522/projectteama/Bullet.java b/src/main/java/bcit/comp2522/projectteama/Bullet.java
index 4e95e16..4e6d894 100644
--- a/src/main/java/bcit/comp2522/projectteama/Bullet.java
+++ b/src/main/java/bcit/comp2522/projectteama/Bullet.java
@@ -4,22 +4,26 @@
import java.awt.*;
-public class Bullet extends Sprite{
+public class Bullet extends Sprite implements Collidable{
protected int damage;
- /**
- * this is a constuctor for the Sprite class that equips the objects with basic
- * functionalities.
- *
- * @param position the PVector position.
- * @param direction the PVector direction.
- * @param size float size.
- * @param speed float speed.
- * @param color Color color.
- * @param window Window window.
- */
- public Bullet(PVector position, PVector direction, float size, float speed, Color color, Window window, int damage) {
- super(position, direction, size, speed, color, window);
+
+ public Bullet(PVector position, PVector direction, float width, float height,
+ float speed, Color color, Window window, Rectangle hitBox, int damage) {
+ super(position, direction, width, height, speed, color, window, hitBox);
this.damage = damage;
}
+ public int getDamage() {
+ return damage;
+ }
+
+ @Override
+ public void handleCollision(Collidable other) {
+ if (other instanceof Enemy) {
+ if (this.isCollidingWith(other)) {
+ // Do something if colliding
+ window.getBManager().remove(this);
+ }
+ }
+ }
}
diff --git a/src/main/java/bcit/comp2522/projectteama/BulletManager.java b/src/main/java/bcit/comp2522/projectteama/BulletManager.java
index 35d72a7..62daa7b 100644
--- a/src/main/java/bcit/comp2522/projectteama/BulletManager.java
+++ b/src/main/java/bcit/comp2522/projectteama/BulletManager.java
@@ -1,8 +1,41 @@
package bcit.comp2522.projectteama;
+import java.awt.*;
+import java.util.ArrayList;
import processing.core.PApplet;
+import processing.core.PVector;
+import processing.event.KeyEvent;
+public class BulletManager extends Manager{
+ private Window window;
-public class BulletManager {
+ private ArrayList bullets = new ArrayList();
+ public BulletManager(Window window) {
+ this.window = window;
+ }
+ public ArrayList getBullets() {
+ return bullets;
+ }
+ //@Override
+ public void add(PVector position, PVector direction) {
+ Bullet bullet = new Bullet(position, direction, 15, 15,
+ 10, new Color(0, 0, 255), window,
+ new Rectangle((int) position.x, (int)direction.y, 30, 30), 1);
+
+ bullet.setHitBox();
+ bullets.add(bullet);
+ }
+
+ @Override
+ public void add() {
+
+ }
+
+
+
+ //@Override
+ public void remove(Bullet bullet) {
+ bullets.remove(bullet);
+ }
}
diff --git a/src/main/java/bcit/comp2522/projectteama/Button.java b/src/main/java/bcit/comp2522/projectteama/Button.java
new file mode 100644
index 0000000..3e2ace9
--- /dev/null
+++ b/src/main/java/bcit/comp2522/projectteama/Button.java
@@ -0,0 +1,42 @@
+package bcit.comp2522.projectteama;
+
+import processing.core.PApplet;
+import processing.core.PConstants;
+
+import java.awt.*;
+
+public class Button {
+
+ //Variables for button size and content
+ float x, y, w, h;
+ String text;
+
+ //Displaying buttons in this window
+ PApplet parent;
+ Window window;
+
+ Button(PApplet parent, float x, float y, float w, float h, String text) {
+ this.parent = parent;
+ this.x = x;
+ this.y = y;
+ this.w = w;
+ this.h = h;
+ this.text = text;
+ }
+
+ //Formatting for the displayed buttons
+ void display() {
+ parent.stroke(0);
+ parent.fill(200);
+ parent.rect(x, y, w, h);
+ parent.fill(0);
+ parent.textSize(20);
+ parent.textAlign(PConstants.CENTER, PConstants.CENTER);
+ parent.text(text, x + w / 2, y + h / 2);
+ }
+
+ public boolean isMouseOver() {
+ return parent.mouseX >= x && parent.mouseX <= x + w &&
+ parent.mouseY >= y && parent.mouseY <= y + h;
+ }
+}
diff --git a/src/main/java/bcit/comp2522/projectteama/Collidable.java b/src/main/java/bcit/comp2522/projectteama/Collidable.java
new file mode 100644
index 0000000..fef18b0
--- /dev/null
+++ b/src/main/java/bcit/comp2522/projectteama/Collidable.java
@@ -0,0 +1,20 @@
+package bcit.comp2522.projectteama;
+
+import java.awt.*;
+
+public interface Collidable {
+ Rectangle getHitBox();
+
+ default boolean isCollidingWith(Collidable other) {
+ Rectangle thisBox = this.getHitBox();
+ Rectangle otherBox = other.getHitBox();
+
+ return thisBox.getX() < otherBox.getX() + otherBox.getWidth() &&
+ thisBox.getX() + thisBox.getWidth() > otherBox.getX() &&
+ thisBox.getY() < otherBox.getY() + otherBox.getHeight() &&
+ thisBox.getY() + thisBox.getHeight() > otherBox.getY();
+ }
+
+ void handleCollision(Collidable other);
+
+}
diff --git a/src/main/java/bcit/comp2522/projectteama/Creature.java b/src/main/java/bcit/comp2522/projectteama/Creature.java
index fdb1d1d..78f96c0 100644
--- a/src/main/java/bcit/comp2522/projectteama/Creature.java
+++ b/src/main/java/bcit/comp2522/projectteama/Creature.java
@@ -4,24 +4,24 @@
import java.awt.*;
-public abstract class Creature extends Sprite{
- protected int lives;
-
- /**
- * this is a constuctor for the Sprite class that equips the objects with basic
- * functionalities.
- *
- * @param position the PVector position.
- * @param direction the PVector direction.
- * @param size float size.
- * @param speed float speed.
- * @param color Color color.
- * @param window Window window.
- */
- public Creature(PVector position, PVector direction, float size, float speed, Color color, Window window, int lives) {
- super(position, direction, size, speed, color, window);
- this.lives = lives;
+
+public abstract class Creature extends Sprite{
+ protected int health;
+
+
+ public Creature(PVector position, PVector direction, float width, float height, float speed, Color color, Window window, Rectangle hitBox, int health) {
+ super(position, direction, width, height, speed, color, window, hitBox);
+ this.health = health;
+ }
+
+ public int getHealth() {
+ return health;
+ }
+
+ public void setHealth(int health) {
+ this.health = health;
}
- abstract void takeDamage();
+ abstract void takeDamage(T object);
+
}
diff --git a/src/main/java/bcit/comp2522/projectteama/DatabaseHandler.java b/src/main/java/bcit/comp2522/projectteama/DatabaseHandler.java
new file mode 100644
index 0000000..f7a1de3
--- /dev/null
+++ b/src/main/java/bcit/comp2522/projectteama/DatabaseHandler.java
@@ -0,0 +1,56 @@
+package bcit.comp2522.projectteama;
+
+import com.mongodb.ConnectionString;
+import com.mongodb.MongoClientSettings;
+import com.mongodb.ServerApi;
+import com.mongodb.ServerApiVersion;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoDatabase;
+import org.bson.Document;
+
+public class DatabaseHandler {
+
+ MongoDatabase database;
+ String myCollection;
+ private Window window;
+
+ /**
+ * DB handler constructor
+ * @param username
+ * @param password
+ * @param window
+ */
+ public DatabaseHandler(String username, String password, Window window) {
+ this.window = window;
+ ConnectionString connectionString = new ConnectionString("mongodb+srv://spaceShoot:spaceshoot@2522project.dtdwv6c.mongodb.net/?retryWrites=true&w=majority");
+ MongoClientSettings settings = MongoClientSettings.builder()
+ .applyConnectionString(connectionString)
+ .serverApi(ServerApi.builder()
+ .version(ServerApiVersion.V1)
+ .build())
+ .build();
+ MongoClient mongoClient = MongoClients.create(settings);
+ this.database = mongoClient.getDatabase("Player");
+ //this.database = mongoClient.getDatabase("Enemy");
+ this.myCollection = "Player_Score";
+ try {
+ this.database.createCollection(this.myCollection);
+ } catch (Exception e){
+ System.out.println("Collection already exists.");
+ }
+
+ }
+
+ /**
+ * Stores a key value pair in the database
+ * @param key
+ */
+ public void put(String key) {
+ Document document = new Document();
+ document.append(key, this.window.getCurrentScore());
+ new Thread (() -> database.getCollection(myCollection).insertOne(document)).start();
+ }
+
+
+}
diff --git a/src/main/java/bcit/comp2522/projectteama/Enemy.java b/src/main/java/bcit/comp2522/projectteama/Enemy.java
index 0106ce8..4142eb1 100644
--- a/src/main/java/bcit/comp2522/projectteama/Enemy.java
+++ b/src/main/java/bcit/comp2522/projectteama/Enemy.java
@@ -2,29 +2,36 @@
import processing.core.PVector;
+
import java.awt.*;
-import java.util.ArrayList;
-public class Enemy extends Creature{
+public class Enemy extends Creature implements Collidable{
+ private int scoreGiven;
+ public Enemy(PVector position, PVector direction, float width, float height,
+ float speed, Color color, Window window, Rectangle hitBox, int health, int scoreGiven) {
+ super(position, direction, width, height, speed, color, window, hitBox, health);
+ }
- /**
- * this is a constuctor for the Sprite class that equips the objects with basic
- * functionalities.
- *
- * @param position the PVector position.
- * @param direction the PVector direction.
- * @param size float size.
- * @param speed float speed.
- * @param color Color color.
- * @param window Window window.
- * @param lives
- */
- public Enemy(PVector position, PVector direction, float size, float speed, Color color, Window window, int lives) {
- super(position, direction, size, speed, color, window, lives);
+ @Override
+ void takeDamage(Bullet bullet) {
+ health = health - bullet.getDamage();
+ if (this.health <= 0) {
+ window.getEManager().remove(this);
+ window.setCurrentScore(window.getCurrentScore() + this.scoreGiven);
+ }
}
@Override
- void takeDamage() {
+ public Rectangle getHitBox() {
+ return null;
+ }
+ @Override
+ public void handleCollision(Collidable other) {
+ if (other instanceof Bullet) {
+ if (this.isCollidingWith(other)) {
+ this.takeDamage((Bullet) other);
+ }
+ }
}
}
diff --git a/src/main/java/bcit/comp2522/projectteama/EnemyManager.java b/src/main/java/bcit/comp2522/projectteama/EnemyManager.java
index 7ab2d4d..3f3652e 100644
--- a/src/main/java/bcit/comp2522/projectteama/EnemyManager.java
+++ b/src/main/java/bcit/comp2522/projectteama/EnemyManager.java
@@ -2,15 +2,12 @@
import java.awt.*;
import java.util.ArrayList;
-import processing.core.PApplet;
+
import processing.core.PVector;
-import processing.event.KeyEvent;
-public class EnemyManager extends Manager{
+public class EnemyManager extends Manager{
ArrayList enemies = new ArrayList();
private Window window;
- int minSize = 10;
- int maxSize = 15;
public EnemyManager(Window window) {
this.window = window;
@@ -22,17 +19,18 @@ public ArrayList getEnemies() {
@Override
public void add() {
- enemies.add(new Enemy(
- new PVector(random(0, this.width), random(0, this.height)),
+ Enemy enemy = new Enemy(
+ new PVector(random(0, window.width), random(0, window.height)),
new PVector(random(-1, 1), random(-1, 1)),
- random(minSize, maxSize),
- random(0, 2),
- new Color(255, 0, 0), window, 3
- ));
+ 30, 30, 2, new Color(255, 255, 0),
+ window, new Rectangle(0, 0, 20, 20), 3, 10);
+ enemy.setHitBox();
+
+ enemies.add(enemy);
}
@Override
- public void remove() {
-
+ public void remove(Enemy enemy) {
+ enemies.remove(enemy);
}
}
diff --git a/src/main/java/bcit/comp2522/projectteama/GameOverMenu.java b/src/main/java/bcit/comp2522/projectteama/GameOverMenu.java
new file mode 100644
index 0000000..873a867
--- /dev/null
+++ b/src/main/java/bcit/comp2522/projectteama/GameOverMenu.java
@@ -0,0 +1,41 @@
+package bcit.comp2522.projectteama;
+
+public class GameOverMenu {
+ Window window;
+ private Button newGameButton1;
+ private Button startMenuButton1;
+ private Button quitButton1;
+
+ public GameOverMenu(Window window) {
+ this.window = window;
+ GameOverMenuButtons();
+ }
+
+
+ public Button getNewGameButton1() {
+ return newGameButton1;
+ }
+
+ public Button getStartMenuButton1() {
+ return startMenuButton1;
+ }
+
+ public Button getQuitButton1() {
+ return quitButton1;
+ }
+
+ public void displayMenu() {
+ newGameButton1.display();
+ quitButton1.display();
+ startMenuButton1.display();
+ }
+
+ public void GameOverMenuButtons() {
+ float width = window.getWidth() / 2 - 100;
+ this.newGameButton1 = new Button(window, window.getWidth() / 2 - 330, window.getHeight() / 2 - 50 , 130, 50, "New Game");
+ this.quitButton1 = new Button(window, window.getWidth() / 2 + 200, window.getWidth() / 2 - 50, 130, 50, "Quit");
+ this.startMenuButton1 = new Button(window, window.getWidth() / 2 + 100, window.getWidth() / 2 - 50, 130, 50, "StartMenu");
+
+// TODO magic numbers
+ }
+}
diff --git a/src/main/java/bcit/comp2522/projectteama/GameStateManager.java b/src/main/java/bcit/comp2522/projectteama/GameStateManager.java
new file mode 100644
index 0000000..fd5932e
--- /dev/null
+++ b/src/main/java/bcit/comp2522/projectteama/GameStateManager.java
@@ -0,0 +1,36 @@
+package bcit.comp2522.projectteama;
+
+public class GameStateManager {
+ public enum GameState {
+ START_MENU,
+ IN_GAME,
+ PAUSE,
+ GAME_OVER
+ }
+ private GameState currentState;
+
+ public GameState getCurrentState() {
+ return currentState;
+ }
+
+ public GameStateManager() {
+ currentState = GameState.START_MENU;
+ }
+
+ public void setInGameState() {
+ currentState = GameState.IN_GAME;
+ }
+
+ public void setGameOverState() {
+ currentState = GameState.GAME_OVER;
+ }
+
+ public boolean isPlaying() {
+ return currentState == GameState.IN_GAME;
+ }
+
+ public boolean isGameOver() {
+ return currentState == GameState.GAME_OVER;
+ }
+
+}
diff --git a/src/main/java/bcit/comp2522/projectteama/Manager.java b/src/main/java/bcit/comp2522/projectteama/Manager.java
index 831ad92..c954911 100644
--- a/src/main/java/bcit/comp2522/projectteama/Manager.java
+++ b/src/main/java/bcit/comp2522/projectteama/Manager.java
@@ -2,7 +2,7 @@
import processing.core.PApplet;
-public abstract class Manager extends PApplet {
+public abstract class Manager extends PApplet {
public abstract void add();
- public abstract void remove();
+ public abstract void remove(T object);
}
diff --git a/src/main/java/bcit/comp2522/projectteama/Player.java b/src/main/java/bcit/comp2522/projectteama/Player.java
index 7b508db..7f1e118 100644
--- a/src/main/java/bcit/comp2522/projectteama/Player.java
+++ b/src/main/java/bcit/comp2522/projectteama/Player.java
@@ -4,32 +4,53 @@
import java.awt.*;
-public class Player extends Creature {
+public class Player extends Creature implements Collidable {
+
+ public Player(PVector position, PVector direction, float width, float height,
+ float speed, Color color, Window window, Rectangle hitBox, int health) {
+ super(position, direction, width, height, speed, color, window, hitBox, health);
+
+ }
+
/**
- * this is a constuctor for the Sprite class that equips the objects with basic
- * functionalities.
- *
- * @param position the PVector position.
- * @param direction the PVector direction.
- * @param size float size.
- * @param speed float speed.
- * @param color Color color.
- * @param window Window window.
- * @param lives
+ * Calculates and returns the current velocity of the sprite based on its direction and speed.
*/
- public Player(PVector position, PVector direction, float size, float speed, Color color, Window window, int lives) {
- super(position, direction, size, speed, color, window, lives);
+ public PVector getVelocity() {
+ return PVector.mult(direction, speed);
}
- public void doFire(Bullet b) {
+ /**
+ * Sets the velocity of the sprite based on the given velocity vector by updating its direction and speed fields.
+ */
+ public void setVelocity(PVector velocity) {
+ this.direction = velocity.copy().normalize();
+ this.speed = velocity.mag();
+ }
+ public void doFire() {
+ window.getBManager().add(this.position, window.getAimDirection());
}
public void upgrade(){
}
@Override
- void takeDamage() {
+ void takeDamage(Enemy enemy) {
+ this.health--;
+ }
+
+ @Override
+ public Rectangle getHitBox() {
+ return hitBox;
+ }
+ @Override
+ public void handleCollision(Collidable other) {
+ if (other instanceof Enemy) {
+ if (isCollidingWith(other)) {
+ takeDamage((Enemy) other);
+ }
+ }
}
+
}
diff --git a/src/main/java/bcit/comp2522/projectteama/PlayerManager.java b/src/main/java/bcit/comp2522/projectteama/PlayerManager.java
index cdcb83c..1869d0b 100644
--- a/src/main/java/bcit/comp2522/projectteama/PlayerManager.java
+++ b/src/main/java/bcit/comp2522/projectteama/PlayerManager.java
@@ -1,36 +1,33 @@
package bcit.comp2522.projectteama;
-import java.awt.*;
-
import processing.core.PVector;
-public class PlayerManager extends Manager{
+import java.awt.*;
- Player p;
+public class PlayerManager extends Manager{
+
+ private Player player;
private Window window;
public PlayerManager(Window window) {
this.window = window;
}
- public Player getP() {
- return p;
+ public Player getPlayer() {
+ return player;
}
@Override
public void add() {
- p = new Player( new PVector(this.width / 2, this.height / 2),
- new PVector(0, 1),
- 9,
- 2,
- new Color(0, 255, 0), window, 3);
-
+ player = new Player(new PVector(window.width/2 , window.height/2), new PVector(0, 0),
+ 30, 30, 2, new Color(0, 255, 0), window,
+ new Rectangle(0, 0, 30, 30), 3);
+ player.setHitBox();
}
-
-
@Override
- public void remove() {
-
+ public void remove(Player player) {
+ window.getGameStateManager().setGameOverState();
}
+
}
diff --git a/src/main/java/bcit/comp2522/projectteama/Sprite.java b/src/main/java/bcit/comp2522/projectteama/Sprite.java
index 79cf8a7..ca4ebd7 100644
--- a/src/main/java/bcit/comp2522/projectteama/Sprite.java
+++ b/src/main/java/bcit/comp2522/projectteama/Sprite.java
@@ -2,8 +2,6 @@
import java.awt.*;
-import java.util.Objects;
-
import processing.core.PVector;
/**
@@ -13,30 +11,22 @@
public class Sprite {
protected PVector position;
protected PVector direction;
- protected float size;
+ protected float width;
+ protected float height;
protected float speed;
protected Color color;
protected Window window;
+ protected Rectangle hitBox;
- /**
- * this is a constuctor for the Sprite class that equips the objects with basic
- * functionalities.
- *
- * @param position the PVector position.
- * @param direction the PVector direction.
- * @param size float size.
- * @param speed float speed.
- * @param color Color color.
- * @param window Window window.
- */
- public Sprite(PVector position, PVector direction, float size,
- float speed, Color color, Window window) {
+ public Sprite(PVector position, PVector direction, float width, float height, float speed, Color color, Window window, Rectangle hitBox) {
this.position = position;
this.direction = direction;
- this.size = size;
+ this.width = width;
+ this.height = height;
this.speed = speed;
- this.window = window;
this.color = color;
+ this.window = window;
+ this.hitBox = hitBox;
}
/**
@@ -45,32 +35,82 @@ public Sprite(PVector position, PVector direction, float size,
public void draw() {
window.pushStyle();
window.fill(this.color.getRed(), this.color.getGreen(), this.color.getBlue());
- window.ellipse(this.position.x, this.position.y, size, size);
+ window.ellipse(this.position.x, this.position.y, getRadius(), getRadius());
window.popStyle();
}
- public PVector getDirection() {
- return direction.copy();
+ public void update() {
+ this.position = this.getPosition().add(this.direction.copy().mult(speed));
+ this.setHitBox();
}
+ public void setPosition(PVector position) {
+ this.position = position;
+ }
public PVector getPosition() {
return position.copy();
}
- public float getSize() {
- return size;
- }
public void setDirection(PVector direction) {
this.direction = direction;
}
- public void setSize(float size) {
- this.size = size;
+ public PVector getDirection() {
+ return direction.copy();
+ }
+
+ public float getWidth() {
+ return width;
+ }
+
+ public void setWidth(float width) {
+ this.width = width;
+ }
+
+ public float getHeight() {
+ return height;
+ }
+
+ public void setHeight(float height) {
+ this.height = height;
}
- public static boolean collided(Sprite a, Sprite b) {
- float distance = PVector.dist(a.getPosition(), b.getPosition());
- return distance <= (a.getSize() + b.getSize());
+ public float getSpeed() {
+ return speed;
+ }
+
+ public void setSpeed(float speed) {
+ this.speed = speed;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public Window getWindow() {
+ return window;
+ }
+
+ public void setWindow(Window window) {
+ this.window = window;
+ }
+
+ public Rectangle getHitBox() {
+ return hitBox;
+ }
+
+ public float getRadius() {
+ return height/2;
+ }
+
+
+ public void setHitBox() {
+ this.hitBox = new Rectangle((int) getPosition().x,
+ (int) getPosition().y, (int) getWidth(), (int)getHeight());
}
}
diff --git a/src/main/java/bcit/comp2522/projectteama/StartMenu.java b/src/main/java/bcit/comp2522/projectteama/StartMenu.java
new file mode 100644
index 0000000..8ca41c8
--- /dev/null
+++ b/src/main/java/bcit/comp2522/projectteama/StartMenu.java
@@ -0,0 +1,59 @@
+package bcit.comp2522.projectteama;
+
+import java.util.ArrayList;
+import processing.core.PApplet;
+import processing.core.PImage;
+import java.awt.*;
+
+
+
+public class StartMenu {
+
+ Window window;
+
+ //Instantiate menu buttons
+ private Button newGameButton;
+ private Button quitButton;
+ private Button settingButton;
+ private Button scoreButton;
+
+ public Button getNewGameButton() {
+ return newGameButton;
+ }
+
+ public Button getQuitButton() {
+ return quitButton;
+ }
+
+ public Button getScoreButton() {
+ return scoreButton;
+ }
+
+ public Button getSettingButton() {
+ return settingButton;
+ }
+
+ //constructor
+ public StartMenu(Window window) {
+ this.window = window;
+ menuButtons();
+ }
+
+ public void displayMenu() {
+ newGameButton.display();
+ quitButton.display();
+ scoreButton.display();
+ settingButton.display();
+ }
+
+ public void menuButtons() {
+ float width = window.getWidth() / 2 - 100;
+ this.newGameButton = new Button(window, window.getWidth() / 2 - 330, window.getHeight() / 2 - 50 , 130, 50, "New Game");
+ this.scoreButton = new Button(window, window.getWidth() / 2 - 150, window.getHeight() / 2 - 50 , 130, 50, "Score");
+ this.quitButton = new Button(window, window.getWidth() / 2 + 200, window.getWidth() / 2 - 50, 130, 50, "Quit");
+ this.settingButton = new Button(window, window.getWidth() / 2 + 25, window.getWidth() / 2 - 50, 130, 50, "Setting");
+// TODO magic numbers
+ }
+
+
+}
diff --git a/src/main/java/bcit/comp2522/projectteama/Window.java b/src/main/java/bcit/comp2522/projectteama/Window.java
index 20629dc..7c7dbea 100644
--- a/src/main/java/bcit/comp2522/projectteama/Window.java
+++ b/src/main/java/bcit/comp2522/projectteama/Window.java
@@ -1,72 +1,274 @@
package bcit.comp2522.projectteama;
import processing.core.PApplet;
+import processing.core.PImage;
import processing.core.PVector;
-import processing.event.KeyEvent;
-import java.awt.*;
-import java.util.ArrayList;
public class Window extends PApplet{
- public Sprite sprite;
- public ArrayList creatures;
- protected Window aa;
- public EnemyManager eMan;
- public PlayerManager pMan;
+ private EnemyManager enemyManager;
+ private PlayerManager playerManager;
+ private BulletManager bulletManager;
+ private DatabaseHandler databaseHandler;
+ private GameStateManager gameStateManager;
+ private PImage backgroundImage;
+ private PImage backgroundImage2;
+ private PImage backgroundImage3;
+ private PVector aimDirection = new PVector(0, -1);
+ private int currentScore = 0;
+ StartMenu startMenu;
+ GameOverMenu gameOverMenu;
+ /**
+ * Sets window size
+ */
+ public void settings() {
+ size(800,800);
+
+ }
+
+ /**
+ * Initializes all required elements
+ */
public void setup() {
this.init();
+ surface.setTitle("Shooting Space"); // Constant
+ backgroundImage = loadImage("images/background.png"); // Move to a constant
+ backgroundImage.resize(width, height);
+ backgroundImage2 = loadImage("images/backgroundI.png"); // TODO
+ backgroundImage2.resize(width, height);
+ backgroundImage3 = loadImage("images/GameOver.png");
+ backgroundImage3.resize(width,height);
+ setupStartMenu();
}
+ /**
+ * Sets up the menu.
+ */
+ public void setupStartMenu() {
+ startMenu = new StartMenu(this);
+ startMenu.menuButtons();
+ }
+
+// /**
+// * Sets up the menu.
+// */
+// public void setupGameOverMenu() {
+// gameOverMenu = new GameOverMenu(this);
+// gameOverMenu.GameOverMenuButtons();
+// }
+
/**
* initializes all the elements that are required.
* these include the player and enemy.
*/
public void init() {
- creatures = new ArrayList();
- pMan = new PlayerManager(this);
- eMan = new EnemyManager(this);
+ playerManager = new PlayerManager(this);
+ enemyManager = new EnemyManager(this);
+ bulletManager = new BulletManager(this);
+ gameStateManager = new GameStateManager();
+ databaseHandler = new DatabaseHandler("spaceShoot", "spaceshoot", this);
- pMan.add();
+ playerManager.add();
- for (int i = 0; i < 10; i++) {
- eMan.add();
+ for (int i = 0; i < 10; i++) { // magic number
+ enemyManager.add();
}
- creatures.addAll(eMan.getEnemies());
- creatures.add(pMan.p);
}
+ /**
+ * Draws the current state of the window based on game state set
+ * by gameStateManager
+ */
public void draw() {
- background(0);
- for (Creature creature : creatures) {
- creature.draw();
+ //When player loses all health
+ if(playerManager.getPlayer().getHealth() <= 0) {
+ playerManager.remove(playerManager.getPlayer());
+ databaseHandler.put("Score");
}
- }
- @Override
- public void keyPressed(KeyEvent event) {
- int keyCode = event.getKeyCode();
- switch (keyCode) {
- case LEFT:
- // handle left
- pMan.getP().setDirection(pMan.getP().getDirection().rotate(-Window.PI / 16));
+ gameStateManager.getCurrentState();
+ switch (gameStateManager.getCurrentState()) {
+ case START_MENU:
+ background(backgroundImage2);
+ startMenu.displayMenu();
+ break;
+ case IN_GAME:
+ background(backgroundImage);
+
+ playerManager.getPlayer().update();
+ playerManager.getPlayer().draw();
+
+ for (Enemy enemy : enemyManager.enemies) {
+ enemy.update();
+ enemy.draw();
+ }
+ for (Bullet bullet : bulletManager.getBullets()) {
+ bullet.update();
+ bullet.draw();
+ }
break;
- case RIGHT:
- // handle right
- pMan.getP().setDirection(pMan.getP().getDirection().rotate(Window.PI / 16));
+ //case PAUSED:
+ // Draw paused screen
+ //break;
+ case GAME_OVER:
+ background(backgroundImage3);
+ gameOverMenu.displayMenu();
+ //setupGameOverMenu();
break;
}
}
+ /**
+ * Processes key presses to control the player sprite
+ */
+ @Override
+ public void keyPressed() {
+ //Handles movement
+ if (key == 'a' || key == 'A') {
+ databaseHandler.put("Score");
+ playerManager.getPlayer().setVelocity(new PVector(-3, playerManager.getPlayer().getVelocity().y)); // TODO
+ } else if (key == 'd' || key == 'D') {
+ playerManager.getPlayer().setVelocity(new PVector(3, playerManager.getPlayer().getVelocity().y));
+ } else if (key == 'w' || key == 'W') {
+ playerManager.getPlayer().setVelocity(new PVector(playerManager.getPlayer().getVelocity().x, -3));
+ } else if (key == 's' || key == 'S') {
+ playerManager.getPlayer().setVelocity(new PVector(playerManager.getPlayer().getVelocity().x, 3));
+ //Handles aiming
+ } else if (keyCode == LEFT) {
+ aimDirection = new PVector(-1, 0).normalize();
+ } else if (keyCode == RIGHT) {
+ aimDirection = new PVector(1, 0).normalize();
+ } else if (keyCode == UP) {
+ aimDirection = new PVector(0, -1).normalize();
+ } else if (keyCode == DOWN) {
+ aimDirection = new PVector(0, 1).normalize();
+ }
+
+ }
+
+ /**
+ * Gets the direction the player is currently aiming.
+ * @return A PVector representing the aim direction
+ */
+ public PVector getAimDirection() {
+ return aimDirection;
+ }
+
+ /**
+ * Sets the current score.
+ * @param currentScore The new current score value.
+ */
+ public void setCurrentScore(int currentScore) {
+ this.currentScore = currentScore;
+ }
+
+ /**
+ * Gets the current score.
+ * @return The current score.
+ */
+ public int getCurrentScore() {
+ return currentScore;
+ }
+
+ /**
+ * Gets the height of the game window.
+ * @return The height of the game window.
+ */
+ public float getHeight() {
+ return height;
+ }
+
+ /**
+ * Gets the width of the game window.
+ * @return The width of the game window.
+ */
+ public float getWidth() { // put above main
+ return width;
+ }
+
+ /**
+ * Gets the game state manager.
+ * @return The game state manager.
+ */
+ public GameStateManager getGameStateManager() {
+ return gameStateManager;
+ }
+
+ /**
+ * Gets the bullet manager.
+ * @return The bullet manager.
+ */
+ public BulletManager getBManager() {
+ return bulletManager;
+ }
+
+ /**
+ * Gets the enemy manager.
+ * @return The enemy manager.
+ */
+ public EnemyManager getEManager() {
+ return enemyManager;
+ }
+
+ /**
+ * Sets key pressed state back to non-pressed state
+ */
+ @Override
+ public void keyReleased() {
+ if ((key == 'a' || key == 'A') && playerManager.getPlayer().getVelocity().x < 0) {
+ playerManager.getPlayer().setVelocity(new PVector(0, playerManager.getPlayer().getVelocity().y));
+ } else if ((key == 'd' || key == 'D') && playerManager.getPlayer().getVelocity().x > 0) {
+ playerManager.getPlayer().setVelocity(new PVector(0, playerManager.getPlayer().getVelocity().y));
+ } else if ((key == 'w' || key == 'W') && playerManager.getPlayer().getVelocity().y < 0) {
+ playerManager.getPlayer().setVelocity(new PVector(playerManager.getPlayer().getVelocity().x, 0));
+ } else if ((key == 's' || key == 'S') && playerManager.getPlayer().getVelocity().y > 0) {
+ playerManager.getPlayer().setVelocity(new PVector(playerManager.getPlayer().getVelocity().x, 0));
+ }
+ if (key == ' ') {
+ playerManager.getPlayer().doFire();
+ }
+ }
+
+ /**
+ * Handles mouse click events
+ */
+ public void mouseClicked() {
+ if (startMenu.getNewGameButton().isMouseOver()) {
+ gameStateManager.setInGameState();
+ draw();
+ }
+ if (startMenu.getQuitButton().isMouseOver()) {
+ exit();
+ }
+ if (startMenu.getScoreButton().isMouseOver()) {
+ exit(); // changed this after the score board implemented;
+ }
+ if (startMenu.getSettingButton().isMouseOver()) {
+ exit(); // changed this after the setting board implemented;
+ }
+// if (gameOverMenu.getStartMenuButton1().isMouseOver()) {
+//
+// }
+// if(gameOverMenu.getNewGameButton1().isMouseOver()) {
+//// gameStateManager.setInGameState();
+//// draw();
+// }
+// if (gameOverMenu.getQuitButton1().isMouseOver()) {
+//// exit();
+// }
+ }
+
/**
* Main function.
*
* @param passedArgs arguments from command line
*/
public static void main(String[] passedArgs) {
- String[] appletArgs = new String[]{"aa"};
- Window aa = new Window();
- PApplet.runSketch(appletArgs, aa);
+ String[] appletArgs = new String[]{"shooter"};
+ Window shooter = new Window();
+ PApplet.runSketch(appletArgs, shooter);
}
+
}
diff --git a/src/test/java/bcit/comp2522/projectteama/EnemyTest.java b/src/test/java/bcit/comp2522/projectteama/EnemyTest.java
new file mode 100644
index 0000000..6490bf9
--- /dev/null
+++ b/src/test/java/bcit/comp2522/projectteama/EnemyTest.java
@@ -0,0 +1,36 @@
+package bcit.comp2522.projectteama;
+
+
+import org.junit.jupiter.api.Test;
+import processing.core.PApplet;
+import processing.core.PVector;
+
+import java.awt.*;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class EnemyTest {
+ Window shooter2;
+
+ @Test
+ void handleCollision() {
+ // Create a new enemy and bullet object
+ String[] appletArgs = new String[]{"shooter2"};
+ shooter2 = new Window();
+ PApplet.runSketch(appletArgs, shooter2);
+ shooter2.init();
+ Enemy enemy = new Enemy(new PVector(0, 0), new PVector(0, 0), 50, 50,
+ 10, new Color(255, 0, 0), shooter2, new Rectangle(0, 0, 50, 50), 2, 10);
+ Bullet bullet = new Bullet(new PVector(0, 0), new PVector(0, 0), 5, 10,
+ 10, new Color(0, 255, 0), shooter2, new Rectangle(0, 0, 5, 10), 1);
+ // Save the enemy's initial health
+ int initialHealth = enemy.getHealth();
+
+ // Call the handleCollision method with the bullet object
+ enemy.handleCollision(bullet);
+
+ // Verify that the enemy's health has been reduced by the bullet's damage
+ int expectedHealth = initialHealth - bullet.getDamage();
+ assertEquals(expectedHealth, enemy.getHealth());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/bcit/comp2522/projectteama/PlayerTest.java b/src/test/java/bcit/comp2522/projectteama/PlayerTest.java
new file mode 100644
index 0000000..4fcedad
--- /dev/null
+++ b/src/test/java/bcit/comp2522/projectteama/PlayerTest.java
@@ -0,0 +1,49 @@
+package bcit.comp2522.projectteama;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import processing.core.PVector;
+
+import java.awt.*;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class PlayerTest {
+
+ private Window window;
+ private Player player;
+
+ @BeforeEach
+ public void setUp() {
+ window = new Window();
+ window.settings();
+ player = new Player(new PVector(window.getWidth() / 2, window.getHeight() / 2), new PVector(0, 0),
+ 30, 30, 2, new Color(0, 255, 0), window, new Rectangle(0, 0, 30, 30), 3);
+ }
+
+ @Test
+ void getVelocity() {
+ }
+
+ @Test
+ void setVelocity() {
+ }
+
+ @Test
+ void testDoFire() {
+ player.doFire();
+
+ }
+
+ @Test
+ void takeDamage() {
+ }
+
+ @Test
+ void getHitBox() {
+ }
+
+ @Test
+ void handleCollision() {
+ }
+}
\ No newline at end of file