Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Hedos

I need to understand! I have a problem with my logical :\

This topic is 5575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.. I was working on my game, and again, when I tried to implement something, I just don''t know what to do... My problem is that: I don''t understand how to control how to add and delete things... I understand the syntax of new, new [], delete and delete []... But I don''t know how to use it correctly... I have the same problem, I don''t understand how to always add something... Even if I use new/delete... For exemple, in my game, I have a Mage, when he press SpaceBar, he cast a FireBall... This should add a FireBall object... 5seconds later, the FireBall will be destroyed. The mage could cast more than 1 fireball at time. So, I need to know what could I do to add an object when the player press SpaceBar, and the player can still create more objects ( cast more fireballs )... Thanks..

Share this post


Link to post
Share on other sites
Advertisement
i assume you have a class Mage ou something like this.

in Mage you shoul have a list of FireBall''s, so you would do something like

Mage.fireBallList.add(new FireBall());

your Mage class should also have a function that is called in every cicle and would go through(sp?) the list to see if any of the fireBalls has to be killed.


Don´t know if this helps you, good luck


PS.
there is no new [] operator



To be considered a genius you just have to say what everybody knows in a way very few understand

Share this post


Link to post
Share on other sites
quote:

PS.
there is no new [] operator



huh??? what about:

char* charArray = new char[1000];

Share this post


Link to post
Share on other sites
quote:

I understand the syntax of new, new [], delete and delete []...
But I don't know how to use it correctly...
I have the same problem, I don't understand how to always add something... Even if I use new/delete...



To add an object you have to do something like this(if you don't want to use linked lists):


FireBall* tempBalls = new FireBall[numBalls];
for(int i=0; i<numBalls; i++) tempBalls[i] = orginalBalls[i];

delete[] originalBalls;
originalBalls = new FireBall[numBalls+1];
for(int i=0; i<numBalls; i++) originalBalls[i] = tempBalls[i];
originalBalls[numBalls] = newBall;
numBalls++;
delete[] tempBalls; // edit: forgot this one :)



However this tends get really slow if you're going to add a thousand balls... So you should use a linked list.

rofl, thats alot of balls :D


[edited by - angry on June 17, 2003 5:23:34 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by angry
quote:

PS.
there is no new [] operator



huh??? what about:

char* charArray = new char[1000];



that''s the new operator





To be considered a genius you just have to say what everybody knows in a way very few understand

Share this post


Link to post
Share on other sites
quote:

that''s the new operator



im lost.... of course it is a new operator, but its not the same as operator new...

operator new
operator new[]

are not the same, the later one is for arrays.

Share this post


Link to post
Share on other sites
quote:
Original post by luxitan
quote:
Original post by angry
char* charArray = new char[1000];



that''s the new operator


No, that''s the new[] operator. It does more than the new operator; specifically, it has to store the length of the array for deletion later on. If you don''t understand this, I suggest a quick read through the C runtime library source.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
lux there are two new and delete operators:

new
new[]

delete
delete[]

they are each completely different.

Share this post


Link to post
Share on other sites
well i don''t consider the new [] as an operator, it''s more like a sintax to use operator new.

the delete [] it''s an operator and totaly (well no totaly) diferent from delete.


at least i think this way, i can be wrong



To be considered a genius you just have to say what everybody knows in a way very few understand

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!