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

📄 landscape.java

📁 thq 发布的《worms》 motorola 源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Landscape
{

    public static final int SNOW = 0;
    public static final int DESERT = 1;
    public static final int GRASS = 2;
    public static final int ROCK = 3;
    public static int type;
    public static final int width = 300;
    public static final int height = 150;
    public static int levelX;
    public static int levelY;
    private static int levX;
    private static int levY;
    public Image landImage;
    public Graphics landGraphics;
    public int heightMap[];
    private Random random;
    public int pixel_heightMap[][];
    public int collision_heightMap[][];
    private Team teams[];
    public static Imp texture[] = new Imp[4];
    public static Imp entities[] = new Imp[4];
    public static int currentLandscapeIndex;
    private int curFrame;
    public static short landscapeThemeColour = 1470;
    private int xList[];
    int x_loop;
    int impact_height;
    int circle_x[];
    int circle_y[];
    int circle_p[];
    boolean circle_init[];
    boolean circle_complete[];

    public Landscape()
    {
        curFrame = 0;
        xList = new int[4];
        circle_x = new int[5];
        circle_y = new int[5];
        circle_p = new int[5];
        circle_init = new boolean[5];
        circle_complete = new boolean[5];
        circle_complete[0] = true;
        circle_complete[1] = true;
        circle_complete[2] = true;
        circle_complete[3] = true;
        circle_complete[4] = true;
        landImage = Image.createImage(300, 150);
        landGraphics = landImage.getGraphics();
        random = new Random(Worms.getTime());
        heightMap = new int[300];
        pixel_heightMap = new int[300][4];
        collision_heightMap = new int[300][4];
    }

    private void buildLandscape(int i, int j)
    {
        if(Math.abs(i - j) <= 1)
            return;
        int k = Math.abs(i - j);
        int l = (Math.abs(random.nextInt()) % 100) * k * 100 - 200;
        int i1 = (heightMap[i] + heightMap[j]) / 2 + l / 100;
        if(i1 > 35200 && l > 0)
            l = -l;
        i1 = (heightMap[i] + heightMap[j]) / 2 + l / 100;
        heightMap[(i + j) / 2] = i1;
        buildLandscape(i, (i + j) / 2);
        buildLandscape(j, (i + j) / 2);
    }

    private void placeEntity(int i, int j)
    {
        if(i >= 165)
            return;
        int k = entities[currentLandscapeIndex].width;
        int l = entities[currentLandscapeIndex].height;
        int i1 = heightMap[i + k] - heightMap[i];
        for(int j1 = i; j1 < i + k; j1++)
            heightMap[j1] = heightMap[i];

        for(int k1 = i + k; k1 < 300; k1++)
            heightMap[k1] -= i1;

    }

    public void drawEntity(int i, int j, Imp imp, int k, boolean flag)
    {
        if(i >= 165 && flag)
        {
            return;
        } else
        {
            imp.setPosition(i, j - imp.height);
            imp.paint(landGraphics);
            return;
        }
    }

    public void generate(Team ateam[])
    {
        teams = ateam;
        for(int i = 0; i < 150; i += texture[currentLandscapeIndex].height)
        {
            for(int j = 0; j < 300; j += texture[currentLandscapeIndex].width)
            {
                texture[currentLandscapeIndex].setPosition(j, i);
                texture[currentLandscapeIndex].paint(landGraphics);
            }

        }

        buildLandscape(0, heightMap.length - 1);
        boolean flag = false;
        boolean flag1 = false;
        for(int k = 0; k < heightMap.length - 1; k++)
            heightMap[k] >>= 9;

        for(int l = 0; l < heightMap.length - 1; l++)
        {
            if(heightMap[l] < 15)
                heightMap[l] = 15;
            if(heightMap[l] > 150 - entities[currentLandscapeIndex].height - 2)
                heightMap[l] = 150 - entities[currentLandscapeIndex].height - 2;
        }

        int i1 = heightMap[30];
        int j1 = (i1 << 8) / 30;
        for(int k1 = 0; k1 < 30; k1++)
            heightMap[k1] = (j1 * k1 >> 8) + (Math.abs(random.nextInt()) % 4 - 2);

        i1 = heightMap[heightMap.length - 30];
        j1 = (i1 << 8) / 30;
        for(int l1 = 0; l1 < 30; l1++)
            heightMap[heightMap.length - l1 - 1] = (j1 * l1 >> 8) + (Math.abs(random.nextInt()) % 4 - 2);

        for(int i2 = 0; i2 < 300; i2++)
            heightMap[i2] += 4;

        xList[0] = (Math.abs(random.nextInt()) % 300) / 2 + 60;
        for(int j2 = 1; j2 < xList.length; j2++)
            xList[j2] = xList[j2 - 1] + 45 + Math.abs(random.nextInt()) % 60;

        for(int k2 = 0; k2 < xList.length; k2++)
            if(xList[k2] >= 165)
                xList[k2] = 0x7fffffff;

        for(int l2 = 0; l2 < xList.length; l2++)
            placeEntity(xList[l2], 0);

        landGraphics.setColor(93, 191, 227);
        for(int i3 = 0; i3 < 300; i3++)
            landGraphics.fillRect(i3, 0, 1, 150 - heightMap[i3]);

        for(int j3 = 0; j3 < 299; j3++)
        {
            landGraphics.setColor(0, 0, 0);
            landGraphics.fillRect(j3, 149 - heightMap[j3], 1, 1);
            switch(currentLandscapeIndex)
            {
            case 0: // '\0'
                landGraphics.setColor(148, 229, 252);
                type = 0;
                break;

            case 1: // '\001'
                landGraphics.setColor(204, 85, 0);
                type = 1;
                break;

            case 2: // '\002'
                landGraphics.setColor(190, 190, 206);
                type = 3;
                break;

            case 3: // '\003'
                landGraphics.setColor(74, 156, 0);
                type = 2;
                break;
            }
            landGraphics.fillRect(j3, (149 - heightMap[j3]) + 1, 1, 4);
        }

        generate_pixelMap();
        generate_collisionMap();
        for(int k3 = 0; k3 < xList.length; k3++)
            if(xList[k3] < heightMap.length)
                try
                {
                    drawEntity(xList[k3], 149 - heightMap[xList[k3]], entities[currentLandscapeIndex], 0, true);
                    if(currentLandscapeIndex == 0)
                    {
                        add_boundingRectangle(xList[k3], heightMap[xList[k3]], 12, 12);
                        add_boundingRectangle(xList[k3] + 12, heightMap[xList[k3]], 24, 48);
                        add_boundingRectangle(xList[k3] + 36, heightMap[xList[k3]] + 24, 12, 12);
                    } else
                    if(currentLandscapeIndex == 1)
                    {
                        add_boundingRectangle(xList[k3], heightMap[xList[k3]] + 16, 16, 32);
                        add_boundingRectangle(xList[k3] + 16, heightMap[xList[k3]], 16, 48);
                        add_boundingRectangle(xList[k3] + 32, heightMap[xList[k3]] + 16, 16, 32);
                    } else
                    {
                        add_boundingRectangle(xList[k3], heightMap[xList[k3]], 8, 20);
                        add_boundingRectangle(xList[k3] + 8, heightMap[xList[k3]], 12, 40);
                        add_boundingRectangle(xList[k3] + 20, heightMap[xList[k3]], 12, 28);
                        add_boundingRectangle(xList[k3] + 32, heightMap[xList[k3]], 11, 34);
                    }
                }
                catch(Exception exception) { }

    }

    public int getLandHeight(int i)
    {
        if(i < 0)
            i = 0;
        if(i >= 150)
            i = 149;
        return heightMap[i];
    }

    public void center(int i, int j)
    {
        levY = j - Game.screenHeight / 2;
        if(levY > 10 - (Game.screenHeight - 150))
            levY = 10 - (Game.screenHeight - 150);
        levX = i - Game.screenWidth / 2;
        if(levX < -30)
            levX = -30;
        if(levX > (300 - Game.screenWidth) + 30)
            levX = (300 - Game.screenWidth) + 30;
        levX = -levX;
        levY = -levY;
    }

    public void assignCenter()
    {
        levelX = levX;
        levelY = levY;
    }

    public boolean earthCollision(int i, int j, boolean flag, Worm worm)
    {
        if(i < 0 || i >= 300 || j < 0 || j >= 150)
            return false;
        if(test_collisionMap(i, 150 - j) == 1)
            return true;
        if(flag)
        {
            for(int k = 0; k < teams.length; k++)
            {
                for(int l = 0; l < teams[k].wormList.length; l++)
                {
                    Worm worm1 = teams[k].wormList[l];
                    if(worm1 != worm)
                    {
                        worm1.getClass();
                        if(worm1.state != 8)
                        {
                            Worm _tmp = worm1;
                            int i1 = Worm.walk.getWidth();
                            Worm _tmp1 = worm1;
                            int j1 = Worm.walk.getHeight();
                            int k1 = worm1.positionX - (i1 >> 1);
                            int l1 = worm1.positionY - (j1 >> 1);
                            if(i >= k1 && i - k1 < i1 && j >= l1 && j - l1 < j1)
                                return true;
                        }
                    }
                }

            }

        }
        return false;
    }

    private int test_pixelMap(int i, int j)
    {
        int k = 0;
        if(j > 127)
            k = 0;
        else
        if(j > 95)
            k = pixel_heightMap[i][3] >> j - 96 & 0x1;
        else
        if(j > 63)
            k = pixel_heightMap[i][2] >> j - 64 & 0x1;
        else
        if(j > 31)
            k = pixel_heightMap[i][1] >> j - 32 & 0x1;
        else
            k = pixel_heightMap[i][0] >> j & 0x1;
        return k;
    }

    public int get_currentHeight(int i, int j)
    {
        j = 150 - j;
        int k = j;
        if(test_collisionMap(i, j) == 0)
            for(; test_collisionMap(i, k) == 0 && k > 0; k--);
        else
            for(; test_collisionMap(i, k) == 1 && k < 127; k++);
        return k;
    }

    private int test_collisionMap(int i, int j)
    {
        int k = 0;
        if(j > 127)
            k = 0;
        else
        if(j > 95)
            k = collision_heightMap[i][3] >> j - 96 & 0x1;
        else
        if(j > 63)
            k = collision_heightMap[i][2] >> j - 64 & 0x1;
        else
        if(j > 31)
            k = collision_heightMap[i][1] >> j - 32 & 0x1;
        else
            k = collision_heightMap[i][0] >> j & 0x1;
        return k;
    }

⌨️ 快捷键说明

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