Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <conio.h>
- using namespace std;
- //Declare the player's position
- int nPlayerX=4, nPlayerY=4;
- //Colour
- HANDLE colour = GetStdHandle(STD_OUTPUT_HANDLE);
- void gotoxy(int x, int y)
- {
- COORD c;
- c.X=x;
- c.Y=y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
- }
- int main()
- {
- while(true)
- {
- //Map drawing
- system("cls");
- //Draw the player to the screen
- gotoxy( nPlayerX, nPlayerY);
- SetConsoleTextAttribute(colour, 14);
- cout<<"@"<<"("<<nPlayerX<<","<<nPlayerY<<")";
- SetConsoleTextAttribute(colour, 15);
- //Input
- char input = getch();
- //Processing
- int nDeltaX;
- int nDeltaY;
- switch(input)
- {
- //Move up
- case 'w':
- nDeltaX = 0;
- nDeltaY = -1;
- break;
- //Move left
- case 'a':
- nDeltaX = -1;
- nDeltaY = 0;
- break;
- //Mode down
- case 's':
- nDeltaX = 0;
- nDeltaY = 1;
- break;
- //Move right
- case 'd':
- nDeltaX = 1;
- nDeltaY = 0;
- break;
- //Ignore
- default:
- break;
- }
- //Check and see if we're allowed to move in the specified direction
- // ( irrelevant, deleted for now)
- nPlayerX += nDeltaX;
- nPlayerY += nDeltaY;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement