-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgamecontrol.rb
111 lines (80 loc) · 2.53 KB
/
gamecontrol.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
begin
require 'rubygems'
rescue LoadError
end
require 'utils'
require 'gosu'
require 'controllers'
require 'actors'
require 'tanks'
require 'environ'
require 'common'
require 'actordsl'
# Manages the game
class GameController
GameState = Struct.new(:window, :world, :phys, :env, :ec, :mouse, :logging_level)
LogLevel = 1
def initialize(window)
@gs = GameState.new
@window = window
@world = Array.new
@jukebox = MusicSystem.new(@window)
@anims = ImageSystem.new(@window)
@phys = PhysicsController.new
@ec = EventController.new
@env = EnvironmentController.new(@window, @world, LogLevel)
@mouse = MousePtr.new(@window, LogLevel, @world, @env, @ec)
@gs.window = @window
@gs.world = @world
@gs.mouse = @mouse
@gs.phys = @phys
@gs.env = @env
@gs.ec = @ec
@gs.logging_level = LogLevel
@actor_dsl = ActorDSL.new(@gs)
setup_interface
setup_world("helga1")
puts "starting game."
end
def setup_interface
puts "setting up interface..."
#setting up font, and background
@font = Gosu::Font.new(@window, Gosu::default_font_name, 20)
#setting up mouse
#setting up game music
playlist = [@jukebox.load_song("assets/music/isee.ogg"),
@jukebox.load_song("assets/music/fugue.ogg"),
@jukebox.load_song("assets/music/lush.ogg")]
@jukebox.make_play_list(:soundtrack, playlist)
#@jukebox.load_play_list(:soundtrack)
@jukebox.loop = true
puts "...done!"
end
def setup_world(level)
puts "setting up game world..."
#setting up environment tiles
width_height = @env.load_env(level)
#setting up actors
@actor_dsl.load_actors(level, *width_height)
puts "...done!"
end
def update
#update music
@jukebox.update
#update mouse & scrolling (mouse is responsible for scrolling)
@mouse.update
#update actors
@world.each { |thing| thing.update }
end
def draw
#update scrolling info from mouse
screen_x, screen_y = @mouse.screen_x, @mouse.screen_y
@env.draw(screen_x, screen_y)
@world.each { |thing| thing.draw(screen_x, screen_y) }
@mouse.draw
@font.draw("mouse (#{@mouse.x.to_i}, #{@mouse.y.to_i})", 840, 10, 3, 1.0, 1.0, 0xffffff00)
end
def button_down(id)
@ec.button_down(id)
end
end