I'm making an ASCII tile-based game. Which way should i go? Should I refresh the console every frame? (like a regular game)
or should I use gotoxy() to cut down the refresh time but add complexity.
Vote and comment.
Use gotoxy(); welcome to the console!
Refresh the map! It's easy and dynamic!
I'm making an ASCII tile-based game. Which way should i go? Should I refresh the console every frame? (like a regular game)
or should I use gotoxy() to cut down the refresh time but add complexity.
Vote and comment.
"If you tell the truth, you don't have to remember anything"
-Mark Twain
Simple is always better, except when it is unquestionably inefficient ( bubblesort ). Go with the option that will save you time porting the game in the future and is easier to code/understand now.
-Prelude
My best code is written with the delete key.
Ok. Anyone else?
"If you tell the truth, you don't have to remember anything"
-Mark Twain
Heheh
>Ok. Anyone else?
Translation: That wasn't the answer I wanted, go away.
-Prelude
My best code is written with the delete key.
Refresh the map
That's the way I do it, and it seems easier
Well, I will disagree because refreshing the map on a console looks awful. gotoxy() will be good experience because it resembles dirty rectangles in "regular" games.
Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/
gotoxy():
+ easy (talking about complezity?)
+ dirty rectangles is easy to implement =>
+ more efficient
- not so portable (but doubt that you can make that game without using some non-portable functions...)
or you could use graphics mode (or textmode(C4350) - though bot of these aren't very portable...) and leave gotoxy()...
>Well, I will disagree because refreshing the map on a console looks awful
He speaks truth there. If you were not doing a console game, I would refresh the map, but refreshing in console does look awful. Its all flashy and seizure-causing.....
So use gotoxy().
>Translation: That wasn't the answer I wanted, go away.
I thought it might sound like that. Not what I intended.
"If you tell the truth, you don't have to remember anything"
-Mark Twain
Poke me with a stick; this is what I have.
It should compile (except for the clrscr() which i haven't even used yet - I will) (You can actually comment it out if you wish to compile)
Code:#include <iostream.h> #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <windows.h> #include <string.h> #include <fstream.h> #define _clrscr //nclude <monkey.h> typedef enum UPARAM {ZIP,UP,DOWN,LEFT,RIGHT,Q,A,Z,W,S,X}; int COL_MAX = 49; int ROW_MAX = 11; int PLAYERX = 1; int PLAYERY = 13; int WINPLAYERX = PLAYERY; int WINPLAYERY = PLAYERX; char ITEM = 'O'; char PLAYER = (char)1; char ItemMessage[50] = "You picked up an item!"; int ItemMessageLength = strlen(ItemMessage); char GamePath[50]; char* message = new char[50]; char MAP[11][49] = {"++____________________________________________++", "|| |O |# ||", "|| | |---------------_ ||", "|| | |> |---_----------_ ||", "|| | | O | | ||", "|| | |> | | | | ||", "|| | | | | ||", "|| |______|______| --------------- ||", "|| ||", "||--------------------------------------------||", "++============================================++"}; void display(); int ReadFiles(); int QueryGame(); int Log(const char* output); void gotoxy(int x,int y); UPARAM PassParam(UPARAM Uparam); int main() { //QueryGame(); //ReadFiles(); message = " "; char input; char arrow; UPARAM Uparam = ZIP; display(); /////////////GAME PUMP/////////////GAME PUMP//////////////////// /////////////GAME PUMP/////////////GAME PUMP//////////////////// /////////////GAME PUMP/////////////GAME PUMP//////////////////// while(1) { //OUTPUT MESSAGE (BLANK IF THERE IS NOTHING TO SAY) if(!strcmpi(message," ")) { } else { gotoxy(ROW_MAX,COL_MAX); printf(message); printf(" "); gotoxy(ROW_MAX,COL_MAX); //Log(); while(!kbhit()); } message = " "; input = getch(); //IF ARROW KEY... if((int)input == -32) { arrow = getch(); switch(arrow) { case 'H': { Uparam = UP; }break; case 'P': { Uparam = DOWN; }break; case 'K': { Uparam = LEFT; }break; case 'M': { Uparam = RIGHT; }break; } } //IF OTHER THAN ARROW KEY... else { switch(input) { case 'x': { return 0; }break; } } //SEND MESSAGE PassParam(Uparam); } /////////////END GAME PUMP/////////////END GAME PUMP//////////////////// /////////////END GAME PUMP/////////////END GAME PUMP//////////////////// /////////////END GAME PUMP/////////////END GAME PUMP//////////////////// return 0; } void display() { char displayer; for(int loop2 = 0; loop2 < ROW_MAX; loop2++) { for(int loop1 = 0; loop1 < COL_MAX; loop1++) { displayer = MAP[loop2][loop1]; printf("%c",displayer); if(loop1 == (COL_MAX - 1)) printf("\n"); } } } UPARAM PassParam(UPARAM Uparam) { switch(Uparam) { case UP: { if(MAP[PLAYERX - 1][PLAYERY] != ' ') { if(MAP[PLAYERX - 1][PLAYERY] == ITEM) { message = ItemMessage; gotoxy(WINPLAYERX,WINPLAYERY); printf(" "); gotoxy(WINPLAYERX,WINPLAYERY - 1); printf("%c",PLAYER); gotoxy(0,ROW_MAX); PLAYERX = PLAYERX - 1; WINPLAYERY = PLAYERX; } else { } } else { gotoxy(WINPLAYERX,WINPLAYERY); printf(" "); gotoxy(WINPLAYERX,WINPLAYERY - 1); printf("%c",PLAYER); gotoxy(0,ROW_MAX); PLAYERX = PLAYERX - 1; WINPLAYERY = PLAYERX; } }break; case DOWN: { if(MAP[PLAYERX + 1][PLAYERY] != ' ') { if(MAP[PLAYERX + 1][PLAYERY] == ITEM) { message = ItemMessage; gotoxy(WINPLAYERX,WINPLAYERY); printf(" "); gotoxy(WINPLAYERX,WINPLAYERY + 1); printf("%c",PLAYER); gotoxy(0,ROW_MAX); PLAYERX = PLAYERX + 1; WINPLAYERY = PLAYERX; } else { } } else { gotoxy(WINPLAYERX,WINPLAYERY); printf(" "); gotoxy(WINPLAYERX,WINPLAYERY + 1); printf("%c",PLAYER); gotoxy(0,ROW_MAX); PLAYERX = PLAYERX + 1; WINPLAYERY = PLAYERX; } }break; case LEFT: { if(MAP[PLAYERX][PLAYERY - 1] != ' ') { if(MAP[PLAYERX][PLAYERY - 1] == ITEM) { message = ItemMessage; gotoxy(WINPLAYERX,WINPLAYERY); printf(" "); gotoxy(WINPLAYERX - 1,WINPLAYERY); printf("%c",PLAYER); gotoxy(0,ROW_MAX); PLAYERY = PLAYERY - 1; WINPLAYERX = PLAYERY; } else { } } else { gotoxy(WINPLAYERX,WINPLAYERY); printf(" "); gotoxy(WINPLAYERX - 1,WINPLAYERY); printf("%c",PLAYER); gotoxy(0,ROW_MAX); PLAYERY = PLAYERY - 1; WINPLAYERX = PLAYERY; } }break; case RIGHT: { if(MAP[PLAYERX][PLAYERY + 1] != ' ') { if(MAP[PLAYERX][PLAYERY + 1] == ITEM) { message = ItemMessage; gotoxy(WINPLAYERX,WINPLAYERY); printf(" "); gotoxy(WINPLAYERX +1,WINPLAYERY); printf("%c",PLAYER); gotoxy(0,ROW_MAX); PLAYERY = PLAYERY + 1; WINPLAYERX = PLAYERY; } else { } } else { gotoxy(WINPLAYERX,WINPLAYERY); printf(" "); gotoxy(WINPLAYERX + 1,WINPLAYERY); printf("%c",PLAYER); gotoxy(0,ROW_MAX); PLAYERY = PLAYERY + 1; WINPLAYERX = PLAYERY; } }break; default: { }break; } return ZIP; } int ReadFiles() { char* COLMAX = new char[2]; char* ROWMAX = new char[2]; ifstream FileReader(GamePath/*\\boarddimensions.txt*/); FileReader>>ROWMAX; FileReader>>COLMAX; FileReader.close(); COL_MAX = atoi(COLMAX); return 0; } int QueryGame() { printf("Input game path\n"); cin.getline(GamePath,50,'\n'); ReadFiles(); clrscr(); return 0; } int Log(const char* output) { ofstream writer(GamePath/*\\Log.txt*/); writer<<message<<endl; return 0; } void gotoxy(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); }
"If you tell the truth, you don't have to remember anything"
-Mark Twain