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

📄 background.java

📁 一个不错的动作类游戏
💻 JAVA
字号:

/**
 * <p>Title: DemoVader</p>
 * <p>Description: .</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: Symbian Ltd</p>
 * @author Alan Newman - alan@sensibledevelopment.net
 * @version 1.0
 */

import javax.microedition.lcdui.*;

public class BackGround{
	
	int[][] imageMap;
	Image[] imageFrames;
	Image image;
	int imageWidth;	
	int imageHeight;
	int tileWidth;
	int tileHeight;
	protected static final int RAW_FRAMES=1;
	protected static final String IMAGE_NAME="background";

	public BackGround(int canvasWidth, int canvasHeight)
	{	
		imageFrames=VaderManager.getFrames(IMAGE_NAME, RAW_FRAMES);
		
		// make assumption that all frames dimensions are equal.
		this.tileWidth=imageFrames[0].getWidth();
		this.tileHeight=imageFrames[0].getHeight();	
		
		int columns=(int)(canvasWidth/tileWidth)+1;
		int rows=(int)(canvasWidth/tileHeight)+1;	
		
		imageWidth=columns*tileWidth;
		imageHeight=rows*tileHeight;		

		imageMap = new int[columns][rows];
		
		int tiles=columns*rows;
		for (int i = 0; i < tiles; i++)    
		{
		  int c = i % columns;
		  int r = (i - c) / columns;
		  setCell(c, r, 0);
		}
		
		int imageWidth=columns*tileWidth;
		int imageHeight=rows*tileHeight;			

		createImage();		
	
		setTileImages(columns, rows);		
	}
	
	public int getHeight()				{return imageHeight;}
	public int getWidth()				{return imageWidth;}
	public int getTileHeight()			{return tileHeight;}
	public int getTileWidth()			{return tileWidth;}
	public Image getImage()				{return image;}
	
	
	private void setCell(int col, int row, int value)
	{
		imageMap[col][row]=value;
	}
	
	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 setTileImages(int columns, int rows)
	{
		Graphics g = image.getGraphics();
		int tiles=columns*rows;		
	
		for (int i = 0; i < tiles; i++)    
		{
		  int c = i % columns;
		  int r = (i - c) / columns;
		  g.drawImage(imageFrames[imageMap[c][r]],c*getTileHeight(),r*getTileWidth(),g.LEFT | g.TOP);
		}
	}
}

⌨️ 快捷键说明

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