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

📄 player.java

📁 一个不错的动作类游戏
💻 JAVA
字号:
import javax.microedition.lcdui.*;

public class Player
{ 
	Image[] imageFrames;
	Image image;
	int imageWidth;	
	int imageHeight;
	int canvasWidth;	
	int canvasHeight;
	protected static final String IMAGE_NAME="player";
	
	protected static final int RAW_FRAMES=1;
	protected int xPos;
	protected int yPos;  
	protected static VaderCanvas gameCanvas;
	protected static VaderManager layerManager;
	
	public Player(int canvasWidth, int canvasHeight)
	{
		imageFrames=VaderManager.getFrames(IMAGE_NAME, RAW_FRAMES);
		this.canvasHeight=canvasHeight;
		this.canvasWidth=canvasWidth;		
		imageWidth=imageFrames[0].getWidth();
		imageHeight=imageFrames[0].getHeight();	
		xPos=(int)canvasWidth/2;
		yPos=(int)canvasHeight-getHeight();
		setPosition(xPos, yPos);
		gameCanvas=layerManager.getGameCanvas();
		createImage();
		setSpriteImage();
	}
  
  	public int getHeight()				{return imageHeight;}
	public int getWidth()				{return imageWidth;}
	public int getCanvasHeight()		{return canvasHeight;}
	public int getCanvasWidth()			{return canvasWidth;}
	public Image getImage()				{return image;}
	private void setX(int x)			{xPos=x;}	
	private void setY(int y)			{yPos=y;}
	public int getX()					{return xPos;}	
	public int getY()					{return yPos;}
  
    public static void setLayerManager(VaderManager manager)		{layerManager=manager;}

  //public void setY(int y)				{setPosition(this.getX(),this.getY()+y);}
  
	private void setPosition(int x, int y)
	{
		setX(x);
		setY(y);
	}
	private void move(int x, int y)
	{
		setX(getX()+x);
		setY(getY()+y);  	
	}
	
	public void left()
	{
		if(this.getX()>0)
		{
			move(-3,0);
		}
	}
	
	public void right()
	{
		if((this.getX()+getWidth())<=getCanvasWidth())
		{
			move(3,0);
		}
	
		// TO DO create a sense of momentum for the UIQ jog dial input method.
	}	
	public void fire()
	{
		layerManager.initBullets();  	
	}
  	private void createImage()
	{
		// allocate memory to store the onscreen background image.
		// assuming all tiles are the same size, make the buffer
		// the screen size plus one row and column.	
		image=Image.createImage(getWidth(), getHeight());
	}
	private void setSpriteImage()
	{
		Graphics g = image.getGraphics();
		g.drawImage(imageFrames[0],0,0,g.LEFT | g.TOP);		
	}
	public void draw()
	{
		Graphics g=layerManager.getGraphics();
		if(imageFrames[0]!=null)
		{
			g.setClip(xPos,yPos,imageWidth,imageHeight);
			g.drawImage(imageFrames[0],xPos,yPos,g.LEFT | g.TOP);
			g.setClip(0,0,getCanvasWidth(),getCanvasHeight());
		}
	}
}

⌨️ 快捷键说明

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