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

📄 baserole.java

📁 简单的用Java做的小游戏主要是用了自己的框架来
💻 JAVA
字号:
package role;

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

import javax.swing.JFrame;

import frame.GameStartFrame;

import assistant.PublicVar;


/**
 * <p>
 * Copyright (C),2008,3,10 
 * 此类为所有角色基类
 * @author : lovo
 * 
 * @version 1.00 2008/3/10
 * 
 */
public class BaseRole {
	/**角色左上角X座标*/
	protected int x;
	
	/**角色左上角Y座标*/
	protected int y;
	
	/**角色图片宽度*/
	protected int width;
	
	/**角色图片高度*/
	protected int height;
	
	/**角色当前图片*/
	protected Image img;
	
	/**角色当前区域*/
	protected Rectangle rect;
	
	/**定义角色状态(决定角色方向)*/
	protected int state;
	
	/**
	 * 构造方法
	 * @param x       角色左上角X座标
	 * @param y       角色左上角Y座标
	 * @param width   角色图片宽度
	 * @param height  角色图片高度
	 * @param img     角色当前图片
	 * @param state   角色状态
	 */
	protected BaseRole(int x,int y,
			int width,int height,int state){
		this.x = x;
		this.y = y;
		this.height = height;
		this.width = width;
		this.state = state;
		rect = new Rectangle(x,y,width,height);
	}
	
	/**
	 * Method:       drawMyself
	 * Desctiptoin:  绘制自身图形
	 * @param g  :   画笔
	 * @param jf :   窗体画布
	 */
	public void drawMyself(Graphics g,JFrame jf){
		this.setDraw(g, jf);
	}
	
	/**
	 * 设置绘制方法
	 * @param g  画笔
	 * @param jf 窗体画布
	 */
	protected void setDraw(Graphics g,JFrame jf){
		this.setRect();//设置角色区域
		g.drawImage(img, x, y, width, height, jf);
		
		/*角色超出屏幕自动移除*/
		if((GameStartFrame.isRightScroll && x<this.width*-1) ||
				(GameStartFrame.isRightScroll == false && x>650) || 
				(this.y>570)){
			PublicVar.roleList.remove(this);
		}
	}
	
	/**
	 * 角色随地图移动
	 * @param state 地图滚动的方向
	 * @param speed 滚动的速度
	 */
	public void moveByMap(int state,int speed){
		if(state ==  PublicVar.RIGHT){
			this.x+=speed;
		}
		else if(state ==  PublicVar.UP){
			this.y+=speed;
		}
	}
	
	/**
	 * 设置当前区域
	 *
	 */
	protected void setRect(){
			this.rect.x = x;
			this.rect.y = y;
	}
	
	/**
	 * 获得当前区域
	 * @return Rectangle矩形区域
	 */
	public Rectangle getRect(){
		return this.rect;
	}
}

⌨️ 快捷键说明

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