Class: CyberarmEngine::Background

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberarm_engine/background.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#angleObject

Returns the value of attribute angle.



3
4
5
# File 'lib/cyberarm_engine/background.rb', line 3

def angle
  @angle
end

#backgroundObject

Returns the value of attribute background.



4
5
6
# File 'lib/cyberarm_engine/background.rb', line 4

def background
  @background
end

#debugObject

Returns the value of attribute debug.



3
4
5
# File 'lib/cyberarm_engine/background.rb', line 3

def debug
  @debug
end

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/cyberarm_engine/background.rb', line 3

def height
  @height
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/cyberarm_engine/background.rb', line 3

def width
  @width
end

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/cyberarm_engine/background.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/cyberarm_engine/background.rb', line 3

def y
  @y
end

#zObject

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_outlineObject



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

#drawObject



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

#updateObject



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