-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameGUI.rb
52 lines (40 loc) · 975 Bytes
/
GameGUI.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
49
50
51
52
require("gosu")
require("./Game.rb")
class GameWindow < Gosu::Window
def initialize(game)
super 640, 480, false
self.caption = "Gosu Tutorial Game"
@game = game
@cell_image = Gosu::Image.new(self, "media/cell.png", true)
@counter = 0
end
def update
@counter += 1
if @counter % 2 == 0
@game.cycle
end
end
def draw
cells = @game.cell_matrix
cells.keys.each do |key|
x, y = key
cell = cells[key]
@cell_image.draw(100 + x * 12, 100 + y * 12, 0, 1, 1, color_for_cell(cell))
end
end
def color_for_cell(cell)
color = Gosu::Color.new(0xff000000)
if(cell.cluster == nil)
color.green = [cell.food * 20, 255].min
else
color.red = 55 + [200, cell.cluster.size*60].min
color.green = 55
color.blue = 55
end
return color
end
end
Game.instance.start(20)
Cluster.new(Game.instance.cell_matrix[[1,1]], 3)
window = GameWindow.new(Game.instance)
window.show