Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <conio.h>
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <stdio.h>
- #define LATIME 30
- #define LUNGIME 30
- #define SIMBOL_MARGINE1 '-'
- #define SIMBOL_MARGINE2 '|'
- #include <windows.h>
- using namespace std;
- void gotoxy( int column, int line ) //
- {
- COORD coord;
- coord.X = column;
- coord.Y = line;
- SetConsoleCursorPosition(
- GetStdHandle( STD_OUTPUT_HANDLE ),
- coord
- );
- }
- bool GAMEEND = false;
- char matTer[LUNGIME][LATIME];
- long long Score,M_ShootRate=0;
- short int pozNava = 15, Player_Lives=3, Monster_Count=16;
- int BulletSpeed,Boss_HP=250;;
- void show_cursor(bool show) //vizibilitate curosor in consola
- {
- HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_CURSOR_INFO infCursor;
- GetConsoleCursorInfo(out, &infCursor);
- infCursor.bVisible = show;
- SetConsoleCursorInfo(out, &infCursor);
- }
- void afisare()
- {
- for (int i = 1; i <= LUNGIME - 1; i++)
- {
- for (int j = 1; j <= LATIME - 1; j++)
- cout << matTer[i][j];
- cout << endl;
- }
- }
- void creare_teren()
- {
- int i;
- for (i = 1; i <= LATIME ; i++)
- matTer[i][1] = matTer[i][LUNGIME - 1] = SIMBOL_MARGINE2;
- for (i = 1; i <= LUNGIME - 1; i++)
- matTer[1][i] = matTer[LATIME - 1][i] = SIMBOL_MARGINE1;
- }
- void nava()
- {
- matTer[LUNGIME-2][pozNava-1] = matTer[LUNGIME-2][pozNava] = matTer[LUNGIME-2][pozNava+1] = matTer[LUNGIME-3][pozNava] = (char)223;
- }
- void Check_KeyPress ()
- {
- char newKey;
- if (_kbhit())
- newKey = _getch();
- if(newKey == 'd' ||newKey == 'D')
- if(pozNava < LATIME-3)
- {
- matTer[LUNGIME-2][pozNava + 2] = matTer[LUNGIME-2][pozNava];
- matTer[LUNGIME-3][pozNava+1] =matTer[LUNGIME-2][pozNava] ;
- matTer[LUNGIME-2][pozNava-1] = matTer[LUNGIME-3][pozNava] = '\0';
- pozNava++;
- }
- if(newKey == 'a' || newKey == 'A')
- if(pozNava > 3)
- {
- matTer[LUNGIME-2][pozNava-2] = matTer[LUNGIME-3][pozNava-1]= char(223);
- matTer[LUNGIME-2][pozNava+1] = matTer[LUNGIME-3][pozNava] = '\0';
- pozNava--;
- }
- if(newKey == (char)32)
- {
- matTer[LUNGIME-4][pozNava] = char(248);
- }
- }
- void Delete_Monster(int x, int y)
- {
- if( matTer[x][y-1]=='\0' && matTer[x][y+1]=='\0')
- matTer[x][y] = matTer[x-1][y] = matTer[x-1][y-1]= matTer[x-1][y+1] = matTer[x-2][y-1] = matTer[x-2][y+1] = '\0';
- else if( matTer[x][y-1]=='o' && matTer[x][y+1]=='\0')
- matTer[x+1][y-1] = matTer[x][y-1] = matTer[x][y]= matTer[x][y-2] = matTer[x-1][y] = matTer[x-1][y-2] = '\0';
- else if( matTer[x][y+1]=='o' && matTer[x][y-1]=='\0')
- matTer[x+1][y+1] = matTer[x][y+1] = matTer[x][y]= matTer[x][y+2] = matTer[x-1][y] = matTer[x-1][y+2] = '\0';
- Monster_Count--;
- }
- int Last_monster(int i)
- {
- for( int j=4; j<=LUNGIME; j+=4)
- if(matTer[j][i]=='o' && matTer[j+4][i]=='\0')
- return j;
- return 0;
- }
- void Generate_Monster_Bullets()
- {
- int M_Shoot;
- M_Shoot=rand()%76;
- if(Last_monster(3)!=0 && M_Shoot<= 10)
- matTer[Last_monster(3)+1][3]='.';
- if(Last_monster(7)!=0 && M_Shoot>=10 &&M_Shoot<=25 )
- matTer[Last_monster(7)+1][7]='.';
- if(Last_monster(11)!=0 && M_Shoot>=20 && M_Shoot<=35)
- matTer[Last_monster(11)+1][11]='.';
- if(Last_monster(15)!=0 && M_Shoot>=30 && M_Shoot<=45)
- matTer[Last_monster(15)+1][15]='.';
- if(Last_monster(19)!=0 && M_Shoot>=40 && M_Shoot<=55)
- matTer[Last_monster(19)+1][19]='.';
- if(Last_monster(23)!=0 && M_Shoot>=50 && M_Shoot<=65)
- matTer[Last_monster(23)+1][23]='.';
- if(Last_monster(27)!=0 && M_Shoot>=60 && M_Shoot<=75)
- matTer[Last_monster(27)+1][27]='.';
- }
- void Bullet_Movement ()
- {
- int i, j;
- for(i=3; i<=LATIME-3; i++)
- for(j=3; j<=LUNGIME-3; j++)
- {
- if (matTer[i][j]==char(248))
- if(i==2)
- matTer[i][j]='\0';
- else if(matTer[i-1][j]=='\0')
- {
- matTer[i-1][j]=char(248);
- matTer[i][j]='\0';
- }
- else if(matTer[i-1][j]=='o')
- {
- Delete_Monster(i-1, j);
- matTer[i][j]='\0';
- Score+= 1000;
- }
- }
- Generate_Monster_Bullets();
- char aux;
- for(i=3; i<=LATIME-3; i++)
- for(j=3; j<=LUNGIME-3; j++)
- {
- if(matTer[j][i]=='.')
- if(matTer[j+1][i]=='\0')
- {
- if(1)
- {
- matTer[j+1][i]='.';
- matTer[j][i]='\0';
- j++;
- }
- }
- else if(matTer[j+1][i]==char(223))
- {
- Player_Lives--;
- Sleep(1500);
- matTer[j][i]='\0';
- Score-=1000;
- if(Player_Lives==0)
- GAMEEND=TRUE;
- }
- else if(matTer[j+1][i]==char(248))
- {
- if(matTer[j+2][i]=='\0' || matTer[j+2][i]==char(223))
- {
- Sleep(120);
- aux=matTer[j+1][i];
- matTer[j+1][i]=matTer[j][i];
- matTer[j][i]=aux;
- }
- else if(matTer[j+2][i]==char(248))
- matTer[j][i]='\0';
- }
- else if (j==LUNGIME-2)
- matTer[j][i]='\0';
- }
- BulletSpeed++;
- }
- void Delete_Bullets()
- {
- for(int i=2; i<=LUNGIME-2; i++)
- for(int j=2; j<=LATIME-2; j++)
- if(matTer[i][j]==char(248) || matTer[i][j]=='.')
- matTer[i][j]='\0';
- }
- void Create_Wave1_Monsters()
- {
- int i, j;
- for(j=2; j<=LATIME-3; j+=4)
- {
- matTer[2][j]= matTer[2][j+2] = matTer[3][j] = matTer[3][j+1]= matTer[3][j+2]=matTer[4][j+1]= 'o';
- }
- for(i=6; i<=LUNGIME/2; i+=4)
- for(j=2; j<=LATIME-3; j+=4)
- if( matTer[i-2][j-3]=='o' && matTer[i-2][j+5]=='o')
- matTer[i][j]= matTer[i][j+2] = matTer[i+1][j] = matTer[i+1][j+1]= matTer[i+1][j+2]=matTer[i+2][j+1]= 'o';
- }
- void Create_Wave2_Monsters()
- {
- int i,j;
- for(i=2; i<=LUNGIME/2; i+=4)
- for(j=2; j<=LATIME-3; j+=4)
- {
- Monster_Count++;
- matTer[i][j]= matTer[i][j+2] = matTer[i+1][j] = matTer[i+1][j+1]= matTer[i+1][j+2]=matTer[i+2][j+1]= 'o';
- }
- }
- void Wave1()
- {
- Create_Wave1_Monsters();
- afisare();
- while (GAMEEND==FALSE && Monster_Count!=0)
- {
- Check_KeyPress();
- Sleep(100);
- gotoxy(0, 0);
- Bullet_Movement();
- afisare();
- Score++;
- cout<<"Scor:"<<Score<<" "<<"Lives: "<<Player_Lives;
- }
- Delete_Bullets();
- }
- void W1_W2_Transition ()
- {
- system("cls");
- gotoxy(13,15);
- cout<<"YOU MANAGED TO DEFEAT THESE";
- gotoxy(9,16);
- cout<<"BUT THERE ARE MORE COMING YOUR WAY";
- gotoxy(19,17);
- cout<<"WATCH OUT!!!";
- Sleep(4000);
- system("cls");
- }
- void Wave2()
- {
- Create_Wave2_Monsters();
- afisare();
- while (GAMEEND==FALSE && Monster_Count!=0)
- {
- Check_KeyPress();
- Sleep(100);
- gotoxy(0, 0);
- Bullet_Movement();
- afisare();
- Score++;
- cout<<"Scor:"<<Score<<" "<<"Lives: "<<Player_Lives;
- }
- Delete_Bullets();
- }
- void W2_B_Transition()
- {
- system("cls");
- gotoxy(19,15);
- cout<<"OH NO!!!";
- gotoxy(9,16);
- cout<<"THEY SENT THE BIG GUY AFTER YOU";
- gotoxy(19,17);
- cout<<"LAST ONE";
- gotoxy(10,18);
- cout<<"DEFEAT IT AND SAVE ALL OF US";
- Sleep(4000);
- system("cls");
- }
- void Spawn_Boss()
- {
- int i;
- matTer[2][5]= matTer[2][LATIME-5] = matTer[3][6]= matTer[3][LATIME-6]=char(219);
- for(i=5; i<=LATIME-5; i++)
- matTer[4][i]=char(219);
- for(i=4; i<=LATIME-4; i++)
- if(i!=8 && i!=21 && i!=10 && i!=9 && i!=20 &&i!=22)
- matTer[5][i]=char(219);
- for(i=3; i<=LATIME-3; i++)
- matTer[6][i]=char(219);
- for(i=3; i<=LATIME-3; i++)
- if(i!=5 && i!=6 && i!=LATIME-5 &&i!= LATIME-6)
- matTer[7][i]=char(219);
- for(i=3; i<=LATIME-3; i++)
- if(i!=5 && i!=6 && i!=LATIME-5 &&i!= LATIME-6)
- matTer[8][i]=char(219);
- matTer[9][3]= matTer[9][4]=matTer[9][7]=matTer[9][8]=matTer[9][LATIME-3]=matTer[9][LATIME-4]=matTer[9][LATIME-7]=matTer[9][LATIME-8]=char(219);
- for (i=7; i<=LATIME-7; i++)
- if(i!=15 && i!= 16 && i!= 14)
- matTer[10][i]=char(219);
- }
- void B_Bullet_Movement()
- {
- int i,j;
- for(i=2; i<=LATIME-1; i++)
- for(j=2; j<=LUNGIME-1; j++)
- {
- if (matTer[i][j]==char(248))
- {
- if(matTer[i-1][j]=='\0')
- {
- matTer[i-1][j]=char(248);
- matTer[i][j]='\0';
- }
- else if(matTer[i-1][j]==char(219))
- {
- Boss_HP--;
- }
- else if(matTer[i-1][j]==char(207) || matTer[i-1][j]==char(220))
- matTer[i][j]=matTer[i-1][j]='\0';
- }
- if(matTer[i][j]==char(220))
- {if(i==LUNGIME-2)
- matTer[i][j]='\0';
- else
- if(matTer[i+1][j]=='\0')
- {matTer[i+1][j]=char(220); matTer[i][j]='\0';}
- else
- if(matTer[i+1][j]==char(223))
- {
- Player_Lives--;
- Score-=1000;
- if(Player_Lives==0)
- GAMEEND=TRUE;
- matTer[i][j]='\0';
- }
- else
- if(matTer[i+1][j]==char(248))
- matTer[i][j]=matTer[i+1][j]='\0';}
- }
- }
- void Boss_Bullet_Rain()
- {
- matTer[10][3]=matTer[10][4]=matTer[10][LATIME-3]=matTer[10][LATIME-4]=char(220);
- int i;
- for(i=8; i<=LATIME-8; i++)
- if(i!=15 && i!= 16 && i!= 14)
- matTer[11][i]=char(220);
- matTer[9][15]=matTer[9][16]=matTer[9][14]= char(220);
- }
- void Boss_Chase_Bullets()
- {
- matTer[10][3]=matTer[10][LATIME-3]=char(207);
- }
- void Boss_Attack ()
- {
- //Boss_Chase_Bullets();
- Boss_Bullet_Rain();
- //if(M_ShootRate%15==0)
- //switch(rand()%3)
- //case 0:
- }
- void Boss_Fight()
- {
- int i;
- M_ShootRate=0;
- srand(time(NULL));
- creare_teren();
- Spawn_Boss();
- system("cls");
- afisare();
- while(GAMEEND==false && Boss_HP!=0)
- {
- Check_KeyPress();
- B_Bullet_Movement();
- Boss_Attack();
- Sleep(100);
- gotoxy(0,0);
- afisare();
- }
- }
- void GameOver_Animation()
- {
- Sleep(5000);
- system("cls");
- cout << "_______________________________________________________________________" << endl;
- cout << "| |" << endl;
- cout << "| **** * * * **** |" << endl;
- cout << "| * * * * * * *_ |" << endl;
- cout << "| * ** ***** * * * | " << endl;
- cout << "| **** * * * * **** |" << endl;
- cout << "| |" << endl;
- cout << "| **** * * **** * *** |" << endl;
- cout << "| * * * * *_ * * * |" << endl;
- cout << "| * * * * * * * |" << endl;
- cout << "| **** * **** * * |" << endl;
- cout << "| |" << endl;
- cout << "| FINAL SCORE: " <<Score<<" |"<< endl;
- cout << "| |" << endl;
- cout << "|______________________________________________________________________|" << endl;
- Sleep(6000);
- }
- int main ()
- {
- char x,y;
- show_cursor(false);
- while(x!='4' )
- {
- cout << "_______________________________________________________________________" << endl;
- cout << "| |" << endl;
- cout << "| * * *** * *** ** * * *** |" << endl;
- cout << "| * * * ** * * * * * * * ** |" << endl;
- cout << "| * * *** *** *** ** * * *** |" << endl;
- cout << "| |" << endl;
- cout << "| SPACE INVADERS |" << endl;
- cout << "| |" << endl;
- cout << "| PRESS 1 TO START GAME |" << endl;
- cout << "| PRESS 2 FOR INSTRUCTIONS |" << endl;
- cout << "| PRESS 3 TO KNOW MORE ABOUT THE GAME |" << endl;
- cout << "| PRESS 4 TO QUIT |" << endl;
- cout << "|______________________________________________________________________|" << endl;
- cin >> x;
- system("cls");
- if(x == '1')
- {
- creare_teren();
- nava();
- Boss_Fight();
- Wave1();
- if(GAMEEND==FALSE)
- {
- W1_W2_Transition();
- Wave2();
- }
- if(GAMEEND==FALSE)
- {
- W2_B_Transition();
- Boss_Fight();
- }
- GameOver_Animation();
- x='4';
- }
- else if(x=='2')
- {
- gotoxy(0, 0);
- cout << "_______________________________________________________________________" << endl;
- cout << "| |"<< endl;
- cout << "| USE 'D' KEY TO MOVE TO RIGHT |"<<endl;
- cout << "| USE 'A' KEY TO MOVE LEFT |"<< endl;
- cout << "| USE SPACEBAR TO SHOOT |"<< endl;
- cout << "| |"<< endl;
- cout << "| YOUR GOAL IS TO KILL ALL THE INVADERS AND SAVE OUR PLANET |"<< endl;
- cout << "| THE WHOLE WORLD COUTS ON YOU. DO NOT DISAPPOINT |"<< endl;
- cout << "| GOOD LUCK IN YOUR JOURNEY |"<< endl;
- cout << "| |"<< endl;
- cout << "| PRESS B TO GO BACK TO MAIN MENU |" << endl;
- cout << "|______________________________________________________________________|" << endl;
- cin >> x;
- system("cls");
- }
- else if(x=='3')
- {
- system("cls");
- cout << "_______________________________________________________________________" << endl;
- cout << "| |"<< endl;
- cout << "| MADE BY: Aenasoaei Denis-Claudiu |"<< endl;
- cout << "| DEVELOPED IN: CODE::BLOCKS IDE |"<< endl;
- cout << "| PROFESOR COORDONATOR: Hulea Monica |"<< endl;
- cout << "| |"<< endl;
- cout << "| PRESS B TO GO BACK TO MAIN MENU |" << endl;
- cout << "|______________________________________________________________________|" << endl;
- cin>> x;
- system("cls");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement