Skip to main content
GameDev.net gamedev.net
🔒 Locked

Platformer game "events"

Started by TimMonteiro Apr 17, 2013 at 4:52 AM 1 replies 2.1k views
Original Post
TimMonteiro
TimMonteiro

Alright, so I'm working on a platformer game, but I can't decide upon the best way to implement "events" into my game. Let's say the player presses the action button while in front of a computer. The game should then pause level physics/entity updates and display a dialogue box. Or say the player reads a notebook they shouldn't have, and an angry villager confronts you (moving from point A to point B). Maybe the screen shakes. Maybe an event calls ANOTHER event if a choice is made/the player has a specific item in their inventory/et cetera.

The thing is, what IS the best way to structure this?

Ludus
Ludus

This is a difficult question, due mainly to how specific it is. Generally, the more specific the problem you're trying to solve is, the more the answer depends on how you've structured the rest of the code thus far. It's always good to remember one of the basic tenets of OOP in these cases - objects should handle everything that deals with itself. In the case of your computer example, it's the computer object that should contain functions to check if the player pressed the action button as well as functions to carry out the consequent events (the dialogue box would likely be a separate event carried out by a dialogue manager object of sorts). In the case of your notebook example, it's the angry villager that should check if the player is reading the notebook (rather than the notebook containing the code to make the villager confront you). Shaking the screen could be a function coded into the camera object, and this function would be called by the angry villager.

proanim
proanim

The way I would do it is to check for true/false value of players action so the thing would remain quite simple for example:

if (player == interact_pc)

{

PhysicsUpdate = 0;

EnitityUpdate = 0;

ShowDialog(text, options);

}

or

if (player == ForbiddenAction)

{

npc = hostile;

NpcAttackPlayer();

}

You can always make some sort of trigger object that executes a script or some other predefined action if the conditions are met.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.