Skip to content

Commit 77e2782

Browse files
committed
Initial work on size
1 parent c2a512e commit 77e2782

File tree

9 files changed

+40
-17
lines changed

9 files changed

+40
-17
lines changed

assets/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"targets":[{"isStage":true,"name":"Stage","variables":{},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"name":"xy-grid","bitmapResolution":1,"dataFormat":"svg","assetId":"4851f7b71585efa5d42cb3a0b2d5fadf","md5ext":"4851f7b71585efa5d42cb3a0b2d5fadf.svg","rotationCenterX":239.99996948242188,"rotationCenterY":180.00003051757812}],"sounds":[],"volume":100,"layerOrder":0,"tempo":60,"videoTransparency":50,"videoState":"on","textToSpeechLanguage":"ro"},{"isStage":false,"name":"Cat 2","variables":{},"lists":{},"broadcasts":{},"blocks":{"?^q)qSDL?G9M_{|/iKKo":{"opcode":"event_whenflagclicked","next":"E-Dyij3.{[^4A?fod0s!","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":-220,"y":100},"E-Dyij3.{[^4A?fod0s!":{"opcode":"motion_gotoxy","next":"lnSU9#[EImmaQJ||MBIw","parent":"?^q)qSDL?G9M_{|/iKKo","inputs":{"X":[1,[4,"0"]],"Y":[1,[4,"0"]]},"fields":{},"shadow":false,"topLevel":false},"lnSU9#[EImmaQJ||MBIw":{"opcode":"motion_pointindirection","next":"}l[bKZnw-AEF;s1PwWnH","parent":"E-Dyij3.{[^4A?fod0s!","inputs":{"DIRECTION":[1,[8,"90"]]},"fields":{},"shadow":false,"topLevel":false},"}l[bKZnw-AEF;s1PwWnH":{"opcode":"control_forever","next":null,"parent":"lnSU9#[EImmaQJ||MBIw","inputs":{"SUBSTACK":[2,"x!I9(wZUPzO#C0bre9l6"]},"fields":{},"shadow":false,"topLevel":false},"x!I9(wZUPzO#C0bre9l6":{"opcode":"control_wait","next":"A4WYwk!9Dx[W~4$:K!w!","parent":"}l[bKZnw-AEF;s1PwWnH","inputs":{"DURATION":[1,[5,"0.25"]]},"fields":{},"shadow":false,"topLevel":false},"A4WYwk!9Dx[W~4$:K!w!":{"opcode":"motion_movesteps","next":"_oV}B!t/:TwFCWcM!j^u","parent":"x!I9(wZUPzO#C0bre9l6","inputs":{"STEPS":[1,[4,"15"]]},"fields":{},"shadow":false,"topLevel":false},"_oV}B!t/:TwFCWcM!j^u":{"opcode":"motion_turnright","next":null,"parent":"A4WYwk!9Dx[W~4$:K!w!","inputs":{"DEGREES":[1,[4,"15"]]},"fields":{},"shadow":false,"topLevel":false}},"comments":{},"currentCostume":0,"costumes":[{"name":"cat 2","bitmapResolution":1,"dataFormat":"svg","assetId":"b19faf9c49fb425c52756c2b229f08cb","md5ext":"b19faf9c49fb425c52756c2b229f08cb.svg","rotationCenterX":128.79883,"rotationCenterY":36.221843067841604}],"sounds":[{"name":"meow2","assetId":"cf51a0c4088942d95bcc20af13202710","dataFormat":"wav","format":"","rate":44100,"sampleCount":26048,"md5ext":"cf51a0c4088942d95bcc20af13202710.wav"}],"volume":100,"layerOrder":1,"visible":true,"x":64.46815584543853,"y":-49.46815584543842,"size":100,"direction":180,"draggable":false,"rotationStyle":"left-right"}],"monitors":[],"extensions":[],"meta":{"semver":"3.0.0","vm":"1.5.68","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"}}
1+
{"targets":[{"isStage":true,"name":"Stage","variables":{"`jEk@4|i[#Fk?(8x)AV.-my variable":["my variable",0]},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"name":"xy-grid","bitmapResolution":1,"dataFormat":"svg","assetId":"4851f7b71585efa5d42cb3a0b2d5fadf","rotationCenterX":239.99996948242188,"rotationCenterY":180.00003051757812}],"sounds":[{"name":"pop","assetId":"83a9787d4cb6f3b7632b4ddfebf74367","dataFormat":"wav","format":"","rate":44100,"sampleCount":1032,"md5ext":"83a9787d4cb6f3b7632b4ddfebf74367.wav"}],"volume":100,"layerOrder":0,"tempo":60,"videoTransparency":50,"videoState":"on","textToSpeechLanguage":null},{"isStage":false,"name":"Sprite1","variables":{},"lists":{},"broadcasts":{},"blocks":{"h);AH_5G|0~qHIOykqR[":{"opcode":"event_whenflagclicked","next":"#LPC*%W4u5k@pisK?ZOo","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":260,"y":499},"#LPC*%W4u5k@pisK?ZOo":{"opcode":"motion_pointindirection","next":"t5L}|Pnnrhd]~~;7XVSr","parent":"h);AH_5G|0~qHIOykqR[","inputs":{"DIRECTION":[1,[8,"90"]]},"fields":{},"shadow":false,"topLevel":false},"t5L}|Pnnrhd]~~;7XVSr":{"opcode":"looks_setsizeto","next":"$^t/:qM0FiQ[=;!5CJPj","parent":"#LPC*%W4u5k@pisK?ZOo","inputs":{"SIZE":[1,[4,"100"]]},"fields":{},"shadow":false,"topLevel":false},"$^t/:qM0FiQ[=;!5CJPj":{"opcode":"control_forever","next":null,"parent":"t5L}|Pnnrhd]~~;7XVSr","inputs":{"SUBSTACK":[2,"fl)`k1)z!q_$SJE,!5V*"]},"fields":{},"shadow":false,"topLevel":false},"fl)`k1)z!q_$SJE,!5V*":{"opcode":"control_repeat","next":"Je|%BP4`t]5$2R^Oj(In","parent":"$^t/:qM0FiQ[=;!5CJPj","inputs":{"TIMES":[1,[6,"36"]],"SUBSTACK":[2,"jfgkF9^;39FUhECp5IS7"]},"fields":{},"shadow":false,"topLevel":false},"jfgkF9^;39FUhECp5IS7":{"opcode":"motion_turnleft","next":"]KC0ACOFLNh8-)yPBV)+","parent":"fl)`k1)z!q_$SJE,!5V*","inputs":{"DEGREES":[1,[4,"5"]]},"fields":{},"shadow":false,"topLevel":false},"]KC0ACOFLNh8-)yPBV)+":{"opcode":"looks_changesizeby","next":null,"parent":"jfgkF9^;39FUhECp5IS7","inputs":{"CHANGE":[1,[4,"10"]]},"fields":{},"shadow":false,"topLevel":false},"Je|%BP4`t]5$2R^Oj(In":{"opcode":"control_repeat","next":null,"parent":"fl)`k1)z!q_$SJE,!5V*","inputs":{"TIMES":[1,[6,"36"]],"SUBSTACK":[2,"$)TF5_|Z`[5)`d$7ztHw"]},"fields":{},"shadow":false,"topLevel":false},"$)TF5_|Z`[5)`d$7ztHw":{"opcode":"motion_turnleft","next":"2c56Jow3}N-Gk2%(1y`s","parent":"Je|%BP4`t]5$2R^Oj(In","inputs":{"DEGREES":[1,[4,"5"]]},"fields":{},"shadow":false,"topLevel":false},"2c56Jow3}N-Gk2%(1y`s":{"opcode":"looks_changesizeby","next":null,"parent":"$)TF5_|Z`[5)`d$7ztHw","inputs":{"CHANGE":[1,[4,"-10"]]},"fields":{},"shadow":false,"topLevel":false}},"comments":{},"currentCostume":0,"costumes":[{"name":"Bananas","bitmapResolution":1,"dataFormat":"svg","assetId":"59bb8ae4beca2b2aeedf392e382bd8c9","md5ext":"59bb8ae4beca2b2aeedf392e382bd8c9.svg","rotationCenterX":75.64650633901132,"rotationCenterY":61.10123227479535}],"sounds":[{"name":"Meow","assetId":"83c36d806dc92327b9e7049a565c6bff","dataFormat":"wav","format":"","rate":44100,"sampleCount":37376,"md5ext":"83c36d806dc92327b9e7049a565c6bff.wav"}],"volume":100,"layerOrder":1,"visible":true,"x":0,"y":0,"size":139.99999999999997,"direction":70,"draggable":false,"rotationStyle":"all around"}],"monitors":[],"extensions":[],"meta":{"semver":"3.0.0","vm":"1.5.76","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"}}

