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

📄 splashscreen.java

📁 J2ME超级坦克大战源码
💻 JAVA
字号:

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;


public final class SplashScreen extends GameCanvas implements Runnable{
    
    /**
     * Splash image.
     */
    private Image imgSplash=null;
    
    /**
     * Guidebee image.
     */
    private Image imgGuidebee=null;
    
    /**
     * pointer image (tank.)
     */
    private Image imgPointer=null;
    
    /**
     * pointer ,user can move this pointer to select 1 player ,2 player etc.
     */
    private Sprite pointer=null;
    
    /**
     * offset X, where is the origin of the picture.
     */
    private int offsetX=0;
    
    /**
     * offset X,
     */
    private int offsetY=0;
    
    /**
     * option position.
     */
    private int[][]pointerPos=new int[3][2];
    
    /**
     * current selection.
     */
    private int currentPointerIndex=0;
    
    /**
     * splash scroll in start time.
     */
    private long animationStartTime=0;
    
    /**
     * splash scroll in period.
     */
    private static long animationPeriod=5000;
    
    /**
     * anmation postion y
     */ 
    private int imgPosY=0;
    
    /**
     * if user click ,stop animation.
     */
    private boolean stopThread=false;
    
    /**
     * the animation thread.
     */
    private Thread animationThread=null;
     
   
    public SplashScreen() {
        super(false);
        setFullScreenMode(true);
        imgSplash=ResourceManager.getInstance()
            .getImage(ResourceManager.SPLASH);
        imgGuidebee=ResourceManager.getInstance()
            .getImage(ResourceManager.GUIDEBEE_LOGO);
        
        offsetX=(getWidth()-imgSplash.getWidth())/2;
        offsetY=(getHeight()-imgSplash.getHeight())/2;
        imgPointer=Image.createImage(ResourceManager.getInstance()
            .getImage(ResourceManager.PLAYER),0,12,24,12,0);
        pointer=new Sprite(imgPointer,12,12);
        pointerPos[0][0]=offsetX+imgSplash.getWidth()/2-50;
        pointerPos[0][1]=offsetY+imgSplash.getHeight()-
               imgGuidebee.getHeight()-32;
        pointerPos[1][0]=offsetX+imgSplash.getWidth()/2-50;
        pointerPos[1][1]=offsetY+imgSplash.getHeight()-
               imgGuidebee.getHeight()-22;
        pointerPos[2][0]=offsetX+imgSplash.getWidth()/2-50;
        pointerPos[2][1]=offsetY+imgSplash.getHeight()-
               imgGuidebee.getHeight()-12;
        pointer.setPosition(pointerPos[0][0],pointerPos[0][1]);

    }
    
    
    public void show(){
        animationStartTime=System.currentTimeMillis();
        imgPosY=getHeight()-offsetY;
        animationThread=new Thread(this);
        animationThread.start();
        pointer.setVisible(false);
        stopThread=false;
    }
    
    
    public void run(){
        Thread thread=Thread.currentThread();
        if(thread==animationThread){
            long tickTime=System.currentTimeMillis();
            while(!stopThread){
                if(tickTime-animationStartTime<animationPeriod){
                    if(imgPosY>0) {
                        imgPosY-=8;
                    }else{
                        break;
                    }
                    repaint();
                    try{
                        Thread.sleep(60);
                    }catch(Exception e){}
                }else{
                    break;
                }
            }
            pointer.setVisible(true);
            stopThread=true;
            imgPosY=0;
            repaint();
        }
    }
    
    
    public void paint(Graphics g){
        //clear background to black
        g.setColor(0x000000);
        g.fillRect(0,0,getWidth(),getHeight());
        g.drawImage(imgSplash,offsetX,offsetY+imgPosY,0);
        g.drawImage(imgGuidebee,offsetX,offsetY+imgSplash.getHeight()-
               imgGuidebee.getHeight()+imgPosY,0);
        pointer.paint(g);
        
    }
    
    
    protected void keyPressed(int keyCode) {
        if(!stopThread) 
        {
            stopThread=true;
            return;
        }
        int gameAction=0;
        switch(keyCode){
            case Canvas.KEY_NUM2:
                    gameAction=Canvas.UP;
                    break;
            case Canvas.KEY_NUM8:
                    gameAction=Canvas.DOWN;
                    break;
            case Canvas.KEY_NUM5:
                    gameAction=Canvas.FIRE;
                    break;
                     
            default:
                    gameAction = getGameAction(keyCode);
        }
        switch(gameAction){
            case Canvas.DOWN:
                currentPointerIndex++;
                if(currentPointerIndex>2)
                    currentPointerIndex=0;
                break;
            case Canvas.UP:
                currentPointerIndex--;
                if(currentPointerIndex<0)
                    currentPointerIndex=2;
                break;
            case Canvas.FIRE:
                ResourceManager.stageScreen.show();
                ResourceManager.setCurrentScreen(ResourceManager.stageScreen);
                break;
        }
        pointer.setPosition(pointerPos[currentPointerIndex][0],
                pointerPos[currentPointerIndex][1]);
        repaint(pointerPos[0][0],pointerPos[0][1],40,40);
        
    }
}

⌨️ 快捷键说明

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