Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Simultanious Operations

Status
Not open for further replies.

TheElusiveYak

Programmer
Feb 8, 2004
19
US
Hello Again,
I am now working on a sprite driven RPG. I am trying to figure out how to get all the npc's to move independently of the charicter but how do i coordinate it so that when the user enters a command to move it immediatly replies even though all the NPC's are still moving. Is there some way to process this effectivly? Any and all help would be appriciated.
 
In Windows I would say you want to multi-thread and make each an object. But in DOS I would say you'll just have to check each of your NPCs on a loop (and your key input) and then move them according to game directions or the keyboard input.

WHILE GAME STILL GOING ON DO
BEGIN
PROCESS KEYPRESS
CHECK NPC1, MOVE IF NECESSARY
CHECK NPC2, MOVE IF NECESSARY
END;

Basically this is why a lot of the 3D games went seriously up in requirements. If you want an example, consult the breakout game in the stock examples that came with TP.
 
The classic way to write games like this is a loop:

do until level completed
deal with npcs
deal with player (look for key and move accordingly)
deal with other things (update score line, whatever)
repeat

The usual problems are to make sure that the loop runs fast enough that everything gets done without obvious delays or jerky action.
The other problem is to make sure that the deal-with-player section isn't stupidly slow if the player decides to do something. This can cause a smoothly-gliding npc to jerk slightly when a key is pressed.

If you're writing in a DOS environment you're probably drawing on the real, displayed screen, in which case there may be visual messy effects. There are various ways to improve this. I experimented a while back with preparing a list of things to draw during the loop, and then doing all the drawing at the end as an extra item:
loop
add npcs to drawing list
add player to drawing list
add any other bits to drawing list
draw everything
repeat

good luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top