Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So, I have a player class with basic actions. During the gameplay he unlocks new abilities. I don't know how to store new actions within the player class. To be precise - I know how, but my method is too messy and i want to clean up code. Also, I want to add to the enemies some of those abilities. In other words, every game entity(expect walls, perhaps :D) should have a collection to which i can add methods that extend entity functionality. How do i make this? Sorry, if my question is too abstact

share|improve this question
3  
It could help if you post the code you already have –  Thomas Jan 27 '13 at 15:21
    
@Thomas has a point, even if it's just some basic pseudo-code so we have a better idea of what path you're on. –  user24851 Jan 27 '13 at 16:42
    
@Thomas well, i posted it below :D –  edwing Jan 27 '13 at 19:08

2 Answers 2

I recommend you approach used in the Artemis Entity System Framework. You can think about your player, enemy, wall etc. like about container (entity) for components. Then you precise actions (systems) for entities with particular set of components.
For example you can create system that allows player to fly when the X key is pressed (in-game condition) and when entity represented player has component flying (in-engine condition). Assume that player has ability for fly only if he has some wings in inventory. If this happen just add component flying to player entity and this will unlock flying for player.

share|improve this answer
    
This is my first game and I want to make everything(within reasonable limits) by myself, but thanks! –  edwing Jan 27 '13 at 18:38
up vote 0 down vote accepted

I've received a great reply on StackOverflow This problem can be solved with dictionary and lambda functions

public Dictionary<string,Action> Powers = new Dictionary<string,Action>();

And add new powers to this dictionary:

Powers["Double Jump"] = () => { //jump code };

Then just call whenever you want Powers["Double Jump"]();

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.