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

📄 seafox.java

📁 经典的潜艇打商船游戏
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        if(m_bPlayFireTorpedo) {
            m_acFireTorpedo.play();
            m_bPlayFireTorpedo = false;
        }
        if(m_bPlayOutOfTorpedoes) {
            m_acOutOfTorpedoes.play();
            m_bPlayOutOfTorpedoes = false;
        }
        if(m_bPlayClank) {
            m_acClank.play();
            m_bPlayClank = false;
        }
        if(m_bPlaySupplies) {
            m_acSupplies.play();
            m_bPlaySupplies = false;
        }
        if(m_bPlaySplash) {
            m_acSplash.play();
            m_bPlaySplash = false;
        }
        if(m_bPlayShark) {
            m_acShark.play();
            m_bPlayShark = false;
        }
    }

}
                                 


class CapitalShip {

    public static final int SHIPS = 10;
    public static final int SHIP_IMAGES = 4;
    public static final int WAKE_IMAGES = 4;
    public static final int BLAST_IMAGES = 4;
    public static final int SINK_IMAGES = 4;
    public static final int BLAST_TIME = 500;
    public static final int SINK_TIME = 999;
    public static final int SCORE_TIME = 999;
    public static final int Y_WATERLINE = 22;
    public static final int X_MARGIN = 40;
    public static final double VELOCITY = 20D;
    public static int m_nXspacing;
    public static int m_nShipsSunk;
    public static long m_lStartTime;
    public static double m_dXoriginStart;
    public static double m_dXoriginNow;
    public static int m_nWakeWidth;
    public static int m_nWakeHeight;
    public static Image m_imageShip[] = new Image[4];
    public static Image m_imageWake[] = new Image[4];
    public static Image m_imageBlast[] = new Image[4];
    public static Image m_imageSink[] = new Image[4];
    public boolean m_bSinkable;
    double m_dXoffset;
    int m_ndxImage;
    static final int NORMAL = 0;
    static final int SINKING = 1;
    static final int SUNK = 2;
    int m_nStatus;
    int m_nPoints;
    int m_nXcenter;
    int m_nX;
    int m_nY;
    long m_lTimeHit;

    public void Draw(Graphics g) {
        m_bSinkable = false;
        if(m_nStatus == 2)
            return;
        if(m_nStatus == 0) {
            double d = m_dXoffset + m_dXoriginNow;
            m_nXcenter = (int)(d + 0.5D);
            if(m_nXcenter > 0)
                m_nXcenter %= m_nXspacing * 10;
            if(m_nXcenter > Seafox.m_nPlayfieldWidth + 40)
                m_nXcenter -= m_nXspacing * 10;
            if(m_nXcenter < -40)
                return;
        }
        if(m_nStatus == 1 && (int)(Seafox.m_lLatestTime - m_lTimeHit) > 2498) {
            m_nStatus = 2;
            return;
        }
        if(m_nStatus == 0 || m_nStatus == 1 && (int)(Seafox.m_lLatestTime - m_lTimeHit) < 500) {
            Image image = m_imageShip[m_ndxImage];
            m_nX = m_nXcenter - image.getWidth(null) / 2;
            m_nY = 22 - image.getHeight(null);
            if(m_nStatus == 0) {
                int j = (m_nX - m_nWakeWidth) + 5;
                int i1 = (22 - m_nWakeHeight) + 1;
                Image image2 = m_imageWake[(Seafox.m_random.nextInt() & 0x7fffffff) % 4];
                g.drawImage(image2, j, i1, null);
            }
            g.drawImage(image, m_nX, m_nY, null);
        }
        if(m_nStatus == 0) {
            m_bSinkable = true;
            return;
        }
        int i = (int)(Seafox.m_lLatestTime - m_lTimeHit);
        if(i <= 500) {
            int k = m_nXcenter - 20;
            int j1 = 0;
            Image image3 = m_imageBlast[(Seafox.m_random.nextInt() & 0x7fffffff) % 4];
            g.drawImage(image3, k, j1, null);
            return;
        }
        if(i <= 1499) {
            int l = (i - 500) / 249;
            Image image1 = m_imageSink[l];
            int l1 = m_nXcenter - image1.getWidth(null) / 2;
            int i2 = 22 - image1.getHeight(null);
            g.drawImage(image1, l1, i2, null);
            return;
        }
        g.setFont(Seafox.m_fontScorePopup);
        g.setColor(Color.yellow);
        String s = new String("" + m_nPoints);
        int k1 = m_nXcenter - 20;
        if(m_nPoints >= 1000)
            k1 -= 7;
        g.drawString(s, k1, 22);
    }

