2D游戏中各对象的父类

 

package cn.littlepage.game;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

public class GameObject {
/*
 * 任何一个2D游戏都必须要有图片,坐标,速度,大小,矩形(碰撞检测)
 * 所以,这个可以做成一个2D游戏的父类
 */
    public Image img;
    public int x,y;
    public int speed;
    public int width,height;
    
    public void drawSelf(Graphics g) {
        g.drawImage(img, x, y, null);
        
    }
    

    public GameObject() {
        super();
        // TODO Auto-generated constructor stub
    }

    public GameObject(Image img, int x, int y, int speed, int width, int height) {
        super();
        this.img = img;
        this.x = x;
        this.y = y;
        this.speed = speed;
        this.width = width;
        this.height = height;
    }
    

    public Rectangle getRect() {
        return new Rectangle(x, y, width, height);
    }
    
    
    
}

 

相关文章:

  • 2021-10-14
  • 2022-12-23
  • 2021-06-06
  • 2021-12-23
  • 2021-04-08
  • 2022-12-23
  • 2021-07-27
  • 2022-01-07
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2021-12-12
  • 2021-06-14
  • 2021-07-18
相关资源
相似解决方案