A grid movement question

Started by
50 comments, last by TheNerd Tk421 20 years, 8 months ago
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]
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
Scott SimontisMy political blog
I relly don''t like Gametutorial... the way they set up there tutorials are terrible.. dont teach me a thing...
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]
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?).
el
I thought there might have been away...i have problems with Win32... i dont know ne where with good tutorials that do work with compiler(Dev C++ 5.0)....
What is a 2D buffer?...and do you know ne good tutorial 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
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.
How do i clear....
i can see...
clear screen
print c at x,y
... sumtin close to that but in C++?

[edited by - TheNerd Tk421 on August 8, 2003 1:45:55 PM]

This topic is closed to new replies.

Advertisement