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

📄 puddle.java

📁 Programming java 2 microedition symbian os一书中作者编写的一个赛车游戏的半成品
💻 JAVA
字号:
/*
 * Copyright 2003, 2004 Symbian Ltd.
 * For License terms see http://www.symbian.com/developer/techlib/codelicense.html
 */

package demoracer;

/**
 * <p>Title: DemoRacer</p>
 * <p>Description: Game API Demo for Symbian MIDP 2.0 Book.</p>
 * @author Alan Newman - alan@sensibledevelopment.net
 * @version 1.0
 */


/*
 * This is a rather simple Sprite class which forms the Puddle graphics
 * this has been separated from the tiled background to allow for collision detection.
 */
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

public class Puddle extends Sprite {
    
    static final int FRAME_COLS = 1;
    static final int FRAME_WIDTH = 1;
    private int xInitial;
    private int yInitial;
    private int frequency;
    
    public Puddle(Image image, int width, int height, int x, int y) {
        super(image, width, height);
        setPosition(x, y);
        xInitial=x;
        yInitial=y;
        frequency = 2*Background.TILE_WIDTH;
    }
    
    // move the puddle along with the tiled background as it move from right to left
    //across the screen
    public void tick() {
        if (frequency == 0) {
            setPosition(xInitial, yInitial);
            frequency = 2*Background.TILE_WIDTH;
        } else{
            move(Background.xMove, Background.yMove);
        }
        
        // set visible to false if it is off screen
        if(getX() + getWidth() <= 0) {//definitely outside Canvas clip area
            setVisible(false);
        } else {
            setVisible(true);
        }
        
        frequency--;
    }
    
}

⌨️ 快捷键说明

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