Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package RedHazard;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.util.Random;
- public class Goal
- {
- public int x, y, width = 25, height = 25;
- public int yspeed;
- public Random random;
- private Redhazard rh;
- public Goal(Redhazard rh)
- {
- this.rh = rh;
- this.random = new Random();
- spawn();
- }
- public void update(Ship ship)
- {
- y += yspeed;
- if(CheckCollision(ship) > 0)
- {
- if(CheckCollision(ship) == 1)
- {
- ship.score += 1;
- }
- spawn();
- }
- }
- public void spawn()
- {
- this.x = random.nextInt(Redhazard.rh.width-50);
- this.y = 0;
- yspeed = random.nextInt(2) + 2;
- }
- public int CheckCollision(Ship ship)
- {
- if(this.x + width > ship.x && this.x < ship.x + ship.width && this.y + height > ship.y && this.y < ship.y + ship.height)
- {
- return 1;
- }
- if(this.y > Redhazard.rh.height)
- {
- return 2;
- }
- return 0;
- }
- public void render(Graphics g)
- {
- g.setColor(Color.GREEN);
- g.fillRect(x, y, width, height);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement