Class: Kawaii::Game

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

Constant Summary collapse

CONFIG_PATH =
File.expand_path(".") +'/config.yml'
CONFIG =
YAML.load_file(CONFIG_PATH)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kawaii/game.rb', line 12

def initialize
  super CONFIG['resolution']['width'], CONFIG['resolution']['height'], CONFIG['fullscreen']
  @width, @height, @fullscreen = CONFIG['resolution']['width'], CONFIG['resolution']['height'], CONFIG['fullscreen']
  @content_root = CONFIG['content_root']
  
  @scene_manager = Kawaii::SceneManager.new(self) 
  # load intro scene
  @scene_manager.push_scene Kawaii::Intro.new @scene_manager

  # stats
  @top_color = Gosu::Color.new(0xFF1EB1FA)
  @bottom_color = Gosu::Color.new(0xFF1D4DB5)
  @font = Gosu::Font.new(self, Gosu::default_font_name, 18)
  @debug = CONFIG['debug']
  
  if @debug
    puts "Game settings:"
    puts "\tResolution: #{width}:#{height}"
    puts "\tFullscreen: #{fullscreen}"
    puts "\tContent root: #{content_root}"
  end
end

Instance Attribute Details

#content_rootObject

Returns the value of attribute content_root.



10
11
12
# File 'lib/kawaii/game.rb', line 10

def content_root
  @content_root
end

#fontObject

Returns the value of attribute font.



10
11
12
# File 'lib/kawaii/game.rb', line 10

def font
  @font
end

#fullscreenObject

Returns the value of attribute fullscreen.



10
11
12
# File 'lib/kawaii/game.rb', line 10

def fullscreen
  @fullscreen
end

#heightObject

Returns the value of attribute height.



10
11
12
# File 'lib/kawaii/game.rb', line 10

def height
  @height
end

#show_fpsObject

Returns the value of attribute show_fps.



10
11
12
# File 'lib/kawaii/game.rb', line 10

def show_fps
  @show_fps
end

#widthObject

Returns the value of attribute width.



10
11
12
# File 'lib/kawaii/game.rb', line 10

def width
  @width
end

Instance Method Details

#before_updateObject



41
42
# File 'lib/kawaii/game.rb', line 41

def before_update
end

#deltaObject



44
45
46
# File 'lib/kawaii/game.rb', line 44

def delta
  16.0 # TODO: real delta
end

#drawObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/kawaii/game.rb', line 52

def draw
  draw_quad(
    0, 0, @top_color,
    @width, 0, @top_color,
    @width, @height, @bottom_color,
    0, @height, @bottom_color,
  )
  @scene_manager.draw
  if @debug
      @font.draw("FPS: #{get_fps}", 14, 14, 0)
  end
end

#get_fpsObject



48
49
50
# File 'lib/kawaii/game.rb', line 48

def get_fps
  1000.0 / delta
end

#updateObject



35
36
37
38
39
# File 'lib/kawaii/game.rb', line 35

def update
  before_update()
  @dt = delta()
  @scene_manager.update @dt
end