-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.rb
68 lines (52 loc) · 1.54 KB
/
core.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
56
57
58
59
60
61
62
63
64
65
66
67
68
DEBUG = true
VERSION = 0.7
def debug(message)
puts "#{Time.now.strftime("%H:%M:%S.%L")} - \t#{message}" if DEBUG
end
# All objects in the game extend from this class, without exception. The tags array contains strings that describe the object, and are used to find it and objects like it when doing callbacks on all objects. This makes it easy to send callbacks to some gameobjects, but not others, and to interact with all objects or just the ones you want without having to keep seperate arrays or use controller classes for each time.
class GameObject
attr_reader :game
attr_reader :tags
def initialize(game)
@game = game
@tags = Array.new
@deleted = false
end
def draw
end
def update
end
def delete
@deleted = true
end
def deleted?
@deleted
end
end
#All game objects are pushed into the "objects" array, without exception. All objects in this array have update and draw called on them, and are deleted if they have their "deleted?" flag set. I also store references to the Gosu window and the objects array for ease of making new graphics and so that objects can do callbacks on all other objects via self.game.objects
class GameState
attr_reader :objects
attr_reader :window
def initialize(window)
@window = window
@objects = Array.new
end
def button_down(id)
nil
end
def update
objects.each &:update
objects.delete_if &:deleted?
end
def draw
objects.each &:draw
end
end
module Zorder
Background = 0
Enemy = 1
Player = 2
Shot = 3
Effects = 4
HUD = 5
end