www.pudn.com > BlackCross.rar > myCanv.java


import java.io.IOException; 
import java.io.InputStream; 
import javax.microedition.lcdui.*; 
 
class myCanv extends Canvas 
    implements Runnable 
{ 
    boolean SCREENSHOT_MODE; 
    boolean DEMO_MODE; 
    int demoVerTimer; 
    boolean APP_END; 
    int targetFPS; 
    hiScore hiscoreTable; 
    gameObjects objects; 
    camera kamera; 
    backgroundHandler bkg; 
    objectAdder adder; 
    fader fade; 
    Image introImage; 
    Image hud_ship; 
    Image hud_num[]; 
    music musik; 
    int x; 
    int y; 
    int mspeed; 
    int mx; 
    int my; 
    int ix; 
    int iy; 
    int wc; 
    int hc; 
    int xc; 
    int yc; 
    boolean db; 
    int w; 
    int h; 
    int numColors; 
    boolean GKEY_UP; 
    boolean GKEY_DOWN; 
    boolean GKEY_LEFT; 
    boolean GKEY_RIGHT; 
    boolean GKEY_FIRE; 
    int turnCnt; 
    int fireTimer; 
    int fireTimer2; 
    boolean FIRST_PAINT; 
    boolean justUpdated; 
    boolean pause; 
    long tidNu; 
    long tidNyss; 
    long tidNyss2; 
    int fps; 
    int tidTCW; 
    int fpsC; 
    int fpsAW; 
    int fpsA; 
    int GAME_MODE; 
    int introTimer; 
    int titleTimer; 
    int titleTimer2; 
    int gameTimer; 
    boolean GAME_OVER; 
    boolean LEVEL_END; 
    int LEVEL; 
    int playerLives; 
    int playerScore; 
    int scoreTab[]; 
    String nuff[] = { 
        "1...", "2...", "3...", "4...", "5..." 
    }; 
    String hiTableScoreString[]; 
    String hiTableNameString[]; 
    int FFI; 
    int gameType; 
    int nompa; 
    int nol; 
    int boss[]; 
    int songs[]; 
    String bokstav[] = { 
        "-", "A", "B", "C", "D", "E", "F", "G", "H", "I",  
        "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",  
        "T", "U", "V", "W", "X", "Y", "Z" 
    }; 
    int hsB[] = { 
        1, 0, 0 
    }; 
    int hsBpos; 
    int hsTimer; 
    int hspos; 
    boolean redo; 
    int reX; 
    int reY; 
    mvs sp; 
    Thread thread; 
    Display d; 
    Font myF; 
    int selStart; 
    int selOptions; 
    int selExit; 
    int selBack; 
    int selDiff; 
    int selLives; 
    int selAudio; 
    int sel; 
    int flash; 
    int flashDir; 
    int gameLives; 
    int gameAudio; 
    int gameDiff; 
     
    public void createHiTableStrings() 
    { 
        for(int i = 0; i < 5; i++) 
        { 
            hiTableScoreString[i] = "" + hiscoreTable.getScore(i); 
            hiTableNameString[i] = hiscoreTable.getName(i); 
        } 
 
    } 
 
    public myCanv(Display display) 
    { 
        SCREENSHOT_MODE = false; 
        DEMO_MODE = false; 
        demoVerTimer = 0; 
        APP_END = false; 
        targetFPS = 15; 
        hiscoreTable = new hiScore(); 
        objects = new gameObjects(SCREENSHOT_MODE); 
        kamera = new camera(); 
        bkg = new backgroundHandler(); 
        adder = new objectAdder(); 
        hud_num = new Image[10]; 
        musik = new music(); 
        x = 20; 
        y = 20; 
        mspeed = 5; 
        mx = 0; 
        my = 0; 
        db = false; 
        GKEY_UP = false; 
        GKEY_DOWN = false; 
        GKEY_LEFT = false; 
        GKEY_RIGHT = false; 
        GKEY_FIRE = false; 
        turnCnt = 0; 
        fireTimer = 0; 
        fireTimer2 = 0; 
        FIRST_PAINT = true; 
        justUpdated = true; 
        pause = false; 
        tidNu = 0L; 
        tidNyss = 0L; 
        tidNyss2 = 0L; 
        fps = 0; 
        tidTCW = 0; 
        fpsC = 0; 
        fpsAW = 0; 
        fpsA = 0; 
        GAME_MODE = 0; 
        introTimer = 0; 
        titleTimer = 0; 
        titleTimer2 = 9999; 
        gameTimer = 0; 
        GAME_OVER = false; 
        LEVEL_END = false; 
        LEVEL = 1; 
        playerLives = 2; 
        playerScore = 0; 
        scoreTab = new int[6]; 
        hiTableScoreString = new String[5]; 
        hiTableNameString = new String[5]; 
        FFI = 0; 
        boss = new int[20]; 
        songs = new int[20]; 
        hsBpos = 0; 
        hsTimer = 0; 
        hspos = -1; 
        redo = false; 
        reX = 0; 
        reY = 0; 
        selStart = 0xffffff; 
        selOptions = 0xffffff; 
        selExit = 0xffffff; 
        selBack = 0xffffff; 
        selDiff = 0xffffff; 
        selLives = 0xffffff; 
        selAudio = 0xffffff; 
        sel = 0; 
        flash = 0; 
        flashDir = 64; 
        gameLives = 1; 
        gameAudio = 0; 
        gameDiff = 1; 
        d = display; 
        myF = Font.getFont(64, 0, 0); 
        try 
        { 
            byte abyte0[] = new byte[64]; 
            InputStream inputstream = getClass().getResourceAsStream("/sets/game.set"); 
            inputstream.read(abyte0, 0, 2); 
            //level 1/2/3/4£ºabyte0[0]=64 abyte0[1]=1 
            inputstream.read(abyte0, 0, 1); 
            gameType = abyte0[0]; 
            //level 1£ºgameType=0 
            //level 2£ºgameType=0 
            //level 3£ºgameType=0 
            //level 4£ºgameType=0 
            inputstream.read(abyte0, 0, 1); 
            nompa = abyte0[0]; 
            //level 1£ºnompa=3 
            //level 2£ºnompa=3 
            //level 3£ºnompa=3 
            //level 4£ºnompa=3 
            inputstream.read(abyte0, 0, 1); 
            nol = abyte0[0]; 
            //level 1£ºnol=5 
            //level 2£ºnol=5 
            //level 3£ºnol=5 
            //level 4£ºnol=5 
            for(int j = 0; j < 20; j++) 
            { 
                inputstream.read(abyte0, 0, 1); 
                boss[j] = abyte0[0]; 
                //level 1£ºboss[0/1/2/3/4]=9 boss[5-19]=0  
                //level 2£ºboss[0/1/2/3/4]=9 boss[5-19]=0 
                //level 3£ºboss[0/1/2/3/4]=9 boss[5-19]=0 
                //level 4£ºboss[0/1/2/3/4]=9 boss[5-19]=0      
            } 
 
            for(int k = 0; k < 20; k++) 
            { 
                inputstream.read(abyte0, 0, 1); 
                songs[k] = abyte0[0]; 
                //level 1£ºsongs[0-19]=0  
                //level 2£ºsongs[0-19]=0 
                //level 3£ºsongs[0-19]=0 
                //level 4£ºsongs[0-19]=0  
            } 
            inputstream.close(); 
        } 
        catch(Exception exception) { } 
        d.setCurrent(this); 
        w = getWidth(); 
        h = getHeight(); 
        if(w > 128) 
        { 
            reX = (w - 128) / 2; 
            redo = true; 
            w = 128; 
        } 
        if(h > 128) 
        { 
            reY = (h - 128) / 2; 
            redo = true; 
            h = 128; 
        } 
        if(h != 128 || w != 128) 
            adder.setObjectAdderProps(w, h); 
        db = isDoubleBuffered(); 
        numColors = d.numColors(); 
        ix = w / 2; 
        iy = h / 2; 
        fade = new fader(w, h, targetFPS); 
        bkg.setBackgroundproperties(w, h); 
        try 
        { 
            introImage = Image.createImage("/intro/tiger.png"); 
            hud_ship = Image.createImage("/hud/lives.png"); 
            for(int i = 0; i < 10; i++) 
                hud_num[i] = Image.createImage("/hud/" + i + ".png"); 
 
        } 
        catch(IOException ioexception) { } 
    } 
 
    public void loadTitleImage() 
    { 
        try 
        { 
            introImage = Image.createImage("/intro/title.png"); 
        } 
        catch(IOException ioexception) { } 
    } 
 
    public void nullTitleImage() 
    { 
        try 
        { 
            introImage = Image.createImage("/intro/null.png"); 
        } 
        catch(IOException ioexception) { } 
    } 
 
    public void initLevel(int i) 
    { 
        bkg.loadTileNumbers(i); 
        bkg.loadTileset(i); 
        kamera.load(i, bkg.tilesWidth[0], bkg.tilesHeight[0]); 
        objects.loadAndInit(i, gameDiff); 
        x = w / 2; 
        y = h + h / 4; 
        objects.mainEnterX = x; 
        objects.mainEnterY = y; 
        objects.main_x = x; 
        objects.main_y = y; 
        objects.makeMainEnter(); 
        adder.load(i); 
    } 
 
    public void mainAnimation(int i, int j) 
    { 
        if(bkg.verticalScroll == 1 && i == 0) 
            if(j == 1) 
            { 
                turnCnt--; 
                if(turnCnt < -2) 
                { 
                    objects.objects[4][0].animationCurrent = 0; 
                    turnCnt = -2; 
                } else 
                { 
                    objects.objects[4][0].animationCurrent = 1; 
                } 
            } else 
            if(j == 2) 
            { 
                turnCnt++; 
                if(turnCnt > 2) 
                { 
                    objects.objects[4][0].animationCurrent = 2; 
                    turnCnt = 2; 
                } else 
                { 
                    objects.objects[4][0].animationCurrent = 1; 
                } 
            } else 
            { 
                turnCnt = 0; 
                objects.objects[4][0].animationCurrent = 1; 
            } 
    } 
 
    public void mainFire() 
    { 
        if(!GAME_OVER && !LEVEL_END) 
        { 
            fireTimer++; 
            if(fireTimer >= 3) 
            { 
                fireTimer = 0; 
                if(objects.main_level == 1) 
                    objects.add(1, 1, x, y, -1, -1); 
                else 
                if(objects.main_level == 2) 
                { 
                    fireTimer2++; 
                    if(fireTimer2 >= 2) 
                    { 
                        objects.add(1, 1, x - 4, y + 3, -1, -1); 
                        objects.add(1, 1, x + 4, y + 3, -1, -1); 
                        fireTimer2 = 0; 
                    } else 
                    { 
                        objects.add(1, 1, x, y, -1, -1); 
                    } 
                } else 
                if(objects.main_level == 3) 
                { 
                    objects.add(1, 1, x - 4, y + 3, -1, -1); 
                    objects.add(1, 1, x + 4, y + 3, -1, -1); 
                    fireTimer2 = 0; 
                } else 
                if(objects.main_level == 4) 
                { 
                    fireTimer2++; 
                    if(fireTimer2 >= 2) 
                    { 
                        objects.add(1, 1, x - 4, y + 3, -1, -1); 
                        objects.add(1, 1, x + 4, y + 3, -1, -1); 
                        fireTimer2 = 0; 
                    } else 
                    { 
                        objects.add(1, 1, x, y, -1, -1); 
                        objects.add(1, 1, x - 4, y + 3, -1, -1); 
                        objects.add(1, 1, x + 4, y + 3, -1, -1); 
                    } 
                } else 
                if(objects.main_level >= 5) 
                { 
                    objects.add(1, 1, x, y, -1, -1); 
                    objects.add(1, 1, x - 4, y + 3, -1, -1); 
                    objects.add(1, 1, x + 4, y + 3, -1, -1); 
                } 
            } 
        } 
    } 
 
    public void convertScore() 
    { 
        int i = playerScore / 1000; 
        int j = (playerScore - i * 1000) / 100; 
        int k = (playerScore - i * 1000 - j * 100) / 10; 
        int l = playerScore - i * 1000 - j * 100 - k * 10; 
        scoreTab[0] = i; 
        scoreTab[1] = j; 
        scoreTab[2] = k; 
        scoreTab[3] = l; 
        scoreTab[4] = 0; 
        scoreTab[5] = 0; 
    } 
 
    public void exitApp() 
    { 
        APP_END = true; 
    } 
 
    protected void paint(Graphics g) 
    { 
        if(pause || justUpdated) 
            return; 
        if(FIRST_PAINT) 
        { 
            if(redo) 
            { 
                xc = g.getClipX(); 
                yc = g.getClipY(); 
                wc = g.getClipWidth(); 
                hc = g.getClipHeight(); 
                g.setColor(0x140000); 
                g.fillRect(0, 0, wc, hc); 
                g.translate(reX, reY); 
                g.setClip(0, 0, 128, 128); 
                xc = 0; 
                yc = 0; 
                wc = 128; 
                hc = 128; 
            } else 
            { 
                xc = g.getClipX(); 
                yc = g.getClipY(); 
                wc = g.getClipWidth(); 
                hc = g.getClipHeight(); 
            } 
            FIRST_PAINT = false; 
            tidNyss = System.currentTimeMillis(); 
            justUpdated = true; 
        } else 
        { 
            if(redo) 
            { 
                g.translate(reX, reY); 
                g.setClip(0, 0, 128, 128); 
            } 
            tidNu = System.currentTimeMillis(); 
            long l = tidNu - tidNyss; 
            if(l < 46L) 
            { 
                try 
                { 
                    Thread.sleep(46L - l); 
                } 
                catch(Exception exception) { } 
                tidNu = System.currentTimeMillis(); 
            } 
            if(tidNu - tidNyss != 0L) 
                fps = 1000 / (int)(tidNu - tidNyss); 
            tidNyss2 = tidNyss; 
            tidNyss = tidNu; 
            fpsC++; 
            fpsA += fps; 
            if(fpsC == 12) 
            { 
                fpsC = 0; 
                fpsAW = fpsA / 12; 
                fpsA = 0; 
            } 
            if(GAME_MODE == 0) 
            { 
                g.setFont(myF); 
                fade.setType(1); 
                g.drawImage(introImage, ix, iy, 3); 
                fade.out(g, introTimer, 0); 
                fade.in(g, introTimer, targetFPS * 3); 
                if(introTimer >= targetFPS * 4) 
                { 
                    loadTitleImage(); 
                    introTimer = 0; 
                    titleTimer = 0; 
                    titleTimer2 = 9999; 
                    musik.load(0, "/aud/title.mid"); 
                    musik.play(28); 
                    GAME_MODE = 1; 
                    fade.setType(0); 
                } 
                introTimer++; 
            } else 
            if(GAME_MODE == 1) 
            { 
                g.setFont(myF); 
                g.drawImage(introImage, ix, iy, 3); 
                flash += flashDir; 
                if(flash == 256) 
                { 
                    flash = 192; 
                    flashDir = -64; 
                } 
                if(flash == 0) 
                    flashDir = 64; 
                selStart = 0xffffff; 
                selOptions = 0xffffff; 
                selExit = 0xffffff; 
                if(sel == 0) 
                    selStart = flash + flash * 256 + 0xff0000; 
                if(sel == 1) 
                    selOptions = flash + flash * 256 + 0xff0000; 
                if(sel == 2) 
                    selExit = flash + flash * 256 + 0xff0000; 
                if(titleTimer2 == 9999) 
                { 
                    if(GKEY_DOWN) 
                    { 
                        titleTimer = 3 * targetFPS; 
                        sel++; 
                        if(sel == 3) 
                            sel = 0; 
                        GKEY_DOWN = false; 
                    } 
                    if(GKEY_UP) 
                    { 
                        titleTimer = 3 * targetFPS; 
                        sel--; 
                        if(sel == -1) 
                            sel = 2; 
                        GKEY_UP = false; 
                    } 
                } 
                g.setColor(selStart); 
                g.drawString("Start", wc / 2, hc / 2 - 2, 0x10 | 1); 
                g.setColor(selOptions); 
                g.drawString("Options", wc / 2, hc / 2 + 8, 0x10 | 1); 
                g.setColor(selExit); 
                g.drawString("Exit", wc / 2, hc / 2 + 18, 0x10 | 1); 
                g.setColor(0xffffff); 
                g.drawString("\2512004 Akatora", wc / 2, hc - 16, 0x10 | 1); 
                if(GKEY_FIRE && titleTimer2 == 9999 && sel == 0) 
                { 
                    sel = 0; 
                    titleTimer2 = titleTimer; 
                } 
                if(GKEY_FIRE && titleTimer2 == 9999 && sel == 1) 
                { 
                    sel = 0; 
                    GAME_MODE = 3; 
                } 
                if(GKEY_FIRE && titleTimer2 == 9999 && sel == 2) 
                    exitApp(); 
                fade.out(g, titleTimer, 0); 
                fade.in(g, titleTimer, titleTimer2); 
                if(titleTimer == titleTimer2 + targetFPS) 
                { 
                    nullTitleImage(); 
                    LEVEL = 1; 
                    objects.main_level = 1; 
                    objects.main_exp = 0; 
                    initLevel(1); 
                    FFI = 29999; 
                    playerLives = gameLives * 2; 
                    objects.main_lives = playerLives; 
                    playerScore = 0; 
                    objects.main_score = playerScore; 
                    objects.main_levelup_counter = 0; 
                    objects.main_levelup = false; 
                    GAME_OVER = false; 
                    LEVEL_END = false; 
                    gameTimer = 0; 
                    objects.main_gameover = false; 
                    objects.main_levelend = false; 
                    objects.gameOverCounter = 0; 
                    System.gc(); 
                    GAME_MODE = 2; 
                    fade.setType(1); 
                    int i = LEVEL & 1; 
                    if(i == 1) 
                        musik.load(0, "/aud/ue.mid"); 
                    else 
                        musik.load(0, "/aud/e.mid"); 
                    musik.play(28); 
                } 
                titleTimer++; 
                if(titleTimer == 120 && titleTimer2 == 9999) 
                { 
                    createHiTableStrings(); 
                    GAME_MODE = 5; 
                } 
            } else 
            if(GAME_MODE == 3) 
            { 
                g.setFont(myF); 
                g.drawImage(introImage, ix, iy, 3); 
                flash += flashDir; 
                if(flash == 256) 
                { 
                    flash = 192; 
                    flashDir = -64; 
                } 
                if(flash == 0) 
                    flashDir = 64; 
                selDiff = 0xffffff; 
                selLives = 0xffffff; 
                selAudio = 0xffffff; 
                selBack = 0xffffff; 
                if(sel == 0) 
                    selDiff = flash + flash * 256 + 0xff0000; 
                if(sel == 1) 
                    selLives = flash + flash * 256 + 0xff0000; 
                if(sel == 2) 
                    selAudio = flash + flash * 256 + 0xff0000; 
                if(sel == 3) 
                    selBack = flash + flash * 256 + 0xff0000; 
                if(GKEY_DOWN) 
                { 
                    sel++; 
                    if(sel == 4) 
                        sel = 0; 
                    GKEY_DOWN = false; 
                } 
                if(GKEY_UP) 
                { 
                    sel--; 
                    if(sel == -1) 
                        sel = 3; 
                    GKEY_UP = false; 
                } 
                g.setColor(selDiff); 
                if(gameDiff == 0) 
                { 
                    g.drawString("Difficulty: Easy", wc / 2, hc / 2 - 2, 0x10 | 1); 
                } 
                if(gameDiff == 1) 
                { 
                    g.drawString("Difficulty: Normal", wc / 2, hc / 2 - 2, 0x10 | 1); 
                } 
                if(gameDiff == 2) 
                { 
                    g.drawString("Difficulty: Hard", wc / 2, hc / 2 - 2, 0x10 | 1); 
                } 
                g.setColor(selLives); 
                if(gameLives == 0) 
                { 
                    g.drawString("Lives: 1", wc / 2, hc / 2 + 8, 0x10 | 1); 
                } 
                if(gameLives == 1) 
                { 
                    g.drawString("Lives: 3", wc / 2, hc / 2 + 8, 0x10 | 1); 
                } 
                if(gameLives == 2) 
                { 
                    g.drawString("Lives: 5", wc / 2, hc / 2 + 8, 0x10 | 1); 
                } 
                g.setColor(selAudio); 
                if(gameAudio == 0) 
                { 
                    g.drawString("Audio: Off", wc / 2, hc / 2 + 18, 0x10 | 1); 
                } 
                if(gameAudio == 1) 
                { 
                    g.drawString("Audio: On", wc / 2, hc / 2 + 18, 0x10 | 1); 
                } 
                g.setColor(selBack); 
                g.drawString("Back", wc / 2, hc / 2 + 28, 0x10 | 1); 
                if(GKEY_LEFT && sel == 0) 
                { 
                    GKEY_LEFT = false; 
                    gameDiff--; 
                    if(gameDiff == -1) 
                        gameDiff = 0; 
                } 
                if(GKEY_RIGHT && sel == 0) 
                { 
                    GKEY_RIGHT = false; 
                    gameDiff++; 
                    if(gameDiff == 3) 
                        gameDiff = 2; 
                } 
                if(GKEY_LEFT && sel == 1) 
                { 
                    GKEY_LEFT = false; 
                    gameLives--; 
                    if(gameLives == -1) 
                        gameLives = 0; 
                } 
                if(GKEY_RIGHT && sel == 1) 
                { 
                    GKEY_RIGHT = false; 
                    gameLives++; 
                    if(gameLives == 3) 
                        gameLives = 2; 
                } 
                if(GKEY_LEFT && sel == 2) 
                { 
                    GKEY_LEFT = false; 
                    gameAudio--; 
                    if(gameAudio == -1) 
                        gameAudio = 0; 
                    musik.deActivate(); 
                } 
                if(GKEY_RIGHT && sel == 2) 
                { 
                    GKEY_RIGHT = false; 
                    gameAudio++; 
                    if(gameAudio == 2) 
                        gameAudio = 1; 
                    musik.activate(); 
                } 
                if(GKEY_FIRE && sel == 3) 
                { 
                    GKEY_FIRE = false; 
                    sel = 0; 
                    GAME_MODE = 1; 
                } 
            } else 
            if(GAME_MODE == 2) 
            { 
                kamera.run(); 
                bkg.yPos = kamera.yPos; 
                bkg.xPos = kamera.xPos; 
                bkg.draw(g); 
                objects.main_lives = playerLives; 
                objects.main_score = playerScore; 
                objects.main_gameover = GAME_OVER; 
                objects.main_levelend = LEVEL_END; 
                objects.main_x = x; 
                objects.main_y = y; 
                objects.collisionDetection(); 
                objects.processAll(); 
                objects.draw(g); 
                x = objects.main_x; 
                y = objects.main_y; 
                playerLives = objects.main_lives; 
                playerScore = objects.main_score; 
                GAME_OVER = objects.main_gameover; 
                LEVEL_END = objects.main_levelend; 
                if(DEMO_MODE && gameTimer == 450) 
                { 
                    musik.stop(0); 
                    FFI = gameTimer; 
                } 
                if(objects.playerState() == 1 || objects.levelEndCounter == 0) 
                { 
                    if(objects.levelEndCounter == 0) 
                    { 
                        musik.load(0, "/aud/clear.mid"); 
                        musik.play(1); 
                    } else 
                    { 
                        musik.stop(0); 
                    } 
                    FFI = gameTimer; 
                } 
                if(objects.levelEndCounter != -1) 
                { 
                    objects.levelEndCounter++; 
                    LEVEL_END = true; 
                } 
                mainFire(); 
                adder.run(objects, targetFPS); 
                if(DEMO_MODE) 
                { 
                    g.setColor(0xff0000); 
                    demoVerTimer++; 
                    if(demoVerTimer > 10) 
                    { 
                        g.drawString("Version", wc / 2, hc - 16, 0x10 | 1); 
                    } else 
                    { 
                        g.drawString("Demo", wc / 2, hc - 16, 0x10 | 1); 
                    } 
                    if(demoVerTimer > 20) 
                        demoVerTimer = 0; 
                } 
                if(objects.lasthit_obj != -1) 
                { 
                    objects.lasthit_counter++; 
                    if(objects.lasthit_counter >= 10) 
                    { 
                        objects.lasthit_counter = 0; 
                        objects.lasthit_obj = -1; 
                    } else 
                    { 
                        int j = objects.objects[0][objects.lasthit_obj].hitsTotal; 
                        if(j > 1) 
                        { 
                            j /= 2; 
                            int l1 = j; 
                            g.setColor(0); 
                            g.fillRect(wc / 2 - j, 18, j * 2, 3); 
                            j = objects.objects[0][objects.lasthit_obj].hitsNum / 2; 
                            if(j < l1 / 3) 
                                g.setColor(0xff0000); 
                            else 
                                g.setColor(0xffff00); 
                            g.fillRect(wc / 2 - j, 19, j * 2, 1); 
                        } 
                    } 
                } 
                g.setColor(0); 
                g.fillRect(2, hc - 8, 25, 6); 
                int k = objects.main_exp * 1000; 
                int i2 = objects.main_level * 63; 
                int k2 = ((k / i2) * 25) / 1000; 
                g.setColor(65280); 
                g.fillRect(2, hc - 7, k2, 4); 
                if(objects.main_levelup) 
                { 
                    objects.main_levelup_counter++; 
                    if(objects.main_levelup_counter >= 20) 
                    { 
                        objects.main_levelup_counter = 0; 
                        objects.main_levelup = false; 
                    } 
                    g.setColor(0xffffff); 
                    g.drawString("Power Up!", wc / 2, hc / 2 - 5, 0x10 | 1); 
                } 
                convertScore(); 
                for(int j3 = 0; j3 < 6; j3++) 
                    g.drawImage(hud_num[scoreTab[j3]], j3 * 9, 1, 20); 
 
                for(int k3 = 0; k3 < playerLives; k3++) 
                    g.drawImage(hud_ship, k3 * 9, 9, 20); 
 
                fade.out(g, gameTimer, 0); 
                fade.in(g, gameTimer, FFI, LEVEL_END, LEVEL); 
                if(gameTimer == FFI + targetFPS) 
                    if(LEVEL_END) 
                    { 
                        if(LEVEL == 4) 
                        { 
                            long l4 = System.currentTimeMillis(); 
                            loadTitleImage(); 
                            LEVEL = 1; 
                            introTimer = 0; 
                            titleTimer = 0; 
                            titleTimer2 = 9999; 
                            GAME_OVER = false; 
                            LEVEL_END = false; 
                            GKEY_FIRE = false; 
                            GKEY_UP = false; 
                            GKEY_DOWN = false; 
                            System.gc(); 
                            fade.setType(0); 
                            hspos = hiscoreTable.checkForHiscore(playerScore * 100); 
                            while(System.currentTimeMillis() - l4 < 8000L) ; 
                            if(hspos == -1) 
                            { 
                                musik.load(0, "/aud/title.mid"); 
                                musik.play(28); 
                                GAME_MODE = 1; 
                            } else 
                            { 
                                hsB[0] = 1; 
                                hsB[1] = 0; 
                                hsB[2] = 0; 
                                hsBpos = 0; 
                                hsTimer = 0; 
                                GAME_MODE = 4; 
                            } 
                        } else 
                        { 
                            long l5 = System.currentTimeMillis(); 
                            LEVEL++; 
                            initLevel(LEVEL); 
                            FFI = 29999; 
                            GAME_OVER = false; 
                            LEVEL_END = false; 
                            gameTimer = 0; 
                            objects.main_gameover = false; 
                            objects.main_levelend = false; 
                            objects.gameOverCounter = 0; 
                            objects.levelEndCounter = -1; 
                            System.gc(); 
                            fade.setType(1); 
                            while(System.currentTimeMillis() - l5 < 8000L) ; 
                            int i4 = LEVEL & 1; 
                            if(i4 == 1) 
                                musik.load(0, "/aud/ue.mid"); 
                            else 
                                musik.load(0, "/aud/e.mid"); 
                            musik.play(28); 
                            GAME_MODE = 2; 
                        } 
                    } else 
                    { 
                        loadTitleImage(); 
                        LEVEL = 1; 
                        introTimer = 0; 
                        titleTimer = 0; 
                        titleTimer2 = 9999; 
                        GAME_OVER = false; 
                        LEVEL_END = false; 
                        GKEY_FIRE = false; 
                        GKEY_UP = false; 
                        GKEY_DOWN = false; 
                        System.gc(); 
                        fade.setType(0); 
                        hspos = hiscoreTable.checkForHiscore(playerScore * 100); 
                        if(hspos == -1) 
                        { 
                            musik.load(0, "/aud/title.mid"); 
                            musik.play(28); 
                            GAME_MODE = 1; 
                        } else 
                        { 
                            hsB[0] = 1; 
                            hsB[1] = 0; 
                            hsB[2] = 0; 
                            hsBpos = 0; 
                            hsTimer = 0; 
                            GAME_MODE = 4; 
                        } 
                        if(DEMO_MODE) 
                        { 
                            demoVerTimer = 0; 
                            GAME_MODE = 66; 
                        } 
                    } 
                gameTimer++; 
            } else 
            if(GAME_MODE == 66) 
            { 
                g.setFont(myF); 
                flash += flashDir; 
                if(flash == 256) 
                { 
                    flash = 192; 
                    flashDir = -64; 
                } 
                if(flash == 0) 
                    flashDir = 64; 
                g.setColor(40); 
                g.fillRect(0, 0, 128, 128); 
                int i1 = flash + flash * 256 + 0xff0000; 
                g.setColor(0xffffff); 
                g.drawString("Buy the", 64, 22, 0x10 | 1); 
                g.drawString("Full Version", 64, 36, 0x10 | 1); 
                g.drawString("Now!", 64, 50, 0x10 | 1); 
                g.setColor(i1); 
                g.drawString("www.akatora.com", 64, 76, 0x10 | 1); 
                demoVerTimer++; 
                if(demoVerTimer >= 75) 
                { 
                    demoVerTimer = 0; 
                    GAME_MODE = 1; 
                } 
            } else 
            if(GAME_MODE == 4) 
            { 
                g.setFont(myF); 
                g.drawImage(introImage, ix, iy, 3); 
                flash += flashDir; 
                if(flash == 256) 
                { 
                    flash = 192; 
                    flashDir = -64; 
                } 
                if(flash == 0) 
                    flashDir = 64; 
                int j1 = flash + flash * 256 + 0xff0000; 
                g.setColor(0xffffff); 
                g.drawString("Great Score!", wc / 2, h - 28, 0x10 | 1); 
                if(hsBpos == 0) 
                    g.setColor(j1); 
                else 
                    g.setColor(0xffffff); 
                g.drawString(bokstav[hsB[0]], wc / 2 - 12, h - 16, 0x10 | 1); 
                if(hsBpos == 1) 
                    g.setColor(j1); 
                else 
                    g.setColor(0xffffff); 
                g.drawString(bokstav[hsB[1]], wc / 2, h - 16, 0x10 | 1); 
                if(hsBpos == 2) 
                    g.setColor(j1); 
                else 
                    g.setColor(0xffffff); 
                g.drawString(bokstav[hsB[2]], wc / 2 + 12, h - 16, 0x10 | 1); 
                if(GKEY_RIGHT) 
                { 
                    hsB[hsBpos]++; 
                    if(hsB[hsBpos] > 25) 
                        hsB[hsBpos] = 0; 
                } 
                if(GKEY_LEFT) 
                { 
                    hsB[hsBpos]--; 
                    if(hsB[hsBpos] < 0) 
                        hsB[hsBpos] = 25; 
                } 
                if(GKEY_FIRE) 
                { 
                    GKEY_FIRE = false; 
                    hsBpos++; 
                    if(hsBpos == 3) 
                    { 
                        String s = bokstav[hsB[0]] + bokstav[hsB[1]] + bokstav[hsB[2]]; 
                        hiscoreTable.setName(hspos, s); 
                        musik.load(0, "/aud/title.mid"); 
                        musik.play(28); 
                        GAME_MODE = 1; 
                        System.gc(); 
                    } else 
                    { 
                        hsB[hsBpos] = 1; 
                    } 
                } 
                fade.out(g, hsTimer, 0); 
                hsTimer++; 
            } else 
            if(GAME_MODE == 5) 
            { 
                g.drawImage(introImage, ix, iy, 3); 
                flash += flashDir; 
                if(flash == 256) 
                { 
                    flash = 192; 
                    flashDir = -64; 
                } 
                if(flash == 0) 
                    flashDir = 64; 
                int k1 = flash; 
                int j2 = flashDir; 
                int l2 = 255 + flash * 256 + flash * 256 * 256; 
                g.setColor(l2); 
                for(int l3 = 0; l3 < 5; l3++) 
                { 
                    g.drawString(nuff[l3], 20, (hc / 2 - 6) + l3 * 10, 0x10 | 1); 
                    g.drawString(hiTableScoreString[l3], 80, (hc / 2 - 6) + l3 * 10, 0x10 | 8); 
                    g.drawString(hiTableNameString[l3], 104, (hc / 2 - 6) + l3 * 10, 0x10 | 1); 
                    k1 += j2; 
                    if(k1 == 256) 
                    { 
                        k1 = 192; 
                        j2 = -64; 
                    } 
                    if(k1 == 0) 
                        j2 = 64; 
                    int i3 = 255 + k1 * 256 + k1 * 256 * 256; 
                    g.setColor(i3); 
                } 
 
                titleTimer++; 
                if(titleTimer == 225 || GKEY_FIRE) 
                { 
                    System.gc(); 
                    GKEY_FIRE = false; 
                    titleTimer = 3 * targetFPS; 
                    GAME_MODE = 1; 
                } 
            } 
            justUpdated = true; 
        } 
    } 
 
    public void keyPressed(int i) 
    { 
        if(GAME_OVER || LEVEL_END) 
            return; 
        switch(getGameAction(i)) 
        { 
        case 3: // '\003' 
        case 4: // '\004' 
        case 7: // '\007' 
        default: 
            break; 
 
        case 1: // '\001' 
            GKEY_UP = true; 
            break; 
 
        case 6: // '\006' 
            GKEY_DOWN = true; 
            break; 
 
        case 2: // '\002' 
            GKEY_LEFT = true; 
            break; 
 
        case 5: // '\005' 
            GKEY_RIGHT = true; 
            break; 
 
        case 8: // '\b' 
            GKEY_FIRE = true; 
            break; 
 
        case 0: // '\0' 
            switch(i) 
            { 
            case 56: // '8' 
                GKEY_UP = true; 
                break; 
 
            case 50: // '2' 
                GKEY_DOWN = true; 
                break; 
 
            case 52: // '4' 
                GKEY_LEFT = true; 
                break; 
 
            case 54: // '6' 
                GKEY_RIGHT = true; 
                break; 
            } 
            break; 
        } 
    } 
 
    public void keyReleased(int i) 
    { 
        switch(getGameAction(i)) 
        { 
        case 3: // '\003' 
        case 4: // '\004' 
        case 7: // '\007' 
        default: 
            break; 
 
        case 1: // '\001' 
            GKEY_UP = false; 
            break; 
 
        case 6: // '\006' 
            GKEY_DOWN = false; 
            break; 
 
        case 2: // '\002' 
            GKEY_LEFT = false; 
            break; 
 
        case 5: // '\005' 
            GKEY_RIGHT = false; 
            break; 
 
        case 8: // '\b' 
            GKEY_FIRE = false; 
            break; 
 
        case 0: // '\0' 
            switch(i) 
            { 
            case 56: // '8' 
                GKEY_UP = false; 
                break; 
 
            case 50: // '2' 
                GKEY_DOWN = false; 
                break; 
 
            case 52: // '4' 
                GKEY_LEFT = false; 
                break; 
 
            case 54: // '6' 
                GKEY_RIGHT = false; 
                break; 
            } 
            break; 
        } 
    } 
 
    public void setSuper(mvs mvs1) 
    { 
        sp = mvs1; 
    } 
 
    public void setThread(Thread thread1) 
    { 
        thread = thread1; 
    } 
 
    public void run() 
    { 
        do 
        { 
            if(APP_END) 
                break; 
            if(pause) 
            { 
                if(SCREENSHOT_MODE) 
                { 
                    if(GKEY_LEFT) 
                    { 
                        justUpdated = true; 
                        pause = false; 
                    } 
                } else 
                { 
                    return; 
                } 
            } else 
            if(justUpdated) 
            { 
                justUpdated = false; 
                if(GAME_MODE == 2) 
                { 
                    if(SCREENSHOT_MODE && GKEY_FIRE) 
                        pause = true; 
                    if(GKEY_LEFT) 
                    { 
                        x -= mspeed; 
                        mainAnimation(0, 1); 
                    } else 
                    if(GKEY_RIGHT) 
                    { 
                        x += mspeed; 
                        mainAnimation(0, 2); 
                    } else 
                    { 
                        mainAnimation(0, 0); 
                    } 
                    if(GKEY_UP) 
                    { 
                        y -= mspeed; 
                        mainAnimation(1, 1); 
                    } else 
                    if(GKEY_DOWN) 
                    { 
                        y += mspeed; 
                        mainAnimation(1, 2); 
                    } else 
                    { 
                        mainAnimation(1, 0); 
                    } 
                    if(x > w) 
                    { 
                        x = w; 
                        GKEY_RIGHT = false; 
                    } 
                    if(x < 0) 
                    { 
                        x = 0; 
                        GKEY_LEFT = false; 
                    } 
                    if(y > h && objects.mainEnterMode < objects.memTime - 9) 
                    { 
                        y = h; 
                        GKEY_DOWN = false; 
                    } 
                    if(y < 0) 
                    { 
                        y = 0; 
                        GKEY_UP = false; 
                    } 
                } 
                repaint(); 
                serviceRepaints(); 
            } 
        } while(true); 
        try 
        { 
            d.setCurrent(null); 
            sp.destroyApp(false); 
            sp.notifyDestroyed(); 
        } 
        catch(Exception exception) { } 
    } 
 
    public void unPause() 
    { 
        justUpdated = true; 
        pause = false; 
    } 
 
    public void pause() 
    { 
        pause = true; 
    } 
 
    public void stop() 
    { 
        hiscoreTable.close(); 
        musik.close(); 
        objects = null; 
        kamera = null; 
        bkg = null; 
        adder = null; 
        System.gc(); 
    } 
 
}