    public boolean CollisionAnalysis(double d, double d1) {
        if(m_bSinkable && d1 <= 22D && d1 >= 12D) {
            int i = m_imageShip[m_ndxImage].getWidth(null) / 2 - 5;
            if((int)d >= m_nXcenter - i && (int)d <= m_nXcenter + i) {
                m_nStatus = 1;
                m_lTimeHit = Seafox.m_lLatestTime;
                m_nShipsSunk++;
                m_nPoints = (Seafox.m_nMission - 1) * 1000 + m_nShipsSunk * 100;
                Seafox.m_nScore += m_nPoints;
                Seafox.m_bPlayBigExplosion = true;
                if(m_nShipsSunk == 10)
                    Seafox.m_player.MissionComplete();
                return true;
            }
        }
        return false;
    }

    CapitalShip() {
    }

}                                  




class DepthCharge {

    public static final int BLAST_IMAGES = 4;
    public static final int BLAST_DURATION = 500;
    public static Image m_imageBlast[] = new Image[4];
    public static final int SPLASH_IMAGES = 4;
    static final int SPLASH_DURATION = 500;
    public static Image m_imageSplash[] = new Image[4];
    public static final int MAX_CHARGES = 3;
    public static int m_nChargeLimit;
    public static int m_nActiveCharges;
    static final int MIN_LAUNCH_INTERVAL = 6000;
    static final int MAX_LAUNCH_INTERVAL = 8000;
    static final Color COLOR = new Color(255, 128, 0);
    static final double LAUNCH_X = 35D;
    static final double LAUNCH_Y = 8D;
    static final double LAUNCH_DISTANCE = 25D;
    static final double LAUNCH_VELOCITY = 20D;
    static final int LAUNCH_SIZE = 2;
    static final double FALL_Y_ACCELERATION = 30D;
    static final double MAX_X_VELOCITY = 6D;
    static final double Y_VELOCITY = 20D;
    static final double MAX_TUMBLE_RATE = 4D;
    static final double MAJOR_AXIS = 8D;
    static final double MINOR_AXIS = 4D;
    static final double MIN_BLAST_RADIUS = 10D;
    static final double MAX_BLAST_RADIUS = 25D;
    public int m_nStatus;
    public static final int INACTIVE = 0;
    public static final int LAUNCHING = 1;
    static final int FALLING = 2;
    static final int TUMBLING = 3;
    static final int EXPLODING = 4;
    long m_lTimeStatusUpdated;
    double m_dYdetonate;
    public Destroyer m_destroyer;
    double m_dX0;
    double m_dY0;
    double m_dX;
    double m_dY;
    double m_dTumbleRate;
    double m_dXvelocity;
    double m_dAngle0;
    double m_dAngle;

    public void Draw(Graphics g) {
        if(m_nStatus == 0)
            return;
        if(m_nStatus == 1 || m_nStatus == 2) {
            g.setColor(COLOR);
            g.fillRect((int)m_dX, (int)m_dY, 2, 2);
            return;
        }
        if(m_nStatus == 3) {
            int ai[] = new int[4];
            int ai1[] = new int[4];
            double d = Math.cos(m_dAngle);
            double d1 = Math.sin(m_dAngle);
            ai[0] = (int)(4D * d + 2D * d1 + m_dX + 0.5D);
            ai1[0] = (int)((4D * d1 - 2D * d) + m_dY + 0.5D);
            ai[1] = (int)((4D * d - 2D * d1) + m_dX + 0.5D);
            ai1[1] = (int)(4D * d1 + 2D * d + m_dY + 0.5D);
            ai[2] = (int)((-4D * d - 2D * d1) + m_dX + 0.5D);
            ai1[2] = (int)(-4D * d1 + 2D * d + m_dY + 0.5D);
            ai[3] = (int)(-4D * d + 2D * d1 + m_dX + 0.5D);
            ai1[3] = (int)((-4D * d1 - 2D * d) + m_dY + 0.5D);
            g.setColor(COLOR);
            g.fillPolygon(ai, ai1, 4);
            if(Seafox.m_lLatestTime - m_lTimeStatusUpdated < 500L) {
                Image image1 = m_imageSplash[((int)(Seafox.m_lLatestTime - m_lTimeStatusUpdated) * 4) / 500];
                int k = (int)m_dX - image1.getWidth(null) / 2;
                int l = 58 - image1.getHeight(null);
                g.drawImage(image1, k, l, null);
            }
            return;
        }
        if(m_nStatus == 4) {
            Image image = m_imageBlast[((int)(Seafox.m_lLatestTime - m_lTimeStatusUpdated) * 4) / 500];
            int i = (int)m_dX - image.getWidth(null) / 2;
            int j = (int)m_dY - image.getHeight(null) / 2;
            g.drawImage(image, i, j, null);
            return;
        } else {
            return;
        }
    }

