fantasy 0.1.13 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +22 -1
  3. data/.yardopts +4 -0
  4. data/CHANGELOG.md +6 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +55 -0
  7. data/README.md +14 -6
  8. data/docs/Actor.html +2737 -0
  9. data/docs/Background.html +961 -0
  10. data/docs/Camera.html +791 -0
  11. data/docs/Clock.html +753 -0
  12. data/docs/Color.html +776 -0
  13. data/docs/Coordinates.html +730 -0
  14. data/docs/Cursor.html +752 -0
  15. data/docs/Disk.html +236 -0
  16. data/docs/Draggable.html +198 -0
  17. data/docs/Fantasy.html +121 -0
  18. data/docs/Game.html +904 -0
  19. data/docs/Global.html +2791 -0
  20. data/docs/Gravitier.html +179 -0
  21. data/docs/HudImage.html +979 -0
  22. data/docs/HudText.html +1151 -0
  23. data/docs/Image.html +506 -0
  24. data/docs/Jumper.html +189 -0
  25. data/docs/Mouse.html +226 -0
  26. data/docs/MoveByCursor.html +374 -0
  27. data/docs/MoveByDirection.html +179 -0
  28. data/docs/Mover.html +305 -0
  29. data/docs/Music.html +524 -0
  30. data/docs/Shape.html +1057 -0
  31. data/docs/Sound.html +374 -0
  32. data/docs/Tilemap.html +491 -0
  33. data/docs/Tween.html +186 -0
  34. data/docs/UserInputs.html +879 -0
  35. data/docs/Utils.html +345 -0
  36. data/docs/_index.html +346 -0
  37. data/docs/class_list.html +51 -0
  38. data/docs/css/common.css +1 -0
  39. data/docs/css/full_list.css +58 -0
  40. data/docs/css/style.css +497 -0
  41. data/docs/file.CHANGELOG.html +121 -0
  42. data/docs/file.README.html +599 -0
  43. data/docs/file_list.html +61 -0
  44. data/docs/frames.html +17 -0
  45. data/docs/index.html +599 -0
  46. data/docs/js/app.js +314 -0
  47. data/docs/js/full_list.js +216 -0
  48. data/docs/js/jquery.js +4 -0
  49. data/docs/method_list.html +1931 -0
  50. data/docs/top-level-namespace.html +978 -0
  51. data/lib/fantasy/actor.rb +455 -123
  52. data/lib/fantasy/background.rb +109 -13
  53. data/lib/fantasy/base.rb +113 -1
  54. data/lib/fantasy/camera.rb +95 -11
  55. data/lib/fantasy/clock.rb +4 -2
  56. data/lib/fantasy/color.rb +158 -153
  57. data/lib/fantasy/coordinates.rb +5 -9
  58. data/lib/fantasy/cursor.rb +2 -1
  59. data/lib/fantasy/disk.rb +12 -8
  60. data/lib/fantasy/draggable.rb +22 -1
  61. data/lib/fantasy/global.rb +59 -31
  62. data/lib/fantasy/hud_image.rb +5 -3
  63. data/lib/fantasy/hud_text.rb +6 -2
  64. data/lib/fantasy/image.rb +12 -4
  65. data/lib/fantasy/includes/gravitier.rb +2 -0
  66. data/lib/fantasy/includes/jumper.rb +3 -2
  67. data/lib/fantasy/includes/log.rb +12 -0
  68. data/lib/fantasy/includes/move_by_cursors.rb +24 -15
  69. data/lib/fantasy/includes/move_by_direction.rb +2 -0
  70. data/lib/fantasy/includes/mover.rb +3 -0
  71. data/lib/fantasy/includes/user_inputs.rb +6 -0
  72. data/lib/fantasy/loop.rb +41 -44
  73. data/lib/fantasy/mouse.rb +2 -0
  74. data/lib/fantasy/music.rb +4 -2
  75. data/lib/fantasy/shape.rb +11 -2
  76. data/lib/fantasy/sound.rb +3 -1
  77. data/lib/fantasy/tilemap.rb +19 -13
  78. data/lib/fantasy/tween.rb +3 -1
  79. data/lib/fantasy/utils.rb +7 -13
  80. data/lib/fantasy/version.rb +1 -1
  81. data/lib/fantasy.rb +2 -0
  82. metadata +90 -4
  83. data/fantasy.gemspec +0 -40
  84. data/fonts/VT323-Regular.ttf +0 -0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Tilemap
2
4
  attr_accessor :position
3
5
 
@@ -5,7 +7,7 @@ class Tilemap
5
7
  @tile_width = tile_width || tile_size
6
8
  @tile_height = tile_height || tile_size
