officereso 04cccbdef1 Code documentation, cleanup, and optimisation
Signed-off-by: officereso <qrs01@snowtx.com>
2019-05-25 15:33:05 -05:00

39 lines
1.6 KiB
Java

package project.Sprites;
import project.Draw;
import project.Expo;
import java.applet.Applet;
import java.awt.*;
public class NPC3 extends Applet {
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 >= 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);
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); // Draws end screen
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.
x = Expo.random(100, 400);
y = 25;
speed = Expo.random(10, 40);
}
}
}