rubysketch 0.5.31 → 0.5.33

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: ee4bec833e545d64ac7822c59d7b52e92a507ac23d909fd6143f15dace1ed8c4
4
- data.tar.gz: 8151adda147364200efe13a96b2fce82b00c01fa25cb84c69f4de6ba5d9a6a4d
3
+ metadata.gz: 9f7acf19e92e5b9a4276ffdb96bd4b9848f750c86f10de18f72f5213c7675598
4
+ data.tar.gz: 3a7f5909fcd8bece149fb5c61758e7cc6f00579d9d57fa3a00fb62bcb24a6a16
5
5
  SHA512:
6
- metadata.gz: d85c90842181d311cee151604fc1c38edc6d5b2d1caba4d3c9f206f512d98b5f93ced450f8ec6aaa760781bdfc61c8d92644cdc2f2b4811c63b7f81f70091ca2
7
- data.tar.gz: 94978e5eadf6fbd607c4762adec4049df1930123be74c5cee46dfb582c0ec76f907f8a3e214cc162d779a9b96bc12a4904cd054f60ecae921db3abdb57a5ff0c
6
+ metadata.gz: 2eba53cce7c607fffed0ef69152a7361623e15cca7948a543eb9cede4d9031c6241b1edf1c9d5c52eca1bae050d0e7b11ae69818d6abd95b965d97df89cb75f2
7
+ data.tar.gz: 5d5f3cec99a11d0a04cdb6242f6b6168b11acde4cc91ff9ca37b53d023fc2bed3dccfd8be983e89a5a02fc4e6724e980ccc988ada3e5937bd2fa3954266dd6a2
data/ChangeLog.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # rubysketch ChangeLog
2
2
 
3
3
 
4
+ ## [v0.5.33] - 2023-10-29
5
+
6
+ - Update dependencies
7
+
8
+
9
+ ## [v0.5.32] - 2023-10-29
10
+
11
+ - Add Shape class
12
+ - Add Circle shape class and Sprite can take 'shape' parameter
13
+
14
+
4
15
  ## [v0.5.31] - 2023-10-25
5
16
 
6
17
  - Add toon.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.31
1
+ 0.5.33
data/examples/physics.rb CHANGED
@@ -17,7 +17,8 @@ draw do
17
17
  end
18
18
 
19
19
  mousePressed do
20
- sp = createSprite mouseX, mouseY, 20, 20
20
+ shape = Circle.new 0, 0, 20
21
+ sp = createSprite mouseX + rand, mouseY + rand, shape: shape
21
22
  sp.dynamic = true
22
23
  sp.restitution = 0.5
23
24
  sprites << sp
@@ -5,6 +5,7 @@ require 'rubysketch/extension'
5
5
  require 'rubysketch/helper'
6
6
 
7
7
  require 'rubysketch/sprite'
8
+ require 'rubysketch/shape'
8
9
  require 'rubysketch/sound'
9
10
  require 'rubysketch/easings'
10
11
  require 'rubysketch/context'
@@ -4,6 +4,7 @@ module RubySketch
4
4
  class Context < Processing::Context
5
5
 
6
6
  Sprite = RubySketch::Sprite
7
+ Circle = RubySketch::Circle
7
8
  Sound = RubySketch::Sound
8
9
 
9
10
  # @private
@@ -141,31 +142,49 @@ module RubySketch
141
142
 
142
143
  # Creates a new sprite and add it to physics engine.
143
144
  #
145
+ # @overload createSprite(x, y, w, h)
146
+ # pos(x, y), size: [w, h]
147
+ # @param [Numeric] x x of the sprite position
148
+ # @param [Numeric] y y of the sprite position
149
+ # @param [Numeric] w width of the sprite
150
+ # @param [Numeric] h height of the sprite
151
+ #
144
152
  # @overload createSprite(image: img)
145
153
  # pos: [0, 0], size: [image.width, image.height]
146
154
  # @param [Image] img sprite image
147
155
  #
148
156
  # @overload createSprite(x, y, image: img)
149
157
  # pos: [x, y], size: [image.width, image.height]
150
- # @param [Numeric] x x of sprite position
151
- # @param [Numeric] y y of sprite position
158
+ # @param [Numeric] x x of the sprite position
159
+ # @param [Numeric] y y of the sprite position
152
160
  # @param [Image] img sprite image
153
161
  #
