fantasy 0.1.5.1 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -1
- data/COLOR_PALETTE.md +159 -0
- data/README.md +59 -9
- data/lib/fantasy/actor.rb +170 -40
- data/lib/fantasy/clock.rb +1 -0
- data/lib/fantasy/color.rb +182 -1
- data/lib/fantasy/coordinates.rb +4 -0
- data/lib/fantasy/cursor.rb +21 -0
- data/lib/fantasy/global.rb +30 -4
- data/lib/fantasy/hud_image.rb +1 -1
- data/lib/fantasy/hud_text.rb +43 -11
- data/lib/fantasy/image.rb +2 -0
- data/lib/fantasy/includes/gravitier.rb +5 -0
- data/lib/fantasy/includes/jumper.rb +10 -0
- data/lib/fantasy/includes/move_by_cursors.rb +39 -11
- data/lib/fantasy/includes/move_by_direction.rb +5 -0
- data/lib/fantasy/includes/mover.rb +20 -0
- data/lib/fantasy/includes/user_inputs.rb +60 -0
- data/lib/fantasy/loop.rb +58 -8
- data/lib/fantasy/mouse.rb +9 -0
- data/lib/fantasy/music.rb +51 -0
- data/lib/fantasy/shape.rb +55 -0
- data/lib/fantasy/sound.rb +2 -0
- data/lib/fantasy/{tile_map.rb → tilemap.rb} +10 -4
- data/lib/fantasy/utils.rb +5 -0
- data/lib/fantasy/version.rb +1 -1
- data/lib/fantasy.rb +12 -2
- metadata +13 -3
@@ -0,0 +1,51 @@
|
|
1
|
+
module Music
|
2
|
+
class << self
|
3
|
+
@@musics = {}
|
4
|
+
@@actual_song = nil
|
5
|
+
|
6
|
+
def play(music_name)
|
7
|
+
stop
|
8
|
+
|
9
|
+
@@actual_song = locate_music(music_name)
|
10
|
+
@@actual_song.play(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def stop
|
14
|
+
@@actual_song.stop unless @@actual_song.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
def volume
|
18
|
+
@@actual_song&.volume
|
19
|
+
end
|
20
|
+
|
21
|
+
def volume=(value)
|
22
|
+
@@actual_song.volume = value unless @@actual_song.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def locate_music(music_name)
|
26
|
+
return @@musics[music_name] if @@musics[music_name]
|
27
|
+
|
28
|
+
puts "Initialize Music: '#{music_name}'"
|
29
|
+
|
30
|
+
file_name = Dir.entries(base_path).find { |e| e =~ /^#{music_name}($|\.)/ }
|
31
|
+
|
32
|
+
raise "Music file not found with name '#{music_name}'" if file_name.nil?
|
33
|
+
|
34
|
+
@@musics[music_name] = Gosu::Song.new("#{base_path}/#{file_name}")
|
35
|
+
|
36
|
+
return @@musics[music_name]
|
37
|
+
end
|
38
|
+
|
39
|
+
def preload_musics
|
40
|
+
return unless Dir.exist?(base_path)
|
41
|
+
|
42
|
+
Dir.each_child(base_path) do |file_name|
|
43
|
+
locate_music(file_name) unless file_name.start_with?(".")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def base_path
|
48
|
+
"#{Dir.pwd}/musics"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Shape
|
2
|
+
include UserInputs
|
3
|
+
|
4
|
+
attr_accessor :kind, :position, :width, :height, :stroke, :color, :fill, :stroke_color, :layer
|
5
|
+
|
6
|
+
def initialize(kind:, position:, width:, height:, stroke: 1, fill: true, color: Color.palette.black, stroke_color: nil)
|
7
|
+
@kind = kind
|
8
|
+
@position = position
|
9
|
+
@width = width
|
10
|
+
@height = height
|
11
|
+
@stroke = stroke
|
12
|
+
@color = color
|
13
|
+
@fill = fill
|
14
|
+
@stroke_color = stroke_color
|
15
|
+
@layer = 1
|
16
|
+
|
17
|
+
Global.shapes << self
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.rectangle(position:, width:, height:, color: Color.palette.black)
|
21
|
+
Shape.new(kind: "rectangle", position: position, width: width, height: height)
|
22
|
+
end
|
23
|
+
|
24
|
+
def draw
|
25
|
+
case @kind
|
26
|
+
when "rectangle"
|
27
|
+
draw_rectangle
|
28
|
+
else
|
29
|
+
raise "Shape.kind not supported: '#{@kind}'. Supported kinds: 'rectangle'"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy
|
34
|
+
Global.shapes.delete(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def draw_rectangle
|
40
|
+
if fill
|
41
|
+
Gosu.draw_rect(@position.x, @position.y, @width, @height, @color)
|
42
|
+
end
|
43
|
+
|
44
|
+
unless stroke.zero?
|
45
|
+
draw_frame(@position.x, @position.y, @width, @height, @stroke, @stroke_color || @color)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def draw_frame(x, y, width, height, stroke, color)
|
50
|
+
Gosu.draw_rect(x, y, width, stroke, color)
|
51
|
+
Gosu.draw_rect(width - stroke + x, y, stroke, height, color)
|
52
|
+
Gosu.draw_rect(x, height - stroke + y, width, stroke, color)
|
53
|
+
Gosu.draw_rect(x, y, stroke, height, color)
|
54
|
+
end
|
55
|
+
end
|
data/lib/fantasy/sound.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class Tilemap
|
2
2
|
attr_accessor :position
|
3
3
|
|
4
4
|
def initialize(map_name:, tiles:, tile_size: nil, tile_width: nil, tile_height: nil)
|
@@ -13,7 +13,7 @@ class TileMap
|
|
13
13
|
@tiles = tiles
|
14
14
|
@position = Coordinates.zero
|
15
15
|
|
16
|
-
@grid =
|
16
|
+
@grid = Tilemap.load_grid(@map_name)
|
17
17
|
end
|
18
18
|
|
19
19
|
def width
|
@@ -32,7 +32,13 @@ class TileMap
|
|
32
32
|
|
33
33
|
line.each do |tile_index|
|
34
34
|
if !tile_index.nil?
|
35
|
-
|
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
|
36
42
|
actor.position.x = @position.x + (tile_position.x * @tile_width)
|
37
43
|
actor.position.y = @position.y + (tile_position.y * @tile_height)
|
38
44
|
end
|
@@ -50,7 +56,7 @@ class TileMap
|
|
50
56
|
@@maps = {}
|
51
57
|
|
52
58
|
def load_grid(map_name)
|
53
|
-
File.readlines(
|
59
|
+
File.readlines(Tilemap.locate_map(map_name), chomp: true).map do |line|
|
54
60
|
line.each_char.map do |char|
|
55
61
|
char == " " ? nil : char.to_i
|
56
62
|
end
|
data/lib/fantasy/utils.rb
CHANGED
@@ -27,4 +27,9 @@ module Utils
|
|
27
27
|
Gosu.draw_rect(x, y + (height - stroke), width, stroke, color)
|
28
28
|
Gosu.draw_rect(x, y, stroke, height, color)
|
29
29
|
end
|
30
|
+
|
31
|
+
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
|
34
|
+
end
|
30
35
|
end
|
data/lib/fantasy/version.rb
CHANGED
data/lib/fantasy.rb
CHANGED
@@ -2,12 +2,21 @@
|
|
2
2
|
require "gosu"
|
3
3
|
|
4
4
|
require_relative "fantasy/version"
|
5
|
+
|
6
|
+
require_relative "fantasy/coordinates"
|
7
|
+
require_relative "fantasy/cursor"
|
8
|
+
require_relative "fantasy/mouse"
|
5
9
|
require_relative "fantasy/includes/move_by_cursors"
|
10
|
+
require_relative "fantasy/includes/move_by_direction"
|
11
|
+
require_relative "fantasy/includes/mover"
|
12
|
+
require_relative "fantasy/includes/gravitier"
|
13
|
+
require_relative "fantasy/includes/jumper"
|
14
|
+
require_relative "fantasy/includes/user_inputs"
|
6
15
|
require_relative "fantasy/tween"
|
7
16
|
require_relative "fantasy/draggable"
|
8
17
|
require_relative "fantasy/color"
|
18
|
+
require_relative "fantasy/shape"
|
9
19
|
require_relative "fantasy/actor"
|
10
|
-
require_relative "fantasy/coordinates"
|
11
20
|
require_relative "fantasy/utils"
|
12
21
|
require_relative "fantasy/global"
|
13
22
|
require_relative "fantasy/clock"
|
@@ -16,7 +25,8 @@ require_relative "fantasy/hud_text"
|
|
16
25
|
require_relative "fantasy/hud_image"
|
17
26
|
require_relative "fantasy/background"
|
18
27
|
require_relative "fantasy/sound"
|
28
|
+
require_relative "fantasy/music"
|
19
29
|
require_relative "fantasy/camera"
|
20
30
|
require_relative "fantasy/image"
|
21
|
-
require_relative "fantasy/
|
31
|
+
require_relative "fantasy/tilemap"
|
22
32
|
require_relative "fantasy/base"
|
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.
|
4
|
+
version: 0.1.11
|
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-03-
|
11
|
+
date: 2022-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".rubocop.yml"
|
49
49
|
- CHANGELOG.md
|
50
|
+
- COLOR_PALETTE.md
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|
@@ -64,15 +65,24 @@ files:
|
|
64
65
|
- lib/fantasy/clock.rb
|
65
66
|
- lib/fantasy/color.rb
|
66
67
|
- lib/fantasy/coordinates.rb
|
68
|
+
- lib/fantasy/cursor.rb
|
67
69
|
- lib/fantasy/draggable.rb
|
68
70
|
- lib/fantasy/global.rb
|
69
71
|
- lib/fantasy/hud_image.rb
|
70
72
|
- lib/fantasy/hud_text.rb
|
71
73
|
- lib/fantasy/image.rb
|
74
|
+
- lib/fantasy/includes/gravitier.rb
|
75
|
+
- lib/fantasy/includes/jumper.rb
|
72
76
|
- lib/fantasy/includes/move_by_cursors.rb
|
77
|
+
- lib/fantasy/includes/move_by_direction.rb
|
78
|
+
- lib/fantasy/includes/mover.rb
|
79
|
+
- lib/fantasy/includes/user_inputs.rb
|
73
80
|
- lib/fantasy/loop.rb
|
81
|
+
- lib/fantasy/mouse.rb
|
82
|
+
- lib/fantasy/music.rb
|
83
|
+
- lib/fantasy/shape.rb
|
74
84
|
- lib/fantasy/sound.rb
|
75
|
-
- lib/fantasy/
|
85
|
+
- lib/fantasy/tilemap.rb
|
76
86
|
- lib/fantasy/tween.rb
|
77
87
|
- lib/fantasy/utils.rb
|
78
88
|
- lib/fantasy/version.rb
|