我***的拖了这么久了才发出来。
INTRODUTION
survive in the mosnter’s attack.shoot&kill them if you need.Will update this game randomly.
TRANSLATION翻译
在怪物的攻击中活下来!必要时也可以开枪反击。AD左右移动W跳跃,空格射击。该游戏没有结束。不定期更新。
UPDATE LOG更新日志
新增BUFF系统!开始游戏时可以选择加成!(如更多血量等等的。。)
CODE
#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 Long_Long_Max 9223372036854775807
#define Int_Max 2147483647
//#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);
}
void CursorSetup(){
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
long long quickpow(long long a,long long b,long long p){
long long ans=1,base=a;
while(b){
if(b%2){
ans*=base;
ans%=p;
}
base=base*base%p;
b>>=1;
}
return ans%p;
}
int getlog(long long x){
int i;
for(i=1;quickpow(2,i,9223372036854775807)<x;i++);
return i;
}
struct Node{
int val;
int front,back;
};
#define Void 0
#define wall 1
#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 air 6
#define monster 9
//--color----------------------------------
#define color_red 10
#define cred 10
#define color_yellow 11
#define cyellow 11
#define color_green 12
#define cgreen 12
#define color_canyon 13
#define ccanyon 13
#define color_blue 14
#define cblue 14
#define color_purple 15
#define cpurple 15
#define color_white 16
#define cwhite 16
#define color_dirt 17
#define cdirt 17
int world[105][105],mob[105][105];
bool check[105][105];
bool flagHP=0;
int PlayerX=10,PlayerY=25,PlayerHP=3;
int shield=10,excsleep=6,plexcsleep=2,level=0,exlevel=1,jump=0;
string Playerdir="r";
int cd=7,scd=7;
bool firststart=1;
unsigned long long frame=0;
char convert[105][105]=
{
"0000000000000000000000000000000000000000",
"01111111111111111111111111111111111111111",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000001111111111000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000001111111110000000000111111111000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01000000000000000000000000000000000000001",
"01111111111111111111111111111111111111111",
};
char speedup[10][9]=
{
" DD ",
" DD ",
" DD ",
" DD ",
" DD ",
" ",
" ",
" YY ",
" Y Y ",
};
char defenseup[9][9]=
{
" CCCC ",
" CWWC ",
" CWWC ",
" CWWC ",
" CC ",
" ",
" ",
" YY ",
" Y Y ",
};
char reloadup[9][9]=
{
" GG Y ",
" G Y ",
" G D ",
" D G ",
" D G ",
" GG ",
" ",
" YY ",
" Y Y ",
};
char hpup[9][9]=
{
" RR RR ",
" RRRRRR ",
" RRRRRR ",
" RRRR ",
" RR ",
" ",
" ",
" YY ",
" Y Y ",
};
void print(int bonus,int line){
if(bonus==0){
for(int j=0;j<8;j++){
if(speedup[line][j]=='R'){
BColor("RED");
printf(" ");
}else if(speedup[line][j]=='W'){
BColor("WHITE");
printf(" ");
}else if(speedup[line][j]=='Y'){
BColor("LYELLOW");
printf(" ");
}else if(speedup[line][j]=='G'){
BColor("LGREEN");
printf(" ");
}else if(speedup[line][j]=='W'){
BColor("WHITE");
printf(" ");
}else if(speedup[line][j]=='C'){
BColor("CANYON");
printf(" ");
}else if(speedup[line][j]=='B'){
BColor("BLUE");
printf(" ");
}else if(speedup[line][j]=='P'){
BColor("PURPLE");
printf(" ");
}else if(speedup[line][j]=='D'){
BColor("DIRT");
printf(" ");
}else{
BColor("BLACK");
printf(" ");
}
}
BColor("BLACK");
}else if(bonus==1){
for(int j=0;j<8;j++){
if(defenseup[line][j]=='R'){
BColor("RED");
printf(" ");
}else if(defenseup[line][j]=='W'){
BColor("WHITE");
printf(" ");
}else if(defenseup[line][j]=='Y'){
BColor("LYELLOW");
printf(" ");
}else if(defenseup[line][j]=='G'){
BColor("LGREEN");
printf(" ");
}else if(defenseup[line][j]=='W'){
BColor("WHITE");
printf(" ");
}else if(defenseup[line][j]=='C'){
BColor("CANYON");
printf(" ");
}else if(defenseup[line][j]=='B'){
BColor("BLUE");
printf(" ");
}else if(defenseup[line][j]=='P'){
BColor("PURPLE");
printf(" ");
}else if(defenseup[line][j]=='D'){
BColor("DIRT");
printf(" ");
}else{
BColor("BLACK");
printf(" ");
}
}
BColor("BLACK");
}else if(bonus==2){
for(int j=0;j<8;j++){
if(reloadup[line][j]=='R'){
BColor("RED");
printf(" ");
}else if(reloadup[line][j]=='W'){
BColor("WHITE");
printf(" ");
}else if(reloadup[line][j]=='Y'){
BColor("LYELLOW");
printf(" ");
}else if(reloadup[line][j]=='G'){
BColor("LGREEN");
printf(" ");
}else if(reloadup[line][j]=='W'){
BColor("WHITE");
printf(" ");
}else if(reloadup[line][j]=='C'){
BColor("CANYON");
printf(" ");
}else if(reloadup[line][j]=='B'){
BColor("BLUE");
printf(" ");
}else if(reloadup[line][j]=='P'){
BColor("PURPLE");
printf(" ");
}else if(reloadup[line][j]=='D'){
BColor("DIRT");
printf(" ");
}else{
BColor("BLACK");
printf(" ");
}
}
BColor("BLACK");
}else if(bonus==3){
for(int j=0;j<8;j++){
if(hpup[line][j]=='R'){
BColor("RED");
printf(" ");
}else if(hpup[line][j]=='W'){
BColor("WHITE");
printf(" ");
}else if(hpup[line][j]=='Y'){
BColor("LYELLOW");
printf(" ");
}else if(hpup[line][j]=='G'){
BColor("LGREEN");
printf(" ");
}else if(hpup[line][j]=='W'){
BColor("WHITE");
printf(" ");
}else if(hpup[line][j]=='C'){
BColor("CANYON");
printf(" ");
}else if(hpup[line][j]=='B'){
BColor("BLUE");
printf(" ");
}else if(hpup[line][j]=='P'){
BColor("PURPLE");
printf(" ");
}else if(hpup[line][j]=='D'){
BColor("DIRT");
printf(" ");
}else{
BColor("BLACK");
printf(" ");
}
}
}
BColor("BLACK");
}
void setup(){
system("mode con cols=50 lines=20");
cls();
cout << "\n\n\n ";
if(exlevel!=level){
Sleep(500);
BColor("CANYON");
cout << "LEVEL UP!";
exlevel=level;
}else if(exlevel==level && !firststart){
Sleep(500);
BColor("RED");
cout << "YOU DIED!";
}else firststart=0;
Sleep(1500);
BColor("BLACK");
cout << "\n";
cout << " pick a bonus!\n\n";
int bonus1=rand()%4,bonus2=rand()%4,bonus3=rand()%4;
PlayerX=10,PlayerY=25,PlayerHP=3,excsleep=6,plexcsleep=2,shield=10,frame=0,cd=7,scd=7;//-----------
for(int i=0;i<=8;i++){
print(bonus1,i);
cout << " ";
print(bonus2,i);
cout << " ";
print(bonus3,i);
cout << "\n";
}
if(bonus1==0)printf(" faster speed ");
if(bonus1==1)printf(" better shield ");
if(bonus1==2)printf("faster reloading");
if(bonus1==3)printf(" more health ");
printf(" ");
if(bonus2==0)printf(" faster speed ");
if(bonus2==1)printf(" better shield ");
if(bonus2==2)printf("faster reloading");
if(bonus2==3)printf(" more health ");
printf(" ");
if(bonus3==0)printf(" faster speed \n");
if(bonus3==1)printf(" better shield \n");
if(bonus3==2)printf("faster reloading\n");
if(bonus3==3)printf(" more health \n");
cout <<" press 1 press 2 press 3 \n";
while(1){
if(KEY_DOWN('1')){
if(bonus1==0){
printf("you got faster speed !\n"),plexcsleep=1;break;
}
if(bonus1==1){
printf("you got better shield !\n"),shield=30;break;
}
if(bonus1==2){
printf("you got faster reloading!\n"),cd=4,scd=4;break;
}
if(bonus1==3){
printf("you got more health !\n"),PlayerHP=5;break;
}
}
if(KEY_DOWN('2')){
if(bonus2==0){
printf("you got faster speed !\n"),plexcsleep=1;break;
}
if(bonus2==1){
printf("you got better shield !\n"),shield=30;break;
}
if(bonus2==2){
printf("you got faster reloading!\n"),cd=4,scd=4;break;
}
if(bonus2==3){
printf("you got more health !\n"),PlayerHP=5;break;
}
}
if(KEY_DOWN('3')){
if(bonus3==0){
printf("you got faster speed !\n"),plexcsleep=1;break;
}
if(bonus3==1){
printf("you got better shield !\n"),shield=30;break;
}
if(bonus3==2){
printf("you got faster reloading!\n"),cd=4,scd=4;break;
}
if(bonus3==3){
printf("you got more health !\n"),PlayerHP=5;break;
}
}
}
Sleep(1000);
for(int i=1;i<=25;i++){
for(int j=1;j<=40;j++){
if(convert[i][j]=='0'){
mob[i][j]=world[i][j]=Void;
}else if(convert[i][j]=='1'){
mob[i][j]=world[i][j]=wall;
}
}
}
cls();
}
void trymove(){
if(GetAsyncKeyState('W') && world[PlayerX+1][PlayerY]==wall){
jump=5;
}
//if(GetAsyncKeyState('S') && world[PlayerX+2][PlayerY]!=wall)PlayerX++;
if(GetAsyncKeyState('A') && world[PlayerX][PlayerY-1]!=wall)PlayerY--,Playerdir="l";
if(GetAsyncKeyState('D') && world[PlayerX][PlayerY+1]!=wall)PlayerY++,Playerdir="r";
if(jump){
if(world[PlayerX-1][PlayerY]==wall){
jump=0;
}else{
PlayerX--;
jump--;
}
}else if(world[PlayerX+1][PlayerY]!=wall){
PlayerX++;
}
//-------------------------------------------------------------------------------
if(KEY_DOWN(' ') && cd>=scd){
if(Playerdir=="u" && mob[PlayerX-1][PlayerY]!=wall){
mob[PlayerX-1][PlayerY]=bup;
}else if(Playerdir=="d" && mob[PlayerX+1][PlayerY]!=wall){
mob[PlayerX+1][PlayerY]=bdown;
}else if(Playerdir=="l" && mob[PlayerX][PlayerY-1]!=wall && world[PlayerX][PlayerY-1]!=wall){
mob[PlayerX][PlayerY-1]=bleft;
}else if(Playerdir=="r" && mob[PlayerX][PlayerY+1]!=wall && world[PlayerX][PlayerY+1]!=wall){
mob[PlayerX][PlayerY+1]=bright;
}
cd=0;
}
}
void update(){
//memset(check,0,sizeof(0));
for(int i=1;i<=25;i++){
for(int j=1;j<=40;j++){
if(frame%100==0){
if(i==2 || i==24 || j==2 || j==39 && mob[i][j]==wall){
if(rand()%(50/level*2)==0)mob[i][j]=monster;
}
}
//bullets
if(mob[i][j]==bdown && !check[i][j]){
mob[i][j]=air;
if(world[i+1][j]!=wall){
if(mob[i+1][j]==monster)mob[i+1][j]=air;
else mob[i+1][j]=bdown;
check[i+1][j]=1;
}
}else if(mob[i][j]==bup && !check[i][j]){
mob[i][j]=air;
if(world[i-1][j]!=wall){
if(mob[i-1][j]==monster)mob[i-1][j]=air;
else mob[i-1][j]=bdown;
check[i-1][j]=1;
}
}else if(mob[i][j]==bright && !check[i][j]){
mob[i][j]=air;
if(world[i][j+1]!=wall){
if(mob[i][j+1]==monster)mob[i][j+1]=air;
else mob[i][j+1]=bright;
check[i][j+1]=1;
}
}else if(mob[i][j]==bleft && !check[i][j]){
mob[i][j]=air;
if(world[i][j-1]!=wall){
if(mob[i][j-1]==monster)mob[i][j-1]=air;
else mob[i][j-1]=bleft;
check[i][j-1]=1;
}
//mob
}else if(mob[i][j]==monster && frame%7==0 && !check[i][j] ){
int needx=0,needy=0;
if(PlayerY<j)needy--;
else if(PlayerY>j)needy++;
if(PlayerX<i && mob[i+1][j]==wall){
int tmp=6;
while(mob[i+needx][j]!=wall && tmp){
tmp--;
needx--;
}
}else{
needx++;
}
/*if(PlayerX<i && PlayerY<j && mob[i-1][j-1]==air /*&& !check[i-1][j-1])mob[i-1][j-1]=monster,check[i-1][j-1]=1;
else if(PlayerX>i && PlayerY>j && mob[i+1][j+1]==air/* && !check[i+1][j+1])mob[i+1][j+1]=monster,check[i+1][j+1]=1;
else if(PlayerX>i && PlayerY<j && mob[i+1][j-1]==air/* && !check[i+1][j-1])mob[i+1][j-1]=monster,check[i+1][j-1]=1;
else if(PlayerX<i && PlayerY>j && mob[i-1][j+1]==air/* && !check[i-1][j+1])mob[i-1][j+1]=monster,check[i-1][j+1]=1;
else{
if(PlayerX<i && mob[i-1][j]==air)needx--;
else if(PlayerX>i && mob[i+1][j]==air)needx++;
if(PlayerY<j && mob[i][j-1]==air)needy--;
else if(PlayerY>j && mob[i][j+1]==air)needy++;
;
}//REAL shithills*/
if(mob[i+needx][j+needy]!=wall && mob[i+needx][j+needy]!=monster && frame%excsleep==0){
mob[i][j]=air;
if(mob[i+needx][j+needy]!=bup && mob[i+needx][j+needy]!=bdown && mob[i+needx][j+needy]!=bleft && mob[i+needx][j+needy]!=bright){
mob[i+needx][j+needy]=monster;
check[i+needx][j+needy]=1;
}else{
check[i][j]=1;
}
}else{
if(mob[i+needx][j]!=wall && mob[i+needx][j]!=monster){
mob[i][j]=air;
if(mob[i+needx][j]!=bup && mob[i+needx][j]!=bdown && mob[i+needx][j]!=bleft && mob[i+needx][j]!=bright){
mob[i+needx][j]=monster;
check[i+needx][j]=1;
}
}else if(mob[i][j+needy]!=wall && mob[i][j+needy]!=monster){
mob[i][j]=air;
if(mob[i][j+needy]!=bup && mob[i][j+needy]!=bdown && mob[i][j+needy]!=bleft && mob[i][j+needy]!=bright){
mob[i][j+needy]=monster;
check[i][j+needy]=1;
}
}
}
//REALLY REALLY REALLY shithills
}
if(i==1 || i==25 || j==1 || j==40)world[i][j]=wall,mob[i][j]=wall;
}
}
//check player
if(cd<scd)cd++;
if(mob[PlayerX][PlayerY]==monster && shield==0)PlayerHP--,shield=30,mob[PlayerX][PlayerY]=air,flagHP=1;
else flagHP=0;
if(shield)shield--;
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<=25;i++){
for(int j=1;j<=40;j++){
if(mob[i][j]==bup || mob[i][j]==bdown || mob[i][j]==bright ||mob[i][j]==bleft){
BColor("BLACK");
if(mob[i][j]==bup || mob[i][j]==bdown)printf("|");
else printf("一");
}else if(i==PlayerX && j==PlayerY){
BColor("WHITE");
printf(" ");
}else if(world[i][j]==wall){
if(flagHP==0)BColor("DIRT");
else BColor("RED");
printf(" ");
}else if(mob[i][j]==monster){
BColor("LRED");
printf(" ");
}else{
BColor("BLACK");
printf(" ");
}
}
BColor("BLACK");
printf("|\n");
}
BColor("BLACK");
printf("--------------------------------------------------------------------------------╯\n");
cout << "X: " << PlayerX << " Y: " << PlayerY << " cooldown: " << cd << " HP:" << PlayerHP << " shield: " << shield << " debug.frame:" << frame <<
" level: " << level << " ";
BColor("RED");
cout << "WAVE: " << frame/100 << "\n";
BColor("BLACK");
}
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 << " MONSTER RUSH\n press any key to continue...\n\n\n\n\n\n made by @sky_of_stars";
while(!kbhit());
system("mode con cols=90 lines=30");
while(1){
level++;
setup();
system("mode con cols=90 lines=30");
cd-=level/4;
scd=cd;
while(1){
frame++;
if(frame>level*600){
break;
}
//if(frame%100==0)spawning();
update();
screenupdate();
if(frame%plexcsleep==0)trymove();
if(PlayerHP<=0){
setup();
system("mode con cols=90 lines=30");
}
}
}
}773行代码祭