154
- # @overload createSprite(x, y, w, h)
155
- # pos(x, y), size: [w, h]
156
- # @param [Numeric] x x of sprite position
157
- # @param [Numeric] y y of sprite position
158
- # @param [Numeric] w width of sprite
159
- # @param [Numeric] h height of sprite
160
- #
161
- # @overload createSprite(x, y, w, h, image: img, offset: off)
162
- # pos: [x, y], size: [w, h], offset: [offset.x, offset.x]
163
- # @param [Numeric] x x of sprite position
164
- # @param [Numeric] y y of sprite position
165
- # @param [Numeric] w width of sprite
166
- # @param [Numeric] h height of sprite
162
+ # @overload createSprite(x, y, image: img, offset: off)
163
+ # pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]
164
+ # @param [Numeric] x x of the sprite position
165
+ # @param [Numeric] y y of the sprite position
166
+ # @param [Image] img sprite image
167
+ # @param [Vector] off offset of the sprite image
168
+ #
169
+ # @overload createSprite(x, y, image: img, shape: shp)
170
+ # pos: [x, y], size: [image.width, image.height]
171
+ # @param [Numeric] x x of the sprite position
172
+ # @param [Numeric] y y of the sprite position
167
173
  # @param [Image] img sprite image
168
- # @param [Vector] off offset of sprite image
174
+ #
175
+ # @overload createSprite(x, y, image: img, offset: off, shape: shp)
176
+ # pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]
177
+ # @param [Numeric] x x of the sprite position
178
+ # @param [Numeric] y y of the sprite position
179
+ # @param [Image] img sprite image
180
+ # @param [Vector] off offset of the sprite image
181
+ # @param [Shape] shp shape of the sprite for physics calculations
182
+ #
183
+ # @overload createSprite(x, y, shape: shp)
184
+ # pos: [x, y], size: [shape.width, shape.height]
185
+ # @param [Numeric] x x of the sprite position
186
+ # @param [Numeric] y y of the sprite position
187
+ # @param [Shape] shp shape of the sprite for physics calculations
169
188
  #
170
189
  def createSprite(*args, **kwargs)
171
190
  addSprite Sprite.new(*args, **kwargs, context: self)
@@ -210,16 +229,16 @@ module RubySketch
210
229
  translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
211
230
  rotate fromDegrees__ degrees
212
231
  translate (-pivot.x) * f.w, (-pivot.y) * f.h
213
- draw.call {drawSprite__ sp, 0, 0, f.w, f.h}
232
+ draw.call {sp.draw__ self, 0, 0, f.w, f.h}
214
233
  end
215
234
  elsif degrees == 0
216
- drawSprite__ sp, f.x, f.y, f.w, f.h
235
+ sp.draw__ self, f.x, f.y, f.w, f.h
217
236
  else
218
237
  pushMatrix do
219
238
  translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
220
239
  rotate fromDegrees__ degrees
221
240
  translate (-pivot.x) * f.w, (-pivot.y) * f.h
222
- drawSprite__ sp, 0, 0, f.w, f.h
241
+ sp.draw__ self, 0, 0, f.w, f.h
223
242
  end
224
243
  end
225
244
  end
@@ -228,18 +247,6 @@ module RubySketch
228
247
 
229
248
  alias drawSprite sprite
230
249
 
231
- # @private
232
- def drawSprite__(sp, x, y, w, h)
233
- img, off = sp.image, sp.offset
234
- if img && off
235
- copy img, off.x, off.y, w, h, x, y, w, h
236
- elsif img
237
- image img, x, y
238
- else
239
- rect x, y, w, h
240
- end
241
- end
242
-
243
250
  # Loads sound file.
244
251
  #
245
252
  # @param [String] path path for sound file
