Archived

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

I have a question on a map for a game.

This topic is 5526 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

Say you had a map like so: ***** ***** ***** o**** o being the player. When the player moves it does this: ***** ***** ***** o**** ***** ***** ***** *o*** If the player moved to the right how could i display that without displaying another screen? Please help i'm stumped. Cory Fisher [edited by - ssjcory on November 30, 2002 11:10:44 PM]

Share this post


Link to post
Share on other sites
well... how''s ur map actually displayed?

*****
*****
*****
*o***

would be the result, right?

Share this post


Link to post
Share on other sites
That is actually how it is displayed. Yes that would be the end result.

Cory Fisher

Share this post


Link to post
Share on other sites
I''m... not quite sure what you''re talking about here...

What do you mean by "without displaying an other screen"? You mean loading an other bitmap...? How''s your map actually done, for that matter? Is it tile-based, a background bitmap...?

When you move the player''s sprite around, just redraw the original location he/she was on and re-plot the sprite at the new location. You don''t have to actually reload the whole screen, just the section that the player was on.

Share this post


Link to post
Share on other sites
Ok, I''m going to make the assumption that you want the player to go RIGHT, not LEFT (i.e. You''re not talking about him going off the edge of the map, which he would if he went left.)

I''m guessing your root problem is that when you move him, you get THIS display after the move[sic]:

*****
*****
*****
o****

*****
*****
*****
*o***

... as opposed to THIS:

*****
*****
*****
*o***

... am I right? In that case you might want to check out windows.h, it has some nice functions for writing a buffer to the screen. Let me know if I got what you were talking about and I''ll fill you in.

Share this post


Link to post
Share on other sites
Snippit with moronic code formatting
that may help

#include "iostream.h"
#include "windows.h" // for system call

int turncount; // the new turncount counter
char input; // the entry for movement
int posx = 1; // set starting pos
int posy = 1; // ditto
int oldposx = 1;
int oldposy = 1;
int map[8][8] = // our map
{
{35,35,35,35,35,35,35,35}, // 35 is ascii ''#'' (pound) wall
{35,46,46,46,46,46,46,35}, // 46 is ''.'' (period) floor
{35,46,46,46,46,46,46,35}, // player icon is ''@''
{35,46,46,46,46,46,46,35},
{35,46,46,46,46,46,46,35},
{35,46,46,46,46,46,46,35},
{35,35,35,35,35,35,35,35},
};
int x = 0, y = 0; // for map drawing purposes

int main()
{
system("cls"); // re-set the map
map[posx][posy] = 64; // draw the player icon
while (x < 8) // loop through the map x cordnates
{
while (y < 8) // ditto but for the y''s
{
cout << (char)map[x][y];// draw the stuff after conversion to ''pictures''
y++; // advance to the nextchar
}

cout << "\n"; y = 0; x++; // next line and reset the y to zero
}
cout << "Turn: " << turncount << " w,a,s,d to move: "; // the "command" line with turncount
cin >> input; // get input values
x = 0; // reset everything to zero for the next draw
y = 0;
if (input == ''d'') // right
{
oldposx = posx; oldposy = posy; // set the old values to the new values
posy++; // move the position
map[posx][posy] = 64;// set the location to the player icon
map[oldposx][oldposy] = 46;// set the old position to the floor icon
turncount++;
main();
}
if (input == ''a'') // down
{
oldposx = posx; oldposy = posy;
posy--;
map[posx][posy] = 64;
map[oldposx][oldposy] = 46;
turncount++;
main();
}
if (input == ''w'') // up
{
oldposx = posx; oldposy = posy;
posx--;
map[posx][posy] = 64;
map[oldposx][oldposy] = 46;
turncount++;
main();
}
if (input == ''s'') // left
{
oldposx = posx; oldposy = posy;
posx++;
map[posx][posy] = 64;
map[oldposx][oldposy] = 46;
turncount++;
main();
}
if (input == ''q'') //''q'' for quit
{
return 0;
}
main(); // back to main for the next draw unless q
}



-shadow

Share this post


Link to post
Share on other sites
I think basically, the command you were looking for was:

system("cls");

I think it''s under conio.h , not sure though. Check the headers. The command clears the screen. Only problem is it might flicker a bit, but that shouldn''t be too much of a problem.

Share this post


Link to post
Share on other sites
It''s under windows.h
Yes the command is system("cls");
You should use windows.h for GetTickCount() which is useful with random numbers via: srand(GetTickCount)
There are other system calls that I have forgotten

-shadow

Share this post


Link to post
Share on other sites
Hey guys cls is what i''m looking for but it didn''t work. Maybe the code is wrong, take a look.
#include
#include
int choice;
int x = 0;
int y = 0;
char map[5][5];
class character{
private:
int health;
int attackpower;
int defensepower;
int magicpower;
public:
setstats(int shealth, int sattackpower, int sdefensepower, int smagicpower){
health = shealth;
attackpower = sattackpower;
defensepower = sdefensepower;
magicpower = smagicpower;
}
int gethealth(){
return health;
}
int getattackpower(){
return attackpower;
}
int getdefensepower(){
return defensepower;
}
int getmagicpower(){
return magicpower;
}
};
main(){
character player;
cout<<"You have 3 options.\n";
cout<<"You can be a:\n";
cout<<"1 Paladin.\n";
cout<<"2 Magician.\n";
cout<<"3 Elf.\n";
cout<<"What would you like to be?";
cin>>choice;
if(choice==1){
player.setstats(50,25,15,20);
}
if(choice==2){
player.setstats(50,15,15,30);
}
if(choice==3){
player.setstats(50,30,20,15);
}
cout<<"\n\n\n";
cout<<"Health: "< cout<<"Attack Power: "< cout<<"Defense Power: "< cout<<"Magic Power: "< cout<<"\n\n\n";
cout<<"You start off in your room.\n";
system("cls");
cout<<"Welcome.\n";
return(0);
}

Share this post


Link to post
Share on other sites
btw:

what about using the ["source"] command ... without the "" of course

[edited by - BB-Pest on December 1, 2002 7:39:22 AM]

Share this post


Link to post
Share on other sites