-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.rb
48 lines (39 loc) · 1.2 KB
/
window.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'gosu'
require 'debugger'
class Window < Gosu::Window
CELL_SIZE = $config[:cell_size]
def initialize(ant_world)
super ant_world.grid_width * CELL_SIZE, ant_world.grid_height * CELL_SIZE + 40, false
self.caption = "ANTS!"
@ant_world = ant_world
@output = Gosu::Font.new(self, "courier new", 20)
end
def update
@ant_world.tick()
end
def draw
(0 ... @ant_world.grid_width).each do |grid_x|
(0 ... @ant_world.grid_height).each do |grid_y|
c = @ant_world.grid[grid_x][grid_y]
x = grid_x * CELL_SIZE
y = grid_y * CELL_SIZE
self.draw_quad(x, y, c, x+CELL_SIZE, y, c, x+CELL_SIZE, y+CELL_SIZE, c, x, y+CELL_SIZE, c, 1)
end
end
@ant_world.ants.each do |ant|
x = ant.x * CELL_SIZE + (CELL_SIZE * 0.25)
y = ant.y * CELL_SIZE + (CELL_SIZE * 0.25)
d = CELL_SIZE * 0.5
c = ant.carry_color
self.draw_quad(x, y, c, x+d, y, c, x+d, y+d, c, x, y+d, c, 2)
end
@output.draw("global score: " + @ant_world.total_score.to_s, 20, @ant_world.grid_height * CELL_SIZE + 10, 2)
end
def button_down(id)
if id == Gosu::KbEscape
close
elsif id == Gosu::MsLeft
debugger
end
end
end