fantasy 0.1.11 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -7
- data/lib/fantasy/actor.rb +11 -0
- data/lib/fantasy/background.rb +1 -1
- data/lib/fantasy/cursor.rb +21 -0
- data/lib/fantasy/disk.rb +31 -0
- data/lib/fantasy/hud_text.rb +3 -1
- data/lib/fantasy/includes/mover.rb +4 -0
- data/lib/fantasy/music.rb +3 -1
- data/lib/fantasy/sound.rb +2 -2
- data/lib/fantasy/version.rb +1 -1
- data/lib/fantasy.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0de009c2a3c9785532dd054f8f33cfb67933bb7f136a291638d8d15339919ff4
|
4
|
+
data.tar.gz: 194a34e34ccaf055175067efc1cbc122f334abfe290f8e78e24c75c4d742ef8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9dd083f303373be39e448140f37ef3efa93f307013a111a7e3fde435a1af2f8705e8064a88fd445e1a57613d7983b15ffbcce21aff50f8d04664b33db76b332
|
7
|
+
data.tar.gz: 2bd16fd118df26b580f543686c5828be62e7c725490cf20e8fab3f4102701713bda9d59e5b011c5e62e2052fdca80df59f529561e71704e7acb54425aa7790d0
|
data/README.md
CHANGED
@@ -96,7 +96,7 @@ Or install it yourself as:
|
|
96
96
|
|
97
97
|
## Features
|
98
98
|
|
99
|
-
### Game
|
99
|
+
### Game Scenes
|
100
100
|
|
101
101
|
Easy to configure 3 basic game states:
|
102
102
|
|
@@ -209,7 +209,7 @@ Simple way to set up:
|
|
209
209
|
- Image background
|
210
210
|
- Repeatable image background
|
211
211
|
|
212
|
-
### Data Persistance
|
212
|
+
### Data Persistance
|
213
213
|
|
214
214
|
Simple mechanism to save data in disk. For user preferences, game progress, high scores and others
|
215
215
|
|
@@ -236,7 +236,7 @@ Multiple movement animation effects like in [DoTween](http://dotween.demigiant.c
|
|
236
236
|
|
237
237
|
## API
|
238
238
|
|
239
|
-
### Game
|
239
|
+
### Game Scenes
|
240
240
|
|
241
241
|
Configure your game elements on each Scene:
|
242
242
|
|
@@ -409,6 +409,21 @@ on_game do
|
|
409
409
|
end
|
410
410
|
```
|
411
411
|
|
412
|
+
### Data Persistance
|
413
|
+
|
414
|
+
```ruby
|
415
|
+
Disk.data.records = [120_000, 11_000, 678]
|
416
|
+
Disk.data.last_level = 3
|
417
|
+
Disk.data.sound_volume = 12
|
418
|
+
Disk.save # data stored in ./disk/data.json
|
419
|
+
|
420
|
+
# ... in another session
|
421
|
+
|
422
|
+
Disk.data.records # => [120_000, 11_000, 678]
|
423
|
+
Disk.data.last_level # => 3
|
424
|
+
Disk.data.sound_volume # => 12
|
425
|
+
```
|
426
|
+
|
412
427
|
### Camera
|
413
428
|
|
414
429
|
```ruby
|
@@ -440,10 +455,10 @@ Music.stop
|
|
440
455
|
|
441
456
|
```ruby
|
442
457
|
# ./maps/sky.txt
|
443
|
-
#0
|
444
|
-
#
|
445
|
-
#
|
446
|
-
#0
|
458
|
+
# 0 0
|
459
|
+
# 0 1
|
460
|
+
# 0 0
|
461
|
+
# 0 01
|
447
462
|
|
448
463
|
planet = Actor.new("planet")
|
449
464
|
star = Actor.new("star")
|
data/lib/fantasy/actor.rb
CHANGED
@@ -160,6 +160,8 @@ class Actor
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def manage_collisions(last_position)
|
163
|
+
@velocity ||= Coordinates.zero # In case it is not initialized yet
|
164
|
+
|
163
165
|
collisions.each do |other|
|
164
166
|
on_collision_do(other)
|
165
167
|
other.on_collision_do(self)
|
@@ -177,6 +179,15 @@ class Actor
|
|
177
179
|
end
|
178
180
|
end
|
179
181
|
|
182
|
+
# # Reset position pixel by pixel
|
183
|
+
# was_collision = false
|
184
|
+
# while collisions.any? && @position != last_position
|
185
|
+
# was_collision = true
|
186
|
+
# last_position_direction = last_position - @position
|
187
|
+
# @position += last_position_direction.normalize
|
188
|
+
# end
|
189
|
+
# was_collision
|
190
|
+
|
180
191
|
if collisions.any? # we don't cache collisions because position may be changed on collision callback
|
181
192
|
@position = last_position
|
182
193
|
|
data/lib/fantasy/background.rb
CHANGED
data/lib/fantasy/cursor.rb
CHANGED
@@ -18,4 +18,25 @@ module Cursor
|
|
18
18
|
def self.space_bar
|
19
19
|
Gosu::KB_SPACE
|
20
20
|
end
|
21
|
+
|
22
|
+
|
23
|
+
def self.left?
|
24
|
+
Gosu.button_down?(Cursor.left)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.right?
|
28
|
+
Gosu.button_down?(Cursor.right)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.up?
|
32
|
+
Gosu.button_down?(Cursor.up)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.down?
|
36
|
+
Gosu.button_down?(Cursor.down)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.space_bar?
|
40
|
+
Gosu.button_down?(Cursor.space_bar)
|
41
|
+
end
|
21
42
|
end
|
data/lib/fantasy/disk.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "json"
|
2
|
+
require "ostruct"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
module Disk
|
6
|
+
@@data_path = "#{Dir.pwd}/disk/data.json"
|
7
|
+
@@data = nil
|
8
|
+
|
9
|
+
def self.data
|
10
|
+
@@data ||= OpenStruct.new(load)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.save
|
14
|
+
dirname = File.dirname(@@data_path)
|
15
|
+
unless File.directory?(dirname)
|
16
|
+
FileUtils.mkdir_p(dirname)
|
17
|
+
end
|
18
|
+
|
19
|
+
File.open(@@data_path, "w") { |f| f.write JSON.pretty_generate(@@data.to_h) }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.load
|
25
|
+
if File.file?(@@data_path)
|
26
|
+
JSON.parse(File.read(@@data_path))
|
27
|
+
else
|
28
|
+
{}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/fantasy/hud_text.rb
CHANGED
@@ -53,10 +53,12 @@ class HudText
|
|
53
53
|
Coordinates.new(0, 0)
|
54
54
|
when "top-right"
|
55
55
|
Coordinates.new(1, 0)
|
56
|
+
when "top-center"
|
57
|
+
Coordinates.new(0.5, 0)
|
56
58
|
when "center"
|
57
59
|
Coordinates.new(0.5, 0.5)
|
58
60
|
else
|
59
|
-
raise "HudText.alignment value not valid '#{@alignment}'. Valid values: 'top-left, top-right, center'"
|
61
|
+
raise "HudText.alignment value not valid '#{@alignment}'. Valid values: 'top-left, top-right, top-center, center'"
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
data/lib/fantasy/music.rb
CHANGED
@@ -3,11 +3,13 @@ module Music
|
|
3
3
|
@@musics = {}
|
4
4
|
@@actual_song = nil
|
5
5
|
|
6
|
-
def play(music_name)
|
6
|
+
def play(music_name, volume: nil)
|
7
7
|
stop
|
8
8
|
|
9
9
|
@@actual_song = locate_music(music_name)
|
10
10
|
@@actual_song.play(true)
|
11
|
+
|
12
|
+
self.volume = volume unless volume.nil?
|
11
13
|
end
|
12
14
|
|
13
15
|
def stop
|
data/lib/fantasy/sound.rb
CHANGED
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.13
|
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-
|
11
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/fantasy/color.rb
|
67
67
|
- lib/fantasy/coordinates.rb
|
68
68
|
- lib/fantasy/cursor.rb
|
69
|
+
- lib/fantasy/disk.rb
|
69
70
|
- lib/fantasy/draggable.rb
|
70
71
|
- lib/fantasy/global.rb
|
71
72
|
- lib/fantasy/hud_image.rb
|