tried to make a fountain point
This commit is contained in:
parent
62edcd43c8
commit
4acb53fa60
|
@ -4,7 +4,7 @@ class Ellipsoid
|
|||
def initialize radius
|
||||
@columns = @rows = radius * 2
|
||||
lower_half = (0...radius).map do |y|
|
||||
x = Math.sqrt(1 - y**2/radius**2)
|
||||
x = Math.sqrt(1 - y**2/radius**2).floor
|
||||
right_half = "#{"\xff" * x}#{"\x00" * (radius - x)}"
|
||||
"#{right_half.reverse}#{right_half}"
|
||||
end.join
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
# An emitter simply emits particles at a regular interval. In this case, every
|
||||
# time spawn is called, a new particle is generated with a random angle of movement and speed.
|
||||
class Emitter
|
||||
def initialize(particles)
|
||||
def initialize(particles, fountain)
|
||||
@particles = particles
|
||||
@fountain = fountain
|
||||
end
|
||||
|
||||
def spawn (x, y)
|
||||
@particles.create(x, y, rand * 360, (rand * 3)+3)
|
||||
@particles.create(x, y, rand * 360, (1/@fountain.distance(x,y) * 6)+3)
|
||||
end
|
||||
|
||||
def draw
|
||||
|
|
10
fountain.rb
Normal file
10
fountain.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class Fountain
|
||||
def initialize (x = 0, y = 0)
|
||||
@x = x
|
||||
@y = y
|
||||
end
|
||||
|
||||
def distance (x, y)
|
||||
return Math.sqrt((@x-x)**2 + (@y-y)**2).floor
|
||||
end
|
||||
end
|
|
@ -36,8 +36,8 @@ class Particle
|
|||
def draw
|
||||
return if dead?
|
||||
draw_layer(ZOrder::Shadow, Gosu::Color.new((@life * 128).floor,0,0,0), @x+2, @y+2)
|
||||
draw_layer(ZOrder::Shape, Gosu::Color.new((@life * 255).floor, 255,255,0))
|
||||
draw_layer(ZOrder::Highlight, Gosu::Color.new((@life * 20).floor,255,255,255))
|
||||
draw_layer(ZOrder::Shape, Gosu::Color.new((@life * 255).floor, 128,128,128))
|
||||
draw_layer(ZOrder::Highlight, Gosu::Color.new((@life * 20).floor,200,200,200))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
require 'gosu'
|
||||
include Gosu
|
||||
require './particle.rb'
|
||||
require './fountain.rb'
|
||||
require './emitter.rb'
|
||||
|
||||
# Our window size
|
||||
|
@ -21,7 +22,8 @@ class GameWindow < Gosu::Window
|
|||
|
||||
@background_image = Gosu::Image.new(self, "images/background.png", true)
|
||||
particles = Particles.new(self)
|
||||
@emitter = Emitter.new(particles)
|
||||
@fountain = Fountain.new
|
||||
@emitter = Emitter.new(particles, @fountain)
|
||||
end
|
||||
|
||||
# Called every tick by gosu to update object positions
|
||||
|
|
Reference in a new issue