7
9
 
8
- if(@tile_height.nil? or @tile_width.nil?)
10
+ if @tile_height.nil? || @tile_width.nil?
9
11
  raise("Tile size is not properly defined. Either you set a `tile_size` or a `tile_width` and `tile_height`")
10
12
  end
11
13
 
@@ -31,16 +33,8 @@ class Tilemap
31
33
  tile_position.x = 0
32
34
 
33
35
  line.each do |tile_index|
34
- if !tile_index.nil?
35
- actor_template = @tiles[tile_index]
36
-
37
- if actor_template.nil?
38
- raise "Tilemap config error. Not found Tile for index '#{tile_index}'"
39
- end
40
-
41
- actor = actor_template.clone
42
- actor.position.x = @position.x + (tile_position.x * @tile_width)
43
- actor.position.y = @position.y + (tile_position.y * @tile_height)
36
+ unless tile_index.nil?
37
+ render_tile(tile_index, tile_position)
44
38
  end
45
39
 
46
40
  tile_position.x += 1
@@ -52,6 +46,18 @@ class Tilemap
52
46
 
53
47
  private
54
48
 
49
+ def render_tile(tile_index, tile_position)
50
+ actor_template = @tiles[tile_index]
51
+
52
+ if actor_template.nil?
53
+ raise "Tilemap config error. Not found Tile for index '#{tile_index}'"
54
+ end
55
+
56
+ actor = actor_template.clone
57
+ actor.position.x = @position.x + (tile_position.x * @tile_width)
58
+ actor.position.y = @position.y + (tile_position.y * @tile_height)
59
+ end
60
+
55
61
  class << self
56
62
  @@maps = {}
57
63
 
@@ -68,13 +74,13 @@ class Tilemap
68
74
 
69
75
  puts "Initialize map: '#{map_name}'"
70
76
 
