Permalink
Browse files

TriangleTrialEmittable allows configuring anything on the trial. Tria…

…l now has color.
  • Loading branch information...
1 parent e2f4dbf commit af5a32403e7b4768b4f1db6bb5363053960d8646 @LoganBarnett LoganBarnett committed Jan 6, 2010
Showing with 36 additions and 32 deletions.
  1. +4 −0 src/behaviors/triangle_trail_emittable.rb
  2. +32 −32 src/game_objects/triangle_trail.rb
@@ -17,6 +17,10 @@ def load
def unload
game_state.remove @emitter
end
+
+ def triangle_trail
+ @emitter
+ end
#Transparency to use. 1.0 is opaque. Default is 0.5.
def alpha
@@ -1,14 +1,15 @@
class TriangleTrail < Jemini::GameObject
#has_behavior :Movable2d
has_behavior :Spatial
- attr_accessor :radius, :alpha
+ attr_accessor :radius, :alpha, :color
def load
@trail = []
@trail_poly_size = 10
@trail_size = 50
@radius = 10
@alpha = 0.5
+ @color = Color.new(0.0, 1.0, 1.0)
@flip = false
#TODO: Remove message when the callback stuff is checked in
@first_move = true
@@ -23,40 +24,39 @@ def load
end
def draw(graphics)
- if @trail.size > 3
- gl = Java::org::newdawn::slick::opengl::renderer::Renderer.get
+ return unless @trail.size > 3
+ gl = Java::org::newdawn::slick::opengl::renderer::Renderer.get
- #Java::org::newdawn::slick::opengl::SlickCallable.new do
- callable_class = Java::org::newdawn::slick::opengl::SlickCallable
- callable_class.enter_safe_block
- # use LWJGL's const directly, Slick's wrapper does not have the triangle strip const
- triangle_strip_enum = Java::org::lwjgl::opengl::GL11::GL_TRIANGLE_STRIP
- gl.gl_begin triangle_strip_enum
- gl.gl_color4f(0.0, 1.0, 1.0, @alpha)
+ #Java::org::newdawn::slick::opengl::SlickCallable.new do
+ callable_class = Java::org::newdawn::slick::opengl::SlickCallable
+ callable_class.enter_safe_block
+ # use LWJGL's const directly, Slick's wrapper does not have the triangle strip const
+ triangle_strip_enum = Java::org::lwjgl::opengl::GL11::GL_TRIANGLE_STRIP
+ gl.gl_begin triangle_strip_enum
+ gl.gl_color4f(@color.red, @color.green, @color.blue, @alpha)
- origin_x, origin_y = calculate_point_on_trail_edge(@trail[1], @trail[0], @radius, @flip)
- gl.gl_vertex2f(origin_x, origin_y)
+ origin_x, origin_y = calculate_point_on_trail_edge(@trail[1], @trail[0], @radius, @flip)
+ gl.gl_vertex2f(origin_x, origin_y)
- flipped_origin_x, flipped_origin_y = calculate_point_on_trail_edge(@trail[1], @trail[0], @radius, !@flip)
- gl.gl_vertex2f(flipped_origin_x, flipped_origin_y)
-
- last_trail_vector = @trail[1]
- #gl.gl_color4f(0.0, 1.0, 1.0, alpha)
- @trail[2..-1].each_with_index do |trail_vector, index|
- next if trail_vector == last_trail_vector
- actual_trail_size = (@trail.size - 1).to_f
- trail_radius = (@radius) * ((actual_trail_size - (index + 2).to_f) / actual_trail_size)
-
- rotated_x, rotated_y = calculate_point_on_trail_edge(trail_vector, last_trail_vector, trail_radius, @flip)
- gl.gl_vertex2f(rotated_x, rotated_y)
- rotated_x, rotated_y = calculate_point_on_trail_edge(trail_vector, last_trail_vector, trail_radius, !@flip)
- gl.gl_vertex2f(rotated_x, rotated_y)
-
- last_trail_vector = trail_vector
- end
- gl.gl_end
- callable_class.leave_safe_block
- end
+ flipped_origin_x, flipped_origin_y = calculate_point_on_trail_edge(@trail[1], @trail[0], @radius, !@flip)
+ gl.gl_vertex2f(flipped_origin_x, flipped_origin_y)
+
+ last_trail_vector = @trail[1]
+ #gl.gl_color4f(0.0, 1.0, 1.0, alpha)
+ @trail[2..-1].each_with_index do |trail_vector, index|
+ next if trail_vector == last_trail_vector
+ actual_trail_size = (@trail.size - 1).to_f
+ trail_radius = (@radius) * ((actual_trail_size - (index + 2).to_f) / actual_trail_size)
+
+ rotated_x, rotated_y = calculate_point_on_trail_edge(trail_vector, last_trail_vector, trail_radius, @flip)
+ gl.gl_vertex2f(rotated_x, rotated_y)
+ rotated_x, rotated_y = calculate_point_on_trail_edge(trail_vector, last_trail_vector, trail_radius, !@flip)
+ gl.gl_vertex2f(rotated_x, rotated_y)
+
+ last_trail_vector = trail_vector
+ end
+ gl.gl_end
+ callable_class.leave_safe_block
end
def calculate_point_on_trail_edge(current_vector, previous_vector, trail_radius, flip)

0 comments on commit af5a324

Please sign in to comment.