block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def evaluateBlockValue(self, eventContainer=eventContainer.EventContainer):
100100
return self.value
101101
elif self.opcode == "sensing_mousey": # mouse y
102102
newX, newY = pygame.mouse.get_pos()
103-
newY = newY - config.screenWidth // 2
103+
newY = newY - config.screenHeight // 2
104104
self.value = newY
105105
return self.value
106106

config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
# Project file name
2626
# If in test mode, set the Scratch project file to load.
27-
projectFileName: str = "projects/LeftRight.sb3"
27+
projectFileName: str = "projects/RotoZoom.sb3"
2828

2929
# Download cache size
3030
# Number of recent downloaded projects stored. 0 means infinity.
@@ -67,7 +67,7 @@
6767
# Screen width/height
6868
# Stage size. You can change that, but most projects won't work with it.
6969
# A scaling mode will be added later.
70-
# Vanilla is 480x360.
70+
# Vanilla is 480x360. Try 640x360 for 16/9 widescreen.
7171
screenWidth: int = 480
7272
screenHeight: int = 360
7373

lang/en.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ en:
4848
zero-division-error: "Project was trying to divide by 0"
4949
costumes-count: "%{sprite} has %{costumes} costumes"
5050
stage-not-found: "There is no stage sprite! Invalid project."
51-
new-sprite-rotation: "Sprite %{name} rotated to %{rot}"
51+
new-sprite-rotation: "Sprite %{name} rotated to %{rot} degrees"
52+
new-sprite-size: "Sprite %{name} resized to %{size}%"

