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.
`###################################################################
`### EVERYTHING BELOW THIS POINT IS PART OF THE EXPLOSION SYSTEM ###
`###################################################################
`prepare the variables for the explosion system
init_explosion_variables:
`set the first object used by the system
global ex_first = 50000
`set the max number of objects the system can use
global ex_max = 50
`a counter to incerement throught he objects
global ex_counter = 0
`an array to determine if the object / explosion is alive
global dim ex_alive(ex_max)
`the curent frame of the explosion is held in an array
global dim ex_frame(ex_max)
`the first image number of the current explosion effect
global dim ex_first_image(ex_max)
`a frame skip delay to slow down the animation
global dim ex_delay(ex_max)
return
`preapre the media for the explosions
function prepare_explosions()
load image \"media\\expl01.png\",10,1
split_image(10,6,5,50101)
load image \"media\\expl02.png\",10,1
split_image(10,6,5,50201)
load image \"media\\expl03.png\",10,1
split_image(10,6,5,50301)
load image \"media\\expl04.png\",10,1
split_image(10,6,5,50401)
load image \"media\\expl05.png\",10,1
split_image(10,6,5,50501)
load image \"media\\expl06.png\",10,1
split_image(10,6,5,50601)
load image \"media\\expl07.png\",10,1
split_image(10,6,5,50701)
load image \"media\\expl08.png\",10,1
split_image(10,6,5,50801)
load image \"media\\expl09.png\",10,1
split_image(10,6,5,50901)
load image \"media\\expl10.png\",10,1
split_image(10,6,5,51001)
load image \"media\\expl11.png\",10,1
split_image(10,6,5,51101)
load image \"media\\expl12.png\",10,1
split_image(10,6,5,51201)
load image \"media\\expl13.png\",10,1
split_image(10,6,5,51301)
load image \"media\\expl14.png\",10,1
split_image(10,6,5,51401)
load image \"media\\expl15.png\",10,1
split_image(10,6,5,51501)
load image \"media\\expl16.png\",10,1
split_image(10,6,5,51601)
load image \"media\\expl17.png\",10,1
split_image(10,6,5,51701)
load image \"media\\expl18.png\",10,1
split_image(10,6,5,51801)
load image \"media\\expl19.png\",10,1
split_image(10,6,5,51901)
load image \"media\\expl20.png\",10,1
split_image(10,6,5,52001)
if image exist(10) = 1 : delete image 10 : endif
for j = 1 to ex_max
make object plain ex_first+j,100,100
disable object zwrite ex_first+j
`the following line causes the explosions to be drawn on top of
`all the other stuff in your scene, rem it out if not needed.
disable object zdepth ex_first+j
ghost object on ex_first+j,3
set object light ex_first+j,0
hide object ex_first+j
next j
endfunction
`spawn an explosion
function spawn_explosion(x#,y#,z#,explosion_type,size#)
if ex_counter = ex_max : ex_counter = 0 : endif
ex_counter = ex_counter +1
ex_alive(ex_counter) = 1
ex_frame(ex_counter) = 1
ex_delay(ex_counter) = 2
select explosion_type
case 1 : ex_first_image(ex_counter) = 50100 : endcase
case 2 : ex_first_image(ex_counter) = 50200 : endcase
case 3 : ex_first_image(ex_counter) = 50300 : endcase
case 4 : ex_first_image(ex_counter) = 50400 : endcase
case 5 : ex_first_image(ex_counter) = 50500 : endcase
case 6 : ex_first_image(ex_counter) = 50600 : endcase
case 7 : ex_first_image(ex_counter) = 50700 : endcase
case 8 : ex_first_image(ex_counter) = 50800 : endcase
case 9 : ex_first_image(ex_counter) = 50900 : endcase
case 10 : ex_first_image(ex_counter) = 51000 : endcase
case 11 : ex_first_image(ex_counter) = 51100 : endcase
case 12 : ex_first_image(ex_counter) = 51200 : endcase
case 13 : ex_first_image(ex_counter) = 51300 : endcase
case 14 : ex_first_image(ex_counter) = 51400 : endcase
case 15 : ex_first_image(ex_counter) = 51500 : endcase
case 16 : ex_first_image(ex_counter) = 51600 : endcase
case 17 : ex_first_image(ex_counter) = 51700 : endcase
case 18 : ex_first_image(ex_counter) = 51800 : endcase
case 19 : ex_first_image(ex_counter) = 51900 : endcase
case 20 : ex_first_image(ex_counter) = 52000 : endcase
endselect
position object ex_first+ex_counter,x#,y#,z#
set object to camera orientation ex_first+ex_counter
zrotate object ex_first+ex_counter,rnd(359)
texture object ex_first+ex_counter,ex_first_image(ex_counter)+ex_frame(ex_counter)
scale object ex_first+ex_counter,size#,size#,size#
show object ex_first+ex_counter
endfunction
`update the explosions
function update_explosions()
for j = 1 to ex_max
if ex_alive(j) = 1
if ex_delay(j) > 0 : ex_delay(j) = ex_delay(j) - 1 : endif
if ex_delay(j) = 0
ex_frame(j) = ex_frame(j) + 1
texture object ex_first+j,ex_first_image(j)+ex_frame(j)
set object to camera orientation ex_first+j
ex_delay(j) = 2
endif
if ex_frame(j) = 30
ex_alive(j) = 0
hide object ex_first+j
endif
endif
next j
endfunction
`kill off all the active explosions
function engine_kill_all_explosions()
for j = 1 to ex_max
ex_alive(j) = 0
ex_frame(j) = 0
hide object ex_first+j
next j
endfunction
`Steve\'s Famous image splitter function to chop the images up
function split_image(baseImage,imgX,imgY,firstImg)
baseSprite = 1
while sprite exist(baseSprite) = 1
inc baseSprite
endwhile
sprite baseSprite,0,0,baseImage
memNo = 1
while memblock exist(memNo) = 1
inc memNo
endwhile
make memblock from image memNo,baseImage
iW = (memblock dword(memNo,0))
iH = (memblock dword(memNo,4))
iD = (memblock dword(memNo,8))
imgWidth = iW / imgX
imgHeight = iH / imgY
mbSize = ((imgWidth * imgHeight) + 3) * 4
memNo2 = memNo + 1
while memblock exist(memNo2) = 1
inc memNo2
endwhile
make memblock memNo2, mbSize
write memblock dWord memNo2,0,imgWidth
write memblock dWord memNo2,4,imgHeight
write memblock dWord memNo2,8,iD
for imagesY = 1 to imgY
for imagesX = 1 to imgX
img = ((imagesY -1) * imgX) + imagesX
NewByte = 12
for rows = 1 to imgHeight
for cols = 1 to imgWidth
offSet1 = (imagesY - 1) * imgWidth * imgHeight * imgX
offset2 = (iW * (rows - 1))
offset3 = imgWidth * (imagesX - 1)
offset4 = cols - 1
imgDword = (offset1 + offset2 + offset3 + offset4 + 3) * 4
write memblock dWord memNo2,NewByte, memblock dWord(memNo,imgDWord)
inc NewByte,4
next cols
next rows
NewByte = 12
make image from memblock (img + firstImg - 1),memNo2
next imagesX
next imagesY
delete memblock memNo
delete memblock memNo2
delete sprite BaseSprite
delete image baseImage
endfunction 0