Advertisement
fewfw

Untitled

May 31st, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package gameobject;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Rectangle;
  6. import java.awt.image.BufferedImage;
  7.  
  8. public class Cactus extends Enemy {
  9.  
  10.     public static final int Y_LAND = 125;
  11.  
  12.     private int posX;
  13.     private int width;
  14.     private int height;
  15.  
  16.     private BufferedImage image;
  17.     private MainCharacter mainCharacter;
  18.  
  19.     private Rectangle rectBound;
  20.  
  21.     public Cactus(MainCharacter mainCharacter, int posX, int width, int height, BufferedImage image) {
  22.         this.posX = posX;
  23.         this.width = width;
  24.         this.height = height;
  25.         this.image = image;
  26.         this.mainCharacter = mainCharacter;
  27.         rectBound = new Rectangle();
  28.     }
  29.  
  30.     public void update() {
  31.         posX -= mainCharacter.getSpeedX();
  32.     }
  33.  
  34.     public void draw(Graphics g) {
  35.         g.drawImage(image, posX, Y_LAND - image.getHeight(), null);
  36.         g.setColor(Color.red);
  37. //      Rectangle bound = getBound();
  38. //      g.drawRect(bound.x, bound.y, bound.width, bound.height);
  39.     }
  40.  
  41.     public Rectangle getBound() {
  42.         rectBound = new Rectangle();
  43.         rectBound.x = (int) posX + (image.getWidth() - width)/2;
  44.         rectBound.y = Y_LAND - image.getHeight() + (image.getHeight() - height)/2;
  45.         rectBound.width = width;
  46.         rectBound.height = height;
  47.         return rectBound;
  48.     }
  49.  
  50.     @Override
  51.     public boolean isOutOfScreen() {
  52.         if(posX < -image.getWidth()) {
  53.             return true;
  54.         }
  55.         return false;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement