• Advertisement

Archived

This topic is now archived and is closed to further replies.

A grid movement question

This topic is 5373 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how to get a figure(letter "C" to be exact) on the screen to stand for the main character.... here is the source code if you have no clue what im talking about... #include <iostream> #include <stdlib.h> #include <iomanip> #include <conio.h> using namespace std; void startup_menu(); int main_menu(); void move(); void location(int, int); int main() { //main loop startup_menu(); return 0; } void location(int xcoord, int ycoord) { cout << setw(73) << "Your location is " << xcoord << ", " << ycoord << endl; } void move() { char dir = 'a'; int x = 10, y = 10; while(dir != 'q') { dir = getch(); ("cls"); switch(dir) { case 'w': y--; system("cls"); cout << "\nYou move North." << endl; break; case 's': y++; cout << "\nYou move South." << endl; break; case 'd': x++; cout << "\nYou move East." << endl; break; case 'a': x--; cout << "\nYou move West." << endl; break; case 'l': location(x,y); break; case 'q': system("cls"); return; default: cout << "Try again"<[edited by - TheNerd Tk421 on August 8, 2003 12:51:03 PM] [edited by - TheNerd Tk421 on August 8, 2003 1:24:05 PM] [edited by - TheNerd Tk421 on August 8, 2003 1:24:41 PM] [edited by - TheNerd Tk421 on August 8, 2003 1:25:18 PM]

Share this post


Link to post
Share on other sites
Advertisement
You would probaly need to provide x y coodinates. Check out GameTutorials under C++, and you might find what you are looking for.

Scott Simontis
If it wasn''t for C, we''d be using BASI, PASAL and OBOL

Share this post


Link to post
Share on other sites
Can ne 1 help me with my problem?.. i need to have a character on the screen that moves when i push the directional keys
( W
A S D )...pls

[edited by - TheNerd Tk421 on August 8, 2003 1:26:05 PM]

Share this post


Link to post
Share on other sites
I don''t think there''s a way of doing it in pure C++ (ie using some kind of function). Maybe you should build a 2 dimensional buffer representing your screen, or use something else (maybe WIN32?).

Share this post


Link to post
Share on other sites
In Borland C++ exists a include file named conio.h .
There are several functions for console screen editing.
gotoxy, color change, ...

Perhaps you can find a conio.h which is compatible with your compiler.

schiggl

Share this post


Link to post
Share on other sites
There''s probably some way to set where you write text onto the screen, but I don''t know what it would be. Try searching google for "c++ console output text location of screen" or somesuch.

I can suggest a rather inelegant solution however: completely clear and redraw the screen every time the character moves. You then don''t need to specify a particular location on the screen after drawing other things.

Share this post


Link to post
Share on other sites

  • Advertisement