tried to make a fountain point

This commit is contained in:
Alexander Yakovlev 2012-12-21 20:26:20 +07:00
parent 62edcd43c8
commit 4acb53fa60
5 changed files with 19 additions and 6 deletions

View file

@ -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

View file

@ -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
View 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

View file

@ -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

View file

@ -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