    public void Launch(Destroyer destroyer) {
        m_nStatus = 1;
        m_lTimeStatusUpdated = Seafox.m_lLatestTime;
        m_destroyer = destroyer;
        m_dX = destroyer.m_dX + 35D;
        m_dY = destroyer.m_dY + 8D;
        m_dYdetonate = Player.m_dY + Player.m_dSubHeight / 2D;
        m_nActiveCharges++;
    }

    public boolean CollisionAnalysis(double d, double d1, double d2, double d3) {
        if(m_nStatus == 4) {
            double d4 = 10D + (15D * (double)(Seafox.m_lLatestTime - m_lTimeStatusUpdated)) / 500D;
            if(d2 > m_dX - d4 && d < m_dX + d4 && d3 > m_dY - d4 && d1 < m_dY + d4) {
                double d5 = 0.0D;
                if(Math.abs(m_dY - d3) < Math.abs(m_dY - d1))
                    d5 = Math.abs(m_dY - d3);
                else
                    d5 = Math.abs(m_dY - d1);
                double d6 = Math.acos(d5 / d4);
                double d7 = Math.abs(d4 * Math.sin(d6));
                if(d2 >= m_dX - d7 && d <= m_dX + d7)
                    return true;
            }
        }
        return false;
    }

    public boolean CollisionAnalysis(double d, double d1, double d2) {
        if(m_nStatus == 3) {
            double d3 = 3D;
            double d4 = Math.abs((m_dX + d3) - d);
            double d5 = Math.abs((m_dY + d3) - d1);
            double d6 = d2 + d3;
            if(d4 <= d6 && d5 <= d6 && Math.sqrt(d4 * d4 + d5 * d5) <= d6) {
                Detonate();
                return true;
            }
        }
        return false;
    }

    DepthCharge() {
    }

    public void Update() {
        if(m_nStatus == 0)
            return;
        if(m_nStatus == 1) {
            double d = (20D * (double)(Seafox.m_lLatestTime - m_lTimeStatusUpdated)) / 1000D;
            m_dX = m_destroyer.m_dX + d + 35D;
            if(d >= 25D) {
                m_nStatus = 2;
                m_lTimeStatusUpdated = Seafox.m_lLatestTime;
                m_dX0 = m_dX;
                m_dY0 = m_dY;
            }
            return;
        }
        if(m_nStatus == 2) {
            double d1 = (double)(Seafox.m_lLatestTime - m_lTimeStatusUpdated) / 1000D;
            m_dX = m_dX0 + (20D + m_destroyer.m_dVelocity) * d1;
            m_dY = m_dY0 + 15D * d1;
            if(m_dY >= 55D) {
                m_nStatus = 3;
                m_lTimeStatusUpdated = Seafox.m_lLatestTime;
                m_dX0 = m_dX;
                m_dY0 = m_dY;
                m_dAngle0 = 3.1415926536000001D * Seafox.m_random.nextDouble();
                m_dTumbleRate = 2D * (Seafox.m_random.nextDouble() - 0.5D) * 4D;
                m_dXvelocity = 2D * (Seafox.m_random.nextDouble() - 0.5D) * 6D;
                Seafox.m_bPlaySplash = true;
            }
            return;
        }
        if(m_nStatus == 3) {
            double d2 = (double)(Seafox.m_lLatestTime - m_lTimeStatusUpdated) / 1000D;
            m_dX = m_dX0 + m_dXvelocity * d2;
            m_dY = m_dY0 + 20D * d2;
            m_dAngle = m_dAngle0 + m_dTumbleRate * d2;
            if(m_dY >= m_dYdetonate)
                Detonate();
            return;
        }
        if(m_nStatus == 4) {
            if(Seafox.m_lLatestTime - m_lTimeStatusUpdated >= 500L) {
                m_nStatus = 0;
                m_lTimeStatusUpdated = Seafox.m_lLatestTime;
                m_nActiveCharges--;
                return;

⌨️ 快捷键说明

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