Class: Kawaii::Game

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/kawaii/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_managerObject

Returns the value of attribute content_manager.



6
7
8
# File 'lib/kawaii/game.rb', line 6

def content_manager
  @content_manager
end

#fontObject

Returns the value of attribute font.



6
7
8
# File 'lib/kawaii/game.rb', line 6

def font
  @font
end

#fullscreenObject

Returns the value of attribute fullscreen.



6
7
8
# File 'lib/kawaii/game.rb', line 6

def fullscreen
  @fullscreen
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/kawaii/game.rb', line 6

def height
  @height
end

#node_managerObject

Returns the value of attribute node_manager.



6
7
8
# File 'lib/kawaii/game.rb', line 6

def node_manager
  @node_manager
end

#physics_managerObject

Returns the value of attribute physics_manager.



6
7
8
# File 'lib/kawaii/game.rb', line 6

def physics_manager
  @physics_manager
end

#show_fpsObject

Returns the value of attribute show_fps.



6
7
8
# File 'lib/kawaii/game.rb', line 6

def show_fps
  @show_fps
end

#widthObject

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_drawObject



71
72
# File 'lib/kawaii/game.rb', line 71

def after_draw
end

#before_drawObject



68
69
# File 'lib/kawaii/game.rb', line 68

def before_draw
end

#deltaObject



60
61
62
# File 'lib/kawaii/game.rb', line 60

def delta
  16.0 # TODO: real delta
end

#drawObject



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_fpsObject



64
65
66
# File 'lib/kawaii/game.rb', line 64

def get_fps
  1000.0 / delta
end


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

#updateObject



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