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

📄 spritepingu.java

📁 j2me_nokia_flash打企鹅手机版
💻 JAVA
字号:
import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

// Referenced classes of package ys.pingu:
//            PinguSprite, PinguMIDlet, PinguCanvas, SpriteYeti

class SpritePingu extends PinguSprite
{

    public static boolean PITCH_FAILED = true;
    public static boolean ON_EDGE = false;
    public static int LANDING_POSX = 0;
    public boolean valid;
    private static final int ANCHOR_IMG = 20;
    private final int PINGU_STICK = 0;
    private final int PINGU_SLIDE = 1;
    private final int PINGU_FLY = 2;
    private boolean hitCountActive;
    private int hitCount;
    private int movingMode;
    private int actJump;
    private int actDance;
    private Image dance0;
    private Image dance3;
    private Image dance4;
    private Image jump;
    private Image fly0;
    private Image flyuplow;
    private Image flyupnorm;
    private Image flyuphigh;
    private Image flydownlow;
    private Image flydownnorm;
    private Image flydownhigh;
    private Image stick;
    private boolean onEdge;
    private Random rand;
    private int bounceTrack[];
    private int actBounceTrack;
    private int shadowColor;

    public SpritePingu(int i, int j, int k)
    {
        super(i, j, k);
        valid = false;
        hitCountActive = false;
        hitCount = 0;
        movingMode = 2;
        actJump = 0;
        actDance = 0;
        dance0 = null;
        dance3 = null;
        dance4 = null;
        jump = null;
        fly0 = null;
        flyuplow = null;
        flyupnorm = null;
        flyuphigh = null;
        flydownlow = null;
        flydownnorm = null;
        flydownhigh = null;
        stick = null;
        onEdge = false;
        rand = new Random(System.currentTimeMillis());
        bounceTrack = new int[20];
        actBounceTrack = -1;
        shadowColor = 0;
        dance0 = PinguMIDlet.loadImage("/dance0.png");
        dance3 = PinguMIDlet.loadImage("/dance3.png");
        dance4 = PinguMIDlet.loadImage("/dance4.png");
        jump = PinguMIDlet.loadImage("/jump.png");
        stick = PinguMIDlet.loadImage("/stick1.png");
        fly0 = PinguMIDlet.loadImage("/fly0.png");
        flyuplow = PinguMIDlet.loadImage("/flyuplow.png");
        flyupnorm = PinguMIDlet.loadImage("/flyupnorm.png");
        flyuphigh = PinguMIDlet.loadImage("/flyuphigh.png");
        flydownlow = PinguMIDlet.loadImage("/flydownlow.png");
        flydownnorm = PinguMIDlet.loadImage("/flydownnorm.png");
        flydownhigh = PinguMIDlet.loadImage("/flydownhigh.png");
        if(dance0 == null || dance3 == null || dance4 == null || jump == null || stick == null || fly0 == null || flyuplow == null || flyupnorm == null || flyuphigh == null || flydownlow == null || flydownnorm == null || flydownhigh == null)
            valid = false;
        else
            valid = true;
        init();
    }

    public void init()
    {
        spriteInit();
        LANDING_POSX = 0;
        PITCH_FAILED = true;
        ON_EDGE = false;
        actJump = 0;
        actDance = 0;
        onEdge = false;
        movingMode = 2;
        hitCount = 0;
        hitCountActive = false;
        actBounceTrack = -1;
    }

    public void draw()
    {
        accelerate(1);
        move(1);
        if(hitCountActive)
            if(hitCount < 2)
            {
                hitCount++;
            } else
            {
                hitCountActive = false;
                if(actPos_y > 38 && actPos_y < 78)
                {
                    actPos_y += rand.nextInt() % 8 - 4;
                    actPos_y = actPos_y >= 38 ? actPos_y : 39;
                    actPos_y = actPos_y <= 78 ? actPos_y : 77;
                    velocity_x = -1 * actPos_y * 1200;
                    velocity_y = -46200 - velocity_x / 2;
                    if(actPos_y < 47)
                    {
                        velocity_x = -1 * actPos_y * 1210;
                        velocity_y = -52200 - velocity_x / 2;
                        acceleration_y = 1374;
                    } else
                    {
                        velocity_y = (velocity_y * 1) / 2;
                        acceleration_y = 647;
                    }
                    PITCH_FAILED = false;
                }
            }
        if(!parked && actPos_x < 54)
        {
            actPos_x = 54;
            if(!onEdge)
            {
                ON_EDGE = true;
                onEdge = true;
                PinguCanvas.GAMESTATE = 4;
            }
        }
        if(PinguCanvas.GAMESTATE == 0)
        {
            PinguCanvas.GC.drawImage(dance0, actPos_x, actPos_y + 24, 20);
            return;
        }
        if(PinguCanvas.GAMESTATE == 1)
        {
            if(actDance < 15)
            {
                if(actDance == 13)
                    PinguCanvas.GC.drawImage(dance3, actPos_x, actPos_y + 24, 20);
                else
                if(actDance == 14)
                    PinguCanvas.GC.drawImage(dance4, actPos_x, actPos_y + 24, 20);
                else
                    PinguCanvas.GC.drawImage(dance0, actPos_x, actPos_y + 24, 20);
                actDance++;
                return;
            }
            PinguCanvas.GAMESTATE = 2;
        }
        if(PinguCanvas.GAMESTATE == 2 && parked)
        {
            velocity_y = 1000;
            acceleration_y = 250;
            parked = false;
        }
        drawFly();
    }

