fantasy 0.1.5.1 → 0.1.7
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.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/fantasy/actor.rb +1 -1
- data/lib/fantasy/clock.rb +1 -0
- data/lib/fantasy/global.rb +15 -3
- data/lib/fantasy/hud_text.rb +13 -5
- 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 +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b920c99d05b572330432388e4cb4bae6ef5b814d8834bb3b05da16375f49bf6
|
4
|
+
data.tar.gz: 2a5d7c01b7f3e98b5c8928f70981f5bf3591badc844f33a1209f49f6883a426d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b791f6790eaa41e1c0cd49ef9faf514ef1fdacf9310f4dcf6cdfe6aeae2ebde28952d2f748c1e4f155dea6145dbbee7755599bf6a2555479b36a0d0390752bc0
|
7
|
+
data.tar.gz: e6be40d13c6b7a8c19e0e3604a1554eaa2f2efbc08ea7a9769e9b3db94407a1d8e3fd18c7ea0e08089ff6643e69e9c251d3de746720f464d6313b29baa288a50
|
data/README.md
CHANGED
@@ -219,12 +219,13 @@ Easy access to keyboard and mouse inputs on any part of the code. Specially in t
|
|
219
219
|
- Remove "on_space_bar" when changing scene (TODO)
|
220
220
|
- Detect when key/mouse button is pressed in the actual frame in any part of the code (TODO)
|
221
221
|
|
222
|
-
###
|
222
|
+
### Tilemap (TODO)
|
223
223
|
|
224
224
|
For easy creation of:
|
225
225
|
|
226
|
-
- Top-down map levels
|
226
|
+
- Top-down map levels
|
227
227
|
- Platformer map levels (TODO)
|
228
|
+
- Allow specific map keys like a=>actor_1, b=>actor_2 (TODO)
|
228
229
|
|
229
230
|
### Tweens (TODO)
|
230
231
|
|
data/lib/fantasy/actor.rb
CHANGED
@@ -54,7 +54,7 @@ class Actor
|
|
54
54
|
|
55
55
|
def draw_debug
|
56
56
|
Utils.draw_frame(position_in_camera.x, position_in_camera.y, width, height, 1, Gosu::Color::RED) if solid
|
57
|
-
Global.
|
57
|
+
Global.pixel_fonts["medium"].draw_text("#{@position.x.floor},#{@position.y.floor}", position_in_camera.x, position_in_camera.y - 20, 1)
|
58
58
|
end
|
59
59
|
|
60
60
|
def position_in_camera
|
data/lib/fantasy/clock.rb
CHANGED
data/lib/fantasy/global.rb
CHANGED
@@ -15,7 +15,7 @@ module Global
|
|
15
15
|
|
16
16
|
attr_accessor :game
|
17
17
|
attr_reader :frame_time # delta_time
|
18
|
-
attr_reader :
|
18
|
+
attr_reader :pixel_fonts
|
19
19
|
attr_reader :references
|
20
20
|
attr_reader :camera
|
21
21
|
attr_reader :game_state
|
@@ -30,13 +30,21 @@ module Global
|
|
30
30
|
@clocks = []
|
31
31
|
@last_frame_at = Time.now
|
32
32
|
@debug = false
|
33
|
-
|
33
|
+
|
34
|
+
@pixel_fonts = {}
|
35
|
+
@pixel_fonts["small"] = Gosu::Font.new(20, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
|
36
|
+
@pixel_fonts["medium"] = Gosu::Font.new(40, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
|
37
|
+
@pixel_fonts["big"] = Gosu::Font.new(60, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
|
38
|
+
@pixel_fonts["huge"] = Gosu::Font.new(100, { name: "#{__dir__}/../../fonts/VT323-Regular.ttf" } )
|
39
|
+
|
34
40
|
@d_key_pressed = false
|
35
41
|
@references = OpenStruct.new
|
36
42
|
@camera = Camera.new(position: Coordinates.zero)
|
37
43
|
@game_state = Global.presentation_proc.nil? ? "game" : "presentation"
|
38
44
|
@scene_started_at = Time.now
|
39
45
|
|
46
|
+
@background = Color.new(r: 0, g: 0, b: 0)
|
47
|
+
|
40
48
|
if @presentation_proc.nil?
|
41
49
|
on_presentation { Global.default_on_presentation }
|
42
50
|
end
|
@@ -108,7 +116,11 @@ module Global
|
|
108
116
|
@hud_images.clear
|
109
117
|
@backgrounds.clear
|
110
118
|
@tile_maps.clear
|
111
|
-
|
119
|
+
|
120
|
+
@clocks.reject(&:persistent?).each do |clock|
|
121
|
+
clock.stop unless clock.thread == Thread.current # no stop current Thread
|
122
|
+
end
|
123
|
+
|
112
124
|
@background = Color.new(r: 0, g: 0, b: 0)
|
113
125
|
end
|
114
126
|
|
data/lib/fantasy/hud_text.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class HudText
|
2
|
-
attr_accessor :text, :size, :color, :visible, :layer, :in_world
|
2
|
+
attr_accessor :text, :size, :color, :visible, :layer, :in_world, :position
|
3
3
|
|
4
4
|
def initialize(position:, text: "")
|
5
5
|
@position = position
|
@@ -17,14 +17,22 @@ class HudText
|
|
17
17
|
|
18
18
|
def draw
|
19
19
|
if visible
|
20
|
-
|
21
|
-
|
20
|
+
font.draw_markup(text, screen_position.x + shadow_offset, screen_position.y - 20 + shadow_offset, 1, 1, 1, Gosu::Color::BLACK)
|
21
|
+
font.draw_markup(text, screen_position.x, screen_position.y - 20, 1, 1, 1, color)
|
22
22
|
end
|
23
23
|
|
24
24
|
draw_debug if Global.debug
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def font
|
28
|
+
found_font = Global.pixel_fonts[@size]
|
29
|
+
if found_font.nil?
|
30
|
+
raise "HudText.size not valid '#{@size}'. Valid sizes: 'small, medium, big, huge'"
|
31
|
+
end
|
32
|
+
found_font
|
33
|
+
end
|
34
|
+
|
35
|
+
def shadow_offset
|
28
36
|
case @size
|
29
37
|
when "small"
|
30
38
|
1
|
@@ -52,6 +60,6 @@ class HudText
|
|
52
60
|
end
|
53
61
|
|
54
62
|
def draw_debug
|
55
|
-
Global.
|
63
|
+
Global.pixel_fonts["medium"].draw_text("#{@position.x.floor},#{@position.y.floor}", @position.x, @position.y, 1)
|
56
64
|
end
|
57
65
|
end
|
@@ -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
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.7
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -72,7 +72,7 @@ files:
|
|
72
72
|
- lib/fantasy/includes/move_by_cursors.rb
|
73
73
|
- lib/fantasy/loop.rb
|
74
74
|
- lib/fantasy/sound.rb
|
75
|
-
- lib/fantasy/
|
75
|
+
- lib/fantasy/tilemap.rb
|
76
76
|
- lib/fantasy/tween.rb
|
77
77
|
- lib/fantasy/utils.rb
|
78
78
|
- lib/fantasy/version.rb
|