Advertisement
nakrit26

Entity Snake Game

May 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package game;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.Rectangle;
  5.  
  6. public class Entity {
  7.    
  8.     private int x,y,size;
  9.     public Entity(int size)
  10.     {
  11.         this.size = size;
  12.     }
  13.    
  14.     public int getX()
  15.     {
  16.         return x;
  17.     }
  18.    
  19.     public int getY()
  20.     {
  21.         return y;
  22.     }
  23.    
  24.     public void setX(int x)
  25.     {
  26.         this.x = x;
  27.     }
  28.    
  29.     public void setY(int y)
  30.     {
  31.         this.y = y;
  32.     }
  33.    
  34.     public void setPosistion(int x,int y)
  35.     {
  36.         this.x = x;
  37.         this.y = y;
  38.     }
  39.    
  40.     public void move(int directionX, int directionY)
  41.     {
  42.         x += directionX;
  43.         y += directionY;
  44.     }
  45.    
  46.     public Rectangle getBound(){
  47.         return new Rectangle(x,y,size,size);
  48.     }
  49.    
  50.     public boolean isHit(Entity s)
  51.     {
  52.         if(s == this){
  53.             return false;
  54.         }
  55.         return getBound().intersects(s.getBound());
  56.     }
  57.    
  58.     public void render(Graphics g2d)
  59.     {
  60.         g2d.fillRect(x + 1, y + 1, size-2, size-2);
  61.        
  62.     }
  63.    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement