rubysketch 0.7.6 → 0.7.7
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/ChangeLog.md +15 -0
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/rubysketch/all.rb +1 -0
- data/lib/rubysketch/context.rb +16 -45
- data/lib/rubysketch/graphics_context.rb +21 -0
- data/lib/rubysketch/shape.rb +1 -1
- data/lib/rubysketch/sound.rb +9 -0
- data/lib/rubysketch/sprite.rb +298 -63
- data/lib/rubysketch.rb +3 -3
- data/rubysketch.gemspec +6 -6
- data/test/test_context.rb +8 -4
- data/test/test_sprite.rb +11 -11
- metadata +25 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 924752d99e2aeba786ac6269ebec2ae9759d029c13a04c1b30567ce79a99f140
|
4
|
+
data.tar.gz: a426c0727fdd728f430e78d1d8862f7fd7bd787c40a17071aaa1dfbe45860930
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5031af2da7f7087e6061041d8df30edc8b90b0329d2d05c9c79cf17dfa0bb0245a5f265fa2426870dfd438cadbef3d95427f6609d0bb4cc7bba43bdcdeaf549
|
7
|
+
data.tar.gz: 6776237d4b24ca6b4fb90110af2e6d90f30d4232a98e57186b23b90edf27f1ccd459b9a4b015845139d599eea2e38758f4a966e2030ef40c816f158fc41bcd68
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
# rubysketch ChangeLog
|
2
2
|
|
3
3
|
|
4
|
+
## [v0.7.7] - 2025-03-07
|
5
|
+
|
6
|
+
- [BREAKING] Change addSprite() and removeSprite() to take only 1 sprite, and can take 'array' parameter for managing user array for sprites
|
7
|
+
|
8
|
+
- Add keyPressed, keyReleased, keyTyped, key, keyCode, keyIsPressed, keyIsDown, and keyIsRepeated to Sprite class.
|
9
|
+
- Add docs for keyPressed, keyReleased, and keyTyped of Sprite class
|
10
|
+
- Add capture=() and capturing?() methods to Sprite class
|
11
|
+
- Add SpriteWorld#offset and SpriteWorld#zoom
|
12
|
+
|
13
|
+
- Move 'sprite' method from RubySketch::Context to RubySketch::GraphicsContext
|
14
|
+
- createSprite can take 'klass' parameter
|
15
|
+
|
16
|
+
- Fix the issue where Sprite#contactEnd is not working
|
17
|
+
|
18
|
+
|
4
19
|
## [v0.7.6] - 2025-01-30
|
5
20
|
|
6
21
|
- Update dependencies: processing
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.7
|
data/lib/rubysketch/all.rb
CHANGED
data/lib/rubysketch/context.rb
CHANGED
@@ -3,6 +3,8 @@ module RubySketch
|
|
3
3
|
|
4
4
|
class Context < Processing::Context
|
5
5
|
|
6
|
+
include GraphicsContext
|
7
|
+
|
6
8
|
Sprite = RubySketch::Sprite
|
7
9
|
SpriteWorld = RubySketch::SpriteWorld
|
8
10
|
Circle = RubySketch::Circle
|
@@ -196,57 +198,26 @@ module RubySketch
|
|
196
198
|
@world__.createSprite(*args, context: self, **kwargs)
|
197
199
|
end
|
198
200
|
|
199
|
-
# Adds
|
201
|
+
# Adds sprite to the physics engine.
|
200
202
|
#
|
201
|
-
# @param [
|
203
|
+
# @param [Array] array user array to store the sprite
|
204
|
+
# @param [Sprite] sprite sprite object
|
202
205
|
#
|
203
|
-
# @return [Sprite]
|
206
|
+
# @return [Sprite] the added sprite
|
204
207
|
#
|
205
|
-
def addSprite(
|
206
|
-
@world__.addSprite
|
208
|
+
def addSprite(array = nil, sprite)
|
209
|
+
@world__.addSprite array, sprite
|
207
210
|
end
|
208
211
|
|
209
|
-
# Removes
|
210
|
-
#
|
211
|
-
# @param [Sprite] sprites sprite objects
|
212
|
-
#
|
213
|
-
# @return [Sprite] first removed sprite
|
212
|
+
# Removes sprite from the physics engine.
|
214
213
|
#
|
215
|
-
|
216
|
-
|
217
|
-
end
|
218
|
-
|
219
|
-
# Draws one or more sprites.
|
214
|
+
# @param [Array] array user array to remove the sprite
|
215
|
+
# @param [Sprite] sprite sprite object
|
220
216
|
#
|
221
|
-
# @
|
217
|
+
# @return [Sprite] the removed sprite
|
222
218
|
#
|
223
|
-
|
224
|
-
|
225
|
-
def sprite(*sprites)
|
226
|
-
sprites.flatten! if sprites.first&.is_a? Array
|
227
|
-
sprites.each do |sp|
|
228
|
-
next if sp.hidden?
|
229
|
-
view, draw = sp.getInternal__, sp.instance_variable_get(:@drawBlock__)
|
230
|
-
f, degrees, pivot = view.frame, view.angle, view.pivot
|
231
|
-
if draw
|
232
|
-
push do
|
233
|
-
translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
|
234
|
-
rotate fromDegrees__ degrees
|
235
|
-
translate (-pivot.x) * f.w, (-pivot.y) * f.h
|
236
|
-
draw.call {sp.draw__ self, 0, 0, f.w, f.h}
|
237
|
-
end
|
238
|
-
elsif degrees == 0
|
239
|
-
sp.draw__ self, f.x, f.y, f.w, f.h
|
240
|
-
else
|
241
|
-
pushMatrix do
|
242
|
-
translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
|
243
|
-
rotate fromDegrees__ degrees
|
244
|
-
translate (-pivot.x) * f.w, (-pivot.y) * f.h
|
245
|
-
sp.draw__ self, 0, 0, f.w, f.h
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
nil
|
219
|
+
def removeSprite(array = nil, sprite)
|
220
|
+
@world__.removeSprite array, sprite
|
250
221
|
end
|
251
222
|
|
252
223
|
alias drawSprite sprite
|
@@ -255,8 +226,8 @@ module RubySketch
|
|
255
226
|
#
|
256
227
|
# @return [SpriteWorld] the new world object
|
257
228
|
#
|
258
|
-
def createWorld(
|
259
|
-
addWorld SpriteWorld.new
|
229
|
+
def createWorld(pixelsPerMeter: 0)
|
230
|
+
addWorld SpriteWorld.new pixelsPerMeter: pixelsPerMeter
|
260
231
|
end
|
261
232
|
|
262
233
|
# Adds worlds
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RubySketch
|
2
|
+
|
3
|
+
|
4
|
+
module GraphicsContext
|
5
|
+
|
6
|
+
# Draws one or more sprites.
|
7
|
+
#
|
8
|
+
# @param [Array<Sprite>] sprites
|
9
|
+
#
|
10
|
+
# @return [nil] nil
|
11
|
+
#
|
12
|
+
def sprite(*sprites)
|
13
|
+
sprites.flatten! if sprites.first&.is_a? Array
|
14
|
+
sprites.each {_1.drawSprite__ self}
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
end# GraphicsContext
|
19
|
+
|
20
|
+
|
21
|
+
end# RubySketch
|
data/lib/rubysketch/shape.rb
CHANGED
data/lib/rubysketch/sound.rb
CHANGED
@@ -33,6 +33,15 @@ module RubySketch
|
|
33
33
|
nil
|
34
34
|
end
|
35
35
|
|
36
|
+
# Returns whether or not playback is in progress.
|
37
|
+
#
|
38
|
+
# @return [Boolean] playing or not
|
39
|
+
#
|
40
|
+
def playing?()
|
41
|
+
clean_stopped_players
|
42
|
+
not @players.empty?
|
43
|
+
end
|
44
|
+
|
36
45
|
# Load a sound file.
|
37
46
|
#
|
38
47
|
# @param [String] path file path
|
data/lib/rubysketch/sprite.rb
CHANGED
@@ -104,6 +104,25 @@ module RubySketch
|
|
104
104
|
@view__.hidden?
|
105
105
|
end
|
106
106
|
|
107
|
+
# Captures key and mouse events
|
108
|
+
#
|
109
|
+
# @param [Boolean] bool whether to capture
|
110
|
+
#
|
111
|
+
# @return [Boolean] the current state
|
112
|
+
#
|
113
|
+
def capture=(bool)
|
114
|
+
@view__.capture = bool ? :all : []
|
115
|
+
bool
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns whether to capture or not
|
119
|
+
#
|
120
|
+
# @return [Boolean] whether to capture
|
121
|
+
#
|
122
|
+
def capturing?()
|
123
|
+
@view__.capturing?
|
124
|
+
end
|
125
|
+
|
107
126
|
# Returns the position of the sprite.
|
108
127
|
#
|
109
128
|
# @return [Vector] position
|
@@ -256,8 +275,8 @@ module RubySketch
|
|
256
275
|
#
|
257
276
|
# @return [Numeric] sprite bottom position
|
258
277
|
#
|
259
|
-
def bottom=(
|
260
|
-
@view__.bottom =
|
278
|
+
def bottom=(n)
|
279
|
+
@view__.bottom = n
|
261
280
|
end
|
262
281
|
|
263
282
|
# Returns the center position of the sprite.
|
@@ -347,8 +366,7 @@ module RubySketch
|
|
347
366
|
# @return [Numeric] radians or degrees depending on angleMode()
|
348
367
|
#
|
349
368
|
def angle()
|
350
|
-
|
351
|
-
c ? c.fromDegrees__(a) : a * Processing::GraphicsContext::DEG2RAD__
|
369
|
+
@context__.fromDegrees__ @view__.angle
|
352
370
|
end
|
353
371
|
|
354
372
|
# Sets the rotation angle of the sprite.
|
@@ -358,9 +376,7 @@ module RubySketch
|
|
358
376
|
# @return [Numeric] angle
|
359
377
|
#
|
360
378
|
def angle=(angle)
|
361
|
-
|
362
|
-
@view__.angle =
|
363
|
-
c ? c.toDegrees__(angle) : angle * Processing::GraphicsContext::RAD2DEG__
|
379
|
+
@view__.angle = @context__.toDegrees__ angle
|
364
380
|
angle
|
365
381
|
end
|
366
382
|
|
@@ -394,7 +410,7 @@ module RubySketch
|
|
394
410
|
# Sets the rotation center of the sprite.
|
395
411
|
# [0.0, 0.0] is the left-top, [1.0, 1.0] is the right-bottom, and [0.5, 0.5] is the center.
|
396
412
|
#
|
397
|
-
# @param [Array<Numeric>]
|
413
|
+
# @param [Array<Numeric>] array an array of pivotX and pivotY
|
398
414
|
#
|
399
415
|
# @return [Array<Numeric>] [pivotX, pivotY]
|
400
416
|
#
|
@@ -498,7 +514,7 @@ module RubySketch
|
|
498
514
|
# @overload offset=(vec)
|
499
515
|
# @param [Vector] vec offset
|
500
516
|
#
|
501
|
-
# @overload
|
517
|
+
# @overload offset=(ary)
|
502
518
|
# @param [Array<Numeric>] ary an array of offsetX and offsetY
|
503
519
|
#
|
504
520
|
# @return [Vector] offset of the sprite image
|
@@ -511,7 +527,7 @@ module RubySketch
|
|
511
527
|
when nil then nil
|
512
528
|
else raise ArgumentError
|
513
529
|
end
|
514
|
-
|
530
|
+
offset
|
515
531
|
end
|
516
532
|
|
517
533
|
# Returns the x-axis offset of the sprite image.
|
@@ -524,13 +540,13 @@ module RubySketch
|
|
524
540
|
|
525
541
|
# Sets the x-axis offset of the sprite image.
|
526
542
|
#
|
527
|
-
# @param [Numeric]
|
543
|
+
# @param [Numeric] x x-axis offset
|
528
544
|
#
|
529
545
|
# @return [Numeric] offset.x
|
530
546
|
#
|
531
|
-
def ox=(
|
532
|
-
self.offset = [
|
533
|
-
|
547
|
+
def ox=(x)
|
548
|
+
self.offset = [x, oy]
|
549
|
+
x
|
534
550
|
end
|
535
551
|
|
536
552
|
# Returns the y-axis offset of the sprite image.
|
@@ -543,12 +559,13 @@ module RubySketch
|
|
543
559
|
|
544
560
|
# Sets the y-axis offset of the sprite image.
|
545
561
|
#
|
546
|
-
# @param [Numeric]
|
562
|
+
# @param [Numeric] y y-axis offset
|
547
563
|
#
|
548
564
|
# @return [Numeric] offset.y
|
549
565
|
#
|
550
|
-
def oy=(
|
551
|
-
self.offset = [ox,
|
566
|
+
def oy=(y)
|
567
|
+
self.offset = [ox, y]
|
568
|
+
y
|
552
569
|
end
|
553
570
|
|
554
571
|
# Returns whether the sprite is movable by the physics engine.
|
@@ -643,7 +660,7 @@ module RubySketch
|
|
643
660
|
@view__.sensor = state
|
644
661
|
end
|
645
662
|
|
646
|
-
# Returns
|
663
|
+
# Returns whether the shape is a sensor or not.
|
647
664
|
#
|
648
665
|
# @return [Boolean] sensor or not
|
649
666
|
#
|
@@ -671,6 +688,48 @@ module RubySketch
|
|
671
688
|
@view__.to_parent(vec.getInternal__).toVector
|
672
689
|
end
|
673
690
|
|
691
|
+
# Returns the last key that was pressed or released.
|
692
|
+
#
|
693
|
+
# @return [String] last key
|
694
|
+
#
|
695
|
+
def key()
|
696
|
+
@view__.key
|
697
|
+
end
|
698
|
+
|
699
|
+
# Returns the last key code that was pressed or released.
|
700
|
+
#
|
701
|
+
# @return [Symbol] last key code
|
702
|
+
#
|
703
|
+
def keyCode()
|
704
|
+
@view__.keyCode
|
705
|
+
end
|
706
|
+
|
707
|
+
# Returns whether or not any key is pressed.
|
708
|
+
#
|
709
|
+
# @return [Boolean] is any key pressed or not
|
710
|
+
#
|
711
|
+
def keyIsPressed()
|
712
|
+
not @view__.keysPressed.empty?
|
713
|
+
end
|
714
|
+
|
715
|
+
# Returns whether or not the key is currently pressed.
|
716
|
+
#
|
717
|
+
# @param keyCode [Numeric] code for the key
|
718
|
+
#
|
719
|
+
# @return [Boolean] is the key pressed or not
|
720
|
+
#
|
721
|
+
def keyIsDown(keyCode)
|
722
|
+
@view__.keysPressed.include? keyCode
|
723
|
+
end
|
724
|
+
|
725
|
+
# Returns whether the current key is repeated or not.
|
726
|
+
#
|
727
|
+
# @return [Boolean] is the key repeated or not
|
728
|
+
#
|
729
|
+
def keyIsRepeated()
|
730
|
+
@view__.keyRepeat
|
731
|
+
end
|
732
|
+
|
674
733
|
# Returns the x-position of the mouse in the sprite coordinates.
|
675
734
|
#
|
676
735
|
# @return [Numeric] x position
|
@@ -757,6 +816,33 @@ module RubySketch
|
|
757
816
|
nil
|
758
817
|
end
|
759
818
|
|
819
|
+
# Defines keyPressed block.
|
820
|
+
#
|
821
|
+
# @return [Boolean] is any key pressed or not
|
822
|
+
#
|
823
|
+
def keyPressed(&block)
|
824
|
+
@view__.keyPressed = block if block
|
825
|
+
keyIsPressed
|
826
|
+
end
|
827
|
+
|
828
|
+
# Defines keyReleased block.
|
829
|
+
#
|
830
|
+
# @return [nil] nil
|
831
|
+
#
|
832
|
+
def keyReleased(&block)
|
833
|
+
@view__.keyReleased = block if block
|
834
|
+
nil
|
835
|
+
end
|
836
|
+
|
837
|
+
# Defines keyTyped block.
|
838
|
+
#
|
839
|
+
# @return [nil] nil
|
840
|
+
#
|
841
|
+
def keyTyped(&block)
|
842
|
+
@view__.keyTyped = block if block
|
843
|
+
nil
|
844
|
+
end
|
845
|
+
|
760
846
|
# Defines mousePressed block.
|
761
847
|
#
|
762
848
|
# @example Print mouse states on mouse press
|
@@ -883,17 +969,17 @@ module RubySketch
|
|
883
969
|
nil
|
884
970
|
end
|
885
971
|
|
886
|
-
# Defines
|
972
|
+
# Defines contactEnd block.
|
887
973
|
#
|
888
974
|
# @example Call jumping() when the player sprite leaves the ground sprite
|
889
|
-
# playerSprite.
|
975
|
+
# playerSprite.contactEnd do |o|
|
890
976
|
# jumping if o == groundSprite
|
891
977
|
# end
|
892
978
|
#
|
893
979
|
# @return [nil] nil
|
894
980
|
#
|
895
|
-
def
|
896
|
-
@view__.
|
981
|
+
def contactEnd(&block)
|
982
|
+
@view__.contactEnd = block if block
|
897
983
|
nil
|
898
984
|
end
|
899
985
|
|
@@ -907,7 +993,7 @@ module RubySketch
|
|
907
993
|
# @return [nil] nil
|
908
994
|
#
|
909
995
|
def contact?(&block)
|
910
|
-
@view__.
|
996
|
+
@view__.willContact = block if block
|
911
997
|
nil
|
912
998
|
end
|
913
999
|
|
@@ -916,6 +1002,30 @@ module RubySketch
|
|
916
1002
|
@view__
|
917
1003
|
end
|
918
1004
|
|
1005
|
+
# @private
|
1006
|
+
def drawSprite__(c)
|
1007
|
+
return if hidden?
|
1008
|
+
view = getInternal__
|
1009
|
+
f, degrees, pivot = view.frame, view.angle, view.pivot
|
1010
|
+
if @drawBlock__
|
1011
|
+
c.push do
|
1012
|
+
c.translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
|
1013
|
+
c.rotate c.fromDegrees__ degrees
|
1014
|
+
c.translate (-pivot.x) * f.w, (-pivot.y) * f.h
|
1015
|
+
@drawBlock__.call {draw__ c, 0, 0, f.w, f.h}
|
1016
|
+
end
|
1017
|
+
elsif degrees != 0
|
1018
|
+
c.pushMatrix do
|
1019
|
+
c.translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
|
1020
|
+
c.rotate c.fromDegrees__ degrees
|
1021
|
+
c.translate (-pivot.x) * f.w, (-pivot.y) * f.h
|
1022
|
+
draw__ c, 0, 0, f.w, f.h
|
1023
|
+
end
|
1024
|
+
else
|
1025
|
+
draw__ c, f.x, f.y, f.w, f.h
|
1026
|
+
end
|
1027
|
+
end
|
1028
|
+
|
919
1029
|
# @private
|
920
1030
|
def draw__(c, x, y, w, h)
|
921
1031
|
img, off = @image__, @offset__
|
@@ -937,10 +1047,10 @@ module RubySketch
|
|
937
1047
|
#
|
938
1048
|
class SpriteWorld
|
939
1049
|
|
940
|
-
# Create a new physics world
|
1050
|
+
# Create a new physics world.
|
941
1051
|
#
|
942
|
-
def initialize(
|
943
|
-
@view, @debug = View.new(
|
1052
|
+
def initialize(pixelsPerMeter: 0)
|
1053
|
+
@view, @debug = View.new(pixelsPerMeter: pixelsPerMeter), false
|
944
1054
|
end
|
945
1055
|
|
946
1056
|
# Creates a new sprite and add it to physics engine.
|
@@ -991,31 +1101,36 @@ module RubySketch
|
|
991
1101
|
#
|
992
1102
|
# @return [Sprite] the new sprite object
|
993
1103
|
#
|
994
|
-
def createSprite(*args, context: nil, **kwargs)
|
1104
|
+
def createSprite(*args, klass: nil, context: nil, **kwargs)
|
1105
|
+
klass ||= RubySketch::Sprite
|
995
1106
|
context ||= Context.context__
|
996
|
-
addSprite
|
1107
|
+
addSprite klass.new(*args, context: context, **kwargs)
|
997
1108
|
end
|
998
1109
|
|
999
|
-
# Adds
|
1110
|
+
# Adds sprite to the physics engine.
|
1000
1111
|
#
|
1001
|
-
# @param [
|
1112
|
+
# @param [Array] array user array to store the sprite
|
1113
|
+
# @param [Sprite] sprite sprite object
|
1002
1114
|
#
|
1003
|
-
# @return [Sprite]
|
1115
|
+
# @return [Sprite] the added sprite
|
1004
1116
|
#
|
1005
|
-
def addSprite(
|
1006
|
-
|
1007
|
-
|
1117
|
+
def addSprite(array = nil, sprite)
|
1118
|
+
@view.add sprite.getInternal__
|
1119
|
+
array&.push sprite
|
1120
|
+
sprite
|
1008
1121
|
end
|
1009
1122
|
|
1010
|
-
# Removes
|
1123
|
+
# Removes sprite from the physics engine.
|
1011
1124
|
#
|
1012
|
-
# @param [
|
1125
|
+
# @param [Array] array user array to remove the sprite
|
1126
|
+
# @param [Sprite] sprite sprite object
|
1013
1127
|
#
|
1014
|
-
# @return [Sprite]
|
1128
|
+
# @return [Sprite] the removed sprite
|
1015
1129
|
#
|
1016
|
-
def removeSprite(
|
1017
|
-
|
1018
|
-
|
1130
|
+
def removeSprite(array = nil, sprite)
|
1131
|
+
@view.remove sprite.getInternal__
|
1132
|
+
array&.delete sprite
|
1133
|
+
sprite
|
1019
1134
|
end
|
1020
1135
|
|
1021
1136
|
# Sets gravity for the physics engine.
|
@@ -1043,6 +1158,96 @@ module RubySketch
|
|
1043
1158
|
nil
|
1044
1159
|
end
|
1045
1160
|
|
1161
|
+
# Returns the offset of the sprite world.
|
1162
|
+
#
|
1163
|
+
# @return [Vector] offset of the sprite world
|
1164
|
+
#
|
1165
|
+
def offset()
|
1166
|
+
s, z = @view.scroll, zoom
|
1167
|
+
Vector.new s.x / z, s.y / z, s.z / z
|
1168
|
+
end
|
1169
|
+
|
1170
|
+
# Sets the offset of the sprite world.
|
1171
|
+
#
|
1172
|
+
# @overload offset=(vec)
|
1173
|
+
# @param [Vector] vec offset
|
1174
|
+
#
|
1175
|
+
# @overload offset=(ary)
|
1176
|
+
# @param [Array<Numeric>] ary an array of offsetX and offsetY
|
1177
|
+
#
|
1178
|
+
# @return [Vector] offset of the sprite world
|
1179
|
+
#
|
1180
|
+
def offset=(arg)
|
1181
|
+
zoom_ = zoom
|
1182
|
+
x, y, z =
|
1183
|
+
case arg
|
1184
|
+
when Vector then [arg.x, arg.y, arg.z]
|
1185
|
+
when Array then [arg[0] || 0, arg[1] || 0, arg[2] || 0]
|
1186
|
+
when nil then [0, 0, 0]
|
1187
|
+
else raise ArgumentError
|
1188
|
+
end
|
1189
|
+
@view.scroll_to x * zoom_, y * zoom_, z * zoom_
|
1190
|
+
offset
|
1191
|
+
end
|
1192
|
+
|
1193
|
+
# Returns the x-axis offset of the sprite world.
|
1194
|
+
#
|
1195
|
+
# @return [Numeric] offset.x
|
1196
|
+
#
|
1197
|
+
def ox()
|
1198
|
+
offset.x
|
1199
|
+
end
|
1200
|
+
|
1201
|
+
# Sets the x-axis offset of the sprite world.
|
1202
|
+
#
|
1203
|
+
# @param [Numeric] x x-axis offset
|
1204
|
+
#
|
1205
|
+
# @return [Numeric] offset.x
|
1206
|
+
#
|
1207
|
+
def ox=(x)
|
1208
|
+
o = offset
|
1209
|
+
o.x = x
|
1210
|
+
self.offset = o
|
1211
|
+
x
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
# Returns the y-axis offset of the sprite world.
|
1215
|
+
#
|
1216
|
+
# @return [Numeric] offset.y
|
1217
|
+
#
|
1218
|
+
def oy()
|
1219
|
+
offset.y
|
1220
|
+
end
|
1221
|
+
|
1222
|
+
# Sets the y-axis offset of the sprite world.
|
1223
|
+
#
|
1224
|
+
# @param [Numeric] x y-axis offset
|
1225
|
+
#
|
1226
|
+
# @return [Numeric] offset.y
|
1227
|
+
#
|
1228
|
+
def oy=(x)
|
1229
|
+
o = offset
|
1230
|
+
o.y = y
|
1231
|
+
self.offset = o
|
1232
|
+
y
|
1233
|
+
end
|
1234
|
+
|
1235
|
+
# Returns the zoom value of the sprite world.
|
1236
|
+
#
|
1237
|
+
# @return [Numeric] zoom
|
1238
|
+
#
|
1239
|
+
def zoom()
|
1240
|
+
@view.zoom
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
# Sets the zoom value of the sprite world.
|
1244
|
+
#
|
1245
|
+
# @return [Numeric] zoom
|
1246
|
+
#
|
1247
|
+
def zoom=(zoom)
|
1248
|
+
@view.zoom = zoom
|
1249
|
+
end
|
1250
|
+
|
1046
1251
|
def debug=(state)
|
1047
1252
|
@view.debug = state
|
1048
1253
|
end
|
@@ -1060,18 +1265,15 @@ module RubySketch
|
|
1060
1265
|
# @private
|
1061
1266
|
class Sprite::View < Reflex::View
|
1062
1267
|
|
1063
|
-
attr_accessor :update,
|
1064
|
-
:mousePressed, :mouseReleased, :mouseMoved, :mouseDragged, :mouseClicked,
|
1065
|
-
:touchStarted, :touchEnded, :touchMoved,
|
1066
|
-
:contact, :contact_end, :will_contact
|
1067
|
-
|
1068
|
-
attr_reader :sprite, :touches
|
1069
|
-
|
1070
1268
|
def initialize(sprite, *args, shape:, physics:, **kwargs, &block)
|
1071
1269
|
@sprite = sprite
|
1072
1270
|
super(*args, **kwargs, &block)
|
1073
1271
|
|
1074
1272
|
@error = nil
|
1273
|
+
@key = nil
|
1274
|
+
@keyCode = nil
|
1275
|
+
@keyRepeat = false
|
1276
|
+
@keysPressed = nil
|
1075
1277
|
@pointer = nil
|
1076
1278
|
@pointerPrev = nil
|
1077
1279
|
@pointersPressed = []
|
@@ -1082,6 +1284,18 @@ module RubySketch
|
|
1082
1284
|
self.static = true if physics
|
1083
1285
|
end
|
1084
1286
|
|
1287
|
+
attr_accessor :update,
|
1288
|
+
:mousePressed, :mouseReleased, :mouseMoved, :mouseDragged, :mouseClicked,
|
1289
|
+
:touchStarted, :touchEnded, :touchMoved,
|
1290
|
+
:keyPressed, :keyReleased, :keyTyped,
|
1291
|
+
:contact, :contactEnd, :willContact
|
1292
|
+
|
1293
|
+
attr_reader :sprite, :key, :keyCode, :keyRepeat, :touches
|
1294
|
+
|
1295
|
+
def keysPressed()
|
1296
|
+
@keysPressed || []
|
1297
|
+
end
|
1298
|
+
|
1085
1299
|
def mouseX()
|
1086
1300
|
@pointer&.x || 0
|
1087
1301
|
end
|
@@ -1111,7 +1325,7 @@ module RubySketch
|
|
1111
1325
|
end
|
1112
1326
|
|
1113
1327
|
def on_update(e)
|
1114
|
-
|
1328
|
+
callBlock @update
|
1115
1329
|
end
|
1116
1330
|
|
1117
1331
|
def on_pointer_down(e)
|
@@ -1119,8 +1333,8 @@ module RubySketch
|
|
1119
1333
|
updatePointersPressedAndReleased e, true
|
1120
1334
|
@pointerDownStartPos = to_screen @pointer.pos
|
1121
1335
|
|
1122
|
-
|
1123
|
-
|
1336
|
+
callBlock @mousePressed if e.any? {|p| p.id == @pointer.id}
|
1337
|
+
callBlock @touchStarted
|
1124
1338
|
|
1125
1339
|
e.block
|
1126
1340
|
end
|
@@ -1130,10 +1344,10 @@ module RubySketch
|
|
1130
1344
|
updatePointersPressedAndReleased e, false
|
1131
1345
|
|
1132
1346
|
if e.any? {|p| p.id == @pointer.id}
|
1133
|
-
|
1134
|
-
|
1347
|
+
callBlock @mouseReleased
|
1348
|
+
callBlock @mouseClicked if mouseClicked?
|
1135
1349
|
end
|
1136
|
-
|
1350
|
+
callBlock @touchEnded
|
1137
1351
|
|
1138
1352
|
@pointerDownStartPos = nil
|
1139
1353
|
@pointersReleased.clear
|
@@ -1143,29 +1357,42 @@ module RubySketch
|
|
1143
1357
|
updatePointerStates e
|
1144
1358
|
|
1145
1359
|
mouseMoved = e.drag? ? @mouseDragged : @mouseMoved
|
1146
|
-
|
1147
|
-
|
1360
|
+
callBlock mouseMoved if e.any? {|p| p.id == @pointer.id}
|
1361
|
+
callBlock @touchMoved
|
1148
1362
|
end
|
1149
1363
|
|
1150
1364
|
def on_pointer_cancel(e)
|
1151
1365
|
on_pointer_up e
|
1152
1366
|
end
|
1153
1367
|
|
1368
|
+
def on_key_down(e)
|
1369
|
+
updateKeyStates e, true
|
1370
|
+
callBlock @keyPressed
|
1371
|
+
callBlock @keyTyped if e.chars&.empty? == false
|
1372
|
+
e.block
|
1373
|
+
end
|
1374
|
+
|
1375
|
+
def on_key_up(e)
|
1376
|
+
updateKeyStates e, false
|
1377
|
+
callBlock @keyReleased
|
1378
|
+
e.block
|
1379
|
+
end
|
1380
|
+
|
1154
1381
|
def on_contact_begin(e)
|
1155
1382
|
return unless @contact
|
1156
1383
|
v = e.view
|
1157
|
-
|
1384
|
+
callBlock @contact, v.sprite if v.respond_to?(:sprite)
|
1158
1385
|
end
|
1159
1386
|
|
1160
1387
|
def on_contact_end(e)
|
1161
|
-
return unless @
|
1388
|
+
return unless @contactEnd
|
1162
1389
|
v = e.view
|
1163
|
-
|
1390
|
+
callBlock @contactEnd, v.sprite if v.respond_to?(:sprite)
|
1164
1391
|
end
|
1165
1392
|
|
1166
1393
|
def will_contact?(v)
|
1167
|
-
return true unless @
|
1168
|
-
|
1394
|
+
return true unless @willContact && v.respond_to?(:sprite)
|
1395
|
+
callBlock @willContact, v.sprite
|
1169
1396
|
end
|
1170
1397
|
|
1171
1398
|
private
|
@@ -1178,6 +1405,14 @@ module RubySketch
|
|
1178
1405
|
|
1179
1406
|
MOUSE_BUTTONS = MOUSE_BUTTON_MAP.values
|
1180
1407
|
|
1408
|
+
def updateKeyStates(event, pressed)
|
1409
|
+
set = (@keysPressed ||= Set.new)
|
1410
|
+
@key = event.chars
|
1411
|
+
@keyCode = event.key
|
1412
|
+
@keyRepeat = pressed && set.include?(@keyCode)
|
1413
|
+
pressed ? set.add(@keyCode) : set.delete(@keyCode)
|
1414
|
+
end
|
1415
|
+
|
1181
1416
|
def updatePointerStates(event)
|
1182
1417
|
pointer = event.find {|p| p.id == @pointer&.id} || event.first
|
1183
1418
|
if !mousePressed? || pointer.id == @pointer&.id
|
@@ -1205,7 +1440,7 @@ module RubySketch
|
|
1205
1440
|
.then {|pos, startPos| (pos - startPos).length < 3}
|
1206
1441
|
end
|
1207
1442
|
|
1208
|
-
def
|
1443
|
+
def callBlock(block, *args)
|
1209
1444
|
block.call(*args) if block && !@error
|
1210
1445
|
rescue Exception => e
|
1211
1446
|
@error = e
|
@@ -1218,8 +1453,8 @@ module RubySketch
|
|
1218
1453
|
# @private
|
1219
1454
|
class SpriteWorld::View < Reflex::View
|
1220
1455
|
|
1221
|
-
def initialize(*a,
|
1222
|
-
create_world
|
1456
|
+
def initialize(*a, pixelsPerMeter: 0, **k, &b)
|
1457
|
+
create_world pixelsPerMeter if pixelsPerMeter > 0
|
1223
1458
|
super(*a, **k, &b)
|
1224
1459
|
@debug = false
|
1225
1460
|
remove wall
|
data/lib/rubysketch.rb
CHANGED
@@ -37,9 +37,9 @@ end
|
|
37
37
|
begin
|
38
38
|
w, c = RubySketch::WINDOW__, RubySketch::CONTEXT__
|
39
39
|
|
40
|
-
c.class.constants
|
41
|
-
|
42
|
-
|
40
|
+
c.class.constants
|
41
|
+
.reject {_1 =~ /__$/}
|
42
|
+
.each {self.class.const_set _1, c.class.const_get(_1)}
|
43
43
|
|
44
44
|
w.__send__ :begin_draw
|
45
45
|
at_exit do
|
data/rubysketch.gemspec
CHANGED
@@ -25,12 +25,12 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.platform = Gem::Platform::RUBY
|
26
26
|
s.required_ruby_version = '>= 3.0.0'
|
27
27
|
|
28
|
-
s.add_dependency 'xot', '~> 0.3.
|
29
|
-
s.add_dependency 'rucy', '~> 0.3.
|
30
|
-
s.add_dependency 'beeps', '~> 0.3.
|
31
|
-
s.add_dependency 'rays', '~> 0.3.
|
32
|
-
s.add_dependency 'reflexion', '~> 0.3.
|
33
|
-
s.add_dependency 'processing', '~> 1.1', '>= 1.1.
|
28
|
+
s.add_dependency 'xot', '~> 0.3.4', '>= 0.3.4'
|
29
|
+
s.add_dependency 'rucy', '~> 0.3.4', '>= 0.3.4'
|
30
|
+
s.add_dependency 'beeps', '~> 0.3.4', '>= 0.3.4'
|
31
|
+
s.add_dependency 'rays', '~> 0.3.4', '>= 0.3.4'
|
32
|
+
s.add_dependency 'reflexion', '~> 0.3.4', '>= 0.3.4'
|
33
|
+
s.add_dependency 'processing', '~> 1.1', '>= 1.1.6'
|
34
34
|
|
35
35
|
s.files = `git ls-files`.split $/
|
36
36
|
s.test_files = s.files.grep %r{^(test|spec|features)/}
|
data/test/test_context.rb
CHANGED
@@ -16,16 +16,20 @@ class TestContext < Test::Unit::TestCase
|
|
16
16
|
|
17
17
|
def test_addSprite()
|
18
18
|
sp = sprite
|
19
|
-
assert_nil context.addSprite()
|
20
19
|
assert_equal sp, context.addSprite(sp)
|
21
|
-
|
20
|
+
|
21
|
+
ary = []
|
22
|
+
assert_equal sp, context.addSprite(ary, sp)
|
23
|
+
assert_equal [sp], ary
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_removeSprite()
|
25
27
|
sp = sprite
|
26
|
-
assert_nil context.removeSprite()
|
27
28
|
assert_equal sp, context.removeSprite(sp)
|
28
|
-
|
29
|
+
|
30
|
+
ary = [sp]
|
31
|
+
assert_equal sp, context.removeSprite(ary, sp)
|
32
|
+
assert_equal [], ary
|
29
33
|
end
|
30
34
|
|
31
35
|
end# TestContext
|
data/test/test_sprite.rb
CHANGED
@@ -272,32 +272,32 @@ class TestSprite < Test::Unit::TestCase
|
|
272
272
|
v = s.instance_variable_get :@view__
|
273
273
|
assert_nil v.update
|
274
274
|
assert_nil v.contact
|
275
|
-
assert_nil v.
|
276
|
-
assert_nil v.
|
275
|
+
assert_nil v.contactEnd
|
276
|
+
assert_nil v.willContact
|
277
277
|
|
278
278
|
s.update {}
|
279
279
|
assert_not_nil v.update
|
280
280
|
assert_nil v.contact
|
281
|
-
assert_nil v.
|
282
|
-
assert_nil v.
|
281
|
+
assert_nil v.contactEnd
|
282
|
+
assert_nil v.willContact
|
283
283
|
|
284
284
|
s.contact {}
|
285
285
|
assert_not_nil v.update
|
286
286
|
assert_not_nil v.contact
|
287
|
-
assert_nil v.
|
288
|
-
assert_nil v.
|
287
|
+
assert_nil v.contactEnd
|
288
|
+
assert_nil v.willContact
|
289
289
|
|
290
|
-
s.
|
290
|
+
s.contactEnd {}
|
291
291
|
assert_not_nil v.update
|
292
292
|
assert_not_nil v.contact
|
293
|
-
assert_not_nil v.
|
294
|
-
assert_nil v.
|
293
|
+
assert_not_nil v.contactEnd
|
294
|
+
assert_nil v.willContact
|
295
295
|
|
296
296
|
s.contact? {}
|
297
297
|
assert_not_nil v.update
|
298
298
|
assert_not_nil v.contact
|
299
|
-
assert_not_nil v.
|
300
|
-
assert_not_nil v.
|
299
|
+
assert_not_nil v.contactEnd
|
300
|
+
assert_not_nil v.willContact
|
301
301
|
end
|
302
302
|
|
303
303
|
def test_inspect()
|
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.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xot
|
@@ -16,100 +16,100 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.
|
19
|
+
version: 0.3.4
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.3.
|
22
|
+
version: 0.3.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.3.
|
29
|
+
version: 0.3.4
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.3.
|
32
|
+
version: 0.3.4
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rucy
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.3.
|
39
|
+
version: 0.3.4
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.3.
|
42
|
+
version: 0.3.4
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 0.3.
|
49
|
+
version: 0.3.4
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 0.3.
|
52
|
+
version: 0.3.4
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: beeps
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 0.3.
|
59
|
+
version: 0.3.4
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.3.
|
62
|
+
version: 0.3.4
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.3.
|
69
|
+
version: 0.3.4
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: 0.3.
|
72
|
+
version: 0.3.4
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: rays
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 0.3.
|
79
|
+
version: 0.3.4
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.3.
|
82
|
+
version: 0.3.4
|
83
83
|
type: :runtime
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.3.
|
89
|
+
version: 0.3.4
|
90
90
|
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version: 0.3.
|
92
|
+
version: 0.3.4
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: reflexion
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
97
|
- - "~>"
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: 0.3.
|
99
|
+
version: 0.3.4
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 0.3.
|
102
|
+
version: 0.3.4
|
103
103
|
type: :runtime
|
104
104
|
prerelease: false
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.3.
|
109
|
+
version: 0.3.4
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: 0.3.
|
112
|
+
version: 0.3.4
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: processing
|
115
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,7 +119,7 @@ dependencies:
|
|
119
119
|
version: '1.1'
|
120
120
|
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: 1.1.
|
122
|
+
version: 1.1.6
|
123
123
|
type: :runtime
|
124
124
|
prerelease: false
|
125
125
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -129,7 +129,7 @@ dependencies:
|
|
129
129
|
version: '1.1'
|
130
130
|
- - ">="
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: 1.1.
|
132
|
+
version: 1.1.6
|
133
133
|
description: A game engine based on the Processing API.
|
134
134
|
email: xordog@gmail.com
|
135
135
|
executables: []
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/rubysketch/context.rb
|
160
160
|
- lib/rubysketch/easings.rb
|
161
161
|
- lib/rubysketch/extension.rb
|
162
|
+
- lib/rubysketch/graphics_context.rb
|
162
163
|
- lib/rubysketch/helper.rb
|
163
164
|
- lib/rubysketch/shape.rb
|
164
165
|
- lib/rubysketch/sound.rb
|