71
- file_name = Dir.entries(base_path).find { |e| e =~ /^#{map_name}($|\.)/ }
77
+ file_name = Dir.entries(base_path).find { |e| e =~ /^#{map_name}($|\.)/ }
72
78
 
73
79
  raise "Map file not found with name '#{map_name}' in #{base_path}" if file_name.nil?
74
80
 
75
81
  @@maps[map_name] = "#{base_path}/#{file_name}"
76
82
 
77
- return @@maps[map_name]
83
+ @@maps[map_name]
78
84
  end
79
85
 
80
86
  def base_path
data/lib/fantasy/tween.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tween
2
4
  def self.move_towards(from:, to:, speed:)
3
5
  direction = to - from
@@ -6,6 +8,6 @@ module Tween
6
8
  return to if step.zero?
7
9
 
8
10
  direction = direction.normalize
9
- return from + (direction * step)
11
+ from + (direction * step)
10
12
  end
11
13
  end
data/lib/fantasy/utils.rb CHANGED
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Utils
2
4
  # https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection
5
+ # rubocop:disable Metrics/AbcSize
3
6
  def self.collision?(actor_1, actor_2)
4
- result =
5
- (
7
+ (
6
8
  actor_1.position.x < (actor_2.position.x + actor_2.width) &&
7
9
  (actor_1.position.x + actor_1.width) > actor_2.position.x &&
8
10
  actor_1.position.y < (actor_2.position.y + actor_2.height) &&
9
11
  actor_1.position.y + actor_1.height > actor_2.position.y
10
12
  )
11
-
12
- result
13
13
  end
14
+ # rubocop:enable Metrics/AbcSize
15
+
14
16
 
15
17
  def self.collision_at?(actor, x, y)
16
18
  (
@@ -21,15 +23,7 @@ module Utils
21
23
  )
22
24
  end
23
25
 
24
- def self.draw_frame(x, y, width, height, stroke, color)
25
- Gosu.draw_rect(x, y, width, stroke, color)
26
- Gosu.draw_rect(x + (width - stroke), y, stroke, height, color)
27
- Gosu.draw_rect(x, y + (height - stroke), width, stroke, color)
28
- Gosu.draw_rect(x, y, stroke, height, color)
29
- end
30
-
31
26
  def self.remap(value:, from_ini:, from_end:, to_ini:, to_end:)
32
- result = to_ini + (value - from_ini) * (to_end - to_ini) / (from_end - from_ini);
33
- result
27
+ to_ini + (value - from_ini) * (to_end - to_ini) / (from_end - from_ini)
34
28
  end
35
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fantasy
4
- VERSION = "0.1.13"
4
+ VERSION = "0.1.17"
5
5
  end
data/lib/fantasy.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "gosu"
3
4
 
4
5
  require_relative "fantasy/version"
@@ -6,6 +7,7 @@ require_relative "fantasy/version"
6
7
  require_relative "fantasy/coordinates"
7
8
  require_relative "fantasy/cursor"
8
9
  require_relative "fantasy/mouse"
10
+ require_relative "fantasy/includes/log"
9
11
  require_relative "fantasy/includes/move_by_cursors"
10
12
  require_relative "fantasy/includes/move_by_direction"
11
13
  require_relative "fantasy/includes/mover"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fantasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Guillen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-01 00:00:00.000000000 Z
11
+ date: 2024-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.2.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  description: Simple toolbox library and lean API to build great mini games in Ruby
42
84
  email:
43
85
  - fguillen.mail@gmail.com
@@ -46,17 +88,60 @@ extensions: []
46
88
  extra_rdoc_files: []
47
89
  files:
48
90
  - ".rubocop.yml"
91
+ - ".yardopts"
49
92
  - CHANGELOG.md
50
93
  - COLOR_PALETTE.md
51
94
  - Gemfile
95
+ - Gemfile.lock
52
96
  - LICENSE.txt
53
97
  - README.md
54
98
  - Rakefile
55
99
  - bin/console
56
100
  - bin/setup
57
- - fantasy.gemspec
101
+ - docs/Actor.html
102
+ - docs/Background.html
103
+ - docs/Camera.html
104
+ - docs/Clock.html
105
+ - docs/Color.html
106
+ - docs/Coordinates.html
107
+ - docs/Cursor.html
108
+ - docs/Disk.html
109
+ - docs/Draggable.html
110
+ - docs/Fantasy.html
111
+ - docs/Game.html
112
+ - docs/Global.html
113
+ - docs/Gravitier.html
114
+ - docs/HudImage.html
115
+ - docs/HudText.html
116
+ - docs/Image.html
117
+ - docs/Jumper.html
118
+ - docs/Mouse.html
119
+ - docs/MoveByCursor.html
120
+ - docs/MoveByDirection.html
121
+ - docs/Mover.html
122
+ - docs/Music.html
123
+ - docs/Shape.html
124
+ - docs/Sound.html
125
+ - docs/Tilemap.html
126
+ - docs/Tween.html
127
+ - docs/UserInputs.html
128
+ - docs/Utils.html
129
+ - docs/_index.html
130
+ - docs/class_list.html
131
+ - docs/css/common.css
132
+ - docs/css/full_list.css
133
+ - docs/css/style.css
134
+ - docs/file.CHANGELOG.html
135
+ - docs/file.README.html
136
+ - docs/file_list.html
137
+ - docs/frames.html
138
+ - docs/index.html
139
+ - docs/js/app.js
140
+ - docs/js/full_list.js
141
+ - docs/js/jquery.js
142
+ - docs/method_list.html
143
+ - docs/top-level-namespace.html
58
144
  - fonts/OFL.txt
59
- - fonts/VT323-Regular.ttf
60
145
  - lib/fantasy.rb
61
146
  - lib/fantasy/actor.rb
62
147
  - lib/fantasy/background.rb
@@ -74,6 +159,7 @@ files:
74
159
  - lib/fantasy/image.rb
75
160
  - lib/fantasy/includes/gravitier.rb
76
161
  - lib/fantasy/includes/jumper.rb
162
+ - lib/fantasy/includes/log.rb
77
163
  - lib/fantasy/includes/move_by_cursors.rb
78
164
  - lib/fantasy/includes/move_by_direction.rb
79
165
  - lib/fantasy/includes/mover.rb
data/fantasy.gemspec DELETED
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/fantasy/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "fantasy"
7
- spec.version = Fantasy::VERSION
8
- spec.authors = ["Fernando Guillen"]
9
- spec.email = ["fguillen.mail@gmail.com"]
10
-
11
- spec.summary = "Simple toolbox library and lean API to build great mini games in Ruby"
12
- spec.description = "Simple toolbox library and lean API to build great mini games in Ruby"
13
- spec.homepage = "https://github.com/fguillen/fantasy"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 3.0.0"
16
-
17
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
-
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/fguillen/fantasy"
21
- spec.metadata["changelog_uri"] = "https://github.com/fguillen/fantasy/blob/main/CHANGELOG.md"
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
- end
29
- end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
-
34
- # Uncomment to register a new dependency of your gem
35
- spec.add_dependency "gosu", "~> 1.4.1"
36
- spec.add_dependency "vector2d", "~> 2.2.3"
37
-
38
- # For more information and examples about making a new gem, checkout our
39
- # guide at: https://bundler.io/guides/creating_gem.html
40
- end
Binary file