Improvements to GameObject and friends

This commit is contained in:
2019-03-30 13:29:30 -05:00
parent a8b8d5aba1
commit 6f9b00ffb5
6 changed files with 150 additions and 89 deletions

View File

@@ -10,6 +10,8 @@ module CyberarmEngine
@game_objects = []
@global_pause = false
@down_keys = {}
setup
end
@@ -24,18 +26,58 @@ module CyberarmEngine
@game_objects.each(&:update)
end
def draw_bounding_box(box)
x,y, max_x, max_y = box.x, box.y, box.max_x, box.max_y
color = Gosu::Color.rgba(255, 127, 64, 240)
# pipe = 4
# Gosu.draw_rect(x-width, y-height, x+(width*2), y+(height*2), color, Float::INFINITY)
# puts "BB render: #{x}:#{y} w:#{x.abs+width} h:#{y.abs+height}"
# Gosu.draw_rect(x, y, x.abs+width, y.abs+height, color, Float::INFINITY)
# TOP LEFT to BOTTOM LEFT
$window.draw_line(
x, y, color,
x, max_y, color,
Float::INFINITY
)
# BOTTOM LEFT to BOTTOM RIGHT
$window.draw_line(
x, max_y, color,
max_x, max_y, color,
Float::INFINITY
)
# BOTTOM RIGHT to TOP RIGHT
$window.draw_line(
max_x, max_y, color,
max_x, y, color,
Float::INFINITY
)
# TOP RIGHT to TOP LEFT
$window.draw_line(
max_x, y, color,
x, y, color,
Float::INFINITY
)
end
def destroy
@options = nil
@game_objects = nil
@options.clear
@game_objects.clear
end
def button_down(id)
@down_keys[id] = true
@game_objects.each do |o|
o.button_down(id)
end
end
def button_up(id)
@down_keys.delete(id)
@game_objects.each do |o|
o.button_up(id)
end