Class: SDC::BaseGame
- Inherits:
-
Object
- Object
- SDC::BaseGame
- Defined in:
- lib/core/BaseGame.rb
Instance Attribute Summary collapse
-
#dt ⇒ Object
readonly
Returns the value of attribute dt.
-
#gravity ⇒ Object
Returns the value of attribute gravity.
-
#meter ⇒ Object
readonly
Returns the value of attribute meter.
-
#second ⇒ Object
readonly
Returns the value of attribute second.
Instance Method Summary collapse
- #decrease_variable(index, value = 1, default: 0) ⇒ Object
-
#get_switch(index) ⇒ Object
Methods for manipulating switches.
-
#get_variable(index, default: nil) ⇒ Object
Methods for manipulating variables.
-
#increase_variable(index, value = 1, default: 0) ⇒ Object
Special numerical options for variables.
-
#initialize ⇒ BaseGame
constructor
A new instance of BaseGame.
- #multiply_variable(index, value, default: 0) ⇒ Object
- #set_switch(index, value: true) ⇒ Object
- #set_variable(index, value) ⇒ Object
- #toggle_switch(index) ⇒ Object
Constructor Details
#initialize ⇒ BaseGame
Returns a new instance of BaseGame.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/core/BaseGame.rb', line 7 def initialize # Distance unit in pixels @meter = 50.0 # Time unit in frames @second = 60.0 # Physics time step @dt = 1.0 # Gravity @gravity = SDC::Coordinates.new(0, 30.0) * (@meter / @second**2) # Basic hash for global and local switches @switches = {} # Basic hash for global and local variables @variables = {} end |
Instance Attribute Details
#dt ⇒ Object (readonly)
Returns the value of attribute dt.
4 5 6 |
# File 'lib/core/BaseGame.rb', line 4 def dt @dt end |
#gravity ⇒ Object
Returns the value of attribute gravity.
5 6 7 |
# File 'lib/core/BaseGame.rb', line 5 def gravity @gravity end |
#meter ⇒ Object (readonly)
Returns the value of attribute meter.
4 5 6 |
# File 'lib/core/BaseGame.rb', line 4 def meter @meter end |
#second ⇒ Object (readonly)
Returns the value of attribute second.
4 5 6 |
# File 'lib/core/BaseGame.rb', line 4 def second @second end |
Instance Method Details
#decrease_variable(index, value = 1, default: 0) ⇒ Object
57 58 59 |
# File 'lib/core/BaseGame.rb', line 57 def decrease_variable(index, value = 1, default: 0) @variables[index] = @variables[index] ? @variables[index] - value : default - value end |
#get_switch(index) ⇒ Object
Methods for manipulating switches
29 30 31 |
# File 'lib/core/BaseGame.rb', line 29 def get_switch(index) return @switches[index] end |
#get_variable(index, default: nil) ⇒ Object
Methods for manipulating variables
43 44 45 |
# File 'lib/core/BaseGame.rb', line 43 def get_variable(index, default: nil) return @variables[index] ? @variables[index] : default end |
#increase_variable(index, value = 1, default: 0) ⇒ Object
Special numerical options for variables
53 54 55 |
# File 'lib/core/BaseGame.rb', line 53 def increase_variable(index, value = 1, default: 0) @variables[index] = @variables[index] ? @variables[index] + value : default + value end |
#multiply_variable(index, value, default: 0) ⇒ Object
61 62 63 |
# File 'lib/core/BaseGame.rb', line 61 def multiply_variable(index, value, default: 0) @variables[index] = @variables[index] ? @variables[index] * value : default * value end |
#set_switch(index, value: true) ⇒ Object
33 34 35 |
# File 'lib/core/BaseGame.rb', line 33 def set_switch(index, value: true) @switches[index] = value end |
#set_variable(index, value) ⇒ Object
47 48 49 |
# File 'lib/core/BaseGame.rb', line 47 def set_variable(index, value) @variables[index] = value end |
#toggle_switch(index) ⇒ Object
37 38 39 |
# File 'lib/core/BaseGame.rb', line 37 def toggle_switch(index) @switches[index] = !@switches[index] end |