Page 1 of 1

Playing Roles CALVERVTUTURP READ THIS!!!

PostPosted: Thu Sep 25, 2008 1:21 am
by BlarghNRawr
Calvervtuturp is making the adventure mode for my smash bros planet ( :mrgreen: ), and he/i need to know how to play roles in RPG games, so all of your party and the enemy takes turns
also the enemy needs to attack a random party member instead of always one

Re: Playing Roles CALVERVTUTURP READ THIS!!!

PostPosted: Sat Sep 27, 2008 9:06 pm
by edh
You could make a variable to hold the current active character. You could actually make an array to store the information you would need in a struct, one struct for each character. Then when you move (keydown or mouse click) the active character would move, do it's action, whatever. When the turn ends, increment the variable for the current character.

WARNING: Rough example follows.
Here is a struct to store a character name, reference to an actor (sprite), some hit points and some magic points. You could do whatever you need. The important piece is probably the actor pointer.

This example also creates an array of two heros and sets some default values.

Code: Select all
struct character {
        char *name;
        Actor* actor;
        int hp;
        int mp;
} heroes[2] = { {"hero one\0", 0, 10, 10}, {"hero two\0", 0, 5, 15} };


Then you could have a global value for which character is active and the total number of actors (for bookkeeping).
Code: Select all
int activeCharacter  = 0;
int numberCharacters = 2;


Then when you want to move one, you could do something like this.
Code: Select all
heroes[activeCharacter].x += 5;


At the end of a character turn you would increment the activeCharacter, taking care to make sure you don't go past the end of the array.
Code: Select all
activeCharacter = (++activeCharacter) % numberCharacters;


To attack one randomly (assuming all characters are in a place where they could be attacked), you would just generate a random number from 0 to numberCharacters.

Re: Playing Roles CALVERVTUTURP READ THIS!!!

PostPosted: Sat Sep 27, 2008 9:41 pm
by BlarghNRawr
O_O
never thought of that :) thnx

Re: Playing Roles CALVERVTUTURP READ THIS!!!

PostPosted: Mon Mar 02, 2009 4:18 pm
by equinox
int mp;
} heroes[2] = { {"hero one\0", 0, 10, 10}, {"hero two\0", 0, 5, 15} };

why instead not to write: heroes[2] = { {"hero.0", 0, 10, 10}, {"hero.1", 0, 5, 15} };