Class: Kawaii::Game
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Kawaii::Game
- Defined in:
- lib/kawaii/game.rb
Instance Attribute Summary collapse
-
#content_manager ⇒ Object
Returns the value of attribute content_manager.
-
#font ⇒ Object
Returns the value of attribute font.
-
#fullscreen ⇒ Object
Returns the value of attribute fullscreen.
-
#height ⇒ Object
Returns the value of attribute height.
-
#node_manager ⇒ Object
Returns the value of attribute node_manager.
-
#physics_manager ⇒ Object
Returns the value of attribute physics_manager.
-
#show_fps ⇒ Object
Returns the value of attribute show_fps.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #add_child(node) ⇒ Object
- #after_draw ⇒ Object
- #before_draw ⇒ Object
- #delta ⇒ Object
- #draw ⇒ Object
- #get_fps ⇒ Object
-
#initialize(width = 800, height = 600, fullscreen = false, content_root = "content", debug = true) ⇒ Game
constructor
A new instance of Game.
- #print_stats ⇒ Object
- #remove_child(node) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(width = 800, height = 600, fullscreen = false, content_root = "content", debug = true) ⇒ Game
Returns a new instance of Game.
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 |
# File 'lib/kawaii/game.rb', line 8 def initialize width = 800, height = 600, fullscreen = false, content_root = "content", debug = true super width, height, fullscreen @width, @height, @fullscreen = width, height, fullscreen # managers @node_manager = Kawaii::NodeManager.new @content_manager = Kawaii::ContentManager.new(self, content_root) @audio_manager = Kawaii::AudioManager.new(self) @input_manager = Kawaii::InputManager.new(self) @physics_manager = Kawaii::PhysicsManager.new # stats @top_color = Gosu::Color.new(0xFF1EB1FA) @bottom_color = Gosu::Color.new(0xFF1D4DB5) @font = Gosu::Font.new(self, Gosu::default_font_name, 18) @debug = debug if @debug puts "Game settings:" puts "\tResolution: #{width}:#{height}" puts "\tFullscreen: #{fullscreen}" puts "\tContent root: #{content_root}" print_stats end end |
Instance Attribute Details
#content_manager ⇒ Object
Returns the value of attribute content_manager.
6 7 8 |
# File 'lib/kawaii/game.rb', line 6 def content_manager @content_manager end |
#font ⇒ Object
Returns the value of attribute font.
6 7 8 |
# File 'lib/kawaii/game.rb', line 6 def font @font end |
#fullscreen ⇒ Object
Returns the value of attribute fullscreen.
6 7 8 |
# File 'lib/kawaii/game.rb', line 6 def fullscreen @fullscreen end |
#height ⇒ Object
Returns the value of attribute height.
6 7 8 |
# File 'lib/kawaii/game.rb', line 6 def height @height end |
#node_manager ⇒ Object
Returns the value of attribute node_manager.
6 7 8 |
# File 'lib/kawaii/game.rb', line 6 def node_manager @node_manager end |
#physics_manager ⇒ Object
Returns the value of attribute physics_manager.
6 7 8 |
# File 'lib/kawaii/game.rb', line 6 def physics_manager @physics_manager end |
#show_fps ⇒ Object
Returns the value of attribute show_fps.
6 7 8 |
# File 'lib/kawaii/game.rb', line 6 def show_fps @show_fps end |
#width ⇒ Object
Returns the value of attribute width.
6 7 8 |
# File 'lib/kawaii/game.rb', line 6 def width @width end |
Instance Method Details
#add_child(node) ⇒ Object
34 35 36 |
# File 'lib/kawaii/game.rb', line 34 def add_child node @node_manager.nodes.push node end |
#after_draw ⇒ Object
71 72 |
# File 'lib/kawaii/game.rb', line 71 def after_draw end |
#before_draw ⇒ Object
68 69 |
# File 'lib/kawaii/game.rb', line 68 def before_draw end |
#delta ⇒ Object
60 61 62 |
# File 'lib/kawaii/game.rb', line 60 def delta 16.0 # TODO: real delta end |
#draw ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/kawaii/game.rb', line 74 def draw draw_quad( 0, 0, @top_color, @width, 0, @top_color, @width, @height, @bottom_color, 0, @height, @bottom_color, ) before_draw @node_manager.draw if @debug @font.draw("FPS: #{get_fps}", 14, 14, 0) end after_draw end |
#get_fps ⇒ Object
64 65 66 |
# File 'lib/kawaii/game.rb', line 64 def get_fps 1000.0 / delta end |
#print_stats ⇒ Object
42 43 44 45 |
# File 'lib/kawaii/game.rb', line 42 def print_stats puts "Statistics:" puts "Nodes: #{node_manager.count}" end |
#remove_child(node) ⇒ Object
38 39 40 |
# File 'lib/kawaii/game.rb', line 38 def remove_child node @node_manager.nodes.delete node end |
#update ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kawaii/game.rb', line 47 def update if self.class.method_defined? :before_update before_update end @dt = delta() @node_manager.update @dt if self.class.method_defined? :after_update after_update end end |