Jump to content
  • Advertisement
Sign in to follow this  
brnm

Game Objetct Properties

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

Hey there, I'm doing a little game where I need a bunch of different objects, each object behaves differently. In my game all game entities are derived from a base class, thus I have a common interface for all of my game entities. Now, each one of those game objects should behave differently upon player interaction, say one object is a chair that upon interaction should command the player character to sit on it, another is a lamp which upon interaction should command the player to switch it on or off, a phone, etc you get the idea. What would be the easiest way to supply each game object with an unique behavior ? (think sims) The most obvious solution would be to create a class for each one of those objects (deriving from a common interface of course), a chair class, a phone class, a lamp class etc. But I'm pretty sure that's not the right way to do it. Oh and I'm aware of scripting, I think I could assign a script to each game object, I could pass the player character to the script and code the behavior inside the script, but I'm trying to avoid scripting. Any thoughts ?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
The most obvious solution would be to create a class for each one of those objects (deriving from a common interface of course), a chair class, a phone class, a lamp class etc. But I'm pretty sure that's not the right way to do it.


There is no right or wrong. It's about reaching a compromise.

Quote:
Oh and I'm aware of scripting, I think I could assign a script to each game object, I could pass the player character to the script and code the behavior inside the script, but I'm trying to avoid scripting.


Why?

Anyway, this type of approach can be done with "actions". For example, each object has a set of actions addressable by name (as example). When a player wants to interact with something, you ask the object to return its available actions ("sit on", "turn on", "turn off").

When player makes a choice, you tell the object to "turn on". That in turn invokes whatever behavior you need.

This type of behavior can be implemented using delegates/function pointers/scripts/inheritance, depending on your language, performance considerations, flexibility, ....

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!