Skip to content

Commit

Permalink
Merge pull request #11 from zenspider/debugging_visualizations
Browse files Browse the repository at this point in the history
Debugging visualizations
  • Loading branch information
awilliams committed Dec 17, 2013
2 parents 682e212 + a613cb2 commit 3723d82
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/rtanque/gui/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@ module Gui
class Shell
attr_reader :shell

DEBUG = ENV["DEBUG_SHELLS"]

def initialize(window, shell)
@window = window
@shell = shell
@x0 = shell.position.x
@y0 = @window.height - shell.position.y
@shell_image = Gosu::Image.new(@window, Gui.resource_path("images/bullet.png"))
end

def draw
position = [self.shell.position.x, @window.height - self.shell.position.y]
@shell_image.draw_rot(position[0], position[1], ZOrder::SHELL, 0, 0.5, 0.5)

if DEBUG then
white = Gosu::Color::WHITE
pos = shell.position
x1, y1 = pos.x, @window.height - pos.y
@window.draw_line @x0, @y0, white, x1, y1, white, ZOrder::SHELL
end
end
end
end
end
end
14 changes: 13 additions & 1 deletion lib/rtanque/gui/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def initialize(match)
super(@arena.width, @arena.height, false, UPDATE_INTERVAL)
self.caption = self.class.name.split('::').first
@background = Gosu::Image.new(self, Gui.resource_path("images/grass.png"))

@draw_procs = []
end

def update
Expand All @@ -46,7 +48,17 @@ def draw_drawables
self.gui_bots.draw
self.gui_shells.draw
self.gui_explosions.draw

@draw_procs.each do |proc|
proc.call self
end

@draw_procs.clear
end

def add_draw_proc &b
@draw_procs << b
end
end
end
end
end

0 comments on commit 3723d82

Please sign in to comment.