Class: GameWindow

Inherits:
Gosu::Window
  • Object
show all
Defined in:
bin/sangaku-eyeball

Instance Method Summary collapse

Constructor Details

#initializeGameWindow

Returns a new instance of GameWindow.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'bin/sangaku-eyeball', line 12

def initialize
  super 800, 600, false
  self.caption = "The Sangaku Eyeball"
  @cursor = Gosu::Image.new(self, File.join(PATH, 'assets', 'cursor.png'), true)
  @target = Gosu::Image.new(self, File.join(PATH, 'assets', 'target.png'), true)
  @poly = Sangaku::Polygon.new
  @line = Sangaku::Line.new([0, 0], [0, 0])
  @mouse = Sangaku::Point.new(0, 0)
  @aabb = nil
  @grid = nil
  @stars = nil
  @state = :waiting
  @running = false
  @smooth = false
end

Instance Method Details

#button_down(id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'bin/sangaku-eyeball', line 42

def button_down(id)
  case id
    when Gosu::KbEscape
      if @state != :drawing
        if @poly.length == 0
          close
        else
          _clear
        end
      end
    when Gosu::MsLeft
      if @state == :waiting && @poly.length == 0
        @state = :drawing
      end
      if @state == :drawing
        @poly << @mouse
      end
    when Gosu::MsRight
      if @state == :drawing
        _commit
      end
    when Gosu::KbRight
      if @poly.length > 2
        if @state == :waiting
          @state = :gridify
        end
        if @state != :drawing
          _step
        end
      end
    when Gosu::KbSpace
      if @poly.length > 2 && @state == :waiting
        @state = :gridify
      end
      if @state != :waiting && @state != :drawing
        @running = !@running
      end
  end
end

#drawObject



82
83
84
85
86
87
88
89
90
91
92
# File 'bin/sangaku-eyeball', line 82

def draw
  @poly.draw(self)
  @line.draw(self) if @state == :drawing
  if @poly.closed?
    @aabb.draw(self)
    @aabb.mid.draw(@target, [-16, -16]) if @state != :fittest
    @grid.draw(self) unless @grid.nil? || @state != :pointify
    @stars.each { |s| s.draw(self) } unless @stars.nil? || @state != :fittest
  end
  @mouse.draw(@cursor, [-8, -8])
end

#updateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'bin/sangaku-eyeball', line 28

def update
  @mouse.x = mouse_x
  @mouse.y = mouse_y
  @line.p1 = @poly.points.last
  @line.p2 = @mouse
  if @running
    _step
    if @aabb.w < 8
      @running = false
      @state = :waiting
    end
  end
end