Multiple NPC & collision.

Signed-off-by: officereso <qrs01@snowtx.com>
This commit is contained in:
officereso 2019-05-24 21:15:11 -05:00
parent bcbd0c6ba9
commit a7469c079c
10 changed files with 370 additions and 73 deletions

View File

@ -10,4 +10,7 @@ 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);
}

View File

@ -13,24 +13,27 @@ public class Draw extends Applet {
}
}
public static void begin(Graphics g){
public static void begin(Graphics g, int score) {
road(g);
LRbtn(g);
//project.Sprites.NPC.NPC(g,Expo.random(110,390));
btns(g);
Expo.setFont(g, "Default", 1, 15);
Expo.drawString(g, "Your score is " + score, 600, 100);
}
public static void end(Graphics g){
Expo.setBackground(g,Colors.red);
Expo.setColor(g,Colors.endGreen);
Expo.setFont(g, "Default", 1, 100);
Expo.drawString(g,"YOU DIED",100,100);
}
public static void LRbtn(Graphics g){
public static void btns(Graphics g) {
Expo.setFont(g,"Default",1,100);
Expo.setColor(g,Colors.startBlue);
Expo.drawString(g,"<=",480,300);
Expo.drawString(g,"=>",620,300);
Expo.fillCircle(g, 650, 271, 20);
Expo.drawString(g, "=>", 660, 300);
}

View File

@ -1,6 +1,6 @@
package project;
import project.Sprites.NPC;
import project.Sprites.*;
import java.applet.Applet;
import java.awt.*;
@ -9,38 +9,57 @@ import java.awt.*;
public class Main extends Applet {
private static boolean start = false;
private Rectangle startBtn = new Rectangle(100,100,340,600);
private Rectangle lBtn = new Rectangle(480,220,120,80);
private Rectangle rBtn = new Rectangle(630,220,120,80);
public static int score = 0;
private Rectangle lBtn = new Rectangle(480, 240, 150, 80);
private static int Px = 150;
private static NPC npc1 = new NPC();
public void paint(Graphics g){
Expo.drawHeading(g, "Quentin Snow and Alekkai", "Final Project");
if (start){
Draw.begin(g);
playerLocomotion(g);
npcLocomotion(g);
private Rectangle rBtn = new Rectangle(660, 240, 150, 80);
public static void npcLocomotion(Graphics g) {
if (score > 3) {
new NPC1(g, Px);
}
else{
Draw.startScreen(g);
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);
}
}
public static void playerLocomotion(Graphics g){
project.Sprites.player.make(g,Px,427);
if (Px <= 107|| Px >= 375){
public static void playerLocomotion(Graphics g) {
project.Sprites.player.make(g, Px, 427);
if (Px <= 107 || Px >= 375) {
Draw.end(g);
Px = 10000;
}
}
public static void npcLocomotion(Graphics g) {
NPC.make(g);
}
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);
}
}
public boolean mouseDown(Event e, int x, int y){
if (startBtn.inside(x,y)){
@ -52,8 +71,9 @@ public class Main extends Applet {
if (rBtn.inside(x,y)){
Px+=10;
}
score++;
System.out.println(score);
repaint();
System.out.println(x+" "+y);
return true;
}
}

View File

@ -1,47 +0,0 @@
package project.Sprites;
import project.Expo;
import java.applet.Applet;
import java.awt.*;
public class NPC extends Applet {
private static int x = Expo.random(100, 400);
private static int y = 100;
private static int speed = Expo.random(10, 20);
public NPC(/*Graphics g, int x, int y*/) {
// Expo.setColor(g, SpriteColors.NPC1Body);
// Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
// Expo.setColor(g, SpriteColors.Tires);
// Expo.fillRectangle(g, x + 5, y + 118, x - 5, y + 138);
// Expo.fillRectangle(g, x + 5, y + 145, x - 5, y + 165);
// Expo.fillRectangle(g, x + 30, y + 118, x + 40, y + 138);
// Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
}
public static void make(Graphics g/*, int x, int y*/) {
y += speed;
Expo.setColor(g, SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
Expo.setColor(g, SpriteColors.Tires);
Expo.fillRectangle(g, x + 5, y + 118, x - 5, y + 138);
Expo.fillRectangle(g, x + 5, y + 145, x - 5, y + 165);
Expo.fillRectangle(g, x + 30, y + 118, x + 40, y + 138);
Expo.fillRectangle(g, x + 30, y + 145, x + 40, y + 165);
}
}
/*
public static void make(Graphics g){
int x = Expo.random(100,400);
Expo.setColor(g,SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, 110, x+35, 170);
Expo.setColor(g,SpriteColors.Tires);
Expo.fillRectangle(g, x+5, 118, x-5, 138);
Expo.fillRectangle(g, x+5, 145, x-5, 165);
Expo.fillRectangle(g, x+30, 118, x+40, 138);
Expo.fillRectangle(g, x+30, 145, x+40, 165);
}
}*/

View File

@ -0,0 +1,53 @@
package project.Sprites;
import project.Draw;
import project.Expo;
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 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;
Expo.setColor(g, SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
Expo.setColor(g, SpriteColors.Tires);
Expo.fillRectangle(g, x + 5, y + 118, x - 5, y + 138);
Expo.fillRectangle(g, x + 5, y + 145, x - 5, y + 165);
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;
}
if (y > 350) {
x = Expo.random(100, 400);
y = 25;
speed = Expo.random(10, 40);
}
}
}
/*
public static void make(Graphics g){
int x = Expo.random(100,400);
Expo.setColor(g,SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, 110, x+35, 170);
Expo.setColor(g,SpriteColors.Tires);
Expo.fillRectangle(g, x+5, 118, x-5, 138);
Expo.fillRectangle(g, x+5, 145, x-5, 165);
Expo.fillRectangle(g, x+30, 118, x+40, 138);
Expo.fillRectangle(g, x+30, 145, x+40, 165);
}
}*/

View File

@ -0,0 +1,53 @@
package project.Sprites;
import project.Draw;
import project.Expo;
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 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;
Expo.setColor(g, SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
Expo.setColor(g, SpriteColors.Tires);
Expo.fillRectangle(g, x + 5, y + 118, x - 5, y + 138);
Expo.fillRectangle(g, x + 5, y + 145, x - 5, y + 165);
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;
}
if (y > 350) {
x = Expo.random(100, 400);
y = 25;
speed = Expo.random(10, 40);
}
}
}
/*
public static void make(Graphics g){
int x = Expo.random(100,400);
Expo.setColor(g,SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, 110, x+35, 170);
Expo.setColor(g,SpriteColors.Tires);
Expo.fillRectangle(g, x+5, 118, x-5, 138);
Expo.fillRectangle(g, x+5, 145, x-5, 165);
Expo.fillRectangle(g, x+30, 118, x+40, 138);
Expo.fillRectangle(g, x+30, 145, x+40, 165);
}
}*/

View File

@ -0,0 +1,53 @@
package project.Sprites;
import project.Draw;
import project.Expo;
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 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;
Expo.setColor(g, SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
Expo.setColor(g, SpriteColors.Tires);
Expo.fillRectangle(g, x + 5, y + 118, x - 5, y + 138);
Expo.fillRectangle(g, x + 5, y + 145, x - 5, y + 165);
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;
}
if (y > 350) {
x = Expo.random(100, 400);
y = 25;
speed = Expo.random(10, 40);
}
}
}
/*
public static void make(Graphics g){
int x = Expo.random(100,400);
Expo.setColor(g,SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, 110, x+35, 170);
Expo.setColor(g,SpriteColors.Tires);
Expo.fillRectangle(g, x+5, 118, x-5, 138);
Expo.fillRectangle(g, x+5, 145, x-5, 165);
Expo.fillRectangle(g, x+30, 118, x+40, 138);
Expo.fillRectangle(g, x+30, 145, x+40, 165);
}
}*/

