ruby2d-camera 1.1.0 → 1.1.1

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: 06037a9f51eba2e45da347b87365f4a58a62aa5c08408aab3a782cdcf377bb77
4
- data.tar.gz: 692821b9a6bbc5a1635d480abd8260359bd8cc5df8bb6dd534235b62c3892ab4
3
+ metadata.gz: 828ab4d3439c8309d22514a0eb9b239616fd6476b28d0a93df8d937f3260e015
4
+ data.tar.gz: e2e06eb639a63168b9822626ab00a8f0f3e2f78b1e5810ae3a9848d72852bacc
5
5
  SHA512:
6
- metadata.gz: a36731f90ce30ac654a70e047d978c9db839e642d4d0b13a17d6c33b2d92c296dd4e4627f64777c2beaf48ade923d742e931e8b90c353abdc8d0480e8fa18cf2
7
- data.tar.gz: 867f0ddcc5147a7e58abf89f600c3dd7e5a38d2b0829d63ac6527b24f0a4cfc3c047082a200887db3164cc4d562d1bb9201b90c5c7a733ec1f214dbc61618221
6
+ metadata.gz: c763e012f4c7e0ecde81fa6634f5b264818c9006656fdd69caece56afd0e7f9729113183b5ee7cec8ec4ba4399a645aa0f579d6da883e23d1b25e2e8be56cbbd
7
+ data.tar.gz: 6c1b41ef44fd6df7ec4c7c758a64a34b167a69773a01dc0862be439944a2dea6833003d9376a9912aad7d0d5d4cf458acf841943d0f759b5b81123e5e35fe8d0
data/CHANGELOG.mdown CHANGED
@@ -6,6 +6,10 @@
6
6
  ![Deprecated](https://img.shields.io/badge/-Deprecated-orange)
7
7
  ![Removed](https://img.shields.io/badge/-Removed-red)
8
8
 
9
+ ## [1.1.1](https://github.com/realtradam/ruby2d-camera/releases/tag/1.1.1) - 2021-09-24
10
+ ![Fixed](https://img.shields.io/badge/-Fixed-blue)
11
+ - Fixed changing z-index after the shape has been added not applying at all
12
+
9
13
  ## [1.1.0](https://github.com/realtradam/ruby2d-camera/releases/tag/1.1.0) - 2021-08-09
10
14
  ![Added](https://img.shields.io/badge/-Added-brightgreen)
11
15
  - Added Camera functions `Camera.coordinate_to_screenspace` and `Camera.coordinate_to_worldspace`
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby2d-camera (1.1.1.beta)
5
+ ruby2d (~> 0.10)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ parallel (1.21.0)
12
+ parser (3.0.2.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (13.0.6)
16
+ regexp_parser (2.1.1)
17
+ rexml (3.2.5)
18
+ rubocop (1.21.0)
19
+ parallel (~> 1.10)
20
+ parser (>= 3.0.0.0)
21
+ rainbow (>= 2.2.2, < 4.0)
22
+ regexp_parser (>= 1.8, < 3.0)
23
+ rexml
24
+ rubocop-ast (>= 1.9.1, < 2.0)
25
+ ruby-progressbar (~> 1.7)
26
+ unicode-display_width (>= 1.4.0, < 3.0)
27
+ rubocop-ast (1.11.0)
28
+ parser (>= 3.0.1.1)
29
+ ruby-progressbar (1.11.0)
30
+ ruby2d (0.11.0)
31
+ unicode-display_width (2.1.0)
32
+
33
+ PLATFORMS
34
+ x86_64-linux
35
+
36
+ DEPENDENCIES
37
+ rake (~> 13.0)
38
+ rubocop (~> 1.7)
39
+ ruby2d-camera!
40
+
41
+ BUNDLED WITH
42
+ 2.2.27
data/README.mdown CHANGED
@@ -21,8 +21,8 @@ Create your object as if you would create it in Ruby2D except you need to prefix
21
21
 
22
22
  ### There are also 2 helpful functions:
23
23
 
24
- - `Camera.coordinate_to_worldspace(x,y)` You pass coordinates on the screen(for example where a player clicked in the window) and it will return the coordinates(in a 2d array) what the coordinates are in the world
25
- - `Camera.coordinate_to_screenspace(x,y)` You pass in a coordinate in the world(for example an enemy in your game) and it will give you the coordinates(in a 2d array) of where on the screen this character appears. Note this function may return values that are outside of the screen if the object is not in view of the camera
24
+ - `Camera.coordinate_to_worldspace(x,y)` You pass in the coordinates on the screen(for example where a player clicked in the window) and it will return the coordinates(in an [x,y] array) what the coordinates are in the world
25
+ - `Camera.coordinate_to_screenspace(x,y)` You pass in the coordinate in the world(for example an enemy in your game) and it will give you the coordinates(in an [x,y] array) of where on the screen this character appears. Note this function may return values that are outside of the screen if the object is not in view of the camera
26
26
 
27
27
  ## How it works:
28
28
 
@@ -28,6 +28,11 @@ module Ruby2D
28
28
  Window.remove(self)
29
29
  end
30
30
 
31
+ def z=(z)
32
+ super(z)
33
+ Ruby2D::Camera._sort_by_z
34
+ end
35
+
31
36
  def remove
32
37
  @hide = true
33
38
  end
@@ -34,6 +34,11 @@ module Camera
34
34
  Window.remove(self)
35
35
  end
36
36
 
37
+ def z=(z)
38
+ super(z)
39
+ Ruby2D::Camera._sort_by_z
40
+ end
41
+
37
42
  def remove
38
43
  @hide = true
39
44
  end
@@ -45,15 +45,20 @@ module Ruby2D
45
45
  end
46
46
 
47
47
  # Methods for moving the shape
48
+ attr_writer :x, :y
49
+
48
50
  def x
49
51
  @x ||= 0
50
52
  end
51
53
 
52
- attr_writer :x, :y
53
-
54
54
  def y
55
55
  @y ||= 0
56
56
  end
57
+
58
+ def z=(z)
59
+ super(z)
60
+ Ruby2D::Camera._sort_by_z
61
+ end
57
62
  end
58
63
  end
59
64
  end
@@ -49,15 +49,20 @@ module Ruby2D
49
49
  end
50
50
 
51
51
  # Methods for moving the shape
52
+ attr_writer :x, :y
53
+
52
54
  def x
53
55
  @x ||= 0
54
56
  end
55
57
 
56
- attr_writer :x, :y
57
-
58
58
  def y
59
59
  @y ||= 0
60
60
  end
61
+
62
+ def z=(z)
63
+ super(z)
64
+ Ruby2D::Camera._sort_by_z
65
+ end
61
66
  end
62
67
  end
63
68
  end
@@ -57,15 +57,20 @@ module Ruby2D
57
57
  end
58
58
 
59
59
  # Methods for moving the shape
60
+ attr_writer :x, :y
61
+
60
62
  def x
61
63
  @x ||= 0
62
64
  end
63
65
 
64
- attr_writer :x, :y
65
-
66
66
  def y
67
67
  @y ||= 0
68
68
  end
69
+
70
+ def z=(z)
71
+ super(z)
72
+ Ruby2D::Camera._sort_by_z
73
+ end
69
74
  end
70
75
  end
71
76
  end
@@ -49,6 +49,11 @@ module Ruby2D
49
49
  Window.remove(self)
50
50
  end
51
51
 
52
+ def z=(z)
53
+ super(z)
54
+ Ruby2D::Camera._sort_by_z
55
+ end
56
+
52
57
  def remove
53
58
  @hide = true
54
59
  end
@@ -57,15 +57,20 @@ module Ruby2D
57
57
  end
58
58
 
59
59
  # Methods for moving the shape
60
+ attr_writer :x, :y
61
+
60
62
  def x
61
63
  @x ||= 0
62
64
  end
63
65
 
64
- attr_writer :x, :y
65
-
66
66
  def y
67
67
  @y ||= 0
68
68
  end
69
+
70
+ def z=(z)
71
+ super(z)
72
+ Ruby2D::Camera._sort_by_z
73
+ end
69
74
  end
70
75
  end
71
76
  end
@@ -46,6 +46,11 @@ module Ruby2D
46
46
  Window.remove(self)
47
47
  end
48
48
 
49
+ def z=(z)
50
+ super(z)
51
+ Ruby2D::Camera._sort_by_z
52
+ end
53
+
49
54
  def remove
50
55
  @hide = true
51
56
  end
@@ -44,15 +44,20 @@ module Ruby2D
44
44
  end
45
45
 
46
46
  # Methods for moving the shape
47
+ attr_writer :x, :y
48
+
47
49
  def x
48
50
  @x ||= 0
49
51
  end
50
52
 
51
- attr_writer :x, :y
52
-
53
53
  def y
54
54
  @y ||= 0
55
55
  end
56
+
57
+ def z=(z)
58
+ super(z)
59
+ Ruby2D::Camera._sort_by_z
60
+ end
56
61
  end
57
62
  end
58
63
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ruby2d
4
4
  module Camera
5
- VERSION = '1.1.0'
5
+ VERSION = '1.1.1'
6
6
  end
7
7
  end
data/lib/ruby2d/camera.rb CHANGED
@@ -16,6 +16,16 @@ module Ruby2D
16
16
  def objects
17
17
  @objects ||= []
18
18
  end
19
+
20
+ end
21
+
22
+ def self._sort_by_z
23
+ @sort_by_z = true
24
+ end
25
+
26
+ def self._resolve_z_sorting
27
+ objects.sort_by!(&:z) if @sort_by_z
28
+ @sort_by_z = false
19
29
  end
20
30
 
21
31
  def self.debug_x
@@ -37,9 +47,9 @@ module Ruby2D
37
47
  # Adding objects so they are
38
48
  # tracked by the Camera
39
49
  def self.<<(item)
40
- objects.push(item) unless objects.include?(item)
41
- objects.sort_by! do |n|
42
- n.z
50
+ unless objects.include?(item)
51
+ objects.push(item)
52
+ self._sort_by_z
43
53
  end
44
54
  end
45
55
 
@@ -50,6 +60,7 @@ module Ruby2D
50
60
  # Redraw all objects that
51
61
  # are tracked by the Camera
52
62
  def self._redraw(auto_purge: false)
63
+ self._resolve_z_sorting
53
64
  objects.each(&:_draw)
54
65
  end
55
66
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2d-camera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tradam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-09 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2d
@@ -36,6 +36,7 @@ files:
36
36
  - ".solargraph.yml"
37
37
  - CHANGELOG.mdown
38
38
  - Gemfile
39
+ - Gemfile.lock
39
40
  - LICENSE.txt
40
41
  - README.mdown
41
42
  - Rakefile
@@ -53,7 +54,6 @@ files:
53
54
  - lib/ruby2d/camera/triangle.rb
54
55
  - lib/ruby2d/camera/version.rb
55
56
  - ruby2d-camera.gemspec
56
- - run.rb
57
57
  homepage: https://github.com/realtradam/ruby2d-camera
58
58
  licenses:
59
59
  - MIT
data/run.rb DELETED
@@ -1,248 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ruby2d'
4
- require 'ruby2d/camera'
5
- require_relative 'house'
6
- require_relative 'room'
7
-
8
- Window.set(icon: './assets/blobcoolthink.png',
9
- width: 1280,
10
- height: 720,
11
- background: 'blue')
12
-
13
-
14
- @player = Camera::Sprite.new('./assets/sprites/mainblob-128.png',
15
- x: 1920 / 1.1,
16
- y: 1080 / 1.1,
17
- width: 50,
18
- height: 50,
19
- clip_width: 128,
20
- loop: true,
21
- time: 1,
22
- z: 99,
23
- animations: {
24
- walk: 0...60,
25
- stand: 60...61
26
- })
27
- @shadow = Camera::Image.new(
28
- 'assets/blobshadow.png',
29
- width: 52,
30
- height: 10,
31
- z: 4
32
- )
33
- #Camera << @shadow
34
- @player.play animation: :walk, loop: true
35
- #Camera << @player
36
-
37
- # UI
38
- Rectangle.new(
39
- width: 350,
40
- height: 135,
41
- color: 'navy',
42
- z: 100
43
- )
44
- @ui_pos_cam = Text.new(
45
- 'pos: 0,0',
46
- x: 10,
47
- y: 10,
48
- color: 'teal',
49
- z: 101
50
- )
51
- @ui_pos_ply = Text.new(
52
- 'pos: 0,0',
53
- x: 10,
54
- y: 40,
55
- color: 'teal',
56
- z: 101
57
- )
58
- @ui_zoom = Text.new(
59
- 'zoom: 0',
60
- x: 10,
61
- y: 70,
62
- color: 'lime',
63
- z: 101
64
- )
65
- @ui_rotation = Text.new(
66
- 'rotation: 0',
67
- x: 10,
68
- y: 100,
69
- color: 'lime',
70
- z: 101
71
- )
72
- Rectangle.new(
73
- x: (Window.width - 120),
74
- width: 120,
75
- height: 45,
76
- color: 'navy',
77
- z: 100
78
- )
79
- @ui_fps = Text.new(
80
- 'fps: 60.00',
81
- x: (Window.width - 110),
82
- y: 10,
83
- color: 'teal',
84
- z: 101
85
- )
86
-
87
-
88
-
89
- # How fast the player can move
90
- @speed = 5
91
-
92
- # Initializing
93
- @player_movement_x = 0
94
- @player_movement_y = 0
95
- @pressed_space = false
96
- @scene_transition_into = false
97
- @scene_transition_out = false
98
- @indoors = false
99
- @house = nil
100
- @room = nil
101
-
102
- on :key do |event|
103
- if event.key == 'w'
104
- @player_movement_y -= @speed unless @scene_transition_into || @scene_transition_out
105
- end
106
- if event.key == 's'
107
- @player_movement_y += @speed unless @scene_transition_into || @scene_transition_out
108
- end
109
- if event.key == 'd'
110
- @player_movement_x += @speed unless @scene_transition_into || @scene_transition_out
111
- end
112
- if event.key == 'a'
113
- @player_movement_x -= @speed unless @scene_transition_into || @scene_transition_out
114
- end
115
- if event.key == 'space'
116
- @pressed_space = true unless @scene_transition_into || @scene_transition_out
117
- end
118
- if event.key == 'q'
119
- Camera.angle += 1 unless @scene_transition_into || @scene_transition_out
120
- end
121
- if event.key == 'e'
122
- Camera.angle -= 1 unless @scene_transition_into || @scene_transition_out
123
- end
124
- if event.key == 'r'
125
- unless @scene_transition_into || @scene_transition_out || Camera.angle.zero?
126
- if Camera.angle <= 180
127
- if Camera.angle > 10
128
- Camera.angle -= 10
129
- else
130
- Camera.angle -=1
131
- end
132
- elsif
133
- if Camera.angle < 350
134
- Camera.angle += 10
135
- else
136
- Camera.angle += 1
137
- end
138
- end
139
- end
140
- end
141
- end
142
-
143
- update do
144
- if (@player.x > 2371 && @player_movement_x.positive?) || (@player.x.negative? && @player_movement_x.negative?)
145
- @player_movement_x = 0
146
- end
147
- if (@player.y > 1608 && @player_movement_y.positive?) || (@player.y.negative? && @player_movement_y.negative?)
148
- @player_movement_y = 0
149
- end
150
- if !@player_movement_y.zero? == !@player_movement_x.zero?
151
- @player_movement_x /= 1.4141
152
- @player_movement_y /= 1.4141
153
- end
154
- @player.x += @player_movement_x
155
- @player.y += @player_movement_y
156
- if @player_movement_x.negative?
157
- @player.play animation: :walk, loop: true
158
- elsif @player_movement_x.positive? || !@player_movement_y.zero?
159
- @player.play animation: :walk, loop: true, flip: :vertical
160
- else
161
- @player.play animation: :stand
162
- end
163
-
164
- if !@scene_transition_into && !@scene_transition_out
165
- Camera.zoom += ((-[Math.sqrt(((@player.x + (@player.width / 2) - Camera.x)**2) + ((@player.y + (@player.width / 2) - Camera.y)**2)), 350].min * 0.004) + 2 - Camera.zoom) * 0.25
166
- Camera.x += (@player.x + (@player.width / 2) - Camera.x) * 0.025
167
- Camera.y += (@player.y + (@player.height / 2) - Camera.y) * 0.025
168
- elsif @scene_transition_into
169
- if Camera.zoom < 250
170
- Camera.zoom *= 1.05
171
- Camera.angle += 5
172
- else
173
- @scene_transition_into = false
174
- @scene_transition_out = true
175
- if @room.nil?
176
- @house.remove
177
- @house = nil
178
- @indoors = true
179
- else
180
- @room.remove
181
- @room = nil
182
- @indoors = false
183
- end
184
- #Camera.remove @background
185
- @background.remove
186
- @background = nil
187
- end
188
- Camera.x += (@player.x + (@player.width / 2) - Camera.x) * 0.25
189
- Camera.y += (@player.y + (@player.height / 2) - Camera.y) * 0.25
190
- elsif @scene_transition_out
191
- if !((Camera.zoom <= (@zoom_transition * 1.001)) && (Camera.angle == @angle_transition))
192
- Camera.zoom /= 1.05
193
- Camera.angle -= 5
194
- else
195
- @scene_transition_out = false
196
- end
197
- end
198
-
199
- if @house.nil? && !@indoors
200
- @house = House.new(750, 300)
201
- @background = Camera::Image.new(
202
- 'assets/background.png',
203
- x: 100, y: 100,
204
- z: -1
205
- )
206
- #Camera << @background
207
- elsif @room.nil? && @indoors
208
- @room = Room.new(750,300)
209
- @background = Camera::Rectangle.new(
210
- color: 'black',
211
- x: 0,
212
- y: 0,
213
- width: 1920,
214
- height: 1080,
215
- z: -1
216
- )
217
- end
218
- @shadow.x = @player.x - 2
219
- @shadow.y = @player.y + 42
220
-
221
- #Camera.remove @house_text
222
- @house_text&.remove
223
- if @indoors
224
- @house_text = @room.visted_by?(@player)
225
- else
226
- @house_text = @house.visted_by?(@player)
227
- end
228
- unless @house_text.nil?
229
- #Camera << @house_text
230
- @house_text.center = true
231
- end
232
- if !@house_text.nil? && @pressed_space && !@scene_transition_into && !@scene_transition_out
233
- @scene_transition_into = true
234
- @angle_transition = Camera.angle
235
- @zoom_transition = Camera.zoom
236
- end
237
- @ui_pos_cam.text = "Camera Position: #{Camera.x.round(1)}, #{Camera.y.round(1)}"
238
- @ui_pos_ply.text = "Player Position: #{@player.x.round(1)}, #{@player.y.round(1)}"
239
- @ui_zoom.text = "Zoom: #{Camera.zoom.round(3)}"
240
- @ui_fps.text = "FPS: #{Window.fps.round(2)}"
241
- @ui_rotation.text = "Angle: #{Camera.angle}"
242
- @player_movement_x = 0
243
- @player_movement_y = 0
244
- @pressed_space = false
245
-
246
- #Camera.redraw
247
- end
248
- show