@@ -0,0 +1,123 @@
1
+ module RubySketch
2
+
3
+
4
+ # Shape class for physics calculations.
5
+ #
6
+ class Shape
7
+
8
+ include Xot::Inspectable
9
+
10
+ # @private
11
+ def initialize(shape)
12
+ @shape = shape or raise ArgumentError
13
+ @shape.instance_variable_set :@owner__, self
14
+ end
15
+
16
+ # Returns the width of the shape.
17
+ #
18
+ # @return [Numeric] width
19
+ #
20
+ def width()
21
+ @shape.width
22
+ end
23
+
24
+ # Returns the height of the shape.
25
+ #
26
+ # @return [Numeric] height
27
+ #
28
+ def height()
29
+ @shape.height
30
+ end
31
+
32
+ alias w width
33
+ alias h height
34
+
35
+ # Set this shape as a sensor object.
36
+ # Sensor object receives contact events, but no collisions.
37
+ #
38
+ # @return [Boolean] sensor or not
39
+ #
40
+ def sensor=(state)
41
+ @shape.sensor = state
42
+ end
43
+
44
+ # Returns weather the shape is a sensor or not.
45
+ #
46
+ # @return [Boolean] sensor or not
47
+ #
48
+ def sensor?()
49
+ @shape.sensor?
50
+ end
51
+
52
+ # Defines contact block.
53
+ #
54
+ # @example Score increases when the shape touches a coin
55
+ # shape.contact do |o|
56
+ # score += 1 if o.coin?
57
+ # end
58
+ #
59
+ # @return [nil] nil
60
+ #
61
+ def contact(&block)
62
+ @shape.contact_begin do |other|
63
+ block.call other.instance_variable_get :@owner__ if block
64
+ end
65
+ nil
66
+ end
67
+
68
+ # Defines contact_end block.
69
+ #
70
+ # @example Call jumping() when the shape leaves the ground sprite
71
+ # shape.contact_end do |o|
72
+ # jumping if o == groundSprite
73
+ # end
74
+ #
75
+ # @return [nil] nil
76
+ #
77
+ def contact_end(&block)
78
+ @shape.contact_end do |other|
79
+ block.call other.instance_variable_get :@owner__ if block
80
+ end
81
+ nil
82
+ end
83
+
84
+ # @private
85
+ def getInternal__()
86
+ @shape
87
+ end
88
+
89
+ # @private
90
+ def draw__(context, x, y, width, height)
91
+ raise NotImplementedError
92
+ end
93
+
94
+ end# Shape
95
+
96
+
97
+ # Circle shape object.
98
+ #
99
+ class Circle < Shape
100
+
101
+ # Initialize circle object.
102
+ #
103
+ # @param [Numeric] x x of the circle shape position
104
+ # @param [Numeric] y y of the circle shape position
105
+ # @param [Numeric] size width and height of the circle shape
106
+ #
107
+ def initialize(x, y, size)
108
+ super Reflex::EllipseShape.new(frame: [x, y, size, size])
109
+ end
110
+
111
+ # @private
112
+ def draw__(c, x, y, w, h)
113
+ f = @shape.frame
114
+ c.pushStyle do
115
+ c.ellipseMode CORNER
116
+ c.ellipse x + f.x, y + f.y, f.w, f.h
117
+ end
118
+ end
119
+
120
+ end# Circle
121
+
122
+
123
+ end# RubySketch
@@ -9,6 +9,13 @@ module RubySketch
9
9
 
10
10
  # Initialize sprite object.
11
11
  #
12
+ # @overload new(x, y, w, h)
13
+ # pos(x, y), size: [w, h]
14
+ # @param [Numeric] x x of the sprite position
15
+ # @param [Numeric] y y of the sprite position
16
+ # @param [Numeric] w width of the sprite
17
+ # @param [Numeric] h height of the sprite
18
+ #
12
19
  # @overload new(image: img)
13
20
  # pos: [0, 0], size: [image.width, image.height]
14
21
  # @param [Image] img sprite image
@@ -19,36 +26,49 @@ module RubySketch
19
26
  # @param [Numeric] y y of the sprite position
20
27
  # @param [Image] img sprite image
21
28
  #
22
- # @overload new(x, y, w, h)
23
- # pos(x, y), size: [w, h]
24
- # @param [Numeric] x x of the sprite position
25
- # @param [Numeric] y y of the sprite position
26
- # @param [Numeric] w width of the sprite
27
- # @param [Numeric] h height of the sprite
29
+ # @overload new(x, y, image: img, offset: off)
30
+ # pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]
31
+ # @param [Numeric] x x of the sprite position
32
+ # @param [Numeric] y y of the sprite position
33
+ # @param [Image] img sprite image
34
+ # @param [Vector] off offset of the sprite image
35
+ #
36
+ # @overload new(x, y, image: img, shape: shp)
37
+ # pos: [x, y], size: [image.width, image.height]
38
+ # @param [Numeric] x x of the sprite position
39
+ # @param [Numeric] y y of the sprite position
40
+ # @param [Image] img sprite image
28
41
  #
29
- # @overload new(x, y, w, h, image: img, offset: off)
30
- # pos: [x, y], size: [w, h], offset: [offset.x, offset.x]
42
+ # @overload new(x, y, image: img, offset: off, shape: shp)
43
+ # pos: [x, y], size: [image.width, image.height], offset: [offset.x, offset.x]
31
44
  # @param [Numeric] x x of the sprite position
32
45
  # @param [Numeric] y y of the sprite position
33
- # @param [Numeric] w width of the sprite
34
- # @param [Numeric] h height of the sprite
35
46
  # @param [Image] img sprite image
36
47
  # @param [Vector] off offset of the sprite image
