📄 fairy.java
字号:
package org.wuhua.game.model;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import org.wuhua.game.util.Log;
/**
* <b>类名:Sprite.java</b> </br>
* 编写日期: 2006-11-29 <br/>
* 程序功能描述:建立精灵物体模型 <br/>
* Demo: <br/>
* Bug: <br/>
*
* 程序变更日期 :<br/>
* 变更作者 :<br/>
* 变更说明 :<br/>
*
* @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
*/
public class Fairy {
static Log log = Log.getLog("Fairy");
/**
* position of Fairy in x offset
*/
int x; // = 0;
/**
* position of Fairy in y offset
*/
int y; // = 0;
/**
* width of layer
*/
int width; // = 0;
/**
* height of layer
*/
int height; // = 0;
/**
* If the Layer is visible it will be drawn when <code>paint</code>
* is called.
*/
boolean visible = true;
/**
* 图片资源
*
*/
Image fairy;
public Fairy(Image fairy,int x, int y){
this.fairy = fairy;
this.x = x;
this.y = y;
}
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
}
public void move(int dx, int dy) {
x += dx;
y += dy;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public final boolean isVisible() {
return visible;
}
public final int getHeight() {
return height;
}
public final int getWidth() {
return width;
}
public final int getX() {
return x;
}
public final int getY() {
return y;
}
public void paint(Graphics g){
if (g == null) {
throw new NullPointerException("Graphics 不存在");
}
if(this.visible){
//log.debug("x=" + x + " y=" + y);
g.drawImage(fairy, x, y, Graphics.TOP | Graphics.HCENTER);
}
}
/**
* 进行简单的碰撞算法, 希望高手可以给个建议。
* @param f
* @return
*/
public final boolean collidesWith(Fairy f){
if((f.getX() >= this.getX() - 20 && f.getX() <= this.getX() + 20)
&& (f.getY() >= this.getY() - 10 && f.getY() <= this.getY()+10 )){
//log.debug("this.getY=" + this.getY());
//log.debug("f.getY=" + f.getY());
return true;
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -