Skip to content

Commit

Permalink
Yay! Sprite fencing now works just like in Scratch!
Browse files Browse the repository at this point in the history
  • Loading branch information
Secret-chest committed Feb 14, 2022
1 parent 111c76a commit 1193e49
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 17 deletions.
1 change: 1 addition & 0 deletions assets/4851f7b71585efa5d42cb3a0b2d5fadf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/4ad7b9275b0693c4d8d22ef1d37f655e.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/83a9787d4cb6f3b7632b4ddfebf74367.wav
Binary file not shown.
1 change: 0 additions & 1 deletion assets/9a4fb3ed82f74f5df24ade1a2aa48920.svg

This file was deleted.

3 changes: 0 additions & 3 deletions assets/cd21514d0531fdffb22204e0ec5ed84a.svg

This file was deleted.

1 change: 1 addition & 0 deletions assets/d6075b0ad126b663644c462b8b55ce3e.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/project.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"targets":[{"isStage":true,"name":"Stage","variables":{"`jEk@4|i[#Fk?(8x)AV.-my variable":["variabila mea",0]},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"assetId":"cd21514d0531fdffb22204e0ec5ed84a","name":"decor1","md5ext":"cd21514d0531fdffb22204e0ec5ed84a.svg","dataFormat":"svg","rotationCenterX":240,"rotationCenterY":180}],"sounds":[{"assetId":"83a9787d4cb6f3b7632b4ddfebf74367","name":"pop","dataFormat":"wav","format":"","rate":44100,"sampleCount":1032,"md5ext":"83a9787d4cb6f3b7632b4ddfebf74367.wav"}],"volume":100,"layerOrder":0,"tempo":60,"videoTransparency":50,"videoState":"on","textToSpeechLanguage":"ro"},{"isStage":false,"name":"Cosmicat","variables":{},"lists":{},"broadcasts":{},"blocks":{"!9~L/Ga.|^g)gSvQM;+$":{"opcode":"event_whenflagclicked","next":"~3R$9k/sN,qYmzk}}w$%","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":360,"y":264},"~3R$9k/sN,qYmzk}}w$%":{"opcode":"procedures_call","next":"vS#O_*:E~FzxQ[H.`?D1","parent":"!9~L/Ga.|^g)gSvQM;+$","inputs":{"arg0":[1,[10,"Message"]]},"fields":{},"shadow":false,"topLevel":false,"mutation":{"tagName":"mutation","children":[],"proccode":"​​log​​ %s","argumentids":"[\"arg0\"]","warp":"false"}},"vS#O_*:E~FzxQ[H.`?D1":{"opcode":"procedures_call","next":"*[]/86-Bc=S`:*9^4Qqk","parent":"~3R$9k/sN,qYmzk}}w$%","inputs":{"arg0":[1,[10,"Warning"]]},"fields":{},"shadow":false,"topLevel":false,"mutation":{"tagName":"mutation","children":[],"proccode":"​​warn​​ %s","argumentids":"[\"arg0\"]","warp":"false"}},"*[]/86-Bc=S`:*9^4Qqk":{"opcode":"procedures_call","next":null,"parent":"vS#O_*:E~FzxQ[H.`?D1","inputs":{"arg0":[1,[10,"Error!"]]},"fields":{},"shadow":false,"topLevel":false,"mutation":{"tagName":"mutation","children":[],"proccode":"​​error​​ %s","argumentids":"[\"arg0\"]","warp":"false"}}},"comments":{},"currentCostume":0,"costumes":[{"assetId":"9a4fb3ed82f74f5df24ade1a2aa48920","name":"Cosmicat","bitmapResolution":1,"md5ext":"9a4fb3ed82f74f5df24ade1a2aa48920.svg","dataFormat":"svg","rotationCenterX":47.2514000162754,"rotationCenterY":57.860045289335886}],"sounds":[],"volume":100,"layerOrder":1,"visible":true,"x":0,"y":0,"size":100,"direction":90,"draggable":false,"rotationStyle":"all around"}],"monitors":[],"extensions":[],"meta":{"semver":"3.0.0","vm":"0.2.0-prerelease.20220208083128","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36"}}
{"targets":[{"isStage":true,"name":"Stage","variables":{},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"assetId":"4851f7b71585efa5d42cb3a0b2d5fadf","name":"xy-grid","bitmapResolution":1,"md5ext":"4851f7b71585efa5d42cb3a0b2d5fadf.svg","dataFormat":"svg","rotationCenterX":239.99997000000002,"rotationCenterY":180.00002999999998}],"sounds":[],"volume":100,"layerOrder":0,"tempo":60,"videoTransparency":50,"videoState":"on","textToSpeechLanguage":"ro"},{"isStage":false,"name":"test4","variables":{},"lists":{},"broadcasts":{},"blocks":{"2*2cr|ML_HC_GyWVj^(v":{"opcode":"event_whenflagclicked","next":"L*/]pE8:_D+Dd~IYaw|A","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":44,"y":44},"L*/]pE8:_D+Dd~IYaw|A":{"opcode":"motion_gotoxy","next":"~[.-N+y|%~1/ppm13nfG","parent":"2*2cr|ML_HC_GyWVj^(v","inputs":{"X":[1,[4,"0"]],"Y":[1,[4,"0"]]},"fields":{},"shadow":false,"topLevel":false},"!!*LiE%JmR)yTT8t*IEw":{"opcode":"control_forever","next":null,"parent":"~[.-N+y|%~1/ppm13nfG","inputs":{"SUBSTACK":[3,"8mH24?BwR!oVHt[sC~k6",null]},"fields":{},"shadow":false,"topLevel":false},"~[.-N+y|%~1/ppm13nfG":{"opcode":"control_wait","next":"!!*LiE%JmR)yTT8t*IEw","parent":"L*/]pE8:_D+Dd~IYaw|A","inputs":{"DURATION":[1,[5,"2"]]},"fields":{},"shadow":false,"topLevel":false},"|DafiWiy1M,Flv:1[OR5":{"opcode":"motion_changexby","next":null,"parent":"8mH24?BwR!oVHt[sC~k6","inputs":{"DX":[1,[4,"4"]]},"fields":{},"shadow":false,"topLevel":false},"8mH24?BwR!oVHt[sC~k6":{"opcode":"control_wait","next":"|DafiWiy1M,Flv:1[OR5","parent":"!!*LiE%JmR)yTT8t*IEw","inputs":{"DURATION":[1,[5,"0.1"]]},"fields":{},"shadow":false,"topLevel":false}},"comments":{},"currentCostume":0,"costumes":[{"assetId":"4ad7b9275b0693c4d8d22ef1d37f655e","name":"test5","bitmapResolution":1,"md5ext":"4ad7b9275b0693c4d8d22ef1d37f655e.svg","dataFormat":"svg","rotationCenterX":12.799997999999988,"rotationCenterY":12.79999799999996}],"sounds":[],"volume":100,"layerOrder":1,"visible":true,"x":240,"y":0,"size":100,"direction":0,"draggable":false,"rotationStyle":"all around"},{"isStage":false,"name":"test3","variables":{},"lists":{},"broadcasts":{},"blocks":{",X2+Ba;j.{5=M,W#sqNq":{"opcode":"event_whenflagclicked","next":"eoD|.{boV!3KJ*wa?2Tl","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":71,"y":167},"eoD|.{boV!3KJ*wa?2Tl":{"opcode":"motion_gotoxy","next":"1Pg.FL7Xxn;dj#]8?o8,","parent":",X2+Ba;j.{5=M,W#sqNq","inputs":{"X":[1,[4,"0"]],"Y":[1,[4,"0"]]},"fields":{},"shadow":false,"topLevel":false},"_X?nnf=yDYoRGtKkk~yn":{"opcode":"control_forever","next":null,"parent":"1Pg.FL7Xxn;dj#]8?o8,","inputs":{"SUBSTACK":[2,"!O@Z6z[3_~LlIfmxkS8F"]},"fields":{},"shadow":false,"topLevel":false},"ap#n-(zet,2tZTR!dO%v":{"opcode":"motion_changeyby","next":null,"parent":"!O@Z6z[3_~LlIfmxkS8F","inputs":{"DY":[1,[4,"4"]]},"fields":{},"shadow":false,"topLevel":false},"1Pg.FL7Xxn;dj#]8?o8,":{"opcode":"control_wait","next":"_X?nnf=yDYoRGtKkk~yn","parent":"eoD|.{boV!3KJ*wa?2Tl","inputs":{"DURATION":[1,[5,"1"]]},"fields":{},"shadow":false,"topLevel":false},"!O@Z6z[3_~LlIfmxkS8F":{"opcode":"control_wait","next":"ap#n-(zet,2tZTR!dO%v","parent":"_X?nnf=yDYoRGtKkk~yn","inputs":{"DURATION":[1,[5,"0.1"]]},"fields":{},"shadow":false,"topLevel":false}},"comments":{},"currentCostume":0,"costumes":[{"assetId":"d6075b0ad126b663644c462b8b55ce3e","name":"test","bitmapResolution":1,"md5ext":"d6075b0ad126b663644c462b8b55ce3e.svg","dataFormat":"svg","rotationCenterX":31.99998500000001,"rotationCenterY":31.999995000000013}],"sounds":[],"volume":100,"layerOrder":2,"visible":true,"x":0,"y":196,"size":100,"direction":0,"draggable":false,"rotationStyle":"all around"}],"monitors":[],"extensions":[],"meta":{"semver":"3.0.0","vm":"0.2.0-prerelease.20220208083128","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36"}}
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# Project file name
# If the "manual" mode is chosen, set the Scratch project file to load.
projectFileName: str = "projects/sa-logs.sb3"
projectFileName: str = "projects/sprite-fencing2-slow.sb3"

