Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / bullet array code help

Author
Message
Neotron
14
Years of Service
User Offline
Joined: 21st Jul 2010
Location: I am in an underworld , making a E.Army
Posted: 15th Jan 2011 15:45
Can someone plz convert this code into darkgdk equivalent code without using the vectors library .


I think its about dynamic arrays but i don't know where to start.

Argent help , 9 days before submission.

ALLAH IS THE GREATEST
May he forgive me
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 15th Jan 2011 15:51
Hi, I added this to the codebase yesterday. It may help a little.

http://forum.thegamecreators.com/?m=forum_view&t=180340&b=6

Warning! May contain Nuts!
Neotron
14
Years of Service
User Offline
Joined: 21st Jul 2010
Location: I am in an underworld , making a E.Army
Posted: 15th Jan 2011 16:13
Sorry i am a beginner and don't know much of the classes.

i was thinking more of structs with dynamic array.

As you can see i need to create a bullet everytime i press fire button, this will create a new structs with the object id and life(counter) in it.Then i would decrement its life by 1 and if its equall to 0 delete the element of which the life is 0.

Sounds simple ......... but i don't know how to do it.

ALLAH IS THE GREATEST
May he forgive me
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 15th Jan 2011 16:32
Classes are basically a struct. All struct, unions and classes in c++ can now have methods (or functions) that are specific to that class. That means you can have the same function name "update()" in as many classes as you like.

Before I wrote that class I added to the docs this:



And then I wrote my code. Now and then I'll do it that way.

Once you start understanding classes they are so useful mainly because of the constructors and destructors. The destructor can be used in GDK to cleanup and objects of allocated memory used by that class. For example in the CameraControl class, I've initialises the bullet class and the destructor frees the memory. You don't need to worry about the destructor because it is called when the class goes out of scope (ie when the program exits).

Warning! May contain Nuts!
Neotron
14
Years of Service
User Offline
Joined: 21st Jul 2010
Location: I am in an underworld , making a E.Army
Posted: 15th Jan 2011 18:14
ok i only need to know how to make a type in c++ with its type declared and how to use the looping for. and how to gain access to the elements inside.

ALLAH IS THE GREATEST
May he forgive me
Neotron
14
Years of Service
User Offline
Joined: 21st Jul 2010
Location: I am in an underworld , making a E.Army
Posted: 16th Jan 2011 07:19
Well ok , i have grasped the vectors and now what i need to do is make a struct with three ints . Then i want to make a vector of it.

The vector may be streched or enlarged if the user presses fire then if one of the int counter reaches 0 , delete that element.

Oh and plz rem the code and a tutorial will be great for me and all the users seeing it.

ALLAH IS THE GREATEST
May he forgive me
Neotron
14
Years of Service
User Offline
Joined: 21st Jul 2010
Location: I am in an underworld , making a E.Army
Posted: 16th Jan 2011 15:22
Um any one who knows how to use the vector and structures?

how about this(i didn't used code sooooo)

struct bullet
{
int life;
int objid;
};
struct bullet p;
vector<struct> p;

ALLAH IS THE GREATEST
May he forgive me
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 16th Jan 2011 15:31
You're almost there. Instead of using:

struct bullet p;

just use:

bullet p;

I'd advise for now to use the basic arrays:

bullet p[10]; // to store 10 bullets

To position the bullet the same as the player:

dbPositionObject(p[loop],dbObjectPositionX(obj),dbObjectPositionY(obj),dbPositionObjectZ(obj));

Then set the angles using this:

dbSetObjectToObjectOrientation(p[loop],obj);

(hopefully no typos there...)

Warning! May contain Nuts!
Neotron
14
Years of Service
User Offline
Joined: 21st Jul 2010
Location: I am in an underworld , making a E.Army
Posted: 16th Jan 2011 15:49
yeah that's what i used to do.

But lets imagine this , my game has 100 guns and all of them fire if they see me.EVEN if half of them see me they fire a bullet every 10 frames. So this creates about ,i don't know , maybe 10000 bullets.

SO if i loop through all of them its ok i use for(int x=0,x<=10000,x++)

But if only one of them sees me , we then have about 50 bullets. And my compiler is just gonna go/loop for 10000 objects just to see if they are active or inactive.I need an alternative, any ideas.

By the way , you are still on the forum WLGfx, you must be a moderator by now.(but who am i to judge?)

If you mind the last two lines , ignore them.

ALLAH IS THE GREATEST
May he forgive me
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 16th Jan 2011 16:46
Nah, not a moderator... lol... I'm watching Star Trek and thinking what to do now... lol

I posted these for anyone who needs help with the <list> library. Take a look and see if they help. I think I might have posted another.

http://forum.thegamecreators.com/?m=forum_view&t=179873&b=6

http://forum.thegamecreators.com/?m=forum_view&t=179051&b=6

Warning! May contain Nuts!

Login to post a reply

Server time is: 2024-09-28 14:01:15
Your offset time is: 2024-09-28 14:01:15