handling of movement & other events

Started by
4 comments, last by ver_T_ex 20 years, 5 months ago
Hi guys, I''m currently working on a 2D Tile Based RPG. So far, everything is great. But now I''ve come to a problem of moving different objects at any time in a very easy way. But moving objects is not the only thing i want to do . Things like, drawing text for 5 seconds or doing other things for a certain time. Those activites all need more than 1 frame. The silliest variant would be like that:

BOOL bMovePlayerRight=TRUE;

if(bMovePlayerRight)
{
Player.MovePlayerRight();
}
That''s too static and nonflexible. So I tought about an event handler class and an event class.

#define EVENT_MOVE_PLAYER_RIGHT		1
#define EVENT_DRAW_TEXT				2

class Event
{
private:
	VOID	*vObject;			// Pointer to the object, we are going to draw the text with e.g.

	VOID	*vData;				// Pointer to 

	int		EventID;			// Tell the class which event 

	double	EventDelay;
	double	EventDuration;

public:
	Init(VOID *vObject,VOID *vData, int EventID, double EventDelay, double EventDuration);
	ExecuteEvent();				// Checks, whether it''s time (EventStartTime + EventDelay) to execute the event

};

class EventHandler
{
private:
	vector<Event> EventList;

public:
	AddEvent(VOID *vObject,VOID *vData, int EventID, double EventDelay, double EventDuration);
	ExecuteEvents();			// loops through the events and executes them

};
I''m unsure about that, so I want to ask you guys about that idea. I don''t know how it is handled in professional designed computer games. Maybe you can tell me something about it. Thanks
Advertisement
That''s pretty much right. Each frame call something like object.update() and that function will move or update the object with a counter based on a flag or some other variables of your choice. Another call, object.activate() or something, will start the counter going and/or set flags for the move procedure to use.

Mark

Flatspace is coming: Topdown Elite for 2004
Is it rational to handle thing like movement of a player and text drawing or other timers in the same event class ?

Are the VOID pointers also good ? (pointers contains either the player object or the CText object)

What about function pointers for a better use?

I have no idea how it could be solved best.
rather than a void *, you might wanna derive your "controllable"
objects from an abstract base class.

class CControlable
{
virtual void Update ( keyList ) = 0;
};


this way you can handle your movements specifically for each objects.
wouldn''t that be IControlable? :D
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
How do complex games handle this stuff ? Do they write a method for each problem in order to run them by a script language ?

(e.g. Object.SetNewMovePos(); Text.DrawTextForATime(); Graphic.AnimateStatusBar(); )

This topic is closed to new replies.

Advertisement