fantasy 0.1.1 → 0.1.3
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/lib/fantasy/actor.rb +2 -3
- data/lib/fantasy/background.rb +34 -0
- data/lib/fantasy/clock.rb +15 -2
- data/lib/fantasy/draggable.rb +0 -9
- data/lib/fantasy/global.rb +16 -7
- data/lib/fantasy/loop.rb +1 -0
- data/lib/fantasy/utils.rb +9 -6
- 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: fe5958bf098b2f7a0190eecbd5a9914c5a232e38863b4e9a19280b44653d771a
|
4
|
+
data.tar.gz: fa8899b7f6f6c04cda1e3ee6d470e940e377395b403d6dd3cddcdbf39583cc30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7830aca33b0a07482782f644301c854f9017ed10bc4602435945a70901e60fdd01adae8ed757f4ecb3a07a51e0b4279a273dbe149c665472e75e7c32e80f28
|
7
|
+
data.tar.gz: 5fee0000ec447edd1849592ab3f5145214d4a84dcf983bf1fff9c05a5ac3655d99bf519d4760ebaba2fadba6194dbf697468cd2483d0b3a77e8ab1611210eb65
|
data/lib/fantasy/actor.rb
CHANGED
@@ -80,13 +80,12 @@ class Actor
|
|
80
80
|
@position = @position + (@direction * @speed * Global.frame_time)
|
81
81
|
|
82
82
|
if solid?
|
83
|
-
|
84
|
-
actual_collisions.each do |actor|
|
83
|
+
collisions.each do |actor|
|
85
84
|
collision_with(actor)
|
86
85
|
actor.collision_with(self)
|
87
86
|
end
|
88
87
|
|
89
|
-
@position = @last_position if
|
88
|
+
@position = @last_position if collisions.any? # we don't cache collisions because position may be changed on collision callback
|
90
89
|
end
|
91
90
|
end
|
92
91
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Background
|
2
|
+
attr_accessor :scale, :color, :visible, :position, :layer
|
3
|
+
|
4
|
+
def initialize(image_name:)
|
5
|
+
@image = Image.new(image_name)
|
6
|
+
@name = image_name
|
7
|
+
@position = Coordinates.zero
|
8
|
+
@scale = 1
|
9
|
+
@visible = true
|
10
|
+
@draggable_on_debug = true
|
11
|
+
@dragging = false
|
12
|
+
@layer = -100
|
13
|
+
|
14
|
+
Global.backgrounds.push(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def width
|
18
|
+
@image.width() * @scale
|
19
|
+
end
|
20
|
+
|
21
|
+
def height
|
22
|
+
@image.height() * @scale
|
23
|
+
end
|
24
|
+
|
25
|
+
def draw
|
26
|
+
if visible
|
27
|
+
@image.draw(x: @position.x, y: @position.y, scale: @scale)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy
|
32
|
+
Global.backgrounds.delete(self)
|
33
|
+
end
|
34
|
+
end
|
data/lib/fantasy/clock.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
class Clock
|
2
|
+
attr_accessor :persistent
|
3
|
+
|
2
4
|
def initialize(&block)
|
3
5
|
@block = block
|
4
6
|
@thread = nil
|
7
|
+
@persistent = false # if persistent, clock is not stopped when loading new scene
|
5
8
|
|
6
9
|
Global.clocks << self
|
7
10
|
end
|
@@ -28,12 +31,22 @@ class Clock
|
|
28
31
|
while(times_executed < times)
|
29
32
|
@block.call
|
30
33
|
times_executed += 1;
|
31
|
-
|
34
|
+
|
35
|
+
seconds_to_sleep = seconds.is_a?(Range) ? rand(seconds) : seconds
|
36
|
+
sleep(seconds_to_sleep)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
41
|
def stop
|
37
|
-
Thread.kill(@thread)
|
42
|
+
Thread.kill(@thread) unless @thread.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def started?
|
46
|
+
!@thread.nil?
|
47
|
+
end
|
48
|
+
|
49
|
+
def persistent?
|
50
|
+
@persistent
|
38
51
|
end
|
39
52
|
end
|
data/lib/fantasy/draggable.rb
CHANGED
@@ -1,26 +1,17 @@
|
|
1
1
|
module Draggable
|
2
2
|
def drag
|
3
|
-
puts "XXX: dragging 1 #{name}"
|
4
3
|
mouse_position = Global.mouse_position
|
5
4
|
|
6
|
-
puts "@draggable_on_debug: #{@draggable_on_debug}"
|
7
|
-
puts "@dragging: #{@dragging}"
|
8
|
-
puts "Gosu.button_down?(Gosu::MS_LEFT): #{Gosu.button_down?(Gosu::MS_LEFT)}"
|
9
|
-
puts "collision: #{Utils.collision_at?(self, mouse_position.x, mouse_position.y)}"
|
10
|
-
|
11
5
|
if @draggable_on_debug && !@dragging && Gosu.button_down?(Gosu::MS_LEFT) && Utils.collision_at?(self, mouse_position.x, mouse_position.y)
|
12
|
-
puts "XXX: dragging start #{name}"
|
13
6
|
@dragging = true
|
14
7
|
@dragging_offset = mouse_position - @position
|
15
8
|
end
|
16
9
|
|
17
10
|
if @dragging && !Gosu.button_down?(Gosu::MS_LEFT)
|
18
|
-
puts "XXX: dragging end #{name}"
|
19
11
|
@dragging = false
|
20
12
|
end
|
21
13
|
|
22
14
|
if @dragging
|
23
|
-
puts "XXX: dragging 3 #{name}"
|
24
15
|
@position = mouse_position - @dragging_offset
|
25
16
|
end
|
26
17
|
end
|
data/lib/fantasy/global.rb
CHANGED
@@ -2,7 +2,7 @@ require "ostruct"
|
|
2
2
|
|
3
3
|
module Global
|
4
4
|
class << self
|
5
|
-
attr_accessor :actors, :hud_texts, :hud_images, :clocks
|
5
|
+
attr_accessor :actors, :hud_texts, :hud_images, :backgrounds, :clocks
|
6
6
|
attr_accessor :debug
|
7
7
|
attr_accessor :setup_proc, :loop_proc, :button_proc
|
8
8
|
attr_accessor :presentation_proc, :game_proc, :end_proc
|
@@ -25,6 +25,7 @@ module Global
|
|
25
25
|
@actors = []
|
26
26
|
@hud_texts = []
|
27
27
|
@hud_images = []
|
28
|
+
@backgrounds = []
|
28
29
|
@clocks = []
|
29
30
|
@last_frame_at = Time.now
|
30
31
|
@debug = false
|
@@ -34,10 +35,17 @@ module Global
|
|
34
35
|
@camera = Camera.new(position: Coordinates.zero)
|
35
36
|
@game_state = Global.presentation_proc.nil? ? "game" : "presentation"
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
if @presentation_proc.nil?
|
39
|
+
on_presentation { Global.default_on_presentation }
|
40
|
+
end
|
41
|
+
|
42
|
+
if @game_proc.nil?
|
43
|
+
on_game { Global.default_on_game }
|
44
|
+
end
|
45
|
+
|
46
|
+
if @end_proc.nil?
|
47
|
+
on_end { Global.default_on_end }
|
48
|
+
end
|
41
49
|
end
|
42
50
|
|
43
51
|
def update
|
@@ -74,7 +82,7 @@ module Global
|
|
74
82
|
puts "Game stage 'presentation'"
|
75
83
|
|
76
84
|
clear_state_elements
|
77
|
-
presentation_proc.call
|
85
|
+
@presentation_proc.call
|
78
86
|
end
|
79
87
|
|
80
88
|
def go_to_game
|
@@ -95,7 +103,8 @@ module Global
|
|
95
103
|
@actors.clear
|
96
104
|
@hud_texts.clear
|
97
105
|
@hud_images.clear
|
98
|
-
@
|
106
|
+
@backgrounds.clear
|
107
|
+
@clocks.reject(&:persistent?).each(&:stop)
|
99
108
|
@background = Color.new(r: 0, g: 0, b: 0)
|
100
109
|
end
|
101
110
|
|
data/lib/fantasy/loop.rb
CHANGED
data/lib/fantasy/utils.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
module Utils
|
2
2
|
# https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection
|
3
3
|
def self.collision?(actor_1, actor_2)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
result =
|
5
|
+
(
|
6
|
+
actor_1.position.x < (actor_2.position.x + actor_2.width) &&
|
7
|
+
(actor_1.position.x + actor_1.width) > actor_2.position.x &&
|
8
|
+
actor_1.position.y < (actor_2.position.y + actor_2.height) &&
|
9
|
+
actor_1.position.y + actor_1.height > actor_2.position.y
|
10
|
+
)
|
11
|
+
|
12
|
+
result
|
10
13
|
end
|
11
14
|
|
12
15
|
def self.collision_at?(actor, x, y)
|
data/lib/fantasy/version.rb
CHANGED
data/lib/fantasy.rb
CHANGED
@@ -12,6 +12,7 @@ require_relative "fantasy/clock"
|
|
12
12
|
require_relative "fantasy/loop"
|
13
13
|
require_relative "fantasy/hud_text"
|
14
14
|
require_relative "fantasy/hud_image"
|
15
|
+
require_relative "fantasy/background"
|
15
16
|
require_relative "fantasy/sound"
|
16
17
|
require_relative "fantasy/camera"
|
17
18
|
require_relative "fantasy/image"
|
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.3
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gosu
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- fonts/VT323-Regular.ttf
|
59
59
|
- lib/fantasy.rb
|
60
60
|
- lib/fantasy/actor.rb
|
61
|
+
- lib/fantasy/background.rb
|
61
62
|
- lib/fantasy/base.rb
|
62
63
|
- lib/fantasy/camera.rb
|
63
64
|
- lib/fantasy/clock.rb
|