Added a power move and fixed NPC7 collision
Signed-off-by: officereso <qrs01@snowtx.com>
This commit is contained in:
parent
3703cd34c0
commit
05eb5e46b7
@ -10,7 +10,5 @@ public class Colors {
|
|||||||
static final Color startBlue = new Color(112, 113, 255);
|
static final Color startBlue = new Color(112, 113, 255);
|
||||||
static final Color red = new Color(255, 6, 0);
|
static final Color red = new Color(255, 6, 0);
|
||||||
static final Color endGreen = new Color(150, 255, 0);
|
static final Color endGreen = new Color(150, 255, 0);
|
||||||
static final Color playerBody = new Color(247, 17, 17);
|
static final Color pBtn = new Color(255, 0, 24);
|
||||||
static final Color Tires = new Color(0, 0, 0);
|
|
||||||
static final Color NPC1Body = new Color(0, 247, 0);
|
|
||||||
}
|
}
|
@ -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);
|
road(g);
|
||||||
btns(g);
|
btns(g);
|
||||||
|
if (score % 50 == 0 || !powerUsed) {
|
||||||
|
pBtn(g);
|
||||||
|
}
|
||||||
Expo.setFont(g, "Arial", 1, 15);
|
Expo.setFont(g, "Arial", 1, 15);
|
||||||
|
Expo.setColor(g, Colors.startBlue);
|
||||||
Expo.drawString(g, "Your score is " + score, 600, 100); // Draws score
|
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.setBackground(g,Colors.red);
|
||||||
Expo.setColor(g,Colors.endGreen);
|
Expo.setColor(g,Colors.endGreen);
|
||||||
Expo.setFont(g, "Arial", 1, 100);
|
Expo.setFont(g, "Arial", 1, 100);
|
||||||
Expo.drawString(g,"YOU DIED",100,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);
|
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){
|
public static void road(Graphics g){
|
||||||
Expo.fillRoundedRectangle(g,100,100,410,500,6);
|
Expo.fillRoundedRectangle(g,100,100,410,500,6);
|
||||||
|
@ -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 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 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 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
|
private static void npcLocomotion(Graphics g) { // Logic for spawning NPC objects
|
||||||
if (score > 3) {
|
if (score > 3) {
|
||||||
@ -48,8 +52,11 @@ public class Main extends Applet {
|
|||||||
|
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
Expo.drawHeading(g, "Quentin Snow and Alekkai", "Final Project");
|
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.
|
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.
|
||||||
Draw.begin(g, score);
|
if (score % 50 == 0) {
|
||||||
|
powerUsed = false;
|
||||||
|
}
|
||||||
|
Draw.begin(g, score, powerUsed);
|
||||||
playerLocomotion(g);
|
playerLocomotion(g);
|
||||||
npcLocomotion(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
|
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
|
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);
|
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
|
start = true; // Set start to true if user has clicked startBtn
|
||||||
}
|
}
|
||||||
if (lBtn.inside(x,y)){
|
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)){
|
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
|
repaint(); // Redraw everything
|
||||||
|
System.out.println(x);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package project.Sprites;
|
package project.Sprites;
|
||||||
|
|
||||||
import project.Draw;
|
|
||||||
import project.Expo;
|
import project.Expo;
|
||||||
|
|
||||||
import java.applet.Applet;
|
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 + 118, x + 40, y + 138);
|
||||||
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
||||||
} else {
|
} else {
|
||||||
Draw.end(g); // Draws end screen
|
|
||||||
collision = true; // Used by Main.java to detect if game is collision
|
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.
|
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package project.Sprites;
|
package project.Sprites;
|
||||||
|
|
||||||
import project.Draw;
|
|
||||||
import project.Expo;
|
import project.Expo;
|
||||||
|
|
||||||
import java.applet.Applet;
|
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 + 118, x + 40, y + 138);
|
||||||
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
||||||
} else {
|
} else {
|
||||||
Draw.end(g); // Draws end screen
|
|
||||||
collision = true; // Used by Main.java to detect if game is collision
|
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.
|
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package project.Sprites;
|
package project.Sprites;
|
||||||
|
|
||||||
import project.Draw;
|
|
||||||
import project.Expo;
|
import project.Expo;
|
||||||
|
|
||||||
import java.applet.Applet;
|
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 + 118, x + 40, y + 138);
|
||||||
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
||||||
} else {
|
} else {
|
||||||
Draw.end(g); // Draws end screen
|
|
||||||
collision = true; // Used by Main.java to detect if game is collision
|
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.
|
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package project.Sprites;
|
package project.Sprites;
|
||||||
|
|
||||||
import project.Draw;
|
|
||||||
import project.Expo;
|
import project.Expo;
|
||||||
|
|
||||||
import java.applet.Applet;
|
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 + 118, x + 40, y + 138);
|
||||||
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
||||||
} else {
|
} else {
|
||||||
Draw.end(g); // Draws end screen
|
|
||||||
collision = true; // Used by Main.java to detect if game is collision
|
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.
|
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package project.Sprites;
|
package project.Sprites;
|
||||||
|
|
||||||
import project.Draw;
|
|
||||||
import project.Expo;
|
import project.Expo;
|
||||||
|
|
||||||
import java.applet.Applet;
|
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 + 118, x + 40, y + 138);
|
||||||
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
||||||
} else {
|
} else {
|
||||||
Draw.end(g); // Draws end screen
|
|
||||||
collision = true; // Used by Main.java to detect if game is collision
|
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.
|
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package project.Sprites;
|
package project.Sprites;
|
||||||
|
|
||||||
import project.Draw;
|
|
||||||
import project.Expo;
|
import project.Expo;
|
||||||
|
|
||||||
import java.applet.Applet;
|
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 + 118, x + 40, y + 138);
|
||||||
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
||||||
} else {
|
} else {
|
||||||
Draw.end(g); // Draws end screen
|
|
||||||
collision = true; // Used by Main.java to detect if game is collision
|
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.
|
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package project.Sprites;
|
package project.Sprites;
|
||||||
|
|
||||||
import project.Draw;
|
|
||||||
import project.Expo;
|
import project.Expo;
|
||||||
|
|
||||||
import java.applet.Applet;
|
import java.applet.Applet;
|
||||||
@ -17,7 +16,7 @@ public class NPC7 extends Applet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void make(Graphics g, int Px) {
|
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
|
y += speed; // Moves NPC down according to its speed
|
||||||
Expo.setColor(g, SpriteColors.NPC7Body);
|
Expo.setColor(g, SpriteColors.NPC7Body);
|
||||||
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
|
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 + 118, x + 40, y + 138);
|
||||||
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
|
||||||
} else {
|
} else {
|
||||||
Draw.end(g); // Draws end screen
|
|
||||||
collision = true; // Used by Main.java to detect if game is collision
|
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.
|
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user