跳到正文

科技·工程

biuld your own parkour!

sky_of_stars约 17 分钟
原文
文章信息与版本

文章信息

发布
2024年6月8日
收录
2025年12月12日
更新
2026年11月9日
篇幅
约 17 分钟

版本

  1. v1当前

INTRODUTION

This is a free biulding parkour game. You can biuld your own parkour map and play it.

KEY INSTRUCTIONS

wasd to move,with two operating modes,one used to test your map and one used to edit the map.
check other stuffs in the exe.

mention\color{red}mention note\color{red}note: this game hasn’t add any saving systems yet,so don’t close it if you don’t want to lose your map!

TRANSLATION 翻译

这是一个可以自由搭建地图的跑酷游戏。

操作自己摸索,WASD移动,剩下的控制台会告诉你

CODE

C++
#include<bits/stdc++.h>
#include<windows.h>
//#include<cmd.h>
#include<conio.h>
#include<bitset>
#include<winuser.h>
//#include<thread>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
//#define SHAKE 5
using namespace std;
extern const int
BLACK=0,
DARKBLUE=1,DBLUE=1,
GREEN=2,
BLUE=3,
RED=4,
PURPLE=5,
DIRT=6,YELLOWGREY=6,
LIGHTGREY=7,LGREY=7,
GREY=8,DGREY=8,DARKGREY=8,
SKYBLUE=9,SBLUE=9,
LGREEN=10,LIGHTGREEN=10,
CANYON=11,
LRED=12,LIGHTRED=12,BRED=12,BRIGHTRED=12,
LPURPLE=13,LIGHTPURPLE=13,
LYELLOW=14,LIGHTYELLOW=14,
WHITE=15
;
typedef BOOL (WINAPI *PROCSETCONSOLEFONT)(HANDLE, DWORD);
PROCSETCONSOLEFONT SetConsoleFont;
void ResizeFont(int a)
{
	HMODULE hKernel32=GetModuleHandle("kernel32");
	SetConsoleFont=(PROCSETCONSOLEFONT)GetProcAddress(hKernel32,"SetConsoleFont");
	SetConsoleFont(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void Color(int text,int background)
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),text+background*16);
}
void BColor(int background)
{
    if(background==15)Color(0,background);
    else Color(15,background);
}
void BColor(string background)
{
	int len=background.length();
	for(int i=0;i<len;i++)
	{
		if(background[i]>96)background[i]-=32;
	}
	if(background=="BLACK")Color(15,0);
	if(background=="DARKBLUE"||background=="DBLUE")Color(15,1);
	if(background=="GREEN")Color(15,2);
	if(background=="BLUE")Color(15,3);
	if(background=="RED")Color(15,4);
	if(background=="PURPLE")Color(15,5);
	if(background=="DIRT"||background=="YELLOWGREY")Color(15,6);
	if(background=="LIGHTGREY"||background=="LGREY")Color(15,7);
	if(background=="GREY"||background=="DGREY"||background=="DARKGREY")Color(15,8);
	if(background=="SKYBLUE"||background=="SBLUE")Color(15,9);
	if(background=="LGREEN"||background=="LIGHTGREEN")Color(15,10);
	if(background=="CANYON")Color(15,11);
	if(background=="LRED"||background=="LIGHTRED"||background=="BRED"||background=="BRIGHTRED")Color(15,12);
	if(background=="LPURPLE"||background=="LIGHTPURPLE")Color(15,13);
	if(background=="LYELLOW"||background=="LIGHTYELLOW")Color(15,14);
	if(background=="WHITE")Color(0,15);
}
void cls()
{
	BColor(BLACK);
	system("cls");
}
struct CTRL
{
	void SetPointerVisual(bool visual)
	{
		//1=show     0=hide
		HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
		CONSOLE_CURSOR_INFO cci;
		GetConsoleCursorInfo(hOut,&cci);
		cci.bVisible=visual;
		SetConsoleCursorInfo(hOut,&cci);
	}
};
extern CTRL Ctrl;
struct Bas
{
	void Hi()
	{
		cout<<"Hello world!";
	}
};
extern Bas Basic;
void PrintByChar(string str,int t)
{
	int len=str.length();
	for(int i=0;i<len;i++)
	{
		Sleep(double(t/len));
		cout<<str[i];
	}
	cout<<endl;
}
struct BigNum
{
	string num;
	int length()
	{
		return num.length();
	}
	void Print()
	{
		bool m=0;
		for(int i=0;i<length();i++)
		{
			if(num[i]!='0')m=1;
			if(m)cout<<num;
		}
	}
	string operator+(const BigNum& B)
	{
		//string a=this->num;
		string b=B.num;
		return "1";
	};
};
struct TO
{
	template < typename T >
	string String( T& n )
    {
        std::ostringstream stm ;
        stm<<fixed<<setprecision(16)<<n;
        return stm.str() ;
    }
};
extern TO To;
int GetWindowPosX()
{
	RECT rect;
	HWND hwnd=GetForegroundWindow();
    GetWindowRect(hwnd,&rect);
    return rect.left;
}
int GetWindowPosY()
{
	RECT rect;
	HWND hwnd=GetForegroundWindow();
    GetWindowRect(hwnd,&rect);
    return rect.top;
}
int GetCursorPosX()
{
	POINT pt={0,0};
	GetCursorPos(&pt);
	return pt.x;
}
int GetCursorPosY()
{
	POINT pt={0,0};
	GetCursorPos(&pt);
	return pt.y;
}
int GetSubX()
{
	return GetCursorPosX()-GetWindowPosX();
}
int GetSubY()
{
	return GetCursorPosY()-GetWindowPosY();
}
void gotoxy(int x,int y)
{
	int xx=0x0b;
	HANDLE hOutput;
	COORD loc;
	loc.X=x;
	loc.Y=y;
	hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hOutput,loc);
}
const char Air=0,Floor=1,Spike=2,End=3,Spring=4,Ladder=5;
char world[101][101];
int playerX=50,playerY=50,jump=0,gamemode=0;
unsigned long long frame=1;
void clearmap(){
	for(int i=1;i<=69;i++){
		for(int j=1;j<=100;j++){
			world[i][j]=Air;
		}
	}
	for(int i=70;i<=100;i++){
		for(int j=1;j<=100;j++){
			world[i][j]=Spike;
		}
	}
}
/*void save(){
	ofstream ofs;
	ofs.open("Parkourmap.txt", ios::out);
	for(int i=1;i<100;i++){
		for(int j=1;j<100;j++){
			ofs<<world[i][j];
		}
	}
	ofs.close();
}
void load(){

}*/
void screenupdate(){
	gotoxy(0,0);
	for(int i=playerX-10;i<=playerX+10;i++){
		for(int j=playerY-10;j<=playerY+10;j++){
			if(i==playerX && j==playerY){
				BColor(WHITE);
				cout << "  ";
			}else if(world[i][j]==Air){
				BColor(SBLUE);
				cout << "  ";
			}else if(world[i][j]==Floor){
				BColor(DIRT);
				cout << "##";
			}else if(world[i][j]==Spike){
				BColor(GREY);
				cout << "%%";
			}else if(world[i][j]==End){
				BColor(PURPLE);
				cout << "()";
			}else if(world[i][j]==Spring){
				BColor(GREEN);
				cout << "TT";
			}else if(world[i][j]==Ladder){
				BColor(BLUE);
				cout << "HH";
			}
		}
		BColor(BLACK);
		putchar('\n');

	}
	cout<<"--------------------------------"<<endl;
	if(gamemode==0)cout << "1-floor 2-spike 3-spring 4-ladder 5-end E-erase 0-clearmap" << endl;
	cout<<"X: "<< playerX<<"  Y: "<< playerY << "  gamemode:  " << gamemode+1 << " test.frame: "<< frame << endl;
}
void dectect(){
	if(GetKeyState(' ')<0){
		gamemode=(gamemode+1)%2;
		if(gamemode==1)playerX=50,playerY=50;
		Sleep(100);
		cls();
	}
	if(gamemode==0){
		if(GetKeyState('W')<0)playerX--;
		if(GetKeyState('S')<0)playerX++;
		if(GetKeyState('A')<0)playerY--;
		if(GetKeyState('D')<0)playerY++;

		if(GetKeyState('1')<0)world[playerX][playerY]=Floor;
		if(GetKeyState('2')<0)world[playerX][playerY]=Spike;
		if(GetKeyState('3')<0)world[playerX][playerY]=Spring;
		if(GetKeyState('4')<0)world[playerX][playerY]=Ladder;
		if(GetKeyState('5')<0)world[playerX][playerY]=End;
		if(GetKeyState('E')<0)world[playerX][playerY]=Air;
		if(GetKeyState('0')<0)clearmap();
	}else{
		//jump
		if(GetKeyState('W')<0){
			if(world[playerX+1][playerY]==Floor || world[playerX+1][playerY]==Spring || world[playerX][playerY]==Ladder)jump+=5;
			else if(world[playerX][playerY]==Ladder)jump=1;
		}
		//spring jump
		if(world[playerX+1][playerY]==Spring)jump+=8;
		if(jump>0)jump--,playerX--;//fall
		else if(world[playerX][playerY]!=Ladder){
			if(world[playerX+1][playerY]==Air || world[playerX+1][playerY]==Spike || world[playerX+1][playerY]==Ladder)playerX++;
		}
		if(world[playerX-1][playerY]==Floor)jump=0;
		// stop jump lower than 0
		if(jump<0)jump=0;

		// go left
		if(GetKeyState('A')<0 && (world[playerX][playerY+1]==Spike || world[playerX][playerY-1]==Air || world[playerX][playerY-1]==Ladder || world[playerX][playerY-1]==End))playerY--;
		//go right
		if(GetKeyState('D')<0 && (world[playerX][playerY+1]==Spike || world[playerX][playerY+1]==Air || world[playerX][playerY+1]==Ladder || world[playerX][playerY+1]==End))playerY++;
		// go down (ladder)
		if(GetKeyState('S')<0 && world[playerX][playerY]==Ladder)playerX++;

	}
	// out of map dectect
	if(playerX>100)playerX=100;
	if(playerX<1)playerX=1;
	if(playerY>100)playerY=100;
	if(playerY<1)playerY=1;
}

void game(){
	cls();
	clearmap();
	while(1){
		frame++;
		screenupdate();
		dectect();
		if(world[playerX][playerY]==End && gamemode==1){
			cls();
			cout << "congradulations! you win!" << endl;
			cout << "press anykey to continue";
			Sleep(1000);
			getch();
			playerX=50,playerY=50;
		}else if(world[playerX][playerY]==Spike && gamemode==1){
			cls();
			cout << "YOU DIED!" << endl;
			cout << "press anykey to restart";
			Sleep(1000);
			getch();
			playerX=50,playerY=50;
		}

		Sleep(50);
	}
}
int main(){
	CONSOLE_CURSOR_INFO cursor_info={1,0};
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
	system("mode con cols=60 lines=25");
	system("title  biuld your own PAKOUR beta version v0.01      By sky_of_stars");
	cout << "\n\n\n                      SUPER PAKOUR               \n\n                  press any key to start";
	Color(BLACK,BLUE);
	getch();
	game();
}
原文