We all need to blow things up in our games, right? This library will do that to any any object for you - i'm using the rose object i play with as a demo for this, but any LinesSprite or Lines3dSprite format object should do! Assuming your line count is "normal", it's entirely reasonable to do this in realtime during your game - indeed, that's what the sample shows - although you could use it to generate an animation instead, with a little modification.
demos:
these are all deliberatly slow so you can see things :).
explosion-demo-nobreak - explode a simple object, dont disconnect the lines
explosion-demo-break - explode a simple object, disconnect the lines
explosion-demo - explode a complex object. Note that, for some reason, this will sometimes crash the vectrex32 hard right now :(. I don't know why! Whjich is a shame, since it looks cool!
How to use in your own stuff:
1) include explosion.bai
2) call the function "prepare_explosion" with the following params:
' Params:
' dimensions - 2 or 3
' obj - the LinesSprite format object
' world_scale - scale of the world
' point - where to explode
' x_impulse - base impulse to hit object with on the x axis
' y_impulse - base impulse to hit object with on the y axis
' x_random - additional random impulse for x
' y_random - additional random impulse for y
' break_apart - true/false - do we break the vectors?
3) call either explode2d or explode3d each frame until you're done with the explosion.
sample:
' get the object
rose_object = rose()
' prepare the object for exploding - just expanding variables here for clarity :)
world_scale = 40
x_impulse = 2.5
y_impulse = 5.0
x_random = 2.5
y_random = 5.0
rose_explosion = prepare_explosion(2, rose_object, world_scale, {0,-400}, {x_impulse, y_impulse}, {x_random, y_random}, 9.8, -400, false)
' put it on the screen
LinesSprite(rose_explosion.dest)
controls = WaitForFrame(JoystickNone, Controller1, JoystickNone)
while controls[1,3] = 0
call explode2d(rose_explosion)
' wait for next frame :)
controls = WaitForFrame(JoystickNone, Controller1, JoystickNone)
endwhile
This is awesome! I'd love to see a video.
- Bob
Quote from: Vectrex32 on April 03, 2020, 12:13:59 PM
This is awesome! I'd love to see a video.
- Bob
video: https://www.youtube.com/watch?v=f1ucBlRXVR4
updated code including this demo attached - press button 2 to explode the cycle.
also in my tools github at https://github.com/jaymzjulian/vectrex32_tools
Back doing vectrex stuff again, finally - when i went to integrate this into a game, i found that it could cause frame rate drops if you had complex objects (specifically, the 220 vertex cycles in vxtron) - if i exploded 1, it was fine, if i exploded 2 at once, the framerate started dropping way back. So I added a cached mode for the ram tradeoff.
' grab 2 seconds worth of explosion - 40frams @ 20 fps ' Note that generating more than about 10k verticies _will_ break things - for this demo, our object is
' 220 broken vertificies - this means it tkaes 220*30*4 array entries for this, or 26400 array entries for
' this precalc - so on large objects, essentially be careful! Especially since you need to multiply that also
' out due to them being 4byte floats/ints - so after 52 frames, the v32 runs out of ram in the generation phase.
' I suspect that's also some not-so-great GC, since we use a bunch of deepcopy stuff in there, BUT... still,
' that's 183kbytes of data at that point, which DOES match with my expectations about what the v32 can handle!
'
' So the short version is, be careful about your frame rates ;)
call fill_cache(ce, 40, 20)
Then in your loop
' grab explosion based off timer
new_data = cached_explosion(ce)
' and display it!
Lines2dSprite(new_data)
It's in the vectrex32_tools github @ https://github.com/jaymzjulian/vectrex32_tools.
If you look up "Parkinson's Law of Data", there's a picture of you. ;-)
Quote from: Vectrex32 on May 29, 2020, 08:44:03 AM
If you look up "Parkinson's Law of Data", there's a picture of you. ;-)
I'm basically a toddler - if there's a limit, i can't resist pushing at it to see where it breaks!