扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:马岩 来源:天极网 2007年11月22日
关键字:
package net.frog_parrot.jump; import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; /** * This class draws the background grass. * * @author Carol Hamer */ public class Grass extends TiledLayer { //--------------------------------------------------------- // Dimension fields // (constant after initialization) /** * The width of the square tiles that make up this layer. */ static final int TILE_WIDTH = 20; /** * This is the order that the frames should be displayed * for the animation. */ static final int[] FRAME_SEQUENCE = { 2, 3, 2, 4 }; /** * This gives the number of squares of grass to put along * the bottom of the screen. */ static int COLUMNS; /** * After how many tiles does the background repeat. */ static final int CYCLE = 5; /** * The fixed Y coordinate of the strip of grass. */ static int TOP_Y; //--------------------------------------------------------- // Instance fields /** * Which tile you are currently on in the frame sequence. */ private int mySequenceIndex = 0; /** * The index to use in the static tiles array to get the * animated tile. */ private int myAnimatedTileIndex; //--------------------------------------------------------- // Gets / sets /** * Takes the width of the screen and sets my columns * to the correct corresponding number. */ static int setColumns(int screenWidth) { COLUMNS = ((screenWidth / 20) + 1)*3; return(COLUMNS); } //--------------------------------------------------------- // Initialization /** * Constructor initializes the image and animation. */ public Grass() throws Exception { super(setColumns(JumpCanvas.DISP_WIDTH), 1, Image.createImage("/images/grass.png"), TILE_WIDTH, TILE_WIDTH); TOP_Y = JumpManager.DISP_HEIGHT - TILE_WIDTH; setPosition(0, TOP_Y); myAnimatedTileIndex = createAnimatedTile(2); for(int i = 0; i < COLUMNS; i++) { if((i % CYCLE == 0) || (i % CYCLE == 2)) { setCell(i, 0, myAnimatedTileIndex); } else { setCell(i, 0, 1); } } } //--------------------------------------------------------- // Graphics /** * Sets the grass back to its initial position. */ void reset() { setPosition(-(TILE_WIDTH*CYCLE), TOP_Y); mySequenceIndex = 0; setAnimatedTile(myAnimatedTileIndex, FRAME_SEQUENCE[mySequenceIndex]); } /** * Alter the background image appropriately for this frame. * @param left Whether the player is moving left. */ void advance(int tickCount) { if(tickCount % 2 == 0) { // Slow the animation down a little. mySequenceIndex++; mySequenceIndex %= 4; setAnimatedTile(myAnimatedTileIndex, FRAME_SEQUENCE[mySequenceIndex]); } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者