This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ReBraLaCC's profile picture

Explosion Animation

Started by ReBraLaCC, 28 May 2016 - 08:14 AM
ReBraLaCC #1
Posted 28 May 2016 - 10:14 AM
I've been trying a lot with finding out a way of getting a randomized explosion on my terminal, but most of the times it doesnt seem to work…. Yes i've tried math.random but i still know what patterns it is going to make and i want them completely random… Maybe some CC master knows how to do this and would be able to help me with this problem…

- ReBraLa
InDieTasten #2
Posted 28 May 2016 - 10:27 AM
2 scnenarios i can think of right now:
- your algorithm isn't utilizing the random input, by cancelling it out in some obscure way you don't see at first sight or making its effect on the outcome very small.
- the generator is giving you the same numbers all the time, because you are seeding it with the same number

for any concrete advice, we have to see your code. you essentially told us nothing, but that you are using math.random somewhere in your code.
Edited on 28 May 2016 - 08:29 AM
ReBraLaCC #3
Posted 28 May 2016 - 11:06 AM
for any concrete advice, we have to see your code. you essentially told us nothing, but that you are using math.random somewhere in your code.


local begin = "expframes/begin"
local secondframes = "expframes/secondframes"
local between = "expframes/between"
local en = "expframes/end"
beginframes = {"btex1","btex2","btex3"}
secondframes = {"scex1","scex1","scex1")
betweenframes = {"btex1","btex2","btex3"}
endframes = {"enex1","enex2","enex3"}
function explosion()
paintutils.drawImage(paintutils.loadImage(begin.."/"..beginframes[math.random(1,3)]),1,1)
paintutils.drawImage(paintutils.loadImage(second.."/"..secondframes[math.random(1,3)]),1,1)
paintutils.drawImage(paintutils.loadImage(between.."/"..betweenframes[math.random(1,3)]),1,1)
paintutils.drawImage(paintutils.loadImage(en.."/"..endframes[math.random(1,3)]),1,1)
end
explosion()
Yevano #4
Posted 28 May 2016 - 12:47 PM
I can see a few possible problems. Your second frame is always the same, because all the entries in secondframes are "scex1". You're also drawing frames really fast (though this depends also on how large those images are). Try sleeping at least one tick between each animation frame. Other than that, maybe you should try generating your frames procedurally rather than picking them up from predefined textures. E.g., you could run a small particle simulation that you then render to the screen somehow.
ReBraLaCC #5
Posted 28 May 2016 - 02:24 PM

local begin = "expframes/begin"
local secondframes = "expframes/secondframes"
local between = "expframes/between"
local en = "expframes/end"
beginframes = {"bex1","bex2","bex3"}
secondframes = {"scex1","scex2","scex3")
betweenframes = {"btex1","btex2","btex3"}
endframes = {"enex1","enex2","enex3"}
function explosion()
paintutils.drawImage(paintutils.loadImage(begin.."/"..beginframes[math.random(1,3)]),1,1)
sleep(0.05)
paintutils.drawImage(paintutils.loadImage(second.."/"..secondframes[math.random(1,3)]),1,1)
sleep(0.05)
paintutils.drawImage(paintutils.loadImage(between.."/"..betweenframes[math.random(1,3)]),1,1)
sleep(0.05)
paintutils.drawImage(paintutils.loadImage(en.."/"..endframes[math.random(1,3)]),1,1)
sleep(0.05)
end
explosion()

Changed the code a bit but I'm getting a weird error

bios.lua:14: [string "explosion"]:7: '}' expected

I don't know why I am getting this error because it is all correct what i seem to find, maybe i still have something wrong, let me know!
Bomb Bloke #6
Posted 28 May 2016 - 02:53 PM
The thing I don't get is how you've managed to keep the thing where you never define a "second" variable.

Anyway, you've got a ) where you meant to put a }.
ReBraLaCC #7
Posted 28 May 2016 - 03:03 PM
Anyway, you've got a ) where you meant to put a }.

wow, i need glasses

The thing I don't get is how you've managed to keep the thing where you never define a "second" variable.

What do you mean second variable?
InDieTasten #8
Posted 28 May 2016 - 06:37 PM
Also I think you should be loading all textures first, and then draw them one after the other instead of rendering one, load the next. render it. load the next. Just load all at once. then draw them on demand
Dragon53535 #9
Posted 28 May 2016 - 08:17 PM
Line 2 reads as secondframes when it should read as second.