C++ 后室·无限#1 游戏制作实录(RPG类型游戏)

博主分享了使用C++制作后室主题RPG游戏的过程,重点讲述了基础结构、循环及Level 0教学关卡的搭建。通过TXT文件加载地图,利用随机函数简化工作,并引入了视界范围设定和退出功能。文章末尾呼吁读者支持。
摘要由CSDN通过智能技术生成

版本号:1.0

嗨,我是一块铌金属

自从上次的字符酷跑以后,我还是觉得不过瘾,边想着开个新坑吧。我正想着做什么游戏呢,打开我的谷歌浏览器,看到收藏里的网址:

这是??后室!

于是乎,闲着没事的我开始决定,制作一个后室游戏!

这期,我们会把基础结构和循环搞定,然后还有第一关:

 首先,搭建我们的基础结构。

很快就建好了,毕竟我们已经做过一个了。

#include <bits/stdc++.h>
#include <conio.h>
#include <windows.h>

using namespace std;

int mp[105][105];

void Clear_Screen() {    
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = {0, 0};
    SetConsoleCursorPosition(hConsole, coordScreen);
}

void color(int m) {
	HANDLE consolehend;
	consolehend = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(consolehend, m);
}

int main() {
	char c;
	while (1) {
		Clear_Screen();
	}
	return 0;
}

你问我为什么没做地图?

因为,后室的层级,仅 wikidot 的后室主层级,就已经有999层了,更别提还有隐秘层级,子层级,再加上 fandom 的不同,差不多就1000多了,这如果直接一个一个判断,那不累死我啊?

所以,我们使用txt文件,把地图载入,至少不会太累(虽然码地图很累,但是值了!所以你怎么还不三联?)

我们先把 Level 0 的地图做出来。

码是不可能我码滴,有随机函数,我怕个啥?

#include <bits/stdc++.h>
#include <conio.h>
#include <windows.h>

using namespace std;

char mp[45][45];
int diffculeClass;
int flourColor;
int wallColor;
string level = "0";

void color(int m) {
	HANDLE consolehend;
	consolehend = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(consolehend, m);
}

void Clear_Screen() {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = {0, 0};
    SetConsoleCursorPosition(hConsole, coordScreen);
}

void print(char c) {
	switch (c) {
		case '0':
			color(flourColor);
			printf("  ");
			break;
		case '1':
			color(wallColor);
			printf("■");
			break;
	}
}

void newMap() {
	string s = "D:/dev-c++/游戏/Backrooms/" + level + ".txt";
	char address[20];
	int len = s.size();
	for (int i = 0; i < len; i++) {
		address[i] = s[i];
	}
	freopen(address, "r", stdin);
	scanf("%d%d%d", &diffculeClass, &flourColor, &wallColor);
	cout << diffculeClass << " " << flourColor << " " << wallColor << endl;
	for (int i = 0; i < 40; i++) {
		cin >> mp[i];
	}
}

int main() {
	char c;
	newMap();
	while (1) {
		Clear_Screen();
		for (int i = 0; i < 40; i++) {
			for (int j = 0; j < 40; j++) {
				print(mp[i][j]);
			}
			color(0xF);
			printf("\n");
		}
	}
	return 0;
}

这样就是了(注意,我以后做完会以 rar 文件打包,请务必把 newMap 函数里的 freopen 的地址改为各位看完文章又不给三联的白嫖怪自己的地址,否则可能会报错)

移动模块之前的已经写过了,直接套用再改一改就好了

#include <bits/stdc++.h>
#include <conio.h>
#include <windows.h>

using namespace std;

int x, y;
char mp[45][45];
int diffculeClass, flourColor, wallColor, peopleColor;
int canSeeCircle = 5;
string level = "0";

void color(int m) {
	HANDLE consolehend;
	consolehend = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(consolehend, m);
}

void Clear_Screen() {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = {0, 0};
    SetConsoleCursorPosition(hConsole, coordScreen);
}

void print(char c) {
	switch (c) {
		case '0':
			color(flourColor);
			printf("  ");
			break;
		case '1':
			color(wallColor);
			printf("■");
			break;
		case '2':
			color(peopleColor); 
			printf("♀");
			break;
	}
}

void newMap() {
	string s = "D:/programming/dev-c++/游戏/Backrooms/" + level + ".txt";
	char address[50];
	int len = s.size();
	for (int i = 0; i < len; i++) {
		address[i] = s[i];
	}
	freopen(address, "r", stdin);
	scanf("%d%d%d%d", &diffculeClass, &flourColor, &wallColor, &peopleColor);
	for (int i = 0; i < 43; i++) {
		cin >> mp[i];
	}
}

void check(int adx, int ady) {
	if (mp[x + adx][y + ady] != '1') {
		mp[x][y] = '0';
		x = x + adx;
		y = y + ady;
		mp[x][y] = '2';
	}
} 

int main() {
	SetConsoleTitle("Backrooms         制作:一块铌金属");
	system("mode con cols=90 lines=50");
	char c;
	newMap();
	srand(time(0));
	x = rand() % 42;
	y = rand() % 42;
	while (mp[x][y] == '1') {
		x = rand() % 42;
		y = rand() % 42;
	}
	mp[x][y] = '2';
	while (1) {
		c = _getch();
		if (c == 'w') {
			check(-1, 0);
		} else if (c == 's') {
			check(1, 0);
		} else if (c == 'a') {
			check(0, -1);
		} else if (c == 'd') {
			check(0, 1);
		}
		Clear_Screen();
		for (int i = x - canSeeCircle; i < x + canSeeCircle + 1; i++) {
			for (int j = y - canSeeCircle; j < y + canSeeCircle + 1; j++) {
				if ((x - i) * (x - i) + (y - j) * (y - j) <= canSeeCircle * canSeeCircle && i >= 0 && i < 42 && j >= 0 && j < 42) {
					print(mp[i][j]);
				} else {
					color(0xF);
					printf("  ");
				}
			}
			printf("\n");
		}
	}
	return 0;
}

不仅如此,我还增加了一个视界范围的设定,就是这样:

退出功能也实现了

尾声

这篇文章也是写了很久才发布,其中有许多的bug,比如穿模啊,其他的什么:

 所以,创作不易,还请给个三联!

  • 12
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值