    public void drawFly()
    {
        if(PITCH_FAILED)
        {
            if(actPos_y < baseline)
            {
                PinguCanvas.GC.drawImage(jump, actPos_x, actPos_y + 24, 20);
                return;
            }
            movingMode = 0;
        } else
        if(SpriteYeti.YETIPOS - actPos_x > 1620 && actPos_y >= baseline && actBounceTrack == -1)
        {
            velocity_x = 0;
            velocity_y = 0;
            parked = true;
            movingMode = 0;
        } else
        if(actPos_y >= baseline && movingMode == 2)
        {
            velocity_x = (velocity_x * 8) / 10;
            velocity_y = (velocity_y * -5) / 10;
            actPos_y = baseline;
            if(actBounceTrack > 4)
            {
                movingMode = 1;
                velocity_y = 0;
                parked = true;
            } else
            {
                if(actBounceTrack < 20)
                    actBounceTrack++;
                bounceTrack[actBounceTrack] = SpriteYeti.YETIPOS + actPos_x;
            }
        }
        if(movingMode == 0)
        {
            velocity_x = 0;
            velocity_y = 0;
            parked = true;
            PinguCanvas.GC.drawImage(stick, actPos_x, actPos_y + 24, 20);
            LANDING_POSX = actPos_x;
            PinguCanvas.GAMESTATE = 5;
            return;
        }
        if(movingMode != 1)
        {
            shadowColor = 255 - actPos_y % 255 - 70;
            if(shadowColor < 0)
                shadowColor *= -1;
            if(shadowColor > 255)
                shadowColor = 255;
            if(shadowColor < 0)
                shadowColor = 0;
            PinguCanvas.GC.setColor(shadowColor, shadowColor, shadowColor);
            PinguCanvas.GC.fillArc(actPos_x + 2, baseline + 24 + 7, 22, 5, 0, 360);
            shadowColor -= 40;
            if(shadowColor < 0)
                shadowColor = 0;
            if(shadowColor > 255)
                shadowColor = 255;
            PinguCanvas.GC.setColor(shadowColor, shadowColor, shadowColor);
            PinguCanvas.GC.fillArc(actPos_x + 6, baseline + 24 + 7, 15, 3, 0, 360);
            PinguCanvas.GC.setColor(0);
            if(actBounceTrack >= 0)
                PinguCanvas.GC.drawImage(fly0, actPos_x, actPos_y + 24, 20);
            else
            if(velocity_y > 0)
            {
                if(velocity_y < 4560)
                    PinguCanvas.GC.drawImage(fly0, actPos_x, actPos_y + 24, 20);
                else
                if(velocity_y < 9120)
                    PinguCanvas.GC.drawImage(flydownlow, actPos_x, actPos_y + 24, 20);
                else
                if(velocity_y < 13680)
                    PinguCanvas.GC.drawImage(flydownnorm, actPos_x, actPos_y + 24, 20);
                else
                    PinguCanvas.GC.drawImage(flydownhigh, actPos_x, actPos_y + 24, 20);
            } else
            if(velocity_y > -4560)
                PinguCanvas.GC.drawImage(fly0, actPos_x, actPos_y + 24, 20);
            else
            if(velocity_y > -9120)
                PinguCanvas.GC.drawImage(flyuplow, actPos_x, actPos_y + 24, 20);
            else
            if(velocity_y > -13680)
                PinguCanvas.GC.drawImage(flyupnorm, actPos_x, actPos_y + 24, 20);
            else
                PinguCanvas.GC.drawImage(flyuphigh, actPos_x, actPos_y + 24, 20);
        }
        if(movingMode == 1)
        {
            velocity_x = 0;
            PinguCanvas.GC.setColor(0xc0c0c0);
            PinguCanvas.GC.fillArc(actPos_x + -13, baseline + 24 + 8, 52, 3, 270, 180);
            PinguCanvas.GC.setColor(0x353535);
            PinguCanvas.GC.fillArc(actPos_x + 2, baseline + 24 + 7, 22, 5, 0, 360);
            PinguCanvas.GC.setColor(0);
            PinguCanvas.GC.drawImage(fly0, actPos_x, actPos_y + 24, 20);
        }
        if(velocity_x == 0)
        {
            velocity_y = 0;
            parked = true;
            LANDING_POSX = actPos_x;
            PinguCanvas.GAMESTATE = 5;
        }
    }

    public void hit()
    {
        hitCountActive = true;
        hitCount = 0;
    }

    public int getVelocity_X()
    {
        return velocity_x;
    }

}

⌨️ 快捷键说明

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