diff --git a/src/project/Colors.java b/src/project/Colors.java index 7c15073..ada150e 100644 --- a/src/project/Colors.java +++ b/src/project/Colors.java @@ -10,7 +10,5 @@ public class Colors { static final Color startBlue = new Color(112, 113, 255); static final Color red = new Color(255, 6, 0); static final Color endGreen = new Color(150, 255, 0); - static final Color playerBody = new Color(247, 17, 17); - static final Color Tires = new Color(0, 0, 0); - static final Color NPC1Body = new Color(0, 247, 0); + static final Color pBtn = new Color(255, 0, 24); } \ No newline at end of file diff --git a/src/project/Draw.java b/src/project/Draw.java index 5d056c2..18a1333 100644 --- a/src/project/Draw.java +++ b/src/project/Draw.java @@ -12,18 +12,24 @@ public class Draw extends Applet { } } - public static void begin(Graphics g, int score) { + public static void begin(Graphics g, int score, boolean powerUsed) { road(g); btns(g); + if (score % 50 == 0 || !powerUsed) { + pBtn(g); + } Expo.setFont(g, "Arial", 1, 15); + Expo.setColor(g, Colors.startBlue); Expo.drawString(g, "Your score is " + score, 600, 100); // Draws score } - public static void end(Graphics g) { // Draws screen that is shown on collision with another car or road shoulder + public static void end(Graphics g, int score) { // Draws screen that is shown on collision with another car or road shoulder Expo.setBackground(g,Colors.red); Expo.setColor(g,Colors.endGreen); Expo.setFont(g, "Arial", 1, 100); Expo.drawString(g,"YOU DIED",100,100); + Expo.setFont(g, "Arial", 1, 20); + Expo.drawString(g, "Score = " + score, 100, 200); } @@ -34,6 +40,15 @@ public class Draw extends Applet { Expo.drawString(g, "=>", 660, 300); } + public static void pBtn(Graphics g) { + Expo.setFont(g, "Arial", 1, 100); + Expo.setColor(g, Colors.pBtn); + Expo.drawString(g, "<=", 480, 400); + Expo.drawString(g, "=>", 660, 400); + Expo.setFont(g, "Arial", 1, 20); + Expo.drawString(g, "Power move! Click the buttons bellow to move five times as far!", 450, 335); + } + public static void road(Graphics g){ Expo.fillRoundedRectangle(g,100,100,410,500,6); diff --git a/src/project/Main.java b/src/project/Main.java index 4358b8d..cbf5241 100644 --- a/src/project/Main.java +++ b/src/project/Main.java @@ -14,6 +14,10 @@ public class Main extends Applet { private Rectangle startBtn = new Rectangle(100, 100, 340, 600); // Rectangle that the user presses to start the game private Rectangle lBtn = new Rectangle(480, 240, 150, 80); // Rectangle that the player presses to move player to the left private Rectangle rBtn = new Rectangle(660, 240, 150, 80); // Rectangle that the player presses to move player to the right + private Rectangle lpBtn = new Rectangle(480, 340, 150, 80); // Rectangle that the player presses to move player to the power left + private Rectangle rpBtn = new Rectangle(660, 340, 150, 80); // Rectangle that the player presses to move player to the power right + private boolean alive = true; // Used to stop score from increasing + private boolean powerUsed = true; // Sets default value for power availability private static void npcLocomotion(Graphics g) { // Logic for spawning NPC objects if (score > 3) { @@ -48,8 +52,11 @@ public class Main extends Applet { public void paint(Graphics g) { Expo.drawHeading(g, "Quentin Snow and Alekkai", "Final Project"); - if (start && !NPC1.collision && !NPC2.collision && !NPC3.collision && !NPC4.collision && !NPC5.collision && !NPC6.collision && !playerHitShoulder) { // Start and keep game running if 1. startBtn has been pressed. 2. No NPCs have detected a collision and player hasn't hit shoulder. - Draw.begin(g, score); + if (start && !NPC1.collision && !NPC2.collision && !NPC3.collision && !NPC4.collision && !NPC5.collision && !NPC6.collision && !NPC7.collision && !playerHitShoulder) { // Start and keep game running if 1. startBtn has been pressed. 2. No NPCs have detected a collision and player hasn't hit shoulder. + if (score % 50 == 0) { + powerUsed = false; + } + Draw.begin(g, score, powerUsed); playerLocomotion(g); npcLocomotion(g); @@ -58,8 +65,9 @@ public class Main extends Applet { Draw.startScreen(g); // Draw the start screen if the game has not started } - if (NPC1.collision || NPC2.collision || NPC3.collision || NPC4.collision || NPC5.collision || NPC6.collision || playerHitShoulder) { // If any NPCs report a collision or player has hit the shoulder draw the end screen - Draw.end(g); + if (NPC1.collision || NPC2.collision || NPC3.collision || NPC4.collision || NPC5.collision || NPC6.collision || NPC7.collision || playerHitShoulder) { // If any NPCs report a collision or player has hit the shoulder draw the end screen + Draw.end(g, score); + alive = false; } } @@ -68,13 +76,24 @@ public class Main extends Applet { start = true; // Set start to true if user has clicked startBtn } if (lBtn.inside(x,y)){ - Px -= 10; // Move player 10 pixels to left when lBtn is pressed + Px -= 8; // Move player 8 pixels to left when lBtn is pressed } if (rBtn.inside(x,y)){ - Px += 10; // Move player 10 pixels to left when lBtn is pressed + Px += 8; // Move player 8 pixels to left when lBtn is pressed + } + if (lpBtn.inside(x, y) && !powerUsed) { + Px -= 30; + powerUsed = true; + } + if (rpBtn.inside(x, y) && !powerUsed) { + Px += 30; + powerUsed = true; + } + if (alive) { + score++; // For every click increase users score } - score++; // For every click increase users score repaint(); // Redraw everything + System.out.println(x); return true; } } \ No newline at end of file diff --git a/src/project/Sprites/NPC1.java b/src/project/Sprites/NPC1.java index 2e27775..90bf96d 100644 --- a/src/project/Sprites/NPC1.java +++ b/src/project/Sprites/NPC1.java @@ -1,6 +1,5 @@ package project.Sprites; -import project.Draw; import project.Expo; import java.applet.Applet; @@ -27,7 +26,6 @@ public class NPC1 extends Applet { Expo.fillRectangle(g, x + 30, y + 118, x + 40, y + 138); Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165); } else { - Draw.end(g); // Draws end screen collision = true; // Used by Main.java to detect if game is collision } if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables. diff --git a/src/project/Sprites/NPC2.java b/src/project/Sprites/NPC2.java index 386960f..4ccf732 100644 --- a/src/project/Sprites/NPC2.java +++ b/src/project/Sprites/NPC2.java @@ -1,6 +1,5 @@ package project.Sprites; -import project.Draw; import project.Expo; import java.applet.Applet; @@ -27,7 +26,6 @@ public class NPC2 extends Applet { Expo.fillRectangle(g, x + 30, y + 118, x + 40, y + 138); Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165); } else { - Draw.end(g); // Draws end screen collision = true; // Used by Main.java to detect if game is collision } if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables. diff --git a/src/project/Sprites/NPC3.java b/src/project/Sprites/NPC3.java index d653761..e723c89 100644 --- a/src/project/Sprites/NPC3.java +++ b/src/project/Sprites/NPC3.java @@ -1,6 +1,5 @@ package project.Sprites; -import project.Draw; import project.Expo; import java.applet.Applet; @@ -27,7 +26,6 @@ public class NPC3 extends Applet { Expo.fillRectangle(g, x + 30, y + 118, x + 40, y + 138); Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165); } else { - Draw.end(g); // Draws end screen collision = true; // Used by Main.java to detect if game is collision } if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables. diff --git a/src/project/Sprites/NPC4.java b/src/project/Sprites/NPC4.java index 36cd5d3..fc73fb2 100644 --- a/src/project/Sprites/NPC4.java +++ b/src/project/Sprites/NPC4.java @@ -1,6 +1,5 @@ package project.Sprites; -import project.Draw; import project.Expo; import java.applet.Applet; @@ -27,7 +26,6 @@ public class NPC4 extends Applet { Expo.fillRectangle(g, x + 30, y + 118, x + 40, y + 138); Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165); } else { - Draw.end(g); // Draws end screen collision = true; // Used by Main.java to detect if game is collision } if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables. diff --git a/src/project/Sprites/NPC5.java b/src/project/Sprites/NPC5.java index f5e75d8..495fe65 100644 --- a/src/project/Sprites/NPC5.java +++ b/src/project/Sprites/NPC5.java @@ -1,6 +1,5 @@ package project.Sprites; -import project.Draw; import project.Expo; import java.applet.Applet; @@ -27,7 +26,6 @@ public class NPC5 extends Applet { Expo.fillRectangle(g, x + 30, y + 118, x + 40, y + 138); Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165); } else { - Draw.end(g); // Draws end screen collision = true; // Used by Main.java to detect if game is collision } if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables. diff --git a/src/project/Sprites/NPC6.java b/src/project/Sprites/NPC6.java index ac14514..f9aed62 100644 --- a/src/project/Sprites/NPC6.java +++ b/src/project/Sprites/NPC6.java @@ -1,6 +1,5 @@ package project.Sprites; -import project.Draw; import project.Expo; import java.applet.Applet; @@ -27,7 +26,6 @@ public class NPC6 extends Applet { Expo.fillRectangle(g, x + 30, y + 118, x + 40, y + 138); Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165); } else { - Draw.end(g); // Draws end screen collision = true; // Used by Main.java to detect if game is collision } if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables. diff --git a/src/project/Sprites/NPC7.java b/src/project/Sprites/NPC7.java index a36ee00..0bac1e3 100644 --- a/src/project/Sprites/NPC7.java +++ b/src/project/Sprites/NPC7.java @@ -1,6 +1,5 @@ package project.Sprites; -import project.Draw; import project.Expo; import java.applet.Applet; @@ -17,7 +16,7 @@ public class NPC7 extends Applet { } public static void make(Graphics g, int Px) { - if (!(y >= 240 && y <= 350 && x >= Px - 40 && x <= Px + 43)) { // Collision detection + if (!(y >= 250 && y <= 350 && x >= Px - 40 && x <= Px + 43)) { // Collision detection y += speed; // Moves NPC down according to its speed Expo.setColor(g, SpriteColors.NPC7Body); Expo.fillRectangle(g, x, y + 110, x + 35, y + 170); @@ -27,7 +26,6 @@ public class NPC7 extends Applet { Expo.fillRectangle(g, x + 30, y + 118, x + 40, y + 138); Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165); } else { - Draw.end(g); // Draws end screen collision = true; // Used by Main.java to detect if game is collision } if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.