⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sprite.java

📁 Java吃豆子游戏
💻 JAVA
字号:
package org.loon.test;

import java.awt.Graphics;
import java.awt.image.ImageObserver;
/**
 * 
 * <p>Title: LoonFramework</p>
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) 2008</p>
 * <p>Company: LoonFramework</p>
 * <p>License: http://www.apache.org/licenses/LICENSE-2.0</p>
 * @author chenpeng  
 * @email:ceponline@yahoo.com.cn 
 * @version 0.1
 */
public class Sprite {
  int x,y,w,h;
  int d=0; //移动方向 0:无 1:右 2:下 4:左 8:上
  int sx,sy,sw,sh; //相对坐标
  CGloader loader;
  Sprite target; //追踪对象
  boolean show = true; //是否绘制

  public Sprite(int x, int y, int w, int h) {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    sx = 0; sy = 0; sw = w; sh = h;
  }
  public Sprite(int x, int y) {
    this(x,y,16,16);
  }

  public void init() {}

  public void setXY(int x, int y) {
  	this.x = x;
  	this.y = y;
  }
  public void setTarget(Sprite target) {
  	this.target = target;
  }
  public void setCGloader(CGloader loader) {
  	this.loader = loader;
  }

  public int getX() {
    return x;
  }
  public int getY() {
    return y;
  }
  public int getW() {
    return w;
  }
  public int getH() {
    return h;
  }
  public int getD() {
  	return d;
  }

  public int[] getOrientation() {
  	int[] atari = {x+sx,y+sy,sw,sh};
  	return atari;
  }
  public void setOrientation(int sx, int sy, int sw, int sh) {
    this.sx = sx; 
    this.sy = sy; 
    this.sw = sw; 
    this.sh = sh; 
  }
  public boolean isHit(int x0, int y0, int w0, int h0) {
  	int x = this.x + sx;
  	int y = this.y + sy;
  	int w = this.sw;
  	int h = this.sh;
	return (x0 <= (x+w-1)) && (y0 <= (y+h-1)) && ((x0+w0-1) >= x) && ((y0+h0-1) >= y);
  }
  public boolean isHit(Sprite enemy) {
  	int[] atari = enemy.getOrientation();
  	return isHit(atari[0],atari[1],atari[2],atari[3]);
  }

  public void run() {}

  public boolean isShow() {
  	return show;
  }
  public void setShow(boolean show) {
  	this.show = show;
  }
  public void draw (Graphics g, ImageObserver observer) {
  	if(show) paint(g,observer);
  }
  public void paint(Graphics g, ImageObserver observer) {}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -