Class: SDC::BaseGame

Inherits:
Object
  • Object
show all
Defined in:
lib/core/BaseGame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBaseGame

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

#dtObject (readonly)

Returns the value of attribute dt.



4
5
6
# File 'lib/core/BaseGame.rb', line 4

def dt
  @dt
end

#gravityObject

Returns the value of attribute gravity.



5
6
7
# File 'lib/core/BaseGame.rb', line 5

def gravity
  @gravity
end

#meterObject (readonly)

Returns the value of attribute meter.



4
5
6
# File 'lib/core/BaseGame.rb', line 4

def meter
  @meter
end

#secondObject (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