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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb68d8561352d746b2ccdbec94196c568436a0164619f325f0762c200d9d4a71
4
- data.tar.gz: a11a5b19442edc60fc11d3c803ec40df543c9f1a176f7f7d6a3b11ad4dcf2eed
3
+ metadata.gz: 0de009c2a3c9785532dd054f8f33cfb67933bb7f136a291638d8d15339919ff4
4
+ data.tar.gz: 194a34e34ccaf055175067efc1cbc122f334abfe290f8e78e24c75c4d742ef8c
5
5
  SHA512:
6
- metadata.gz: e705ad65f134cf775e3bf2ef847643bbd8a2efcc49630837f555f57df019573c9356190db394cddb647ed95420441ea0ce8d42099ba43f006c89e05b63452fa9
7
- data.tar.gz: c6e6506581053c11940b0fd3bed2205ae4b003a2efd35016a84e04640cc75ad9300a8276ff8562ec8f33eba229b3017c7ba4f38306d165271d637e7c0e51b66a
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 Scene transitions
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 (TODO)
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 Scene transitions
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 0 0
444
- # 1 0
445
- #
446
- #0 0 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
 
@@ -1,5 +1,5 @@
1
1
  class Background
2
- attr_accessor :scale, :color, :visible, :position, :layer
2
+ attr_accessor :scale, :color, :visible, :position, :layer, :replicable
3
3
 
4
4
  def initialize(image_name:)
5
5
  @image = Image.new(image_name)
@@ -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
@@ -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
@@ -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
 
@@ -1,4 +1,8 @@
1
1
  module Mover
2
+ def impulse(direction:, force:)
3
+ add_force(direction.normalize * force)
4
+ end
5
+
2
6
  def add_force(force)
3
7
  @acceleration ||= Coordinates.zero
4
8
  @acceleration += force
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
@@ -2,8 +2,8 @@ module Sound
2
2
  class << self
3
3
  @@sounds = {}
4
4
 
5
- def play(sound_name)
6
- locate_sound(sound_name).play
5
+ def play(sound_name, volume: 1)
6
+ locate_sound(sound_name).play(volume)
7
7
  end
8
8
 
9
9
  def locate_sound(sound_name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fantasy
4
- VERSION = "0.1.11"
4
+ VERSION = "0.1.13"
5
5
  end
data/lib/fantasy.rb CHANGED
@@ -30,3 +30,4 @@ require_relative "fantasy/camera"
30
30
  require_relative "fantasy/image"
31
31
  require_relative "fantasy/tilemap"
32
32
  require_relative "fantasy/base"
33
+ require_relative "fantasy/disk"
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.11
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-03-26 00:00:00.000000000 Z
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