Code documentation, cleanup, and optimisation
Signed-off-by: officereso <qrs01@snowtx.com>
This commit is contained in:
parent
f1713a1fb4
commit
04cccbdef1
3
.idea/dictionaries/QRSnow.xml
generated
Normal file
3
.idea/dictionaries/QRSnow.xml
generated
Normal file
@ -0,0 +1,3 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="QRSnow" />
|
||||
</component>
|
@ -5,8 +5,7 @@ import java.awt.*;
|
||||
|
||||
public class Draw extends Applet {
|
||||
public static void startScreen(Graphics g){
|
||||
|
||||
for(int i=0;i<=20;i++){
|
||||
for (int i = 0; i <= 20; i++) { // Draws the word START in a fall to the bottom left style.
|
||||
Expo.setRandomColor(g);
|
||||
Expo.setFont(g, "Arial", 1, 100 - i);
|
||||
Expo.drawString(g,"START",100+i*5,200+i*7);
|
||||
@ -17,10 +16,10 @@ public class Draw extends Applet {
|
||||
road(g);
|
||||
btns(g);
|
||||
Expo.setFont(g, "Arial", 1, 15);
|
||||
Expo.drawString(g, "Your score is " + score, 600, 100);
|
||||
Expo.drawString(g, "Your score is " + score, 600, 100); // Draws score
|
||||
}
|
||||
|
||||
public static void end(Graphics g){
|
||||
public static void end(Graphics g) { // 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);
|
||||
@ -28,7 +27,7 @@ public class Draw extends Applet {
|
||||
}
|
||||
|
||||
|
||||
public static void btns(Graphics g) {
|
||||
public static void btns(Graphics g) { // Draws buttons responsible the user presses for player locomotion
|
||||
Expo.setFont(g, "Arial", 1, 100);
|
||||
Expo.setColor(g,Colors.startBlue);
|
||||
Expo.drawString(g,"<=",480,300);
|
||||
|
@ -7,33 +7,17 @@ import java.awt.*;
|
||||
|
||||
|
||||
public class Main extends Applet {
|
||||
private static boolean start = false;
|
||||
private Rectangle startBtn = new Rectangle(100,100,340,600);
|
||||
private static int score = 0;
|
||||
private Rectangle lBtn = new Rectangle(480, 240, 150, 80);
|
||||
private static int Px = 150;
|
||||
private Rectangle rBtn = new Rectangle(660, 240, 150, 80);
|
||||
private static boolean start = false; // Control for when game is started
|
||||
private static boolean playerHitShoulder = false;
|
||||
private static int score = 0; // Default player score
|
||||
private static int Px = 150; // Default Px(Player x)
|
||||
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
|
||||
|
||||
public void paint(Graphics g) {
|
||||
Expo.drawHeading(g, "Quentin Snow and Alekkai", "Final Project");
|
||||
if (start && !NPC1.ended && !NPC2.ended && !NPC3.ended && !NPC4.ended && !NPC5.ended && !NPC6.ended) {
|
||||
Draw.begin(g, score);
|
||||
playerLocomotion(g);
|
||||
npcLocomotion(g);
|
||||
|
||||
}
|
||||
if (!start) {
|
||||
Draw.startScreen(g);
|
||||
}
|
||||
|
||||
if (NPC1.ended || NPC2.ended || NPC3.ended || NPC4.ended || NPC5.ended || NPC6.ended) {
|
||||
Draw.end(g);
|
||||
}
|
||||
}
|
||||
|
||||
private static void npcLocomotion(Graphics g) {
|
||||
private static void npcLocomotion(Graphics g) { // Logic for spawning NPC objects
|
||||
if (score > 3) {
|
||||
new NPC1(g, Px);
|
||||
new NPC1(g, Px); // Px is passed to NPCs for collision detection purposes
|
||||
}
|
||||
if (score > 30) {
|
||||
new NPC2(g, Px);
|
||||
@ -52,28 +36,42 @@ public class Main extends Applet {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void playerLocomotion(Graphics g) {
|
||||
project.Sprites.player.make(g, Px, 427);
|
||||
if (Px <= 107 || Px >= 375) {
|
||||
Draw.end(g);
|
||||
Px = 10000;
|
||||
Player.make(g, Px, 427); // Draw the player according to its Px
|
||||
if (Px <= 107 || Px >= 375) { // Logic to detect if player has it the shoulder of road
|
||||
playerHitShoulder = true;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
playerLocomotion(g);
|
||||
npcLocomotion(g);
|
||||
|
||||
}
|
||||
if (!start) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mouseDown(Event e, int x, int y){
|
||||
if (startBtn.inside(x,y)){
|
||||
start = true;
|
||||
start = true; // Set start to true if user has clicked startBtn
|
||||
}
|
||||
if (lBtn.inside(x,y)){
|
||||
Px-=10;
|
||||
Px -= 10; // Move player 10 pixels to left when lBtn is pressed
|
||||
}
|
||||
if (rBtn.inside(x,y)){
|
||||
Px+=10;
|
||||
Px += 10; // Move player 10 pixels to left when lBtn is pressed
|
||||
}
|
||||
score++;
|
||||
repaint();
|
||||
score++; // For every click increase users score
|
||||
repaint(); // Redraw everything
|
||||
return true;
|
||||
}
|
||||
}
|
@ -7,18 +7,18 @@ import java.applet.Applet;
|
||||
import java.awt.*;
|
||||
|
||||
public class NPC1 extends Applet {
|
||||
public static boolean ended = false;
|
||||
private static int x = Expo.random(100, 400);
|
||||
private static int y = -15;
|
||||
private static int speed = Expo.random(10, 40);
|
||||
public static boolean collision = false;
|
||||
private static int x = Expo.random(100, 400); // Where NPC starts on road
|
||||
private static int y = -15; // Default starting position for NPC. Negative because NPC is draw from bottom left to top right.
|
||||
private static int speed = Expo.random(10, 40); // Value to move NPC down
|
||||
|
||||
public NPC1(Graphics g, int Px) {
|
||||
make(g, Px);
|
||||
}
|
||||
|
||||
public static void make(Graphics g, int Px) {
|
||||
if (!(y >= 250 && y <= 350 && x >= Px - 40 && x <= Px + 43) && !ended) {
|
||||
y += speed;
|
||||
if (!(y >= 240 && y <= 350 && x >= Px - 40 && x <= Px + 43)) { // Collision detection
|
||||
y += speed; // Moves NPC down according to its speed
|
||||
Expo.setColor(g, SpriteColors.NPC1Body);
|
||||
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
|
||||
Expo.setColor(g, SpriteColors.Tires);
|
||||
@ -27,10 +27,10 @@ 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);
|
||||
ended = true;
|
||||
Draw.end(g); // Draws end screen
|
||||
collision = true; // Used by Main.java to detect if game is collision
|
||||
}
|
||||
if (y > 350) {
|
||||
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||
x = Expo.random(100, 400);
|
||||
y = 25;
|
||||
speed = Expo.random(10, 40);
|
||||
|
@ -7,18 +7,18 @@ import java.applet.Applet;
|
||||
import java.awt.*;
|
||||
|
||||
public class NPC2 extends Applet {
|
||||
public static boolean ended = false;
|
||||
private static int x = Expo.random(100, 400);
|
||||
private static int y = -15;
|
||||
private static int speed = Expo.random(10, 40);
|
||||
public static boolean collision = false;
|
||||
private static int x = Expo.random(100, 400); // Where NPC starts on road
|
||||
private static int y = -15; // Default starting position for NPC. Negative because NPC is draw from bottom left to top right.
|
||||
private static int speed = Expo.random(10, 40); // Value to move NPC down
|
||||
|
||||
public NPC2(Graphics g, int Px) {
|
||||
make(g, Px);
|
||||
}
|
||||
|
||||
public static void make(Graphics g, int Px) {
|
||||
if (!(y >= 250 && y <= 350 && x >= Px - 40 && x <= Px + 43) && !ended) {
|
||||
y += speed;
|
||||
if (!(y >= 240 && y <= 350 && x >= Px - 40 && x <= Px + 43)) { // Collision detection
|
||||
y += speed; // Moves NPC down according to its speed
|
||||
Expo.setColor(g, SpriteColors.NPC1Body);
|
||||
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
|
||||
Expo.setColor(g, SpriteColors.Tires);
|
||||
@ -27,10 +27,10 @@ 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);
|
||||
ended = true;
|
||||
Draw.end(g); // Draws end screen
|
||||
collision = true; // Used by Main.java to detect if game is collision
|
||||
}
|
||||
if (y > 350) {
|
||||
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||
x = Expo.random(100, 400);
|
||||
y = 25;
|
||||
speed = Expo.random(10, 40);
|
||||
|
@ -7,18 +7,18 @@ import java.applet.Applet;
|
||||
import java.awt.*;
|
||||
|
||||
public class NPC3 extends Applet {
|
||||
public static boolean ended = false;
|
||||
private static int x = Expo.random(100, 400);
|
||||
private static int y = -15;
|
||||
private static int speed = Expo.random(10, 40);
|
||||
public static boolean collision = false;
|
||||
private static int x = Expo.random(100, 400); // Where NPC starts on road
|
||||
private static int y = -15; // Default starting position for NPC. Negative because NPC is draw from bottom left to top right.
|
||||
private static int speed = Expo.random(10, 40); // Value to move NPC down
|
||||
|
||||
public NPC3(Graphics g, int Px) {
|
||||
make(g, Px);
|
||||
}
|
||||
|
||||
public static void make(Graphics g, int Px) {
|
||||
if (!(y >= 250 && y <= 350 && x >= Px - 40 && x <= Px + 43) && !ended) {
|
||||
y += speed;
|
||||
if (!(y >= 240 && y <= 350 && x >= Px - 40 && x <= Px + 43)) { // Collision detection
|
||||
y += speed; // Moves NPC down according to its speed
|
||||
Expo.setColor(g, SpriteColors.NPC1Body);
|
||||
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
|
||||
Expo.setColor(g, SpriteColors.Tires);
|
||||
@ -27,10 +27,10 @@ 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);
|
||||
ended = true;
|
||||
Draw.end(g); // Draws end screen
|
||||
collision = true; // Used by Main.java to detect if game is collision
|
||||
}
|
||||
if (y > 350) {
|
||||
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||
x = Expo.random(100, 400);
|
||||
y = 25;
|
||||
speed = Expo.random(10, 40);
|
||||
|
@ -7,18 +7,18 @@ import java.applet.Applet;
|
||||
import java.awt.*;
|
||||
|
||||
public class NPC4 extends Applet {
|
||||
public static boolean ended = false;
|
||||
private static int x = Expo.random(100, 400);
|
||||
private static int y = -15;
|
||||
private static int speed = Expo.random(10, 40);
|
||||
public static boolean collision = false;
|
||||
private static int x = Expo.random(100, 400); // Where NPC starts on road
|
||||
private static int y = -15; // Default starting position for NPC. Negative because NPC is draw from bottom left to top right.
|
||||
private static int speed = Expo.random(10, 40); // Value to move NPC down
|
||||
|
||||
public NPC4(Graphics g, int Px) {
|
||||
make(g, Px);
|
||||
}
|
||||
|
||||
public static void make(Graphics g, int Px) {
|
||||
if (!(y >= 250 && y <= 350 && x >= Px - 40 && x <= Px + 43) && !ended) {
|
||||
y += speed;
|
||||
if (!(y >= 240 && y <= 350 && x >= Px - 40 && x <= Px + 43)) { // Collision detection
|
||||
y += speed; // Moves NPC down according to its speed
|
||||
Expo.setColor(g, SpriteColors.NPC1Body);
|
||||
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
|
||||
Expo.setColor(g, SpriteColors.Tires);
|
||||
@ -27,10 +27,10 @@ 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);
|
||||
ended = true;
|
||||
Draw.end(g); // Draws end screen
|
||||
collision = true; // Used by Main.java to detect if game is collision
|
||||
}
|
||||
if (y > 350) {
|
||||
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||
x = Expo.random(100, 400);
|
||||
y = 25;
|
||||
speed = Expo.random(10, 40);
|
||||
|
@ -7,18 +7,18 @@ import java.applet.Applet;
|
||||
import java.awt.*;
|
||||
|
||||
public class NPC5 extends Applet {
|
||||
public static boolean ended = false;
|
||||
private static int x = Expo.random(100, 400);
|
||||
private static int y = -15;
|
||||
private static int speed = Expo.random(10, 40);
|
||||
public static boolean collision = false;
|
||||
private static int x = Expo.random(100, 400); // Where NPC starts on road
|
||||
private static int y = -15; // Default starting position for NPC. Negative because NPC is draw from bottom left to top right.
|
||||
private static int speed = Expo.random(10, 40); // Value to move NPC down
|
||||
|
||||
public NPC5(Graphics g, int Px) {
|
||||
make(g, Px);
|
||||
}
|
||||
|
||||
public static void make(Graphics g, int Px) {
|
||||
if (!(y >= 250 && y <= 350 && x >= Px - 40 && x <= Px + 43) && !ended) {
|
||||
y += speed;
|
||||
if (!(y >= 240 && y <= 350 && x >= Px - 40 && x <= Px + 43)) { // Collision detection
|
||||
y += speed; // Moves NPC down according to its speed
|
||||
Expo.setColor(g, SpriteColors.NPC1Body);
|
||||
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
|
||||
Expo.setColor(g, SpriteColors.Tires);
|
||||
@ -27,10 +27,10 @@ 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);
|
||||
ended = true;
|
||||
Draw.end(g); // Draws end screen
|
||||
collision = true; // Used by Main.java to detect if game is collision
|
||||
}
|
||||
if (y > 350) {
|
||||
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||
x = Expo.random(100, 400);
|
||||
y = 25;
|
||||
speed = Expo.random(10, 40);
|
||||
|
@ -7,18 +7,18 @@ import java.applet.Applet;
|
||||
import java.awt.*;
|
||||
|
||||
public class NPC6 extends Applet {
|
||||
public static boolean ended = false;
|
||||
private static int x = Expo.random(100, 400);
|
||||
private static int y = -15;
|
||||
private static int speed = Expo.random(10, 40);
|
||||
public static boolean collision = false;
|
||||
private static int x = Expo.random(100, 400); // Where NPC starts on road
|
||||
private static int y = -15; // Default starting position for NPC. Negative because NPC is draw from bottom left to top right.
|
||||
private static int speed = Expo.random(10, 40); // Value to move NPC down
|
||||
|
||||
public NPC6(Graphics g, int Px) {
|
||||
make(g, Px);
|
||||
}
|
||||
|
||||
public static void make(Graphics g, int Px) {
|
||||
if (!(y >= 250 && y <= 350 && x >= Px - 40 && x <= Px + 43) && !ended) {
|
||||
y += speed;
|
||||
if (!(y >= 240 && y <= 350 && x >= Px - 40 && x <= Px + 43)) { // Collision detection
|
||||
y += speed; // Moves NPC down according to its speed
|
||||
Expo.setColor(g, SpriteColors.NPC1Body);
|
||||
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
|
||||
Expo.setColor(g, SpriteColors.Tires);
|
||||
@ -27,10 +27,10 @@ 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);
|
||||
ended = true;
|
||||
Draw.end(g); // Draws end screen
|
||||
collision = true; // Used by Main.java to detect if game is collision
|
||||
}
|
||||
if (y > 350) {
|
||||
if (y > 350) { // Used to "respawn" NPC once its y reaches a certain point. Does this by resetting all variables.
|
||||
x = Expo.random(100, 400);
|
||||
y = 25;
|
||||
speed = Expo.random(10, 40);
|
||||
|
@ -5,8 +5,8 @@ import project.Expo;
|
||||
import java.applet.Applet;
|
||||
import java.awt.*;
|
||||
|
||||
public class player extends Applet {
|
||||
public static void make(Graphics g, int x, int y) {
|
||||
public class Player extends Applet {
|
||||
public static void make(Graphics g, int x, int y) { // Draws player at location of passes x and y integers
|
||||
Expo.setColor(g, SpriteColors.playerBody);
|
||||
Expo.fillRectangle(g, x, y, x+35, y+60);
|
||||
Expo.setColor(g, SpriteColors.Tires);
|
||||
@ -15,11 +15,4 @@ public class player extends Applet {
|
||||
Expo.fillRectangle(g, x+30, y+8, x+40, y+28);
|
||||
Expo.fillRectangle(g, x+30, y+35, x+40, y+55);
|
||||
}
|
||||
}
|
||||
// Expo.setColor(g,SpriteColors.playerBody);
|
||||
// Expo.fillRectangle(g, 100, 100, 135, 160);
|
||||
// Expo.setColor(g,SpriteColors.Tires);
|
||||
// Expo.fillRectangle(g, 105, 108, 95, 128);
|
||||
// Expo.fillRectangle(g, 105, 135, 95, 155);
|
||||
// Expo.fillRectangle(g, 130, 108, 140, 128);
|
||||
// Expo.fillRectangle(g, 130, 135, 140, 155);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user