From be3b16cd7b3884fbb402ec41ed218dd55a493000 Mon Sep 17 00:00:00 2001 From: officereso Date: Fri, 24 May 2019 10:59:39 -0500 Subject: [PATCH] NPC spawning started Signed-off-by: officereso --- src/project/Draw.java | 2 +- src/project/Main.java | 26 +++++++++++++-------- src/project/Sprites/{NPC1.java => NPC.java} | 20 +++++++++++----- 3 files changed, 31 insertions(+), 17 deletions(-) rename src/project/Sprites/{NPC1.java => NPC.java} (61%) diff --git a/src/project/Draw.java b/src/project/Draw.java index 3da9b06..7ca06d0 100644 --- a/src/project/Draw.java +++ b/src/project/Draw.java @@ -18,7 +18,7 @@ public class Draw extends Applet { public static void begin(Graphics g){ road(g); LRbtn(g); - //project.Sprites.NPC1.NPC1(g,Expo.random(110,390)); + //project.Sprites.NPC.NPC(g,Expo.random(110,390)); } public static void end(Graphics g){ diff --git a/src/project/Main.java b/src/project/Main.java index 94a2d9c..120c40b 100644 --- a/src/project/Main.java +++ b/src/project/Main.java @@ -1,5 +1,7 @@ package project; +import project.Sprites.NPC; + import java.applet.Applet; import java.awt.*; @@ -10,6 +12,8 @@ public class Main extends Applet { private Rectangle lBtn = new Rectangle(480,220,120,80); private Rectangle rBtn = new Rectangle(630,220,120,80); private static int Px = 150; + private static boolean btnException = true; + private static boolean spwNpc1, spwNpc2 = true; public void paint(Graphics g){ Expo.drawHeading(g, "Quentin Snow and Alekkai", "Final Project"); @@ -17,6 +21,7 @@ public class Main extends Applet { Draw.begin(g); playerLocomotion(g); npcLocomotion(g); + } else{ Draw.startScreen(g); @@ -33,30 +38,31 @@ public class Main extends Applet { } public static void npcLocomotion(Graphics g){ - project.Sprites.NPC1 npc1 = new project.Sprites.NPC1(g); - int v = 70; - int y = 100; - v++; - npc1.make(g,v,y); - - System.out.println(v); + if (spwNpc1){ + NPC npc1 = new NPC(g); + spwNpc1 = false; + } + if (spwNpc2){ + NPC npc2 = new NPC(g); + spwNpc2 = false; + } } public boolean mouseDown(Event e, int x, int y){ + btnException = true; if (startBtn.inside(x,y)){ start = true; - repaint(); } if (lBtn.inside(x,y)){ Px-=10; - repaint(); } if (rBtn.inside(x,y)){ Px+=10; - repaint(); } + btnException = false; + repaint(); System.out.println(x+" "+y); return true; } diff --git a/src/project/Sprites/NPC1.java b/src/project/Sprites/NPC.java similarity index 61% rename from src/project/Sprites/NPC1.java rename to src/project/Sprites/NPC.java index 0d43c62..4e3ba89 100644 --- a/src/project/Sprites/NPC1.java +++ b/src/project/Sprites/NPC.java @@ -5,12 +5,9 @@ import project.Expo; import java.applet.Applet; import java.awt.*; -public class NPC1 extends Applet { - public NPC1(Graphics g) { - - } - public static void make(Graphics g, int x, int y){ - // int x = Expo.random(100,400); +public class NPC extends Thread { + public NPC(Graphics g) { + int x = Expo.random(100,400); Expo.setColor(g,colorsTemp.NPC1Body); Expo.fillRectangle(g, x, 110, x+35, 170); Expo.setColor(g,colorsTemp.Tires); @@ -19,6 +16,17 @@ public class NPC1 extends Applet { Expo.fillRectangle(g, x+30, 118, x+40, 138); Expo.fillRectangle(g, x+30, 145, x+40, 165); } + public static void make(Graphics g){ + int x = Expo.random(100,400); + Expo.setColor(g,colorsTemp.NPC1Body); + Expo.fillRectangle(g, x, 110, x+35, 170); + Expo.setColor(g,colorsTemp.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); + + } } // Expo.setColor(g,colorsTemp.NPC1Body); // Expo.fillRectangle(g, 100, 100, 135, 160);