Facebook
From kriss, 7 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 337
  1. package dev.kris.justi.simplegame.ui;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.Rectangle;
  5. import java.awt.event.MouseEvent;
  6.  
  7. public abstract class UIObject {
  8.  
  9.        
  10.         protected float x,y;
  11.         protected int width, height;
  12.         protected Rectangle bounds;
  13.         protected boolean hovering = false;
  14.        
  15.         public UIObject(float x,float y,int width, int height){
  16.                 System.out.println("utworzylem obiekt");
  17.                 this.x=x;
  18.                 this.y=y;
  19.                 this.width=width;
  20.                 this.height=height;
  21.                 bounds = new Rectangle((int)x,(int)y,width,height);
  22.                 }
  23.        
  24.        
  25.         public abstract void tick();
  26.        
  27.         public abstract void render(Graphics g);
  28.        
  29.         public abstract void onClick();
  30.        
  31.         public abstract void renderSetUp(Graphics g);
  32.        
  33.         public abstract void renderGame(Graphics g);
  34.        
  35.         public abstract void renderMulti(Graphics g);
  36.        
  37.         public void onMouseMove(MouseEvent e){
  38.                 if(bounds.contains(e.getX(),e.getY()))
  39.                         hovering= true;
  40.                 else
  41.                         hovering= false;
  42.         }
  43.        
  44.         public void onMouseRelease(MouseEvent e){     // oznacza ze myszka zostala nacisnieta
  45.                
  46.                 if(hovering)
  47.                         onClick();
  48.         }
  49.  
  50.  
  51.         public float getX() {
  52.                 return x;
  53.         }
  54.  
  55.  
  56.         public void setX(float x) {
  57.                 this.x = x;
  58.         }
  59.  
  60.  
  61.         public float getY() {
  62.                 return y;
  63.         }
  64.  
  65.  
  66.         public void setY(float y) {
  67.                 this.y = y;
  68.         }
  69.  
  70.  
  71.         public int getWidth() {
  72.                 return width;
  73.         }
  74.  
  75.  
  76.         public void setWidth(int width) {
  77.                 this.width = width;
  78.         }
  79.  
  80.  
  81.         public int getHeight() {
  82.                 return height;
  83.         }
  84.  
  85.  
  86.         public void setHeight(int height) {
  87.                 this.height = height;
  88.         }
  89.  
  90.  
  91.         public boolean isHovering() {
  92.                 return hovering;
  93.         }
  94.  
  95.  
  96.         public void setHovering(boolean hovering) {
  97.                 this.hovering = hovering;
  98.         }
  99.        
  100. }
  101.