2019-05-18 19:35:36 -05:00
package project ;
2019-05-24 21:15:11 -05:00
import project.Sprites.* ;
2019-05-24 10:59:39 -05:00
2019-05-17 15:08:45 -05:00
import java.applet.Applet ;
import java.awt.* ;
2019-05-18 22:11:42 -05:00
2019-05-19 17:07:54 -05:00
public class Main extends Applet {
2019-05-25 15:33:05 -05:00
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
2019-05-26 17:05:27 -05:00
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
2019-05-24 21:15:11 -05:00
2019-05-25 15:33:05 -05:00
private static void npcLocomotion ( Graphics g ) { // Logic for spawning NPC objects
2019-05-24 21:15:11 -05:00
if ( score > 3 ) {
2019-05-25 15:33:05 -05:00
new NPC1 ( g , Px ) ; // Px is passed to NPCs for collision detection purposes
2019-05-24 21:15:11 -05:00
}
if ( score > 30 ) {
new NPC2 ( g , Px ) ;
}
if ( score > 35 ) {
new NPC3 ( g , Px ) ;
}
if ( score > 50 ) {
new NPC4 ( g , Px ) ;
}
if ( score > 70 ) {
new NPC5 ( g , Px ) ;
}
if ( score > 80 ) {
new NPC6 ( g , Px ) ;
}
2019-05-25 15:56:13 -05:00
if ( score > 140 ) {
new NPC7 ( g , Px ) ; // The "grandma NPC", very "slow", good luck
}
2019-05-24 21:15:11 -05:00
}
2019-05-24 18:52:25 -05:00
2019-05-24 21:30:20 -05:00
private static void playerLocomotion ( Graphics g ) {
2019-05-25 15:33:05 -05:00
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 ;
2019-05-24 21:15:11 -05:00
}
}
2019-05-25 15:33:05 -05:00
public void paint ( Graphics g ) {
Expo . drawHeading ( g , " Quentin Snow and Alekkai " , " Final Project " ) ;
2019-05-26 17:05:27 -05:00
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 ) ;
2019-05-25 15:33:05 -05:00
playerLocomotion ( g ) ;
npcLocomotion ( g ) ;
}
if ( ! start ) {
Draw . startScreen ( g ) ; // Draw the start screen if the game has not started
}
2019-05-26 17:05:27 -05:00
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 ;
2019-05-25 15:33:05 -05:00
}
}
2019-05-21 15:19:55 -05:00
2019-05-20 15:25:25 -05:00
public boolean mouseDown ( Event e , int x , int y ) {
if ( startBtn . inside ( x , y ) ) {
2019-05-25 15:33:05 -05:00
start = true ; // Set start to true if user has clicked startBtn
2019-05-20 15:25:25 -05:00
}
2019-05-21 20:26:01 -05:00
if ( lBtn . inside ( x , y ) ) {
2019-05-26 17:05:27 -05:00
Px - = 8 ; // Move player 8 pixels to left when lBtn is pressed
2019-05-21 20:26:01 -05:00
}
if ( rBtn . inside ( x , y ) ) {
2019-05-26 17:05:27 -05:00
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
2019-05-21 15:25:21 -05:00
}
2019-05-25 15:33:05 -05:00
repaint ( ) ; // Redraw everything
2019-05-26 17:05:27 -05:00
System . out . println ( x ) ;
2019-05-20 15:25:25 -05:00
return true ;
2019-05-17 15:08:45 -05:00
}
2019-05-24 21:23:35 -05:00
}