lang/ro.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ ro:
4848
zero-division-error: "Proiectul a încercat să împartă la 0"
4949
costumes-count: "%{sprite} are %{costumes} costume"
5050
stage-not-found: "Nu există scena! Proiect invalid."
51-
new-sprite-rotation: "Personajul %{name} a fost rotit la %{rot}"
51+
new-sprite-rotation: "Personajul %{name} a fost rotit la %{rot} grade"
52+
new-sprite-size: "Personajul %{name} a fost redimensionat la %{size}%"

projects/RotoZoom.sb3

52.4 KB
Binary file not shown.

sb3Unpacker.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ def sb3Unpack(sb3):
5151
t.y = targetObj["y"]
5252
t.direction = targetObj["direction"]
5353
t.size = targetObj["size"]
54+
t.rotationStyle = targetObj["rotationStyle"]
5455
t.currentCostume = targetObj["currentCostume"]
5556
t.isStage = targetObj["isStage"]
5657
t.name = targetObj["name"]
57-
if not t.isStage:
58-
t.rotationStyle = targetObj["rotationStyle"]
59-
else:
60-
t.rotationStyle = "all around"
6158

6259
# Get costumes
6360
for costumeObj in targetObj["costumes"]:

scratch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ def execute(block, s, events=eventContainer.EventContainer()):
255255
elif opcode == "motion_pointindirection": # point in direction ()
256256
s.setRot(float(block.getInputValue("direction", eventContainer=events)))
257257

258+
elif opcode == "looks_changesizeby": # turn cw () degrees
259+
s.setSizeDelta(float(block.getInputValue("change", eventContainer=events)))
260+
261+
elif opcode == "looks_setsizeto": # turn cw () degrees
262+
s.setSize(float(block.getInputValue("size", eventContainer=events)))
263+
264+
elif opcode == "motion_pointindirection": # point in direction ()
265+
s.setRot(float(block.getInputValue("direction", eventContainer=events)))
266+
258267
elif opcode == "motion_movesteps": # move () steps
259268
offset = pygame.math.Vector2(float(block.getInputValue("steps", eventContainer=events)), 0)
260269
offset.rotate_ip(90 + s.direction)

