Created
January 26, 2016 17:00
-
-
Save anonymous/3816d896baba94b1067e to your computer and use it in GitHub Desktop.
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 "stdafx.h" | |
#include <iostream> | |
#include <conio.h> | |
using namespace std; | |
#define K_UP 72 | |
#define K_DOWN 80 | |
#define K_LEFT 75 | |
#define K_RIGHT 77 | |
#define WORLD_X 20 | |
#define WORLD_Y 20 | |
char values[128] = { 'e', }; | |
char rendered[WORLD_X][WORLD_Y]; | |
char player = '#'; | |
int key = 0; | |
int posx = 10; | |
int posy = 10; | |
int world[WORLD_X][WORLD_Y]; | |
int get_input() { | |
if (_kbhit()) { | |
return _getch(); | |
} | |
else { | |
return 0; | |
} | |
} | |
void init() { | |
// Fill world with 0s, rendered with spaces | |
for (int x = 0; x <= WORLD_X; x++) { | |
for (int y = 0; y <= WORLD_Y; y++) { | |
world[x][y] = 0; | |
//rendered[x][y] = ' '; //MAGIC MAGIC MAGIC MAGIC <<<---------- | |
} | |
} | |
} | |
void render() { | |
for (int x = 0; x <= WORLD_X; x++) { | |
for (int y = 0; y <= WORLD_Y; y++) { | |
if (x == posx && y == posy) { | |
cout << player; | |
} | |
else { | |
cout << values[world[x][y]]; // TU SIE WYPIERDALA | |
} | |
} | |
cout << endl; | |
} | |
} | |
int main() | |
{ | |
init(); | |
while (true) { // Game loop | |
key = get_input(); | |
if (key) { | |
switch (key) { | |
case K_UP: | |
posx--; | |
break; | |
case K_DOWN: | |
posx++; | |
break; | |
case K_LEFT: | |
posy--; | |
break; | |
case K_RIGHT: | |
posy++; | |
break; | |
} | |
system("cls"); | |
render(); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment