metro-ld25 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +12 -0
- data/Guardfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +189 -0
- data/Rakefile +18 -0
- data/bin/metro +16 -0
- data/changelog.md +157 -0
- data/lib/assets/menu-movement.wav +0 -0
- data/lib/assets/menu-selection.wav +0 -0
- data/lib/assets/missing.ogg +0 -0
- data/lib/assets/missing.png +0 -0
- data/lib/assets/missing.wav +0 -0
- data/lib/assets/missing_animation.png +0 -0
- data/lib/commands/generate_game.rb +13 -0
- data/lib/commands/generate_model.rb +25 -0
- data/lib/commands/generate_scene.rb +36 -0
- data/lib/commands/generate_view.rb +21 -0
- data/lib/commands/thor.rb +83 -0
- data/lib/core_ext/class.rb +14 -0
- data/lib/core_ext/numeric.rb +59 -0
- data/lib/gosu_ext/color.rb +62 -0
- data/lib/gosu_ext/gosu_constants.rb +53 -0
- data/lib/locale/en.yml +35 -0
- data/lib/locale/locale.rb +1 -0
- data/lib/metro.rb +140 -0
- data/lib/metro/animation.rb +135 -0
- data/lib/metro/animation/after_interval_factory.rb +12 -0
- data/lib/metro/animation/animation_factory.rb +15 -0
- data/lib/metro/animation/easing/ease_in.rb +15 -0
- data/lib/metro/animation/easing/easing.rb +51 -0
- data/lib/metro/animation/easing/linear.rb +15 -0
- data/lib/metro/animation/has_animations.rb +70 -0
- data/lib/metro/animation/implicit_animation.rb +100 -0
- data/lib/metro/animation/on_update_operation.rb +96 -0
- data/lib/metro/animation/scene_animation.rb +16 -0
- data/lib/metro/asset_path.rb +97 -0
- data/lib/metro/events/control_definition.rb +11 -0
- data/lib/metro/events/controls.rb +42 -0
- data/lib/metro/events/event_data.rb +60 -0
- data/lib/metro/events/event_dictionary.rb +52 -0
- data/lib/metro/events/event_factory.rb +17 -0
- data/lib/metro/events/event_relay.rb +300 -0
- data/lib/metro/events/event_state_manager.rb +63 -0
- data/lib/metro/events/events.rb +3 -0
- data/lib/metro/events/has_events.rb +108 -0
- data/lib/metro/events/hit_list.rb +75 -0
- data/lib/metro/events/unknown_sender.rb +5 -0
- data/lib/metro/font.rb +69 -0
- data/lib/metro/game.rb +102 -0
- data/lib/metro/game/dsl.rb +68 -0
- data/lib/metro/image.rb +68 -0
- data/lib/metro/logging.rb +33 -0
- data/lib/metro/missing_scene.rb +21 -0
- data/lib/metro/models/audio/song.rb +33 -0
- data/lib/metro/models/draws.rb +86 -0
- data/lib/metro/models/key_value_coding.rb +38 -0
- data/lib/metro/models/model.rb +236 -0
- data/lib/metro/models/model_factory.rb +32 -0
- data/lib/metro/models/models.rb +62 -0
- data/lib/metro/models/properties/animation_property.rb +115 -0
- data/lib/metro/models/properties/array_property.rb +24 -0
- data/lib/metro/models/properties/boolean_property.rb +27 -0
- data/lib/metro/models/properties/color_property.rb +116 -0
- data/lib/metro/models/properties/dimensions_property.rb +84 -0
- data/lib/metro/models/properties/font_property.rb +130 -0
- data/lib/metro/models/properties/image_property.rb +96 -0
- data/lib/metro/models/properties/model_property.rb +84 -0
- data/lib/metro/models/properties/numeric_property.rb +29 -0
- data/lib/metro/models/properties/options_property/no_option.rb +29 -0
- data/lib/metro/models/properties/options_property/options.rb +94 -0
- data/lib/metro/models/properties/options_property/options_property.rb +125 -0
- data/lib/metro/models/properties/position_property.rb +90 -0
- data/lib/metro/models/properties/property.rb +221 -0
- data/lib/metro/models/properties/property_owner.rb +137 -0
- data/lib/metro/models/properties/sample_property.rb +84 -0
- data/lib/metro/models/properties/scale_property.rb +80 -0
- data/lib/metro/models/properties/song_property.rb +89 -0
- data/lib/metro/models/properties/text_property.rb +75 -0
- data/lib/metro/models/ui/animated_sprite.rb +85 -0
- data/lib/metro/models/ui/border.rb +95 -0
- data/lib/metro/models/ui/fps.rb +54 -0
- data/lib/metro/models/ui/generic.rb +66 -0
- data/lib/metro/models/ui/grid_drawer.rb +74 -0
- data/lib/metro/models/ui/image.rb +87 -0
- data/lib/metro/models/ui/label.rb +175 -0
- data/lib/metro/models/ui/menu.rb +214 -0
- data/lib/metro/models/ui/model_label.rb +65 -0
- data/lib/metro/models/ui/model_labeler.rb +79 -0
- data/lib/metro/models/ui/rectangle.rb +59 -0
- data/lib/metro/models/ui/sprite.rb +79 -0
- data/lib/metro/models/ui/tile_map.rb +162 -0
- data/lib/metro/models/ui/ui.rb +13 -0
- data/lib/metro/parameters/command_line_args_parser.rb +68 -0
- data/lib/metro/parameters/options.rb +25 -0
- data/lib/metro/parameters/parameters.rb +2 -0
- data/lib/metro/sample.rb +40 -0
- data/lib/metro/scene.rb +477 -0
- data/lib/metro/scenes.rb +154 -0
- data/lib/metro/song.rb +56 -0
- data/lib/metro/template_message.rb +60 -0
- data/lib/metro/transitions/edit_transition_scene.rb +100 -0
- data/lib/metro/transitions/fade_transition_scene.rb +66 -0
- data/lib/metro/transitions/scene_transitions.rb +44 -0
- data/lib/metro/transitions/transition_scene.rb +19 -0
- data/lib/metro/units/bounds.rb +8 -0
- data/lib/metro/units/calculation_validations.rb +74 -0
- data/lib/metro/units/dimensions.rb +60 -0
- data/lib/metro/units/point.rb +51 -0
- data/lib/metro/units/rectangle_bounds.rb +85 -0
- data/lib/metro/units/scale.rb +46 -0
- data/lib/metro/units/units.rb +6 -0
- data/lib/metro/version.rb +32 -0
- data/lib/metro/views/json_view.rb +60 -0
- data/lib/metro/views/no_view.rb +34 -0
- data/lib/metro/views/parsers.rb +42 -0
- data/lib/metro/views/scene_view.rb +107 -0
- data/lib/metro/views/view.rb +133 -0
- data/lib/metro/views/writers.rb +43 -0
- data/lib/metro/views/yaml_view.rb +94 -0
- data/lib/metro/window.rb +94 -0
- data/lib/setup_handlers/exit_if_dry_run.rb +26 -0
- data/lib/setup_handlers/game_execution.rb +65 -0
- data/lib/setup_handlers/load_game_configuration.rb +65 -0
- data/lib/setup_handlers/load_game_files.rb +101 -0
- data/lib/setup_handlers/move_to_game_directory.rb +25 -0
- data/lib/setup_handlers/reload_game_on_game_file_changes.rb +79 -0
- data/lib/templates/game/README.md.tt +52 -0
- data/lib/templates/game/assets/brand.jpg +0 -0
- data/lib/templates/game/assets/hero.png +0 -0
- data/lib/templates/game/lib/custom_easing.rb +32 -0
- data/lib/templates/game/metro.tt +63 -0
- data/lib/templates/game/models/hero.rb +62 -0
- data/lib/templates/game/scenes/brand_scene.rb +19 -0
- data/lib/templates/game/scenes/brand_to_title_scene.rb +13 -0
- data/lib/templates/game/scenes/first_scene.rb +28 -0
- data/lib/templates/game/scenes/game_scene.rb +43 -0
- data/lib/templates/game/scenes/title_scene.rb +15 -0
- data/lib/templates/game/views/brand.yaml +4 -0
- data/lib/templates/game/views/brand_to_title.yaml +8 -0
- data/lib/templates/game/views/first.yaml +26 -0
- data/lib/templates/game/views/title.yaml +11 -0
- data/lib/templates/message.erb +23 -0
- data/lib/templates/model.rb.tt +111 -0
- data/lib/templates/scene.rb.tt +140 -0
- data/lib/templates/view.yaml.tt +11 -0
- data/lib/tmxed_ext/tile_set.rb +34 -0
- data/metro.gemspec +56 -0
- data/spec/core_ext/numeric_spec.rb +78 -0
- data/spec/core_ext/string_spec.rb +33 -0
- data/spec/gosu_ext/color_spec.rb +80 -0
- data/spec/metro/events/event_state_manager_spec.rb +5 -0
- data/spec/metro/models/key_value_coding_spec.rb +61 -0
- data/spec/metro/models/properties/array_property_spec.rb +60 -0
- data/spec/metro/models/properties/color_property_spec.rb +85 -0
- data/spec/metro/models/properties/dimensions_spec.rb +29 -0
- data/spec/metro/models/properties/font_property_spec.rb +127 -0
- data/spec/metro/models/properties/numeric_property_spec.rb +46 -0
- data/spec/metro/models/properties/options_property/no_option_spec.rb +25 -0
- data/spec/metro/models/properties/options_property/options_property_spec.rb +133 -0
- data/spec/metro/models/properties/options_property/options_spec.rb +125 -0
- data/spec/metro/models/properties/position_property_spec.rb +90 -0
- data/spec/metro/models/ui/label_spec.rb +259 -0
- data/spec/metro/parameters/command_line_args_parser_spec.rb +42 -0
- data/spec/metro/scene_spec.rb +15 -0
- data/spec/metro/scene_views/json_view_spec.rb +27 -0
- data/spec/metro/scene_views/yaml_view_spec.rb +38 -0
- data/spec/metro/scenes_spec.rb +77 -0
- data/spec/metro/units/point_spec.rb +132 -0
- data/spec/metro/views/view_spec.rb +53 -0
- data/spec/setup_handlers/exit_if_dry_run_spec.rb +27 -0
- data/spec/setup_handlers/reload_game_on_game_file_changes_spec.rb +68 -0
- data/spec/spec_helper.rb +20 -0
- metadata +374 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
module Metro
|
2
|
+
class Model
|
3
|
+
|
4
|
+
#
|
5
|
+
# A sample property maintains a Gosu::Sample.
|
6
|
+
#
|
7
|
+
# A sample is stored in the properties as the path in the assets folder and is converted into
|
8
|
+
# a Gosu::Sample when it is retrieved within the system. When retrieving a sample the Sample
|
9
|
+
# Property will attempt to use a sample that already exists that meets that criteria.
|
10
|
+
#
|
11
|
+
# @example Defining a sample property
|
12
|
+
#
|
13
|
+
# class Hero < Metro::Model
|
14
|
+
# property :sample
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# @example Defining a sample property providing a default
|
18
|
+
#
|
19
|
+
# class Hero < Metro::Model
|
20
|
+
# property :sample, path: 'pickup.wav'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# @example Using a sample property with a different property name
|
24
|
+
#
|
25
|
+
# class Hero < Metro::Model
|
26
|
+
# property :pickup_sample, type: :sample, path: 'pickup.wav'
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
class SampleProperty < Metro::Model::Property
|
30
|
+
|
31
|
+
# By default, getting an unsupported value will return the default sample
|
32
|
+
get do |value|
|
33
|
+
default_sample
|
34
|
+
end
|
35
|
+
|
36
|
+
# Bu default, setting sn unsupported value will save the default sample filename
|
37
|
+
set do |value|
|
38
|
+
default_sample_filename
|
39
|
+
end
|
40
|
+
|
41
|
+
# Generate a sample from the specified string filepath
|
42
|
+
get String do |filename|
|
43
|
+
self.class.sample_for path: filename, window: model.window
|
44
|
+
end
|
45
|
+
|
46
|
+
# The assumption here is that the string is a sample filepath
|
47
|
+
set String do |filename|
|
48
|
+
filename
|
49
|
+
end
|
50
|
+
|
51
|
+
# Setting the song value with a Metro::Sample will save the string filepath
|
52
|
+
set Metro::Sample do |sample|
|
53
|
+
sample.path
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# @return the default sample for the sample property. This is based on the default
|
58
|
+
# sample name.
|
59
|
+
#
|
60
|
+
def default_sample
|
61
|
+
self.class.sample_for path: default_sample_filename, window: model.window
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# @return a string sample name that is default. If the property was not created with
|
66
|
+
# a default value the the default sample is the missing sample found in Metro.
|
67
|
+
#
|
68
|
+
def default_sample_filename
|
69
|
+
options[:path] or "missing.wav"
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Returns a Metro::Sample. This is composed of the metadata provided and a Gosu::Sample.
|
74
|
+
#
|
75
|
+
# @param [Hash] options the path, window, and other parameters necessary to generate
|
76
|
+
# a sample.
|
77
|
+
#
|
78
|
+
def self.sample_for(options)
|
79
|
+
Metro::Sample.create(options)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Metro
|
2
|
+
class Model
|
3
|
+
|
4
|
+
#
|
5
|
+
# A scale property maintains an x and y scaling factor.
|
6
|
+
#
|
7
|
+
# A scale property also defines a `x_factor` property and a `y_factor`
|
8
|
+
# property which allows a more direct interface. Changing these values will
|
9
|
+
# update the scale the next time that it is used.
|
10
|
+
#
|
11
|
+
# A scale is stored in the properties as a string representation and is
|
12
|
+
# converted into a Scale when it is retrieved within the system.
|
13
|
+
#
|
14
|
+
# @example Defining a scale property
|
15
|
+
#
|
16
|
+
# class Scoreboard < Metro::Model
|
17
|
+
# property :font
|
18
|
+
# property :color
|
19
|
+
# property :scale
|
20
|
+
#
|
21
|
+
# def draw
|
22
|
+
# image.draw text, x, y, z_order, x_factor, y_factor, color
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# @example Defining a scale property providing a default
|
28
|
+
#
|
29
|
+
# class Hero < Metro::Model
|
30
|
+
# property :image, path: 'hero.jpg'
|
31
|
+
# property :scale, default: "1.0,1.0"
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# @example Using a scale property with a different property name
|
35
|
+
#
|
36
|
+
# class Hero < Metro::Model
|
37
|
+
# property :image, path: 'hero.jpg'
|
38
|
+
# property :enraged_scale, type: :scale, default: "4.0,4.0"
|
39
|
+
# property :angle
|
40
|
+
# property :color
|
41
|
+
#
|
42
|
+
# def draw
|
43
|
+
# image.draw_rot x, y, z_order, angle.to_f, 0.5, 0.5,
|
44
|
+
# enraged_scale_factor_x, enraged_scale_factor_y, color
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
class ScaleProperty < Property
|
49
|
+
define_property :x_factor
|
50
|
+
|
51
|
+
define_property :y_factor
|
52
|
+
|
53
|
+
get do |value|
|
54
|
+
default_scale
|
55
|
+
end
|
56
|
+
|
57
|
+
get String do |value|
|
58
|
+
Scale.parse(value)
|
59
|
+
end
|
60
|
+
|
61
|
+
set do |value|
|
62
|
+
default_scale.to_s
|
63
|
+
end
|
64
|
+
|
65
|
+
set String do |value|
|
66
|
+
value
|
67
|
+
end
|
68
|
+
|
69
|
+
set Scale do |value|
|
70
|
+
value.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
def default_scale
|
74
|
+
(options[:default] and options[:default].is_a? Scale) ? options[:default] : Scale.one
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Metro
|
2
|
+
class Model
|
3
|
+
|
4
|
+
#
|
5
|
+
# A song property maintains a Gosu::Song.
|
6
|
+
#
|
7
|
+
# A song is stored in the properties as the path in the assets folder and is converted into
|
8
|
+
# a Gosu::Song when it is retrieved within the system. When retrieving a song the Song
|
9
|
+
# Property will attempt to use a song that already exists that meets that criteria.
|
10
|
+
#
|
11
|
+
# The songs are cached within the song property to help performance by reducing the unncessary
|
12
|
+
# creation of similar song.
|
13
|
+
#
|
14
|
+
# @example Defining a song property
|
15
|
+
#
|
16
|
+
# class Song < Metro::Model
|
17
|
+
# property :song
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# @example Defining a song property providing a default
|
21
|
+
#
|
22
|
+
# class Song < Metro::Model
|
23
|
+
# property :song, path: 'happy-song.wav'
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# @example Using a song property with a different property name
|
27
|
+
#
|
28
|
+
# class Song < Metro::Model
|
29
|
+
# property :intro, type: :song, path: 'intro-song.wav'
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
class SongProperty < Metro::Model::Property
|
33
|
+
|
34
|
+
# By default, getting an unsupported value will return the default song
|
35
|
+
get do |value|
|
36
|
+
default_song
|
37
|
+
end
|
38
|
+
|
39
|
+
# By default, setting an unsupported value will save the default song
|
40
|
+
set do |value|
|
41
|
+
default_song_name
|
42
|
+
end
|
43
|
+
|
44
|
+
# Generate a song from the specified string filepath
|
45
|
+
get String do |filename|
|
46
|
+
self.class.song_for path: filename, window: model.window
|
47
|
+
end
|
48
|
+
|
49
|
+
# The assumption here is that the string is a song filepath
|
50
|
+
set String do |filename|
|
51
|
+
filename
|
52
|
+
end
|
53
|
+
|
54
|
+
# Setting the song value with a Metro::Song will save the string filepath
|
55
|
+
set Metro::Song do |song|
|
56
|
+
song.path
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# @return the default song for the song property. This is based on the default
|
61
|
+
# song name.
|
62
|
+
#
|
63
|
+
def default_song
|
64
|
+
self.class.song_for path: default_song_name, window: model.window
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# @return a string song name that is default. If the property was not created with
|
69
|
+
# a default value the the default song is the missing song found in Metro.
|
70
|
+
#
|
71
|
+
def default_song_name
|
72
|
+
options[:path] or 'missing.ogg'
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Returns a Metro::Song. This is composed of the metadata provided and a Gosu::Song.
|
77
|
+
#
|
78
|
+
# Songs are cached within the property to increase performance.
|
79
|
+
#
|
80
|
+
# @param [Hash] options the path, window, and other parameters necessary to generate
|
81
|
+
# a song.
|
82
|
+
#
|
83
|
+
def self.song_for(options)
|
84
|
+
Song.find_or_create(options)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Metro
|
2
|
+
class Model
|
3
|
+
|
4
|
+
#
|
5
|
+
# A text property maintains a string of text
|
6
|
+
#
|
7
|
+
# Text is stored as text in properties. When retrieving the text, the contents of the text will
|
8
|
+
# be evaluated within the instance of the model's scene. Which means that text may contain
|
9
|
+
# escaped variables referencing anything in the scene or the game.
|
10
|
+
#
|
11
|
+
# @example Defining a text property
|
12
|
+
#
|
13
|
+
# class Scoreboard < Metro::Model
|
14
|
+
# property :font
|
15
|
+
# property :position
|
16
|
+
# property :color
|
17
|
+
# property :scale
|
18
|
+
# property :text
|
19
|
+
#
|
20
|
+
# def draw
|
21
|
+
# font.draw text, x, y, z_order, x_factor, y_factor, color
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# @example Defining with a default and text that will be instance evaluated.
|
27
|
+
#
|
28
|
+
# class ScoreBoard < Metro::Model
|
29
|
+
# property :score
|
30
|
+
# property :text, default: 'Score is #{score}'
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# @example Using a text property with a different property name
|
34
|
+
#
|
35
|
+
# class Hero < Metro::Model
|
36
|
+
# proeprty :font
|
37
|
+
# property :position
|
38
|
+
# property :color
|
39
|
+
# property :scale
|
40
|
+
# property :description, type: :text
|
41
|
+
#
|
42
|
+
# def draw
|
43
|
+
# font.draw description, x, y, z_order, x_factor, y_factor, color
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
class TextProperty < Property
|
48
|
+
|
49
|
+
# When no text is found for the field use the default text.
|
50
|
+
get do |value|
|
51
|
+
evalute_within_scene default_text
|
52
|
+
end
|
53
|
+
|
54
|
+
# When getting the text, evaluate the text within the scene.
|
55
|
+
get String do |value|
|
56
|
+
evalute_within_scene(value)
|
57
|
+
end
|
58
|
+
|
59
|
+
# When saving, simply save whatever is given as text.
|
60
|
+
set do |value|
|
61
|
+
value.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
def evalute_within_scene(text)
|
65
|
+
model.scene.instance_eval( "\"#{text}\"" )
|
66
|
+
end
|
67
|
+
|
68
|
+
def default_text
|
69
|
+
options[:default] || 'TEXT NOT SPECIFIED!'
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Metro
|
2
|
+
module UI
|
3
|
+
|
4
|
+
#
|
5
|
+
# A sprite is a Metro model that is specially designed to draw and manage
|
6
|
+
# an animation. A sprite maintains an animation, location information, and
|
7
|
+
# rotation.
|
8
|
+
#
|
9
|
+
class AnimatedSprite < Model
|
10
|
+
|
11
|
+
# @attribute
|
12
|
+
# The animation that will be drawn for the sprite
|
13
|
+
property :animation
|
14
|
+
|
15
|
+
# @attribute
|
16
|
+
# The point at which the sprite should be drawn
|
17
|
+
property :position
|
18
|
+
|
19
|
+
# @attribute
|
20
|
+
# This is the color of the spirte. The color usually remains white, and
|
21
|
+
# the color property is implemented by the `alpha` value is the one thing
|
22
|
+
# that is altered to fade in and fade out the sprite.
|
23
|
+
property :color
|
24
|
+
|
25
|
+
# @attribute
|
26
|
+
# The scale at which to draw the sprite. This is default scale of 1.
|
27
|
+
property :scale
|
28
|
+
|
29
|
+
# @attribute
|
30
|
+
# The center, horizontal position, as expressed in a ratio, of the image.
|
31
|
+
property :center_x, type: :numeric, default: 0.5
|
32
|
+
|
33
|
+
# @attribute
|
34
|
+
# The center, vertical position, as expressed in a ratio, of the image.
|
35
|
+
property :center_y, type: :numeric, default: 0.5
|
36
|
+
|
37
|
+
# @attribute
|
38
|
+
# The angle at which the sprite should be drawn. This is by default 0.
|
39
|
+
property :angle
|
40
|
+
|
41
|
+
# @attribute
|
42
|
+
# The height and width of the sprite is based on the image of the sprite.
|
43
|
+
property :dimensions do
|
44
|
+
Dimensions.of current_image.width, current_image.height
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [RectangleBounds] the bounds of the sprite.
|
48
|
+
def bounds
|
49
|
+
Bounds.new left: left, right: right, top: top, bottom: bottom
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Float] the left-most x position of the sprite
|
53
|
+
def left
|
54
|
+
x - width * center_x
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Float] the right-most x position of the sprite
|
58
|
+
def right
|
59
|
+
left + width * x_factor
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [Float] the top-most y position of the sprite
|
63
|
+
def top
|
64
|
+
y - height * center_y
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Float] the bottom-most y position of the sprite
|
68
|
+
def bottom
|
69
|
+
top + height * y_factor
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [Gosu::Image] the current image in the animation sequence.
|
73
|
+
def current_image
|
74
|
+
animation.image
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# By default the sprite will draw the current image of the animation.
|
79
|
+
#
|
80
|
+
def draw
|
81
|
+
current_image.draw_rot x, y, z_order, angle, center_x, center_y, x_factor, y_factor, color
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Metro
|
2
|
+
module UI
|
3
|
+
|
4
|
+
#
|
5
|
+
# Draws a rectanglar border around the specififed position and dimensions
|
6
|
+
# with the width provided. This is an unfilled rectangle.
|
7
|
+
#
|
8
|
+
class Border < Model
|
9
|
+
|
10
|
+
# @attribute
|
11
|
+
# The starting position of the border.
|
12
|
+
property :position
|
13
|
+
|
14
|
+
# @attribute
|
15
|
+
# The dimension of the border.
|
16
|
+
property :dimensions
|
17
|
+
|
18
|
+
# @attribute
|
19
|
+
# The color which to use to draw the border.
|
20
|
+
property :color, default: "rgba(255,255,255,1.0)"
|
21
|
+
|
22
|
+
# @attribute
|
23
|
+
# The width of the border lines
|
24
|
+
property :border, default: 2
|
25
|
+
|
26
|
+
def draw
|
27
|
+
draw_border
|
28
|
+
end
|
29
|
+
|
30
|
+
def draw_border
|
31
|
+
draw_top
|
32
|
+
draw_bottom
|
33
|
+
draw_left
|
34
|
+
draw_right
|
35
|
+
end
|
36
|
+
|
37
|
+
def draw_top
|
38
|
+
draw_line left_with_border, top, right, top_with_border
|
39
|
+
end
|
40
|
+
|
41
|
+
def draw_left
|
42
|
+
draw_line left, top, left_with_border, bottom_with_border
|
43
|
+
end
|
44
|
+
|
45
|
+
def draw_right
|
46
|
+
draw_line right, top, right_with_border, bottom_with_border
|
47
|
+
end
|
48
|
+
|
49
|
+
def draw_bottom
|
50
|
+
draw_line left_with_border, bottom, right,bottom_with_border
|
51
|
+
end
|
52
|
+
|
53
|
+
def draw_line(start_x,start_y,finish_x,finish_y)
|
54
|
+
window.draw_quad start_x, start_y, color,
|
55
|
+
finish_x, start_y, color,
|
56
|
+
finish_x, finish_y, color,
|
57
|
+
start_x, finish_y, color, z_order
|
58
|
+
end
|
59
|
+
|
60
|
+
def left
|
61
|
+
x
|
62
|
+
end
|
63
|
+
|
64
|
+
def left_with_border
|
65
|
+
x + border
|
66
|
+
end
|
67
|
+
|
68
|
+
def right
|
69
|
+
x + width
|
70
|
+
end
|
71
|
+
|
72
|
+
def right_with_border
|
73
|
+
right + border
|
74
|
+
end
|
75
|
+
|
76
|
+
def top
|
77
|
+
y
|
78
|
+
end
|
79
|
+
|
80
|
+
def top_with_border
|
81
|
+
top + border
|
82
|
+
end
|
83
|
+
|
84
|
+
def bottom
|
85
|
+
y + height
|
86
|
+
end
|
87
|
+
|
88
|
+
def bottom_with_border
|
89
|
+
bottom + border
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|