-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.rb
More file actions
89 lines (73 loc) · 1.97 KB
/
window.rb
File metadata and controls
89 lines (73 loc) · 1.97 KB
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
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
81
82
83
84
85
86
87
88
89
require 'gosu'
require_relative 'blockmatrix.rb'
require_relative 'blockgenerator.rb'
module ZOrder
Background, Matrix,Block,UI = *0..3
end
class GameWindow < Gosu::Window
def initialize
super 800, 600, false
@debug = true
self.caption = "Game"
@font = Gosu::Font.new(20)
@img = "img/matrix_block.png"
@blockSize = 60
@percentagew = width * 0.80
@blocksX = (@percentagew / @blockSize).to_i
@blocksY = (height/@blockSize).to_i
@multiplier = 10
@backUpMultiplier = @multiplier
@blockMatrix = BlockMatrix.new(@img,@blocksX,@blocksY,width*0.15,@blockSize/2,@percentagew,height)
@blockGenerator = BlockGenerator.new(@blockSize/2,@blockSize,width,height,@blocksX * @blocksY, @multiplier,@blocksX,@blocksY)
updateTime
@pause = false
@before = false
end
def update
if !@pause
@blockGenerator.updateCurrentBlock
if(@currentTime >= @timeToReset)
@blockGenerator.update
updateTime
end
@currentTime = Time.now.to_f
if Gosu::button_down? Gosu::KbDown
@blockGenerator.setSpeed2x
else
@blockGenerator.setSpeed
end
end
checkPause
checkExit
end
def draw
if @debug
#Show fps
@font.draw("fps: #{Gosu.fps} ", 0,height/100,ZOrder::UI, 0.75, 0.75, 0xff_ffff00)
@font.draw("Stopped?: #{@pause? "Si":"No"} ", 0,20,ZOrder::UI, 0.75, 0.75, 0xff_ffffff)
end
@blockMatrix.draw(ZOrder::Matrix)
@blockGenerator.draw(ZOrder::Block)
end
def updateTime
@currentTime = Time.now.to_f
@timeToReset = (Time.now.to_f + @blockGenerator.getSeconds)
end
def checkPause
if @before && !(Gosu::button_down? Gosu::KbP)
@before = false
end
if (Gosu::button_down? Gosu::KbP) && !@before
@pause = !@pause
puts "Pausing..."
@before = true
end
end
def checkExit
if Gosu::button_down? Gosu::KbEscape
abort("Exiting...")
end
end
end
window = GameWindow.new
window.show