衍生游戏#1 PAINTBALL RUSH
sky_of_stars · · 科技·工程
本文衍生自作者的上上一篇游戏MONSTER RUSH。
INTRODUCTION
Paint as much as blocks you can to win! You can also use paintball guns to shoot your enemy and slow them.Player1 use wasd to move and q to fire.Player2 use ijkl to move and u to fire.
TRANSLATION 翻译
尽可能的把方块染成自己队伍的颜色来赢!也可以用彩弹枪来眩晕敌人。玩家一用wasd操控方向,q射击。玩家二用ijkl操控方向,u射击。
CODE
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<bitset>
#include<winuser.h>
#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()
{
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);
}
using namespace std;
#define air 0
#define red 1
#define blue 7
#define wall 6
#define bullet_left 2
#define bleft 2
#define bullet_right 3
#define bright 3
#define bullet_up 4
#define bup 4
#define bullet_down 5
#define bdown 5
#define sred 8
#define sblue 9
int Player1X,Player1Y,Player2X,Player2Y,p1cd=40,p1scd=40,p2cd=40,p2scd=40,p1shield=10,p2shield=10,frame=0;
string Player1dir,Player2dir;
int broadcast=0;
int world[105][105],mob[105][105];
bool check[105][105];
short own[50][50];
void setup(){
cls();
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
BColor(LYELLOW);
printf(" ");
}
cout << "\n";
}
Sleep(1000);
Player1X=5,Player1Y=5,Player2X=15,Player2Y=15,p1shield=10,p2shield=10,frame=0;
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
if(rand()%30==0)world[i][j]=wall,mob[i][j]=wall;
else world[i][j]=air,mob[i][j]=air;
if(i==1 || i==20 || j==1 || j==20)world[i][j]=wall,mob[i][j]=wall;
}
}
}
void trymove(){
if(!p1shield){
if(GetAsyncKeyState('W') && world[Player1X-1][Player1Y]!=wall)Player1X--,Player1dir="u";
if(GetAsyncKeyState('S') && world[Player1X+1][Player1Y]!=wall)Player1X++,Player1dir="d";
if(GetAsyncKeyState('A') && world[Player1X][Player1Y-1]!=wall)Player1Y--,Player1dir="l";
if(GetAsyncKeyState('D') && world[Player1X][Player1Y+1]!=wall)Player1Y++,Player1dir="r";
//-------------------------------------------------------------------------------
if(KEY_DOWN('Q') && p1cd>=p1scd){
if(Player1dir=="u" && mob[Player1X-1][Player1Y]!=wall){
mob[Player1X-1][Player1Y]=bup;
check[Player1X-1][Player1Y]=1;
own[Player1X-1][Player1Y]=1;
world[Player1X-1][Player1Y]=red;
}else if(Player1dir=="d" && mob[Player1X+1][Player1Y]!=wall){
mob[Player1X+1][Player1Y]=bdown;
check[Player1X+1][Player1Y]=1;
own[Player1X+1][Player1Y]=1;
world[Player1X+1][Player1Y]=red;
}else if(Player1dir=="l" && mob[Player1X][Player1Y-1]!=wall){
mob[Player1X][Player1Y-1]=bleft;
check[Player1X][Player1Y-1]=1;
own[Player1X][Player1Y-1]=1;
world[Player1X][Player1Y-1]=red;
}else if(Player1dir=="r" && mob[Player1X][Player1Y+1]!=wall){
mob[Player1X][Player1Y+1]=bright;
check[Player1X][Player1Y+1]=1;
own[Player1X][Player1Y+1]=1;
world[Player1X][Player1Y+1]=red;
}
p1cd=0;
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if(!p2shield){
if(GetAsyncKeyState('I') && world[Player2X-1][Player2Y]!=wall)Player2X--,Player2dir="u";
if(GetAsyncKeyState('K') && world[Player2X+1][Player2Y]!=wall)Player2X++,Player2dir="d";
if(GetAsyncKeyState('J') && world[Player2X][Player2Y-1]!=wall)Player2Y--,Player2dir="l";
if(GetAsyncKeyState('L') && world[Player2X][Player2Y+1]!=wall)Player2Y++,Player2dir="r";
//-------------------------------------------------------------------------------
if(KEY_DOWN('U') && p2cd>=p2scd){
if(Player2dir=="u" && mob[Player2X-1][Player2Y]!=wall){
mob[Player2X-1][Player2Y]=bup;
check[Player2X-1][Player2Y]=1;
own[Player2X-1][Player2Y]=2;
world[Player2X-1][Player2Y]=blue;
}else if(Player2dir=="d" && mob[Player2X+1][Player2Y]!=wall){
mob[Player2X+1][Player2Y]=bdown;
check[Player2X+1][Player2Y]=1;
own[Player2X+1][Player2Y]=2;
world[Player2X+1][Player2Y]=blue;
}else if(Player2dir=="l" && mob[Player2X][Player2Y-1]!=wall){
mob[Player2X][Player2Y-1]=bleft;
check[Player2X][Player2Y-1]=1;
own[Player2X][Player2Y-1]=2;
world[Player2X][Player2Y-1]=blue;
}else if(Player2dir=="r" && mob[Player2X][Player2Y+1]!=wall){
mob[Player2X][Player2Y+1]=bright;
check[Player2X][Player2Y+1]=1;
own[Player2X][Player2Y+1]=2;
world[Player2X][Player2Y+1]=blue;
}
p2cd=0;
}
}
}
void update(){
//memset(check,0,sizeof(0));
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
if(mob[i-1][j]==bdown && !check[i-1][j])
{
mob[i-1][j]=air;
if(world[i][j]!=wall){
//if(i==player1X && j==player1Y || i==player2X && i==player2Y)mob[i][j]=air;
//else
mob[i][j]=bdown;
check[i][j]=1;
own[i][j]=own[i-1][j];
if(own[i][j]==1)world[i][j]=red;
else world[i][j]=blue;
}else{
if(own[i-1][j]==1){
world[i-1][j]=sred;
if(world[i-1][j-1]!=wall)world[i-1][j-1]=red;
if(world[i-1][j+1]!=wall)world[i-1][j+1]=red;
}else{
world[i-1][j]=sblue;
if(world[i-1][j-1]!=wall)world[i-1][j-1]=blue;
if(world[i-1][j+1]!=wall)world[i-1][j+1]=blue;
}
}
}else if(mob[i+1][j]==bup && !check[i+1][j])
{
mob[i+1][j]=air;
if(world[i][j]!=wall){
//if(i==player1X && j==player1Y || i==player2X && i==player2Y)mob[i][j]=air;
//else
mob[i][j]=bup;
check[i][j]=1;
own[i][j]=own[i+1][j];
if(own[i][j]==1)world[i][j]=red;
else world[i][j]=blue;
}else{
if(own[i+1][j]==1){
world[i+1][j]=sred;
if(world[i+1][j-1]!=wall)world[i+1][j-1]=red;
if(world[i+1][j+1]!=wall)world[i+1][j+1]=red;
}else{
world[i+1][j]=sblue;
if(world[i+1][j-1]!=wall)world[i+1][j-1]=blue;
if(world[i+1][j+1]!=wall)world[i+1][j+1]=blue;
}
}
}else if(mob[i][j-1]==bright && !check[i][j-1])
{
mob[i][j-1]=air;
if(world[i][j]!=wall){
//if(i==player1X && j==player1Y || i==player2X && i==player2Y)mob[i][j]=air;
//else
mob[i][j]=bright;
check[i][j]=1;
own[i][j]=own[i][j-1];
if(own[i][j]==1)world[i][j]=red;
else world[i][j]=blue;
}else{
if(own[i][j-1]==1){
world[i][j-1]=sred;
if(world[i-1][j-1]!=wall)world[i-1][j-1]=red;
if(world[i+1][j-1]!=wall)world[i+1][j-1]=red;
}else{
world[i][j-1]=sblue;
if(world[i-1][j-1]!=wall)world[i-1][j-1]=blue;
if(world[i+1][j-1]!=wall)world[i+1][j-1]=blue;
}
}
}else if(mob[i][j+1]==bleft && !check[i][j+1])
{
mob[i][j+1]=air;
if(world[i][j]!=wall){
//if(i==player1X && j==player1Y || i==player2X && i==player2Y)mob[i][j]=air;
//else
mob[i][j]=bleft;
check[i][j]=1;
own[i][j]=own[i][j+1];
if(own[i][j]==1)world[i][j]=red;
else world[i][j]=blue;
}else{
if(own[i][j+1]==1){
world[i][j+1]=sred;
if(world[i-1][j+1]!=wall)world[i-1][j+1]=red;
if(world[i+1][j+1]!=wall)world[i+1][j+1]=red;
}else{
world[i][j+1]=sblue;
if(world[i-1][j+1]!=wall)world[i-1][j+1]=blue;
if(world[i+1][j+1]!=wall)world[i+1][j+1]=blue;
}
}
}
}
}
//check player
if(p1cd<p1scd)p1cd++;
if((mob[Player1X][Player1Y]==bleft || mob[Player1X][Player1Y]==bright || mob[Player1X][Player1Y]==bdown || mob[Player1X][Player1Y]==bup) && p1shield==0)p1shield=30,mob[Player1X][Player1Y]=air,broadcast=1;
if(p1shield)p1shield--;
world[Player1X][Player1Y]=red;
if(p2cd<p2scd)p2cd++;
if((mob[Player2X][Player2Y]==bleft || mob[Player2X][Player2Y]==bright || mob[Player2X][Player2Y]==bdown || mob[Player2X][Player2Y]==bup) && p2shield==0)p2shield=30,mob[Player2X][Player2Y]=air,broadcast=2;
if(p2shield)p2shield--;
world[Player2X][Player2Y]=blue;
memset(check,0,sizeof(check));
}
/*void spawning(){
for(int i=1;i<=40;i++){
for(int j=1;j<=40;j++){
if(i==2 || i==39 || j==2 || j==39){
if(rand()%20==0)mob[i][j]=monster;
}
}
}
}*/
void screenupdate(){
gotoxy(0,0);
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
if(mob[i][j]==bup || mob[i][j]==bdown || mob[i][j]==bright ||mob[i][j]==bleft){
if(world[i][j]==red)BColor("LRED");
else if(world[i][j]==blue)BColor("SBLUE");
else BColor("LGREY");
if(mob[i][j]==bup || mob[i][j]==bdown)printf("|");
else printf("一");
}else if(i==Player1X && j==Player1Y){
if(p1shield)BColor("BLUE");
else BColor("WHITE");
printf("P1");
}else if(i==Player2X && j==Player2Y){
if(p2shield)BColor("RED");
else BColor("WHITE");
printf("P2");
}else if(world[i][j]==wall){
BColor("DIRT");
printf(" ");
}else if(world[i][j]==red){
BColor("LRED");
printf(" ");
}else if(world[i][j]==blue){
BColor("SBLUE");
printf(" ");
}else if(world[i][j]==sred){
BColor("RED");
printf(" ");
}else if(world[i][j]==sblue){
BColor("BLUE");
printf(" ");
}else{
BColor("LGREY");
printf(" ");
}
}
BColor("BLACK");
printf("|\n");
}
BColor("BLACK");
printf("----------------------------------------╯\n");
cout << "X1: " << Player1X << " Y1: " << Player1Y << "X2: " << Player2X << " Y2: " << Player2Y << " debug.frame:" << frame << "\nMatch left:" << 5000-frame;
if(broadcast==1)cout << "\n >>> Player2 HEADSHOT x_x Player1!";
else if(broadcast==2)cout << "\n >>> Player1 HEADSHOT x_x Player2!";
BColor("BLACK");
}
void finalcheck(){
system("mode con cols=60 lines=35");
int rblock=0,bblock=0;
for(int x=1;x<=20;x++){
for(int y=1;y<=20;y++){
gotoxy(0,0);
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
if(i==x && y==j){
BColor("LYELLOW");
printf("()");
if(world[i][j]==red || world[i][j]==sred)rblock++;
else if(world[i][j]==blue || world[i][j]==sblue)bblock++;
}else if(mob[i][j]==bup || mob[i][j]==bdown || mob[i][j]==bright ||mob[i][j]==bleft){
if(world[i][j]==red)BColor("LRED");
else if(world[i][j]==blue)BColor("SBLUE");
else BColor("LGREY");
if(mob[i][j]==bup || mob[i][j]==bdown)printf("|");
else printf("一");
}else if(i==Player1X && j==Player1Y){
if(p1shield)BColor("BLUE");
else BColor("WHITE");
printf("P1");
}else if(i==Player2X && j==Player2Y){
if(p2shield)BColor("RED");
else BColor("WHITE");
printf("P2");
}else if(world[i][j]==wall){
BColor("DIRT");
printf(" ");
}else if(world[i][j]==red){
BColor("LRED");
printf(" ");
}else if(world[i][j]==blue){
BColor("SBLUE");
printf(" ");
}else if(world[i][j]==sred){
BColor("RED");
printf(" ");
}else if(world[i][j]==sblue){
BColor("BLUE");
printf(" ");
}else{
BColor("LGREY");
printf(" ");
}
}
BColor("BLACK");
printf("|\n");
}
printf("----------------------------------------╯\n");
BColor("RED");
cout << "Player1 painted blocks:";
BColor("BLACK");
cout << " " << rblock << " vs. ";
BColor("BLUE");
cout << "Player2 painted blocks:";
BColor("BLACK");
cout << " " << bblock;
}
}
cls();
BColor("BLACK");
cout << "SO THE WINNER IS...";
Sleep(3000);
BColor("BLACK");
if(rblock==bblock){
cout << "BOTH!\n\n";
cout << " Player1:Player2=";
BColor("DIRT");
cout << rblock << ":" << bblock << endl;
}else if(rblock>bblock){
cout << "PLAYER 1!\n\n";
cout << " Player1:Player2=";
BColor("DIRT");
cout << rblock;
BColor("BLACK");
cout << ":" << bblock << endl;
}else if(bblock>rblock){
cout << "PLAYER 2!\n\n";
cout << " Player1:Player2=";
BColor("BLACK");
cout << rblock << ":";
BColor("DIRT");
cout << bblock << endl;
}
BColor("BLACK");
Sleep(5000);
cout << "\n restarting...";
Sleep(1000);
}
int main(){
srand(time(0));
system("mode con cols=30 lines=15");
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
cout << " PAINTBALL RUSH\n press any key to continue...\n\n\n\n\n\n made by @sky_of_stars";
while(!kbhit());
system("mode con cols=50 lines=30");
while(1){
setup();
p1scd=p1cd;
p2scd=p2cd;
while(1){
frame++;
//if(frame%100==0)spawning();
update();
screenupdate();
if(frame%2==0)trymove();
if(frame==5001){
finalcheck();
break;
}
}
}
}