48
+ # @param [Shape] shp shape of the sprite for physics calculations
49
+ #
50
+ # @overload new(x, y, shape: shp)
51
+ # pos: [x, y], size: [shape.width, shape.height]
52
+ # @param [Numeric] x x of the sprite position
53
+ # @param [Numeric] y y of the sprite position
54
+ # @param [Shape] shp shape of the sprite for physics calculations
37
55
  #
38
56
  def initialize(
39
- x = 0, y = 0, w = nil, h = nil, image: nil, offset: nil,
57
+ x = 0, y = 0, w = nil, h = nil, image: nil, offset: nil, shape: nil,
40
58
  physics: true, context: nil)
41
59
 
42
- w ||= (image&.width || 0)
43
- h ||= (image&.height || 0)
60
+ w ||= (image&.width || shape&.width || 0)
61
+ h ||= (image&.height || shape&.height || 0)
44
62
  raise 'invalid size' unless w >= 0 && h >= 0
45
63
  raise 'invalid image' if image && !image.getInternal__.is_a?(Rays::Image)
64
+ raise 'invalid shape' if shape && !shape.getInternal__.is_a?(Reflex::Shape)
46
65
 
47
66
  @context__ = context || Context.context__
67
+ @shape__ = shape
48
68
  @view__ = SpriteView.new(
49
69
  self, x: x, y: y, w: w, h: h,
50
- physics: physics, density: 1, friction: 0, restitution: 0,
51
- back: :white)
70
+ shape: @shape__, physics: physics, back: :white)
71
+ @view__.set density: 1, friction: 0, restitution: 0
52
72
 
53
73
  self.image = image if image
54
74
  self.offset = offset if offset
@@ -878,6 +898,20 @@ module RubySketch
878
898
  @view__
879
899
  end
880
900
 
901
+ # @private
902
+ def draw__(c, x, y, w, h)
903
+ img, off = @image__, @offset__
904
+ if img && off
905
+ c.copy img, off.x, off.y, w, h, x, y, w, h
906
+ elsif img
907
+ c.image img, x, y
908
+ elsif @shape__
909
+ @shape__.draw__ c, x, y, w, h
910
+ else
911
+ c.rect x, y, w, h
912
+ end
913
+ end
914
+
881
915
  end# Sprite
882
916
 
883
917
 
@@ -891,7 +925,7 @@ module RubySketch
891
925
 
892
926
  attr_reader :sprite, :touches
893
927
 
894
- def initialize(sprite, *args, physics:, **kwargs, &block)
928
+ def initialize(sprite, *args, shape:, physics:, **kwargs, &block)
895
929
  @sprite = sprite
896
930
  super(*args, **kwargs, &block)
897
931
 
@@ -902,6 +936,7 @@ module RubySketch
902
936
  @pointersReleased = []
903
937
  @touches = []
904
938
 
939
+ self.shape = shape.getInternal__ if shape
905
940
  self.static = true if physics
906
941
  end
907
942
 
data/rubysketch.gemspec CHANGED
@@ -28,9 +28,9 @@ Gem::Specification.new do |s|
28
28
  s.add_runtime_dependency 'xot', '~> 0.1.39'
29
29
  s.add_runtime_dependency 'rucy', '~> 0.1.40'
30
30
  s.add_runtime_dependency 'beeps', '~> 0.1.42'
31
- s.add_runtime_dependency 'rays', '~> 0.1.44'
32
- s.add_runtime_dependency 'reflexion', '~> 0.1.52'
33
- s.add_runtime_dependency 'processing', '~> 0.5.28'
31
+ s.add_runtime_dependency 'rays', '~> 0.1.45'
32
+ s.add_runtime_dependency 'reflexion', '~> 0.1.53'
33
+ s.add_runtime_dependency 'processing', '~> 0.5.29'
34
34
 
35
35
  s.add_development_dependency 'rake'
36
36
  s.add_development_dependency 'test-unit'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysketch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.31
4
+ version: 0.5.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-24 00:00:00.000000000 Z
11
+ date: 2023-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -58,42 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.44
61
+ version: 0.1.45
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.44
68
+ version: 0.1.45
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: reflexion
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.52
75
+ version: 0.1.53
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.1.52
82
+ version: 0.1.53
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: processing
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.5.28
89
+ version: 0.5.29
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.5.28
96
+ version: 0.5.29
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -165,6 +165,7 @@ files:
165
165
  - lib/rubysketch/easings.rb
166
166
  - lib/rubysketch/extension.rb
167
167
  - lib/rubysketch/helper.rb
168
+ - lib/rubysketch/shape.rb
168
169
  - lib/rubysketch/sound.rb
169
170
  - lib/rubysketch/sprite.rb
170
171
  - pod.rake