targetSprite.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ def setXy(self, x, y):
8888
self.y = y
8989
# print(_("debug-prefix"), _("new-sprite-position", x=x, y=y, name=self.name), file=sys.stderr)
9090
#rect = self.sprite.get_rect(topleft=(self.x - self.target.costumes[self.target.currentCostume].rotationCenterX, self.y - self.target.costumes[self.target.currentCostume].rotationCenterY))
91-
offset = self.target.costumes[self.target.currentCostume].offset - pygame.math.Vector2(self.sprite.get_width() / 2, self.sprite.get_height() / 2)
91+
if not self.isStage:
92+
self.image = pygame.transform.smoothscale(self.sprite, (self.size, self.size))
93+
else:
94+
self.image = self.sprite
95+
offset = self.target.costumes[self.target.currentCostume].offset.elementwise() * self.size / 100 - pygame.math.Vector2(self.sprite.get_width() / 2, self.sprite.get_height() / 2).elementwise() * self.size / 100
9296

9397
if self.rotationStyle == "all around":
94-
self.image = pygame.transform.rotate(self.sprite, 90 - self.direction)
98+
self.image = pygame.transform.rotate(self.image, 90 - self.direction)
9599
offset.rotate_ip(90 + self.direction)
96100
elif self.rotationStyle == "left-right":
97101
angle = self.direction % 360
@@ -101,13 +105,12 @@ def setXy(self, x, y):
101105
else:
102106
self.flipped = False
103107
if self.flipped:
104-
self.image = pygame.transform.flip(self.sprite, True, False)
105-
offset = self.target.costumes[self.target.currentCostume].offset - pygame.math.Vector2(self.sprite.get_width() / 2, self.sprite.get_height() / 2)
108+
self.image = pygame.transform.flip(self.image, True, False)
109+
offset = self.target.costumes[self.target.currentCostume].offset.elementwise() * self.size / 100 - pygame.math.Vector2(self.sprite.get_width() / 2, self.sprite.get_height() / 2).elementwise() * self.size / 100
106110
else:
107-
self.image = self.sprite
108-
offset = pygame.math.Vector2(-self.target.costumes[self.target.currentCostume].offset.x, self.target.costumes[self.target.currentCostume].offset.y) - pygame.math.Vector2(-self.sprite.get_width() / 2, self.sprite.get_height() / 2)
111+
offset = pygame.math.Vector2(-self.target.costumes[self.target.currentCostume].offset.x, self.target.costumes[self.target.currentCostume].offset.y).elementwise() * self.size / 100 - pygame.math.Vector2(-self.sprite.get_width() / 2, self.sprite.get_height() / 2).elementwise() * self.size / 100
109112
else:
110-
self.image = self.sprite
113+
self.image = self.image
111114

112115
relativePosition = pygame.math.Vector2(self.spriteRect.centerx, self.spriteRect.centery)
113116
position = pygame.math.Vector2(self.x - self.sprite.get_width() / 2 + scratch.WIDTH / 2, self.y - self.sprite.get_height() / 2 + scratch.HEIGHT / 2)
@@ -132,6 +135,18 @@ def setRotDelta(self, drot):
132135
rot = self.direction + drot
133136
self.setRot(rot)
134137

138+
# Set self rotation
139+
def setSize(self, size):
140+
self.size = size
141+
print(_("debug-prefix"), _("new-sprite-size", size=size, name=self.name), file=sys.stderr)
142+
143+
self.setXy(self.x, self.y)
144+
145+
# Relatively set self rotation (turn)
146+
def setSizeDelta(self, dsize):
147+
size = self.size + dsize
148+
self.setSize(size)
149+
135150
# Change costume
136151
def setCostume(self, costumeId):
137152
self.target.currentCostume = costumeId % len(self.target.costumes)

0 commit comments

Comments
 (0)