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.

Newcomers DBPro Corner / how do i extract just what i need from this explosion function?

Author
Message
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 8th Sep 2011 21:30 Edited at: 8th Sep 2011 22:17
I want to use this explosion method but i have never used functions before, could someone tell me how i could whittle this code down to just what i need.
I want to use explosion 6 only and i need to play it once at the location of my exploding space ship , then hide till needed again.
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 9th Sep 2011 17:39 Edited at: 9th Sep 2011 17:43
Calling functions is just like calling regular DBPro commands, except that you have total control over what actions are performed. They can really simplify your code, as tasks that need performing many times need only be written once (in a function) and then called as often as needed.

Anyway, the code snippet you've provided has the following function names within it:



The first, "init_explosion_variables", is a subroutine that sets up the required variables - this is not quite the same thing as a function. Place this command at the top of your code to "call" it:

Whenever your program sees this, it will jump to the line "init_explosion_variables:", execute the statements following it until it reaches "return", and then jump back to where it started from.

The others are proper functions and are called by simply typing:

etc. Looking at the code, I'm guessing explosion 6 is stored in file "media\\expl06.png\", so the rest aren't needed. You could also modify "Spawn_Explosion" as only explosion 6 will ever be used. Thus, the functions could be whittled down to this:



There is a further optimisation you could make in Spawn_Explosion, as the case statement is no longer needed if only explosion 6 is generated). I'll leave that for you to do...

To run these functions, create a program that looks something like this:



I haven't tested this code out (my last snippet, the example, might give problems if you press and hold the spacekey as you'll constantly spawn an explosion), but play around with it.

Hope this has helped!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 9th Sep 2011 19:11
Thanks Robert !
Im having a play with it now , got your demo working as a seperate project . Holding the space key seems to freeze the animation on the last frame before it kills it off

i will try and add it to my main project now
Robert The Robot
17
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 9th Sep 2011 20:56
Thought it might do something odd. Instead of this:

try:


It's just a little flag to make sure you can't spawn another explosion until the space bar has been released.

Actually, you might want to nip back to the original explosion set of code and modify it so that all 20 explosion types use the same image set. Tht way, you can have multiple explosions on screen at any one time.

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 9th Sep 2011 21:36
its ok the death code in my main project has a timer so only runs for one cycle when the timer = 1 .

Login to post a reply

Server time is: 2024-11-24 01:51:29
Your offset time is: 2024-11-24 01:51:29