View Full Version : help starting a game.
qwertiop
04-15-2002, 10:53 AM
ok, i am trying to make a basic game, like an overhead action game, with basic ascii graphics. I want to set up the game in some sort of time loop, so I can move the enimies around every 1 sec, or whatever. I used the getch() function to get keyboard input, for moveing the player, but the problem is that when the program executed the getch(), it pauses and waits for the user input. this means that everything else can only move when the player moves. does this make any sense? how would I go about doing this?
Leeman_s
04-15-2002, 12:51 PM
I would like to know as well
GodLike
04-15-2002, 12:58 PM
can you tell what kind of enemies you do
what size
and more about the game
??
qwertiop
04-15-2002, 02:33 PM
there just basic enemies, represented on the screen with 1 character, (for ex: 'o') starting out, all I want to do is have the enemies chase after the player, and let the player be able to move at the same time. If the enemy touches the play, he dies. Once I get that to work I can add to it.
Tazar_Azar
04-15-2002, 03:00 PM
Hmm.. I am not really sure either but this might work. Create another function for the computer like
void MoveComputer(hOutput, STRUCT computer);
or something. Make it so it moves randomly about or something in a certain area, and if the player moves, make it so it moves towards the player. I am not sure if thats what your wanting or not though... I kind of confused myself.
MrWizard
04-15-2002, 03:11 PM
Here's some sample code from a game I wrote a long time ago. I understand why you don't want the game to wait for the getch( ), so basically you just want to be informed when someone DOES hit a key. Try this. Also you must include the header file CONIO.H NOTE: This is only a code snippet
int keycode;
// If a key is hit do something!
if( kbhit() )
{
keyCode = getch();
// Left movement
if( keyCode == 49 )
{
pBoss->Move( keyCode );
}
// Down movement
else if( keyCode == 50 )
{
pBoss->Move( keyCode );
}
// Right movement
else if( keyCode == 51 )
{
pBoss->Move( keyCode );
}
// Up movement
else if( keyCode == 53 )
{
pBoss->Move( keyCode );
}
else if( keyCode == 109 )
{
if( !bRandom )
{
bRandom = true;
pBoss->Move( keyCode );
}
else
{
bRandom = false;
}
}
}
Xterria
04-15-2002, 04:12 PM
yeah but it looks to me like that code would stop or atleast slow down the other moving sprites when you move your character
Dual-Catfish
04-15-2002, 07:20 PM
Yes, most likely for a fraction of a second :)
um.. i'd highly consider going to http://www.gametutorials.com and check out the console tutorials to get a decent idea of how to do this stuff..
*sigh* if only C++ could use true multithreading like Java.
MrWizard
04-15-2002, 10:53 PM
Originally posted by Xterria
yeah but it looks to me like that code would stop or atleast slow down the other moving sprites when you move your character
No noticeable slow down for me. It worked fine and I had a decent amount of stuff on the screen.
xds4lx
04-16-2002, 12:12 AM
C++ can do multithreading, you just have to find the right 3rd party libraries or OS support. I know you can download a Win32/Dos port of the POSIX pthreads, heres a link: http://sources.redhat.com/pthreads-win32/ ,enjoy.
heat511
04-16-2002, 08:10 AM
im making a game like you are qwertiop
im using a two dimensional character array to hold the background
then vaiables to hold the top and left positions of the enemies
and a set of variables to hold the position of the guy
use the code mr wizard gave you, but modify it and call a make screen function at the end of it
in the make screen code clear the screen and then show the 2 d array
the hardest part is collision detection
Actually here is the game i have partially finished. It might help you. It is poorly commented and pretty ridiculous at points but it should help you. Enemies are not programmed yet, and your keys are up down left right and escape to end. Walls fall randomly and will eventually block your way. Unfortunetly its only 40% finished, but its only my second game and I think it's pretty good so far. (The death animation may have some glitches, I haven't looked at it in awhile)
i would suggest using COORD type structs to hold the cursor position and the positions of the players and enemies, so that way you don't have to keep making calls to the setConsoleCursorPosition...
qwertiop
04-16-2002, 06:01 PM
thanks everyone, your responses were a big help. i got the main stuff working now.
frenchfry164
04-16-2002, 07:05 PM
I like how Allegro handles the keyboard. It's very easy to use.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.