View File

@ -0,0 +1,53 @@
package project.Sprites;
import project.Draw;
import project.Expo;
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 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;
Expo.setColor(g, SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
Expo.setColor(g, SpriteColors.Tires);
Expo.fillRectangle(g, x + 5, y + 118, x - 5, y + 138);
Expo.fillRectangle(g, x + 5, y + 145, x - 5, y + 165);
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;
}
if (y > 350) {
x = Expo.random(100, 400);
y = 25;
speed = Expo.random(10, 40);
}
}
}
/*
public static void make(Graphics g){
int x = Expo.random(100,400);
Expo.setColor(g,SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, 110, x+35, 170);
Expo.setColor(g,SpriteColors.Tires);
Expo.fillRectangle(g, x+5, 118, x-5, 138);
Expo.fillRectangle(g, x+5, 145, x-5, 165);
Expo.fillRectangle(g, x+30, 118, x+40, 138);
Expo.fillRectangle(g, x+30, 145, x+40, 165);
}
}*/

View File

@ -0,0 +1,53 @@
package project.Sprites;
import project.Draw;
import project.Expo;
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 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;
Expo.setColor(g, SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
Expo.setColor(g, SpriteColors.Tires);
Expo.fillRectangle(g, x + 5, y + 118, x - 5, y + 138);
Expo.fillRectangle(g, x + 5, y + 145, x - 5, y + 165);
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;
}
if (y > 350) {
x = Expo.random(100, 400);
y = 25;
speed = Expo.random(10, 40);
}
}
}
/*
public static void make(Graphics g){
int x = Expo.random(100,400);
Expo.setColor(g,SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, 110, x+35, 170);
Expo.setColor(g,SpriteColors.Tires);
Expo.fillRectangle(g, x+5, 118, x-5, 138);
Expo.fillRectangle(g, x+5, 145, x-5, 165);
Expo.fillRectangle(g, x+30, 118, x+40, 138);
Expo.fillRectangle(g, x+30, 145, x+40, 165);
}
}*/

View File

@ -0,0 +1,53 @@
package project.Sprites;
import project.Draw;
import project.Expo;
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 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;
Expo.setColor(g, SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, y + 110, x + 35, y + 170);
Expo.setColor(g, SpriteColors.Tires);
Expo.fillRectangle(g, x + 5, y + 118, x - 5, y + 138);
Expo.fillRectangle(g, x + 5, y + 145, x - 5, y + 165);
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;
}
if (y > 350) {
x = Expo.random(100, 400);
y = 25;
speed = Expo.random(10, 40);
}
}
}
/*
public static void make(Graphics g){
int x = Expo.random(100,400);
Expo.setColor(g,SpriteColors.NPC1Body);
Expo.fillRectangle(g, x, 110, x+35, 170);
Expo.setColor(g,SpriteColors.Tires);
Expo.fillRectangle(g, x+5, 118, x-5, 138);
Expo.fillRectangle(g, x+5, 145, x-5, 165);
Expo.fillRectangle(g, x+30, 118, x+40, 138);
Expo.fillRectangle(g, x+30, 145, x+40, 165);
}
}*/