Class: CyberarmEngine::Background
- Inherits:
-
Object
- Object
- CyberarmEngine::Background
- Defined in:
- lib/cyberarm_engine/background.rb
Instance Attribute Summary collapse
-
#angle ⇒ Object
Returns the value of attribute angle.
-
#background ⇒ Object
Returns the value of attribute background.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
- #debug_outline ⇒ Object
- #draw ⇒ Object
-
#initialize(x: 0, y: 0, z: 0, width: 0, height: 0, background: Gosu::Color::BLACK, angle: 0, debug: false) ⇒ Background
constructor
A new instance of Background.
- #shortest_distance(point, la, lb) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(x: 0, y: 0, z: 0, width: 0, height: 0, background: Gosu::Color::BLACK, angle: 0, debug: false) ⇒ Background
Returns a new instance of Background.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cyberarm_engine/background.rb', line 6 def initialize(x: 0, y: 0, z: 0, width: 0, height: 0, background: Gosu::Color::BLACK, angle: 0, debug: false) @x = x @y = y @z = z @width = width @height = height @debug = debug @paint = Paint.new(background) @angle = angle @top_left = Vector.new(@x, @y) @top_right = Vector.new(@x + @width, @y) @bottom_left = Vector.new(@x, @y + @height) @bottom_right = Vector.new(@x + @width, @y + @height) end |
Instance Attribute Details
#angle ⇒ Object
Returns the value of attribute angle.
3 4 5 |
# File 'lib/cyberarm_engine/background.rb', line 3 def angle @angle end |
#background ⇒ Object
Returns the value of attribute background.
4 5 6 |
# File 'lib/cyberarm_engine/background.rb', line 4 def background @background end |
#debug ⇒ Object
Returns the value of attribute debug.
3 4 5 |
# File 'lib/cyberarm_engine/background.rb', line 3 def debug @debug end |
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/cyberarm_engine/background.rb', line 3 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
3 4 5 |
# File 'lib/cyberarm_engine/background.rb', line 3 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/cyberarm_engine/background.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/cyberarm_engine/background.rb', line 3 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
3 4 5 |
# File 'lib/cyberarm_engine/background.rb', line 3 def z @z end |
Instance Method Details
#debug_outline ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cyberarm_engine/background.rb', line 59 def debug_outline # Top Gosu.draw_line( @x, @y, Gosu::Color::RED, @x + @width, @y, Gosu::Color::RED, @z ) # Right Gosu.draw_line( @x + @width, @y, Gosu::Color::RED, @x + @width, @y + @height, Gosu::Color::RED, @z ) # Bottom Gosu.draw_line( @x + @width, @y + @height, Gosu::Color::RED, @x, @y + @height, Gosu::Color::RED, @z ) # Left Gosu.draw_line( @x, @y + @height, Gosu::Color::RED, @x, @y, Gosu::Color::RED, @z ) end |
#draw ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cyberarm_engine/background.rb', line 23 def draw Gosu.clip_to(@x, @y, @width, @height) do Gosu.draw_quad( @top_left.x, @top_left.y, @paint.top_left, @top_right.x, @top_right.y, @paint.top_right, @bottom_right.x, @bottom_right.y, @paint.bottom_right, @bottom_left.x, @bottom_left.y, @paint.bottom_left, @z ) end debug_outline if @debug end |
#shortest_distance(point, la, lb) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cyberarm_engine/background.rb', line 48 def shortest_distance(point, la, lb) a = la.x - lb.x b = la.y - lb.y c = Gosu.distance(la.x, la.y, lb.x, lb.y) p a, b, c d = (a * point.x + b * point.y + c).abs / Math.sqrt(a * a + b * b) puts "Distance: #{d}" exit! d end |
#update ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cyberarm_engine/background.rb', line 37 def update @top_left.x = @x @top_left.y = @y @top_right.x = @x + @width @top_right.y = @y @bottom_left.x = @x @bottom_left.y = @y + @height @bottom_right.x = @x + @width @bottom_right.y = @y + @height end |