Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def particle_spawner
- pic_index = 21
- spawn_interval = 20
- on_screen_particle = []
- rand_pos_x = []; target_pos_x = []; current_pos_x = []
- rand_pos_y = []; target_pos_y = []; current_pos_y = []
- rand_scale = []; target_scale = []; current_scale = []
- rand_angle = []; target_angle = []; current_angle = []
- rand_speed = []
- lifetime = []
- index = pic_index
- spawn_loop = 40
- #update function
- loop do
- #--------------------------------------------------------------
- # Check if you should spawn particle
- #--------------------------------------------------------------
- p (on_screen_particle)
- if (spawn_loop >= spawn_interval)
- if (on_screen_particle.empty?)
- index = pic_index
- else
- for i in pic_index..pic_index+10
- if (!on_screen_particle.include?(i))
- #msgbox(on_screen_particle)
- #msgbox("particale #" + i.to_s + " is not in the array!")
- #msgbox("so, spawn a particle with #" + i.to_s)
- index = i
- break
- end
- end
- end
- #msgbox(index)
- on_screen_particle.insert(0, index)
- #msgbox(on_screen_particle)
- #--------------------------------------------------------------
- # Spawning a new particle
- #--------------------------------------------------------------
- rand_pos_x.insert(0, rand(484) + 30); target_pos_x.insert(0, rand_pos_x[0] + 10 + rand(20))
- rand_pos_y.insert(0, rand(356) + 30); target_pos_y.insert(0, rand_pos_y[0] - 100 - rand(20))
- rand_scale.insert(0, 100 + rand(100)); target_scale.insert(0, rand_scale[0] + rand(30))
- rand_angle.insert(0, -30 + rand(60)); target_angle.insert(0, rand_angle[0] - 30 + rand(60))
- rand_speed.insert(0, 40 + rand(80))
- lifetime.insert(0, 0)
- screen.pictures[on_screen_particle[0]].show(
- "Screenfx/Heart_Particle" , 1,
- rand_pos_x[0],
- rand_pos_y[0],
- rand_scale[0],
- rand_scale[0],
- 100, 1)
- current_pos_x.insert(0, rand_pos_x)
- current_pos_y.insert(0, rand_pos_y)
- current_scale.insert(0, rand_scale)
- current_angle.insert(0, rand_angle)
- screen.pictures[on_screen_particle[0]].start_tone_change(
- Tone.new(0,255,0,255), 1)
- rotate_pic(on_screen_particle[0],rand_angle[0],1,1)
- spawn_loop = 0
- else
- spawn_loop += 1
- end
- #--------------------------------------------------------------
- # If no particle exist in canvas, next
- #--------------------------------------------------------------
- if (on_screen_particle.count < 1)
- wait(1)
- next
- end
- #--------------------------------------------------------------
- # updating the position of particles
- #--------------------------------------------------------------
- for i in 0..on_screen_particle.count-1
- #msgbox(rand_pos_y[i].to_s + target_pos_y[i].to_s + )
- current_pos_x[i] = lerp( rand_pos_x[i], target_pos_x[i], lifetime[i]*100/rand_speed[i])
- current_pos_y[i] = lerp( rand_pos_y[i], target_pos_y[i], lifetime[i]*100/rand_speed[i])
- current_scale[i] = lerp( rand_scale[i], target_scale[i], lifetime[i]*100/rand_speed[i])
- current_angle[i] = lerp( rand_angle[i], target_angle[i], lifetime[i]*100/rand_speed[i])
- screen.pictures[on_screen_particle[i]].move(
- 1,
- current_pos_x[i],
- current_pos_y[i],
- current_scale[i],
- current_scale[i],
- 100,0,1
- )
- rotate_pic(on_screen_particle[i],current_angle[i],1,1)
- lifetime[i] += 1
- if(lifetime[i] >= rand_speed[i])
- erase_pic(on_screen_particle[i])
- #msgbox("deleting particle #"+ on_screen_particle[i].to_s )
- on_screen_particle.delete_at(i)
- rand_pos_x.delete_at(i); target_pos_x.delete_at(i); current_pos_x.delete_at(i)
- rand_pos_y.delete_at(i); target_pos_y.delete_at(i); current_pos_y.delete_at(i)
- rand_scale.delete_at(i); target_scale.delete_at(i); current_scale.delete_at(i)
- rand_angle.delete_at(i); target_angle.delete_at(i); current_angle.delete_at(i)
- rand_speed.delete_at(i)
- lifetime.delete_at(i)
- # msgbox(on_screen_particle.count)
- end
- end
- wait(1)
- end
- end
- def lerp(origin, destination, time)
- return (origin * (100-time) + destination * time)/100
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement