forked from f3lixz/the-next-big-thing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.rb
55 lines (47 loc) · 1.07 KB
/
game.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
53
54
55
require "gosu"
require_relative "player"
require_relative "bullet"
require_relative "enemy"
class GameWindow < Gosu::Window
attr_reader :entities
def initialize
super 640, 480, false
self.caption = "Wordpress game lulz"
@background_image = Gosu::Image.new(self, "resources/images/lisinge.jpg", true)
player = Player.new(self)
player.warp(320, 240)
@entities = []
@entities << player
@last_enemy_time = Time.now
end
def update
cleanup
if(Time.now - @last_enemy_time > 3)
create_enemy
end
@entities.each do |entity|
entity.update
end
end
def cleanup
@entities.each do |entity|
@entities.delete(entity) if !entity.alive
end
end
def create_enemy
@last_enemy_time = Time.now
prng = Random.new()
@entities << Enemy.new(self, prng.rand(0..640), prng.rand(0..480), prng.rand(0..359), 7)
end
def draw
@entities.each(&:draw)
@background_image.draw(0, 0, 0);
end
def button_down(id)
if id == Gosu::KbEscape
close
end
end
end
window = GameWindow.new
window.show