Class: Yeah::Game Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/yeah/game.rb

Overview

This class is abstract.

Subclass this to make a game.

A Game is subclassed to create the core of a game project.

A project's Game is instantiated at runtime. Its #setup is called one time, then #update is called repeatedly.

I/O objects are provided and can be used to build a modern video game.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Game

Returns a new instance of Game

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/yeah/game.rb', line 47

def initialize(options = {})
  options = defaults.merge(options)
  @ticker = options[:ticker]
  @display = options[:display]
  @keyboard = options[:keyboard]
  @mouse = options[:mouse]

  setup

  @ticker.on_tick { |e| update(e) }
end

Instance Attribute Details

#displayDisplay (readonly)

Returns display for drawing

Returns:

  • (Display)

    display for drawing


34
35
36
# File 'lib/yeah/game.rb', line 34

def display
  @display
end

#keyboardKeyboard (readonly)

Returns keyboard input

Returns:


37
38
39
# File 'lib/yeah/game.rb', line 37

def keyboard
  @keyboard
end

#mouseMouse (readonly)

Returns mouse input

Returns:

  • (Mouse)

    mouse input


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

def mouse
  @mouse
end

#tickerTicker (readonly)

Returns ticker used for game loop and one-shot input

Returns:

  • (Ticker)

    ticker used for game loop and one-shot input


31
32
33
# File 'lib/yeah/game.rb', line 31

def ticker
  @ticker
end

Class Method Details

.defaultGame

Returns default subclass (i.e. project game)

Returns:

  • (Game)

    default subclass (i.e. project game)


13
14
15
# File 'lib/yeah/game.rb', line 13

def default
  subclasses.last
end

Instance Method Details

#setupObject

This method is abstract.

Setup game at start.


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

def setup
end

#update(elapsed) ⇒ Object

This method is abstract.

Update game on tick.

Parameters:

  • elapsed (Numeric)

    time since last update


67
68
# File 'lib/yeah/game.rb', line 67

def update(elapsed)
end