# Extract on project run
# Set whether to extract the project assets on run.
Expand Down Expand Up @@ -46,7 +46,7 @@
# Allow off-screen sprites
# Again, most projects will break.
# Vanilla is false.
allowOffScreenSprites: bool = True
allowOffScreenSprites: bool = False


# "For this project" values
Expand Down
Binary file added projects/sprite-fencing2-slow.sb3
Binary file not shown.
2 changes: 1 addition & 1 deletion sb3Unpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def sb3Unpack(sb3):
b.topLevel = blockObj["topLevel"]
b.inputs = blockObj["inputs"]
b.fields = blockObj["fields"]
if "mutation" in blockObj:
if b.opcode == "procedures_call":
b.proccode = blockObj["mutation"]["proccode"]
b.warp = blockObj["mutation"]["warp"]
b.blockRan = False
Expand Down
2 changes: 1 addition & 1 deletion scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def execute(block, s, keys=[]):
block.screenRefresh = True
if not block.waiting:
# Get time delay and convert it to milliseconds
block.timeDelay = int(round(float(int(block.getInputValue("duration"))) * 1000))
block.timeDelay = int(round(float(float(block.getInputValue("duration"))) * 1000))
block.waiting = True
block.executionTime = 0
print("DEBUG: Waiting for", block.timeDelay, "ms", file=sys.stderr)
Expand Down
16 changes: 8 additions & 8 deletions targetSprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ def setXy(self, x, y):
# Do sprite fencing
if not config.allowOffScreenSprites:
if self.rect.width > 32:
if x > scratch.WIDTH - scratch.WIDTH / 2 + self.rect.width - 16:
x = scratch.WIDTH - scratch.WIDTH / 2 + self.rect.width - 16
if x < scratch.WIDTH / 2 - scratch.WIDTH - self.rect.width + 16:
x = scratch.WIDTH / 2 - scratch.WIDTH - self.rect.width + 16
if y > scratch.HEIGHT - scratch.HEIGHT / 2 + self.rect.height - 16:
y = scratch.HEIGHT - scratch.HEIGHT / 2 + self.rect.height - 16
if y < scratch.HEIGHT / 2 - scratch.HEIGHT - self.rect.height + 16:
y = scratch.HEIGHT / 2 - scratch.HEIGHT - self.rect.height + 16
if x > scratch.WIDTH - scratch.WIDTH / 2 + (self.rect.width / 2 - 16):
x = scratch.WIDTH - scratch.WIDTH / 2 + (self.rect.width / 2 - 16)
if x < scratch.WIDTH / 2 - scratch.WIDTH - (self.rect.width / 2 + 16):
x = scratch.WIDTH / 2 - scratch.WIDTH - (self.rect.width / 2 + 16)
if y > scratch.HEIGHT - scratch.HEIGHT / 2 + (self.rect.height / 2 - 16):
y = scratch.HEIGHT - scratch.HEIGHT / 2 + (self.rect.height / 2 - 16)
if y < scratch.HEIGHT / 2 - scratch.HEIGHT - (self.rect.height / 2 + 16):
y = scratch.HEIGHT / 2 - scratch.HEIGHT - (self.rect.height / 2 + 16)
else:
if x > scratch.WIDTH - scratch.WIDTH / 2:
x = scratch.WIDTH - scratch.WIDTH / 2
Expand Down

0 comments on commit 1193e49

Please sign in to comment.