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

📄 mario.java

📁 超级玛丽的源代码
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Mario.java

import java.util.Hashtable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Mario
{

    public Mario(Main main, GameFC gameFC)
    {
        w = 12;
        h = 20;
        curSkin = 3;
        dir = 1;
        skinTime = 0L;
        jumpF = 0;
        jf = false;
        deadJump = 0;
        this.main = main;
        this.gameFC = gameFC;
        Image frames = (Image)main.cache.get("mario.png");
        skins = new Image[8];
        skins[3] = main.extractFrame(frames, w, h, 0);
        skins[4] = main.extractFrame(frames, w, h, 1);
        skins[5] = main.extractFrame(frames, w, h, 2);
        skins[2] = main.flipHorizontal(skins[3]);
        skins[1] = main.flipHorizontal(skins[4]);
        skins[0] = main.flipHorizontal(skins[5]);
        skins[6] = main.extractFrame(frames, w, h, 3);
        skins[7] = main.flipHorizontal(skins[6]);
        xF = 0;
        yF = 650 - gameFC.landscape.h * 10 - h * 10;
    }

    public void paint(Graphics g)
    {
        Graphics _tmp = g;
        Graphics _tmp1 = g;
        g.drawImage(skins[curSkin], xF / 10, yF / 10, 0x10 | 4);
    }

    public void move(int where)
    {
        dir = where;
        int dxF = 0;
        long curTime = System.currentTimeMillis();
        switch(dir)
        {
        default:
            break;

        case -1: 
            if(curSkin > 2)
                curSkin = 2;
            else
            if(curTime > skinTime + 200L)
            {
                skinTime = curTime;
                curSkin--;
                if(curSkin < 0)
                    curSkin = 2;
            }
            dxF = -30;
            if(xF + dxF < 0)
                dxF = 0;
            break;

        case 1: // '\001'
            if(curSkin < 3)
                curSkin = 3;
            else
            if(curTime > skinTime + 200L)
            {
                skinTime = curTime;
                curSkin++;
                if(curSkin > 5)
                    curSkin = 3;
            }
            dxF = 30;
            break;
        }
        Landscape landscape = gameFC.landscape;
        int pos1[] = gameFC.landscape.getPosition((xF + dxF) / 10 + w / 2, yF / 10 + h / 4);
        int mi1 = pos1[0];
        int mj1 = pos1[1];
        int pos2[] = gameFC.landscape.getPosition((xF + dxF) / 10 + w / 2, (yF / 10 + h) - h / 4);
        int mi2 = pos2[0];
        int mj2 = pos2[1];
        if(!landscape.isEmpty(mi1, mj1) || !landscape.isEmpty(mi2, mj2))
            dxF = 0;
        xF += dxF;
    }

    public void jump()
    {
        if(!jf)
            jumpF = 230;
    }

    public void idle()
    {
        long curTime = System.currentTimeMillis();
        if(curTime > skinTime + 200L)
            switch(dir)
            {
            case -1: 
                curSkin = 2;
                break;

            case 1: // '\001'
                curSkin = 3;
                break;
            }
        if(jf)
            switch(dir)
            {
            case -1: 
                curSkin = 1;
                break;

            case 1: // '\001'
                curSkin = 4;
                break;
            }
        Landscape landscape = gameFC.landscape;
        if(jumpF > 0)
        {
            int pos[] = gameFC.landscape.getPosition(xF / 10 + w / 2, yF / 10 - 3);
            int mi = pos[0];
            int mj = pos[1];
            if(landscape.isEmpty(mi, mj))
            {
                yF -= 30;
                jumpF -= 30;
            } else
            {
                jumpF = 0;
            }
            jf = true;
        } else
        {
            int pos[] = gameFC.landscape.getPosition(xF / 10 + w / 2, yF / 10 + h);
            int mi = pos[0];
            int mj = pos[1];
            if(landscape.isEmpty(mi, mj))
            {
                yF += 30;
                jf = true;
            } else
            {
                yF = landscape.yF + (mj * landscape.h - h) * 10;
                jf = false;
            }
        }
        int sxF = 0;
        int syF = 0;
        if(xF > 480)
            sxF = xF - 480;
        if(yF + h * 10 < 0)
            syF = -650;
        if(yF + h * 10 > 650)
            syF = 650;
        landscape.scroll(-sxF, -syF);
    }

    public void dead()
    {
        long curTime = System.currentTimeMillis();
        if(curSkin < 6)
            curSkin = 6;
        if(curTime > skinTime + 100L)
        {
            curSkin++;
            if(curSkin > 7)
                curSkin = 6;
        }
    }

    private Image skins[];
    private Main main;
    private GameFC gameFC;
    public int xF;
    public int yF;
    public int w;
    public int h;
    private int curSkin;
    private int dir;
    private long skinTime;
    private int jumpF;
    private boolean jf;
    public int deadJump;
    public static final int MOVE_LEFT = -1;
    public static final int MOVE_RIGHT = 1;
}

⌨️ 快捷键说明

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