Reputation: 3358
I'm making a Flash turn-based RPG to practice OOP (who doesn't :P) I have a pretty good setup with the Weapons, Items, and all that Jazz. Though I'm currently considering how I will make my characters.
Currently I have an player
and enemy
class that extends the battler
class.
Battler
/ \
/ \
Player Enemy
My player
class has some functions that initialize the player itself, adding the graphics and all that. My party
class calls on player
, passing a paramater like so: player.setup(1) with 1 being the playerID.
To Clarify this is my player pseudocode:
{ setup(player_id)
player = **??????player_id??????????**
name = player.name
character_name = player.character_name
character_index = player.character_index
weapon_id = player.returnWeapon
/*---------
armor1_id = player.returnArmor //increase for other body parts
----------*/
level = player.level
}
My question, or more of a problem is how I will store the player data. I need to have many players as this is a game with many players in a party.
How will I actually use something like player.returnArmor
? Because when I do that it just calls a function, and it will not know who that player is (I guess I could use parameters, like player.returnArmor(player)
but I think there is a better way to do this.
Any language is welcome, but just so you don't use assembly language as an example ;), C++, Actionscript 3, Ruby, and/or Java is fine. Please Help Me! Thank you in advance.
Upvotes: 0
Views: 364
Reputation: 5265
It might be worth considering using an entity system, where each item in the game is treated as a collection of unrelated properties (location, velocity, bitmap/mesh) which can be managed separately. This tends to make the hard problems easier (scalability, synchronisation, storage).
Upvotes: 2
Reputation: 8145
In AS3 you can have static and instance functions. If you call player.returnarmor()
, you're calling a static function. You want to have an instance function, and call it for the instance of the player whose armor value you want.
If you have a few (<4) characters, you can just have named variables for each, but more than 3 or 4 and you should just have an array or other container for them.
var mainProtagonist:player;
var spunkySidekick:player;
var whiteMage:player;
var players:Array = new Array();
players.push(mainProtagonist);
players.push(spunkySidekick);
players.push(whiteMage);
Then to get a player's armor...we'll say you want the spunky sidekick's armor:
players[1].returnarmor();
// or
spunkySidekick.returnarmor();
You might have an array of all the players in existence, as well as another array, when used in battle, with just the players in the current party/battle. That way your enemies can target players at random, and only from those currently in the battle.
Upvotes: 2