Module: SDC
- Defined in:
- lib/core/AI.rb,
lib/core/Map.rb,
lib/core/Data.rb,
lib/core/Text.rb,
lib/core/Debug.rb,
lib/core/Event.rb,
lib/core/Scene.rb,
lib/core/Button.rb,
lib/core/Entity.rb,
lib/core/Limiter.rb,
lib/core/Marshal.rb,
lib/core/BaseGame.rb,
lib/core/MainLoop.rb,
lib/core/MapConfig.rb,
lib/core/CustomTile.rb,
lib/core/ActionShape.rb,
lib/core/SDCMain/Input.rb,
lib/core/SDCMain/Utility.rb,
lib/core/SpecialContainer.rb,
lib/core/SDCMain/Constants.rb,
lib/core/SDCMain/TextInput.rb,
lib/core/SDCMain/Variables.rb,
lib/core/SDCMain/Attributes.rb,
engine_docs/automatic_doc_Font.rb,
engine_docs/automatic_doc_Text.rb,
engine_docs/automatic_doc_Tile.rb,
engine_docs/automatic_doc_View.rb,
engine_docs/automatic_doc_Color.rb,
engine_docs/automatic_doc_Event.rb,
engine_docs/automatic_doc_Music.rb,
engine_docs/automatic_doc_Sound.rb,
engine_docs/automatic_doc_Sript.rb,
engine_docs/automatic_doc_Script.rb,
engine_docs/automatic_doc_Sprite.rb,
engine_docs/automatic_doc_Window.rb,
engine_docs/automatic_doc_IntRect.rb,
engine_docs/automatic_doc_Texture.rb,
engine_docs/automatic_doc_Tileset.rb,
engine_docs/automatic_doc_Collider.rb,
engine_docs/automatic_doc_EventKey.rb,
engine_docs/automatic_doc_MapLayer.rb,
engine_docs/automatic_doc_DrawShape.rb,
engine_docs/automatic_doc_EventType.rb,
engine_docs/automatic_doc_FloatRect.rb,
engine_docs/automatic_doc_EventMouse.rb,
engine_docs/automatic_doc_Coordinates.rb,
engine_docs/automatic_doc_SoundBuffer.rb,
engine_docs/automatic_doc_RenderStates.rb,
engine_docs/automatic_doc_DrawShapeLine.rb,
engine_docs/automatic_doc_CollisionShape.rb,
engine_docs/automatic_doc_DrawShapePoint.rb,
engine_docs/automatic_doc_DrawShapeCircle.rb,
engine_docs/automatic_doc_CollisionShapeBox.rb,
engine_docs/automatic_doc_DrawShapeTriangle.rb,
engine_docs/automatic_doc_CollisionShapeLine.rb,
engine_docs/automatic_doc_DrawShapeRectangle.rb,
engine_docs/automatic_doc_CollisionShapePoint.rb,
engine_docs/automatic_doc_CollisionShapeCircle.rb,
engine_docs/automatic_doc_CollisionShapeTriangle.rb
Overview
TODO: Replace this at some point with a hash-structure TODO: Generalize
this for other applications
Defined Under Namespace
Modules: AI, Collider, Data, Debug, EventKey, EventMouse, EventType, Marshal, Script
Classes: Actionshape, BaseGame, Button, CollisionShape, CollisionShapeBox, CollisionShapeCircle, CollisionShapeLine, CollisionShapePoint, CollisionShapeTriangle, Color, Coordinates, CustomTile, DrawShape, DrawShapeCircle, DrawShapeLine, DrawShapePoint, DrawShapeRectangle, DrawShapeTriangle, Entity, Event, FloatRect, Font, Hitshape, Hurtshape, IntRect, Limiter, Map, MapConfig, MapLayer, Music, RenderStates, Scene, Sound, SoundBuffer, SpecialContainer, Sprite, Sript, Text, Texture, Tile, Tileset, View, Window
Constant Summary
collapse
- C_NULL =
"\0"
- C_BELL =
"\a"
- C_BACKSPACE =
"\b"
- C_TAB =
"\t"
- C_NEWLINE =
"\n"
- C_VERT_TAB =
"\v"
- C_FORM_FEED =
"\f"
- C_CAR_RET =
"\r"
- C_CTRL_Z =
"\z"
- C_ESCAPE =
"\e"
- C_CTRL_BACK =
"\x7F"
- XY0 =
Empty Coordinates object as a constant Using this might save time on
functions needing a constant vector
SDC::Coordinates.new(0.0, 0.0).freeze
- COLOR_RED =
SDC::Color.new(255, 0, 0).freeze
- COLOR_GREEN =
SDC::Color.new(0, 255, 0).freeze
- COLOR_BLUE =
SDC::Color.new(0, 0, 255).freeze
- COLOR_BLACK =
SDC::Color.new(0, 0, 0).freeze
- COLOR_WHITE =
SDC::Color.new(255, 255, 255).freeze
- COLOR_TRANSPARENT =
SDC::Color.new(0, 0, 0, 0).freeze
- COLOR_YELLOW =
SDC::Color.new(255, 255, 0).freeze
- COLOR_CYAN =
SDC::Color.new(0, 255, 255).freeze
- COLOR_MAGENTA =
SDC::Color.new(255, 0, 255).freeze
Class Method Summary
collapse
-
.decrease_variable(index, value = 1, default: 0) ⇒ Object
-
.draw_height ⇒ Object
-
.draw_text(index: nil, font_index: nil, font: nil, text: "", size: 10, z: 0, draw_window: SDC.window, coordinates: SDC::Coordinates.new, color: nil) ⇒ Object
-
.draw_texture(index: nil, file_index: nil, filename: nil, z: 0, draw_window: SDC.window, color: SDC::COLOR_WHITE, scale: SDC.xy(1, 1), coordinates: SDC::Coordinates.new) ⇒ Object
Other utility methods for rapid development.
-
.draw_width ⇒ Object
-
.game ⇒ Object
-
.game=(value) ⇒ Object
-
.get_mouse_coords ⇒ Object
Returns the mouse coordinate for the current view.
-
.get_mouse_point ⇒ Object
-
.get_mouse_pos ⇒ Object
Returns an integer array with two elements of the pixel coordinates.
-
.get_switch(index) ⇒ Object
-
.get_variable(index, default: nil) ⇒ Object
-
.handle_backspace_input(text_buffer) ⇒ Object
-
.handle_ctrl_backspace_input(text_buffer) ⇒ Object
-
.increase_variable(index, value = 1, default: 0) ⇒ Object
-
.is_ctrl_char(char) ⇒ Object
-
.key(key) ⇒ Object
-
.key_pressed?(key, override_text_input: false) ⇒ Boolean
Script routines for easier readability, directly referencing other methods.
-
.left_klick? ⇒ Boolean
-
.limiter ⇒ Object
-
.limiter=(value) ⇒ Object
-
.main_routine(scene_class, game_class: nil, title: "", width: 800, height: 600, limiter: nil) ⇒ Object
Main routine as an entry point for the Shidacea engine.
-
.mouse_button(button) ⇒ Object
-
.mouse_button_pressed?(button) ⇒ Boolean
-
.mouse_touching?(shape, offset: SDC.xy) ⇒ Boolean
-
.multiply_variable(index, value, default: 0) ⇒ Object
-
.next_scene ⇒ Object
-
.next_scene=(value) ⇒ Object
-
.play_music(index: nil, file_index: nil, filename: nil, volume: 100.0, pitch: 1.0) ⇒ Object
-
.play_sound(index: nil, file_index: nil, filename: nil, volume: 100.0, pitch: 1.0) ⇒ Object
-
.process_text_input(event: nil, text_buffer: nil, override: false) ⇒ Object
TODO: Allow specific input class.
-
.reset_switch(index, value: false) ⇒ Object
-
.right_klick? ⇒ Boolean
-
.scene ⇒ Object
-
.scene=(value) ⇒ Object
-
.set_draw_size(width, height) ⇒ Object
-
.set_switch(index, value: true) ⇒ Object
-
.set_variable(index, value) ⇒ Object
-
.stop_music(index, file_index: nil, filename: nil) ⇒ Object
-
.text_input ⇒ Object
-
.text_input=(value) ⇒ Object
-
.toggle_switch(index) ⇒ Object
-
.window ⇒ Object
-
.window=(value) ⇒ Object
-
.xy(x = 0.0, y = 0.0) ⇒ Object
Class Method Details
.decrease_variable(index, value = 1, default: 0) ⇒ Object
31
32
33
|
# File 'lib/core/SDCMain/Variables.rb', line 31
def self.decrease_variable(index, value = 1, default: 0)
@game.decrease_variable(index, value, default: default)
end
|
.draw_height ⇒ Object
77
78
79
|
# File 'lib/core/SDCMain/Attributes.rb', line 77
def self.draw_height
return @draw_height
end
|
.draw_text(index: nil, font_index: nil, font: nil, text: "", size: 10, z: 0, draw_window: SDC.window, coordinates: SDC::Coordinates.new, color: nil) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/core/SDCMain/Utility.rb', line 16
def self.draw_text(index: nil, font_index: nil, font: nil, text: "", size: 10, z: 0, draw_window: SDC.window, coordinates: SDC::Coordinates.new, color: nil)
text_obj = SDC::Data.load_text(index = index, content: text, size: size, font_index: font_index, font: font)
puts "Warning: Text index #{index} not loaded." if !text_obj
text_obj.color = color if color
draw_window.draw_translated(text_obj, z, coordinates)
end
|
.draw_texture(index: nil, file_index: nil, filename: nil, z: 0, draw_window: SDC.window, color: SDC::COLOR_WHITE, scale: SDC.xy(1, 1), coordinates: SDC::Coordinates.new) ⇒ Object
Other utility methods for rapid development
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/core/SDCMain/Utility.rb', line 5
def self.draw_texture(index: nil, file_index: nil, filename: nil, z: 0, draw_window: SDC.window, color: SDC::COLOR_WHITE, scale: SDC.xy(1, 1), coordinates: SDC::Coordinates.new)
texture = SDC::Data.load_texture(index, file_index: file_index, filename: filename)
puts "Warning: Texture index #{index} not loaded." if !texture
sprite = SDC::Sprite.new
sprite.link_texture(texture)
sprite.color = color
sprite.scale = scale
draw_window.draw_translated(sprite, z, coordinates)
end
|
.draw_width ⇒ Object
73
74
75
|
# File 'lib/core/SDCMain/Attributes.rb', line 73
def self.draw_width
@draw_width
end
|
.game ⇒ Object
44
45
46
|
# File 'lib/core/SDCMain/Attributes.rb', line 44
def self.game
return @game
end
|
.game=(value) ⇒ Object
48
49
50
|
# File 'lib/core/SDCMain/Attributes.rb', line 48
def self.game=(value)
@game = value
end
|
.get_mouse_coords ⇒ Object
Returns the mouse coordinate for the current view. If you want to check for
another view, you need to activate it first or execute any mouse check
methods in a view block.
.get_mouse_point ⇒ Object
33
34
35
|
# File 'lib/core/SDCMain/Input.rb', line 33
def self.get_mouse_point
return SDC::CollisionShapePoint.new(self.get_mouse_coords)
end
|
.get_mouse_pos ⇒ Object
Returns an integer array with two elements of the pixel coordinates.
Therefore, window scaling WILL change the dimensions of the area the mouse
can operate in.
.get_switch(index) ⇒ Object
11
12
13
|
# File 'lib/core/SDCMain/Variables.rb', line 11
def self.get_switch(index)
return @game.get_switch(index)
end
|
.get_variable(index, default: nil) ⇒ Object
3
4
5
|
# File 'lib/core/SDCMain/Variables.rb', line 3
def self.get_variable(index, default: nil)
return @game.get_variable(index, default: default)
end
|
3
4
5
|
# File 'lib/core/SDCMain/TextInput.rb', line 3
def self.handle_backspace_input(text_buffer)
text_buffer.chop!
end
|
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/core/SDCMain/TextInput.rb', line 7
def self.handle_ctrl_backspace_input(text_buffer)
text_buffer.rstrip!
last_space = text_buffer.rindex(" ")
if last_space then
text_buffer[last_space+1..-1] = ""
else
text_buffer.clear
end
end
|
.increase_variable(index, value = 1, default: 0) ⇒ Object
27
28
29
|
# File 'lib/core/SDCMain/Variables.rb', line 27
def self.increase_variable(index, value = 1, default: 0)
@game.increase_variable(index, value, default: default)
end
|
.is_ctrl_char(char) ⇒ Object
18
19
20
|
# File 'lib/core/SDCMain/TextInput.rb', line 18
def self.is_ctrl_char(char)
return (char.ord < 32 || char == C_CTRL_BACK)
end
|
.key(key) ⇒ Object
9
10
11
|
# File 'lib/core/SDCMain/Input.rb', line 9
def self.key(key)
return SDC::EventKey.const_get(key) if SDC::EventKey.const_defined?(key)
end
|
.key_pressed?(key, override_text_input: false) ⇒ Boolean
Script routines for easier readability, directly referencing other methods
5
6
7
|
# File 'lib/core/SDCMain/Input.rb', line 5
def self.key_pressed?(key, override_text_input: false)
return @window.has_focus? && (override_text_input || !@text_input) && SDC::EventKey.const_defined?(key) && SDC::EventKey.is_pressed?(SDC::EventKey.const_get(key))
end
|
.left_klick? ⇒ Boolean
45
46
47
|
# File 'lib/core/SDCMain/Input.rb', line 45
def self.left_klick?
return self.mouse_button_pressed?(:Left)
end
|
.limiter ⇒ Object
52
53
54
|
# File 'lib/core/SDCMain/Attributes.rb', line 52
def self.limiter
return @limiter
end
|
.limiter=(value) ⇒ Object
56
57
58
|
# File 'lib/core/SDCMain/Attributes.rb', line 56
def self.limiter=(value)
@limiter = value
end
|
.main_routine(scene_class, game_class: nil, title: "", width: 800, height: 600, limiter: nil) ⇒ Object
Main routine as an entry point for the Shidacea engine
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/core/MainLoop.rb', line 12
def self.main_routine(scene_class, game_class: nil, title: "", width: 800, height: 600, limiter: nil)
begin
SDC.window = SDC::Window.new(title, width, height)
SDC.set_draw_size(width, height)
SDC.limiter = limiter ? limiter : SDC::Limiter.new(max: 720, renders_per_second: 60, ticks_per_second: 60, gc_per_second: 60)
GC.disable
SDC.limiter.set_update_routine do
SDC.scene.process_events
SDC.scene.main_update
if !SDC.next_scene then SDC.scene.at_exit
SDC.scene = nil
return false
elsif SDC.next_scene != true then SDC.scene.at_exit
SDC.scene = SDC.next_scene.new
SDC.next_scene = true
SDC.scene.at_init
end
end
SDC.limiter.set_draw_routine do
SDC.scene.main_draw
end
SDC.limiter.set_gc_routine do
GC.enable
GC.start
GC.disable
end
SDC.game = game_class&.new
SDC.scene = scene_class.new
SDC.next_scene = true
SDC::Debug.on_debug do
c = 0
ti = Time.now
while SDC.window.is_open? do
c += 1
break if !SDC.limiter.tick
if c == SDC::limiter.max then
puts "FPS: #{SDC.limiter.renders_per_second / (Time.now - ti)}"
c = 0
ti = Time.now
end
end
end
SDC::Debug.on_release do
while SDC.window.is_open? do
break if !SDC.limiter.tick
end
end
SDC.window.close
GC.enable
rescue Exception => exc
f = File.open("log.txt", "a")
f.puts "Error in main loop at #{Time.now}:"
f.puts exc.inspect
f.puts exc.backtrace.join("\n")
f.puts ""
f.close
raise exc
end
end
|
17
18
19
|
# File 'lib/core/SDCMain/Input.rb', line 17
def self.mouse_button(button)
return SDC::EventMouse.const_get(button) if SDC::EventMouse.const_defined?(button)
end
|
.mouse_touching?(shape, offset: SDC.xy) ⇒ Boolean
37
38
39
|
# File 'lib/core/SDCMain/Input.rb', line 37
def self.mouse_touching?(shape, offset: SDC.xy)
return SDC::Collider.test(self.get_mouse_point, SDC.xy, shape, offset)
end
|
.multiply_variable(index, value, default: 0) ⇒ Object
35
36
37
|
# File 'lib/core/SDCMain/Variables.rb', line 35
def self.multiply_variable(index, value, default: 0)
@game.multiply_variable(index, value, default: default)
end
|
.next_scene ⇒ Object
36
37
38
|
# File 'lib/core/SDCMain/Attributes.rb', line 36
def self.next_scene
return @next_scene
end
|
.next_scene=(value) ⇒ Object
40
41
42
|
# File 'lib/core/SDCMain/Attributes.rb', line 40
def self.next_scene=(value)
@next_scene = value
end
|
.play_music(index: nil, file_index: nil, filename: nil, volume: 100.0, pitch: 1.0) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/core/SDCMain/Utility.rb', line 34
def self.play_music(index: nil, file_index: nil, filename: nil, volume: 100.0, pitch: 1.0)
music = SDC::Data.load_music_track(index, file_index: file_index, filename: filename)
music.volume = volume
music.pitch = pitch
music.play
end
|
.play_sound(index: nil, file_index: nil, filename: nil, volume: 100.0, pitch: 1.0) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/core/SDCMain/Utility.rb', line 24
def self.play_sound(index: nil, file_index: nil, filename: nil, volume: 100.0, pitch: 1.0)
sound_buffer = SDC::Data.load_sound_buffer(index, file_index: file_index, filename: filename)
sound = SDC::Sound.new
sound.link_sound_buffer(sound_buffer)
sound.volume = volume
sound.pitch = pitch
sound.play
end
|
.process_text_input(event: nil, text_buffer: nil, override: false) ⇒ Object
TODO: Allow specific input class
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/core/SDCMain/TextInput.rb', line 24
def self.process_text_input(event: nil, text_buffer: nil, override: false)
if event.has_type?(:TextEntered) then
char = event.text_char
if block_given? then
filter_result = yield(char, text_buffer)
char = filter_result if filter_result
return if override
end
if char == C_BACKSPACE then
self.handle_backspace_input(text_buffer)
elsif char == C_CTRL_BACK then
self.handle_ctrl_backspace_input(text_buffer)
elsif self.is_ctrl_char(char) then
else
text_buffer.concat(char)
end
end
end
|
.reset_switch(index, value: false) ⇒ Object
19
20
21
|
# File 'lib/core/SDCMain/Variables.rb', line 19
def self.reset_switch(index, value: false)
@game.set_switch(index, value: value)
end
|
.right_klick? ⇒ Boolean
41
42
43
|
# File 'lib/core/SDCMain/Input.rb', line 41
def self.right_klick?
return self.mouse_button_pressed?(:Right)
end
|
.scene ⇒ Object
28
29
30
|
# File 'lib/core/SDCMain/Attributes.rb', line 28
def self.scene
return @scene
end
|
.scene=(value) ⇒ Object
32
33
34
|
# File 'lib/core/SDCMain/Attributes.rb', line 32
def self.scene=(value)
@scene = value
end
|
.set_draw_size(width, height) ⇒ Object
68
69
70
71
|
# File 'lib/core/SDCMain/Attributes.rb', line 68
def self.set_draw_size(width, height)
@draw_width = width
@draw_height = height
end
|
.set_switch(index, value: true) ⇒ Object
15
16
17
|
# File 'lib/core/SDCMain/Variables.rb', line 15
def self.set_switch(index, value: true)
@game.set_switch(index, value: value)
end
|
.set_variable(index, value) ⇒ Object
7
8
9
|
# File 'lib/core/SDCMain/Variables.rb', line 7
def self.set_variable(index, value)
@game.set_variable(index, value)
end
|
.stop_music(index, file_index: nil, filename: nil) ⇒ Object
42
43
44
45
46
|
# File 'lib/core/SDCMain/Utility.rb', line 42
def self.stop_music(index, file_index: nil, filename: nil)
music = SDC::Data.load_music_track(index, file_index: file_index, filename: filename)
music.stop
end
|
.text_input ⇒ Object
60
61
62
|
# File 'lib/core/SDCMain/Attributes.rb', line 60
def self.text_input
return @text_input
end
|
.text_input=(value) ⇒ Object
64
65
66
|
# File 'lib/core/SDCMain/Attributes.rb', line 64
def self.text_input=(value)
@text_input = value
end
|
.toggle_switch(index) ⇒ Object
23
24
25
|
# File 'lib/core/SDCMain/Variables.rb', line 23
def self.toggle_switch(index)
@game.toggle_switch(index)
end
|
.window ⇒ Object
20
21
22
|
# File 'lib/core/SDCMain/Attributes.rb', line 20
def self.window
return @window
end
|
.window=(value) ⇒ Object
24
25
26
|
# File 'lib/core/SDCMain/Attributes.rb', line 24
def self.window=(value)
@window = value
end
|
.xy(x = 0.0, y = 0.0) ⇒ Object
16
17
18
|
# File 'lib/core/SDCMain/Attributes.rb', line 16
def self.xy(x = 0.0, y = 0.0)
return Coordinates.new(x, y)
end
|