java 之2D過氣遊戲類的寫法
阿新 • • 發佈:2018-08-16
speed graphic 坐標 對象 做成 ted ack todo img
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);
}
}
java 之2D過氣遊戲類的寫法