C++我的世界

制作中会有卡顿但也能玩。

#include <iostream>
#include <conio.h>
#include <string>
#include <map>
#include <cmath>
#include <windows.h>
#include <time.h> 
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int fallspeed;
int jumpspeed = -3;
int gravity = 1;
int y = 400, x = 500;
int restartposy, restartposx, face, health = 1000, lasthealth = 1000, breath = 100, hungry = 1000, dienum;
bool attack, defense, hurt, mode;
struct TNT
{
    int y;
    int x;
    int time;
    bool issave;
};
struct BLOCK
{
    int color;
    string ch;
    string type;
};
struct MOB
{
    int fallspeed;
    int health;
    bool hurt;
    int y;
    int x;
    int attack;
    string shap;
    bool isenemy;
    int color;
    string name;
};
struct ARROW
{
    string shap;
    double y;
    double x;
    double fallspeed;
    double plusx;
};
TNT tnt[20];
string die;
ARROW arrow[100];
MOB mobs[50] = {
    {0,1000,0,0,0,100,"危",true,7,"危"},
    {0,10,0,0,0,10,"  ",true,7,"  "},
    {0,1000,0,0,0,100,"MM",false,7,"MM"},
    {0,100000,0,90,70,-100,"AC",true,7,"Accept"},
    {0,10000,0,90,70,500,"BO",true,7,"BOSS"},
    {0,100000,0,90,70,-1000,"AK",true,7,"AK"},
};
MOB mob[100] = {
    {0,1000,0,92,4,100,"WA",true,7,"Wrong Anwser"},
    {0,1000,0,92,4,100,"TL",true,7,"Time Limit Error"},
    {0,2000,0,92,4,300,"CE",true,7,"Compile Error"},
    {0,1000,0,45,9,100,"WA",true,7,"Wrong Anwser"},
    {0,100000,0,90,70,-100,"AC",true,7,"Accept"},
    {0,100000,0,90,70,-1000,"AK",true,7,"AK"},
    {0,10000,0,90,70,500,"UK",true,7,"Unknown Error"},
    {0,1000,0,92,3,0,"MM",false,7,"MM"},
    {0,1000,0,92,3,0,"MM",false,7,"MM"},
    {0,1000,0,90,15,0,"MM",false,7,"MM"},
    {0,1000,0,90,80,0,"MM",false,7,"MM"},
};
BLOCK block[32] = {
    {0,"  ","air"},
    {6,"██","block"},
    {8,"██","block"},
    {2,"██","block"}, 
    {15,"██","block"}, 
    {4,"██","block"},
    {14,"▓▓","fallblock"},
    {8,"II","fallblock"},
    {9,"██","water"},
    {9,"▇▇","water"},
    {9,"▆▆","water"},
    {9,"▅▅","water"},
    {9,"▄▄","water"},
    {9,"▃▃","water"},
    {9,"▂▂","water"},
    {9,"▁▁","water"},
    {12,"██","lava"},
    {12,"▇▇","lava"},
    {12,"▆▆","lava"},
    {12,"▅▅","lava"},
    {12,"▄▄","lava"},
    {12,"▃▃","lava"},
    {12,"▂▂","lava"},
    {12,"▁▁","lava"},
    {12,"危","background"},
    {6,"██","background"},
    {10,"▓▓","background"},
    {15,"▓▓","background"},
    {15,"▅▅","bomb"},
    {12,"Ⅲ","TNT"}
    {7,"Ⅲ","TNT"},
    {6,"∷","ladder"},
};
int board[1005][1005];
int setboard[1005][1005];
int bag[100];
int clear_buffer()
{
    while(kbhit())
    {
        if(getch() != EOF); 
        for(int i = 1; i <= 256; i++)
        {
            if(GetAsyncKeyState(i));
        }
    }
    return 0;
}
void color(int a)
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);

}
int init()
{
    for(int j = 0; j < 100; j++)
    {
        bag[j] = 0;
    }
    for(int i = 0; i < 1000; i++)
    {
        for(int j = 0; j < 1000; j++)
        {
            board[i][j] = 0;
        }
    } 
    double lasty = rand() % 101 + 400;
    for(int i = 5; i < 1000; i += 5)
    {
        double y = rand() % 21 - 10 + lasty;
        y = min(450.0, y);
        double high = lasty;
        int dirt = rand() % 5 + 2; 
        for(int j = i - 5; j < i; j++)
        {
            high += (y - lasty) / 5; 
            for(int k = 999; k >= (int)high; k--)
            {
                if(k == (int)high) 
                {
                    setboard[k][j] = 3; 
                    if(high <= 350) 
                    {
                        setboard[k][j] = 4; 
                    }
                }
                else if(k - dirt <= (int)high) 
                {
                    setboard[k][j] = 1;
                }
                else 
                {
                    setboard[k][j] = 2; 
                }
            }
        }
        lasty = y;
    }
    int dirt = rand() % 5 + 2;
    double high = lasty;
    for(int j = 995; j < 999; j++)
    {
        for(int k = 999; k >= (int)high; k--)
        {
            if(k == (int)high)
            {
                setboard[k][j] = 3;
                if(high <= 350)
                {
                    setboard[k][j] = 4;
                }
            }
            else if(k - dirt <= (int)high)
            {
                setboard[k][j] = 1;
            }
            else 
            {
                setboard[k][j] = 2;
            }
        }
    }
    for(int i = 0; i < 1000; i++)
    {
        for(int j = 600; j >= 410; j--)
        {
            if(setboard[j][i] == 0)
            {
                setboard[j][i] = 8;
            }
        }
    }
    for(int i = 0; i < 1000; i++)
    {
        bool a = 0;
        for(int j = 999; j >= 0; j--)
        {
            if(a && setboard[j][i] != 0  && setboard[j][i] != 8)
            {
                setboard[j][i] = 6;
                continue;
            }
            if(setboard[j][i] == 8)
            {
                continue;
            }
            if(setboard[j][i + 3] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
            if(setboard[j][i + 2] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
            if(setboard[j][i + 1] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
            if(setboard[j][i - 1] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
            if(setboard[j][i - 2] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
            if(setboard[j][i - 3] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
            if(setboard[j - 2][i] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
            if(setboard[j - 1][i] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
            if(setboard[j - 3][i] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
            if(setboard[j - 4][i] == 8)
            {
                a = true;
                setboard[j][i] = 6;
            }
        }
    }
    //树 
    for(int i = 0; i < 1000; i++)
    {
        for(int j = 0; j < 1000; j++)
        {
            if(setboard[j][i] == 0 && block[setboard[j + 1][i]].type == "block")
            {
                if(rand() % 10 == 1)
                {
                    setboard[j][i] = 25;
                    setboard[j - 1][i] = 25;
                    setboard[j - 2][i] = 25;
                    setboard[j - 3][i] = 25;
                    setboard[j - 3][i + 1] = 26;
                    setboard[j - 3][i - 1] = 26;
                    setboard[j - 4][i + 2] = 26; 
                    setboard[j - 4][i + 1] = 26;
                    setboard[j - 4][i] = 26;
                    setboard[j - 4][i - 1] = 26;
                    setboard[j - 4][i - 2] = 26;
                    setboard[j - 5][i + 2] = 26;
                    setboard[j - 5][i + 1] = 26;
                    setboard[j - 5][i] = 26;
                    setboard[j - 5][i - 1] = 26;
                    setboard[j - 5][i - 2] = 26;
                    setboard[j - 6][i + 1] = 26;
                    setboard[j - 6][i] = 26;
                    setboard[j - 6][i - 1] = 26;
                    if(j <= 350)
                    {
                        setboard[j - 3][i + 1] = 27;
              

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
你提到的关于"C"和"OpenGL"的文章是关于开发一个新版本的Minecraft游戏。这个版本与之前的版本相比有一些较大的改进, 包括无限大小且更为复杂的地形, 更好的渲染和处理速度等方面。程序的开发基于"C"和OpenGL这两个技术,开发周期大约为3天。文章的前半部分介绍了实现效果,后半部分则对部分开发细节进行了说明。 在开发过程中,使用了gluLookAt函数来定义一个视图矩阵,它可以用来设置相机在世界坐标中的位置、相机镜头对准的物体的位置以及相机向上方向的方向。通过调整相应的参数,可以实现桌子的平移操作。 为了实现无限大小地形的实时渲染,文章采用了分块渲染和存储的策略。每个块被视为一个独立的渲染单位,每个块包含16*16*256个方块(cube)。为了提高渲染效率,可以采用OpenGL的Instancing技术来实现快速渲染。在存储方面,每个块被存储为一个单独的文件,并按照方块的坐标顺序存储每个方块的类型。 总的来说,这篇文章探讨了使用C和OpenGL开发一个新版本Minecraft的过程,介绍了一些实现效果和开发细节。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [[OpenGL]使用C++开发无限地形的Minecraft(我的世界 第二版)](https://blog.csdn.net/Mahabharata_/article/details/88079736)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [基于C++OpenGL实现的小桌茶壶图形绘制](https://blog.csdn.net/sheziqiong/article/details/125257824)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值