Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ROGUE/main.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
198 lines (175 sloc)
7.24 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
#include<windows.h> | |
#include<conio.h> | |
#include<cstdlib> | |
#include<time.h> | |
#include<fstream> | |
#include "core.h" | |
#include "loadMap.h" | |
#include "menu.h" | |
#include <vector> | |
#pragma comment(lib,"Winmm.lib") | |
#include <mmsystem.h> | |
char buttonPressed; | |
bool exitGame=false; | |
bool inGame=true; | |
Player player; | |
//------------------changed-------------------------- | |
int framesDelay; | |
//'------------------------------------------------- | |
void displayInfo(int x,int y){ | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),9); | |
moveto(2,20); | |
cout<<"location:"<<'('<<x<<','<<y<<')'<<endl; | |
moveto(2,34); | |
} | |
void checkInput(){ | |
buttonPressed='0'; | |
if(_kbhit()==1){ | |
buttonPressed=getch(); | |
} | |
} | |
void start() | |
/* places objects on the map*/{ | |
srand(time(NULL)); | |
//loadMap("level_1.txt"); | |
loadMap("maplevel1.txt"); | |
placeObjects(); | |
moveto(player.x,player.y); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); | |
cout<<"P"; | |
} | |
void updateState() | |
/*this function checks the collisions beteween objects in the game*/ | |
{ | |
if((buttonPressed=='w')||(buttonPressed=='s')||(buttonPressed=='a')||(buttonPressed=='d')){ | |
mciSendString("play sfxMusic.wav", NULL, 0, NULL); //add sfxx music | |
if(buttonPressed=='w'){ | |
if (readLocation(player.x,player.y-1)!='#' && readLocation(player.x-1,player.y)!='o' && readLocation(player.x,player.y-1)!='<' && readLocation(player.x,player.y-1)!='>' && readLocation(player.x,player.y-1)!='^'){ | |
if (pickableItem(player.x,player.y-1,buttonPressed)==1){ | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),1); | |
moveto(player.x,player.y-2); | |
cout<<'@'; | |
moveto(player.x,player.y); | |
cout<<" "; | |
player.y-=1; | |
moveto(player.x,player.y); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); | |
cout<<"P"; | |
} | |
else{ | |
if (readLocation(player.x,player.y-1)!='@'){//checking if pickable object is alligned vertically with wall | |
moveto(player.x,player.y); | |
cout<<" "; | |
player.y-=1; | |
moveto(player.x,player.y); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); | |
cout<<"P"; | |
} | |
} | |
} | |
displayInfo(player.x,player.y); | |
} | |
if (buttonPressed=='s'){ | |
if (readLocation(player.x,player.y+1)!='#' && readLocation(player.x-1,player.y)!='o' && readLocation(player.x,player.y+1)!='<' && readLocation(player.x,player.y+1)!='>' && readLocation(player.x,player.y+1)!='^'){ | |
if (pickableItem(player.x,player.y+1,buttonPressed)==1){ | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),1); | |
moveto(player.x,player.y+2); | |
cout<<'@'; | |
moveto(player.x,player.y); | |
cout <<' '; | |
player.y+=1; | |
moveto(player.x,player.y); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); | |
cout<<"P"; | |
} | |
else{ | |
if (readLocation(player.x,player.y+1)!='@'){ | |
moveto(player.x,player.y); | |
cout<<" "; | |
player.y+=1; | |
moveto(player.x,player.y); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); | |
cout<<"P"; | |
} | |
} | |
} | |
displayInfo(player.x,player.y); | |
} | |
if (buttonPressed=='a'){ | |
if (readLocation(player.x-1,player.y)!='#' && readLocation(player.x-2,player.y)!='o' && readLocation(player.x-1,player.y)!='<' && readLocation(player.x-1,player.y)!='>' && readLocation(player.x-1,player.y)!='^') { | |
if (pickableItem(player.x-1,player.y,buttonPressed)==1){ | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),1); | |
moveto(player.x-2,player.y); | |
cout<<'@'; | |
moveto(player.x,player.y); | |
cout <<' '; | |
player.x-=1; | |
moveto(player.x,player.y); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); | |
cout<<"P"; | |
} | |
else{ | |
if (readLocation(player.x-1,player.y)!='@'){ | |
moveto(player.x,player.y); | |
cout<<" "; | |
player.x-=1; | |
moveto(player.x,player.y); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); | |
cout<<"P"; | |
} | |
} | |
} | |
displayInfo(player.x,player.y); | |
} | |
if(buttonPressed=='d'){ | |
if (readLocation(player.x+1,player.y)!='#' && readLocation(player.x-1,player.y)!='o' && readLocation(player.x+1,player.y)!='>' && readLocation(player.x+1,player.y)!='<' && readLocation(player.x+1,player.y)!='^'){ | |
if(pickableItem(player.x+1,player.y,buttonPressed)==1){ | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),1); | |
moveto(player.x+2,player.y); | |
cout<<'@'; | |
moveto(player.x,player.y); | |
cout<<' '; | |
player.x+=1; | |
moveto(player.x,player.y); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); | |
cout<<'P'; | |
} | |
else{ | |
if (readLocation(player.x+1,player.y)!='@'){ | |
moveto(player.x,player.y); | |
cout<<" "; | |
player.x+=1; | |
moveto(player.x,player.y); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),11); | |
cout<<"P"; | |
} | |
} | |
} | |
displayInfo(player.x,player.y); | |
} | |
} | |
} | |
int main(){ | |
present_the_main_nenu(); | |
PlaySound(TEXT("backgroundMusic.wav"), NULL, SND_FILENAME | SND_LOOP | SND_ASYNC); //add bacground music | |
start(); | |
while(player.lleft >= 0){ | |
updateState(); | |
checkInput(); | |
if (buttonPressed=='e'){ | |
system("CLS"); | |
moveto(52,20); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),6); | |
cout<<"GAME OVER "; | |
} | |
if(player.lleft==0){ | |
system("CLS"); | |
moveto(52,20); | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),6); | |
cout<<"You ran out of moves "; | |
} | |
} | |
return 0; | |
} |