Results 1 to 6 of 6

Thread: Structure for storing weapons

  1. #1
    Senior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Arlon, Belgium
    Posts
    477

    Structure for storing weapons

    Hi,

    I've a problem with my structure. I'd like to use
    a structure for storing the weapons + params and
    the bullet fired.

    Here's my structure :


    // **********************************************
    typedef struct
    {

    char Name[25];
    float x, y, z;
    int Speed, Power;

    } WEAPON_CONFIG;


    // **********************************************
    typedef struct
    {

    int Number_Weapon;
    WEAPON_CONFIG* Bullet;

    } WEAPON;


    For using the structure, I initialise it with :

    WEAPON Weapon_Use;


    And in my program, I use the structure like this :

    Weapon_Use.Bullet[i].Name[0] = ...
    Weapon_Use.Bullet[i].Power = ...

    etc ...

    In fact, I'd like to use a structure like this :

    Weapon_Use[0].Bullet[0].Power = ...

    The "Weapon_Use[]" variable will be used for storing each weapon
    (Desert Eagle, Magnum, ...)

    And the "...Bullet[]" variable will be used for each bullet fired.

    How can I adapt this structure :

    Weapon_Use.Bullet[0].Power

    In this :

    Weapon_Use[0].Bullet[0].Power


    Thanks in advance ...

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Arlon, Belgium
    Posts
    477

    Re: Structure for storing weapons

    I've made a mistake, here's the new structure :


    // **********************************************
    typedef struct
    {

    char Name[25];
    float x, y, z;
    int Speed, Power;

    } WEAPON_CONFIG;


    // **********************************************
    typedef struct
    {

    int Number_Weapon;
    WEAPON_CONFIG* Weapon;

    } WEAPON;

    How can I adapt this structure :

    Weapon_Use.Weapon[0].Power

    In this :

    Weapon_Use[0].Weapon[0].Bullet[0].Power

    Thanks.

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: Structure for storing weapons

    I must admit I haven;t read all of your post. But you wangt an array if structs where each struct has an array of structs in it, like a 2d array. If so you malloc the first struct and then loop through each of that array and malloc the second struct.

  4. #4
    Member Contributor
    Join Date
    Apr 2002
    Location
    brooklyn, ny
    Posts
    65

    Re: Structure for storing weapons

    typedef struct
    {
    int x,y,z;
    }gun;

    typedef strucct
    {
    int x,y,z;
    gun GUN[10];
    }hand;

    main()
    {
    hand HAND[10];
    HAND[0].GUN[0].x=whatever.....

    You get the idea...

  5. #5
    Senior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Arlon, Belgium
    Posts
    477

    Re: Structure for storing weapons

    Thanks a lot, I'm gonna try this.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Structure for storing weapons

    I sort of have a diffent approach and things to think about.

    First once the bullet, laser pulse, etc. has left the gun, it should become it own object.

    // Define ammo
    typedef struct
    {
    int player; // who fired it!
    int type; // 0 = hand, 1 = bullett, etc.
    int range;
    int speed;
    // start_position
    int c_x, c_y, c_z;
    // direction vector
    int v_x, v_y, v_z;
    // current_position
    int c_x, c_y, c_z; once the distance between start and current exceed range kill object.
    }

    // Define weapon
    typedef struct
    {
    int type; Type of weapon
    int damage;
    int firing_rate; How fast can it shoot, hand gun vs. machine gun
    int speed; bullett vs. laser
    int range; hand vs. bullett
    int picked_up; Does the player have the gun.
    int ammo; current ammo supply
    int ammo_max; max ammount he can carry.

    }Weapon;


    // Define player
    typedef struct
    {
    char name[30];
    weapon Weapon[8]; // Max weapons in game are 8 but could be what ever number
    int score;
    int healt;
    int gun_selected;
    }Player;


    static struct Player player[8];


    example:
    shoot()
    {
    if (player[0].weapon[player[0].gun_selected].ammo > 0) // Check to see if any ammo left to shoot
    {
    spawn_shot(player[0].weapon[player[0].gun_selected])
    player[0].weapon[player[0].gun_selected].ammo--; take away ammo.
    }

    I hope this helps.


    Originally posted by Leyder Dylan:
    Hi,

    I've a problem with my structure. I'd like to use
    a structure for storing the weapons + params and
    the bullet fired.

    Here's my structure :


    // **********************************************
    typedef struct
    {

    char Name[25];
    float x, y, z;
    int Speed, Power;

    } WEAPON_CONFIG;


    // **********************************************
    typedef struct
    {

    int Number_Weapon;
    WEAPON_CONFIG* Bullet;

    } WEAPON;


    For using the structure, I initialise it with :

    WEAPON Weapon_Use;


    And in my program, I use the structure like this :

    Weapon_Use.Bullet[i].Name[0] = ...
    Weapon_Use.Bullet[i].Power = ...

    etc ...

    In fact, I'd like to use a structure like this :

    Weapon_Use[0].Bullet[0].Power = ...

    The "Weapon_Use[]" variable will be used for storing each weapon
    (Desert Eagle, Magnum, ...)

    And the "...Bullet[]" variable will be used for each bullet fired.

    How can I adapt this structure :

    Weapon_Use.Bullet[0].Power

    In this :

    Weapon_Use[0].Bullet[0].Power


    Thanks in advance ...

Similar Threads

  1. Can we use structure of structure in opencl?
    By MenkaMore in forum OpenCL
    Replies: 0
    Last Post: 05-11-2014, 06:00 AM
  2. FPS: Camera rotation and weapons
    By PascalM123 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-06-2010, 02:19 AM
  3. MD2 weapons rendering
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 02-23-2005, 09:01 AM
  4. Render weapons in players viewport
    By Luminous Blue in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 07-24-2002, 02:25 PM
  5. [3TE]-Weapons section updated!
    By Cem UZUNLAR in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 04-01-2001, 05:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean