How can I use this--> STRUCT ?

Non-platform specific questions.

How can I use this--> STRUCT ?

Postby equinox » Fri Mar 06, 2009 5:17 pm

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


...Now how do I create a hero one....ecc?

Tnk1000 for help.
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: How can I use this--> STRUCT ?

Postby makslane » Fri Mar 06, 2009 8:16 pm

What you want to do with this struct?
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: How can I use this--> STRUCT ?

Postby skydereign » Sat Mar 07, 2009 1:12 am

If I understand what you are trying to do, create a player struct, then I would do a typedef and then create an array of struct pointers. I believe you only need one type of struct for your hero and let's just say enemies. The actor would have internal values that tell it which struct it is, an example being cloneindex. All of this can get a little tricky if you want to make the players on the go, as you would need to set up a realloc system. But if you know how many structs you need, then creating a struct pointer array can accomplish what you want. I would do this in the create actor for view, as it is the first actor related event.
view->CreateActor->Script Editor
Code: Select all
int i;
int j;
for (i = 0; i > 2; i++)
{
    for (j = 0; j > 5; j++)
    {
        charArray[i][j]=character_create();
    }
}

As you can tell, this needs a function called character_create, which would go into global code.
GlobalCode
Code: Select all
character_t *
character_create (void)
{
    character_t * self = calloc(1, sizeof(character_t));
    return(self);
}

This also requires a struct character_t, and more.
Note you need to create charArray[][], which is a struct * array. I can go more in depth or make a demo if need be, this is a bit circumstantial... I hope this cleared things up more than not, or at least pointed you in the right direction.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How can I use this--> STRUCT ?

Postby equinox » Sat Mar 07, 2009 8:15 am

HI,

You were very kind to explain.

If you can, please, to make myself a exmple, so I can study and understand better.

Tnk1000.

score += 1...for moment..

This code is your:
I can not understand how to use it to create "ACTOR/SPRITE" and read / write variables for ex: HERO HERO :0-.1 ..... EROE.n

struct actorName
{
double x;
double y;
char[] name;
char[] clonename;
int cloneindex;
int height;
int width;
int animindex;
int animpos;
int nframes;
int transp;
int r;
int g;
int b;
double directional_velocity;
double angle;
double xvelocity;
double yvelocity;
double xscreen;
double yscreenl
double xprevious;
double yprevious;
// And many many more.... The ones you create as actor variables appear
// Not sure on all the types but I think they are right
}
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: How can I use this--> STRUCT ?

Postby skydereign » Sun Mar 08, 2009 11:04 am

Okay, it sounds like you are trying to create your own actor... What I am doing is to create structs out in memory. Essentially an array of them, to use a struct you would need a handle. So I use a function that creates a struct and hands back a pointer to the struct. Each actor has its own internal values, such as cloneindex. I use cloneindex, along with the character type, HERO being 0, ENEMY being 1. With these values, they are plugged into the array, and I now have a pointer to the struct, allowing me to manipulate the struct. Because hero and enemy are closely related, I kept the same struct, and organized them into an array. If I am not making any sense just say so. Here is a demo of what I am talking about, maybe that will make more sense.
Attachments
basicStruct.zip
(4.27 KiB) Downloaded 85 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron