Skip to content

Commit 54e060d

Browse files
committed
Update 2
1 parent b1ac186 commit 54e060d

10 files changed

Lines changed: 51 additions & 42 deletions

assets/cd21514d0531fdffb22204e0ec5ed84a.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

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":"backdrop1","dataFormat":"svg","assetId":"cd21514d0531fdffb22204e0ec5ed84a","md5ext":"cd21514d0531fdffb22204e0ec5ed84a.svg","rotationCenterX":240,"rotationCenterY":180}],"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":"{$QhU(~Y{qa/r`=G{mGX","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":300,"y":340},"{$QhU(~Y{qa/r`=G{mGX":{"opcode":"control_repeat","next":"n?!h.4XtS|xZ{E!@:LIA","parent":"?^q)qSDL?G9M_{|/iKKo","inputs":{"TIMES":[1,[6,"24"]],"SUBSTACK":[2,"hqsMZs4WIfY8fR:Z$[V0"]},"fields":{},"shadow":false,"topLevel":false},"hqsMZs4WIfY8fR:Z$[V0":{"opcode":"motion_turnright","next":null,"parent":"{$QhU(~Y{qa/r`=G{mGX","inputs":{"DEGREES":[1,[4,"15"]]},"fields":{},"shadow":false,"topLevel":false},"n?!h.4XtS|xZ{E!@:LIA":{"opcode":"control_repeat","next":null,"parent":"{$QhU(~Y{qa/r`=G{mGX","inputs":{"TIMES":[1,[6,"24"]],"SUBSTACK":[2,"(n:YlSsRp5g^wzTXf%;G"]},"fields":{},"shadow":false,"topLevel":false},"(n:YlSsRp5g^wzTXf%;G":{"opcode":"motion_turnleft","next":null,"parent":"n?!h.4XtS|xZ{E!@:LIA","inputs":{"DEGREES":[1,[4,"15"]]},"fields":{},"shadow":false,"topLevel":false}},"comments":{},"currentCostume":0,"costumes":[{"name":"cat 2","bitmapResolution":1,"dataFormat":"svg","assetId":"a5be96044eb1c9e916de6d1c5818d89d","md5ext":"a5be96044eb1c9e916de6d1c5818d89d.svg","rotationCenterX":128.79883728212386,"rotationCenterY":36.22184985320345}],"sounds":[{"name":"meow2","assetId":"cf51a0c4088942d95bcc20af13202710","dataFormat":"wav","format":"","rate":44100,"sampleCount":26048,"md5ext":"cf51a0c4088942d95bcc20af13202710.wav"}],"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":"1.2.54","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"}}
1+
{"targets":[{"isStage":true,"name":"Stage","variables":{},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"name":"xy-grid","bitmapResolution":1,"dataFormat":"svg","assetId":"4851f7b71585efa5d42cb3a0b2d5fadf","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":"{$QhU(~Y{qa/r`=G{mGX","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":300,"y":340},"{$QhU(~Y{qa/r`=G{mGX":{"opcode":"control_repeat","next":null,"parent":"?^q)qSDL?G9M_{|/iKKo","inputs":{"TIMES":[1,[6,"12"]],"SUBSTACK":[2,"hqsMZs4WIfY8fR:Z$[V0"]},"fields":{},"shadow":false,"topLevel":false},"hqsMZs4WIfY8fR:Z$[V0":{"opcode":"motion_turnright","next":null,"parent":"{$QhU(~Y{qa/r`=G{mGX","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":0,"y":0,"size":100,"direction":90,"draggable":false,"rotationStyle":"all around"}],"monitors":[],"extensions":[],"meta":{"semver":"3.0.0","vm":"1.5.48","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"}}

background.png

-777 Bytes
Binary file not shown.

config.py

Lines changed: 1 addition & 1 deletion
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/Rotation2.sb3"
27+
projectFileName: str = "projects/Rotation2-medium.sb3"
2828

2929
# Download cache size
3030
# Number of recent downloaded projects stored. 0 means infinity.

main.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
from targetSprite import TargetSprite
7676
import eventContainer
7777
import select
78+
from scratch import display, setProject, mainWindow
7879

7980
sys.stdout = sys.__stdout__
8081

@@ -119,35 +120,12 @@ def buttonbox(self):
119120
self.bind("<Escape>", lambda event: self.cancelPressed())
120121

121122

122-
# Start tkinter for showing some popups, and hide main window
123-
mainWindow = tk.Tk()
124-
mainWindow.withdraw()
125-
126123
# Clean the cache if limit is exceeded
127124
downloads = sorted(Path("./download/").iterdir(), key=os.path.getmtime)
128125
downloadsToDelete = downloads[config.cachedDownloads:]
129126
for f in downloadsToDelete:
130127
os.remove(f)
131128

132-
# Get project file name based on options and arguments
133-
if len(sys.argv) > 1:
134-
setProject = sys.argv[1]
135-
else:
136-
if config.testMode:
137-
if not config.projectFileName.endswith(".sb3"):
138-
if "http" not in config.projectFileName\
139-
or "https" not in config.projectFileName:
140-
setProject = downloader.downloadByID(config.projectFileName, "./download")
141-
else:
142-
setProject = downloader.downloadByURL(config.projectFileName, "./download")
143-
else:
144-
setProject = config.projectFileName
145-
else:
146-
fileTypes = [(_("sb3-desc"), ".sb3"), (_("all-files-desc"), ".*")]
147-
setProject = filedialog.askopenfilename(parent=mainWindow,
148-
initialdir=os.getcwd(),
149-
title=_("choose-project-title"),
150-
filetypes=fileTypes)
151129

152130
# Get project data and create sprites
153131
targets, project = sb3Unpacker.sb3Unpack(setProject)
@@ -174,15 +152,6 @@ def buttonbox(self):
174152
HEIGHT = config.projectScreenHeight
175153
WIDTH = config.projectScreenWidth
176154

177-
# Get project name and set icon
178-
projectName = Path(setProject).stem
179-
icon = pygame.image.load("icon.svg")
180-
181-
# Create project player and window
182-
display = pygame.display.set_mode([WIDTH, HEIGHT])
183-
pygame.display.set_caption(_("window-title", projectName=projectName, s2pVersionString="Scratch2Python " + __version__))
184-
pygame.display.set_icon(icon)
185-
186155
# Extract if requested
187156
if config.extractOnProjectRun:
188157
print(_("extracting-project"))

projects/Balls.sb3

7.83 KB
Binary file not shown.

projects/Rotation2-medium.sb3

29.3 KB
Binary file not shown.

projects/Rotation2-small.sb3

29.3 KB
Binary file not shown.

scratch.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
import time
1616
from datetime import datetime
1717
import eventContainer
18+
from pathlib import Path
19+
import tkinter as tk
20+
import downloader
21+
from tkinter import filedialog
22+
import tkinter.simpledialog
23+
24+
__version__ = "v0.8.0"
25+
__author__ = "Secret-chest"
1826

1927
i18n.set("locale", config.language)
2028
i18n.set("filename_format", "{locale}.{format}")
@@ -32,9 +40,42 @@ class SpriteNotFoundError(Exception):
3240
sys.stdout = open(os.devnull, "w")
3341

3442

43+
# Start tkinter for showing some popups, and hide main window
44+
mainWindow = tk.Tk()
45+
mainWindow.withdraw()
46+
47+
48+
# Get project file name based on options and arguments
49+
if len(sys.argv) > 1:
50+
setProject = sys.argv[1]
51+
else:
52+
if config.testMode:
53+
if not config.projectFileName.endswith(".sb3"):
54+
if "http" not in config.projectFileName\
55+
or "https" not in config.projectFileName:
56+
setProject = downloader.downloadByID(config.projectFileName, "./download")
57+
else:
58+
setProject = downloader.downloadByURL(config.projectFileName, "./download")
59+
else:
60+
setProject = config.projectFileName
61+
else:
62+
fileTypes = [(_("sb3-desc"), ".sb3"), (_("all-files-desc"), ".*")]
63+
setProject = filedialog.askopenfilename(parent=mainWindow,
64+
initialdir=os.getcwd(),
65+
title=_("choose-project-title"),
66+
filetypes=fileTypes)
67+
68+
3569
HEIGHT = config.projectScreenHeight
3670
WIDTH = config.projectScreenWidth
3771

72+
# Create project player and window
73+
projectName = Path(setProject).stem
74+
icon = pygame.image.load("icon.svg")
75+
display = pygame.display.set_mode([WIDTH, HEIGHT])
76+
pygame.display.set_caption(_("window-title", projectName=projectName, s2pVersionString="Scratch2Python " + __version__))
77+
pygame.display.set_icon(icon)
78+
3879
# Key maps to convert the key option in blocks to Pygame constants
3980
KEY_MAPPING = {
4081
"up arrow": pygame.K_UP,

targetSprite.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@ def setXy(self, x, y):
8484
# Set X and Y
8585
self.x = x
8686
self.y = y
87-
print(_("debug-prefix"), _("new-sprite-position", x=x, y=y, name=self.name), file=sys.stderr)
87+
print("aici")
88+
# print(_("debug-prefix"), _("new-sprite-position", x=x, y=y, name=self.name), file=sys.stderr)
89+
#rect = self.sprite.get_rect(topleft=(self.x - self.target.costumes[self.target.currentCostume].rotationCenterX, self.y - self.target.costumes[self.target.currentCostume].rotationCenterY))
8890
offset = pygame.Vector2(self.target.costumes[self.target.currentCostume].rotationCenterX, self.target.costumes[self.target.currentCostume].rotationCenterY)
89-
offset = offset.rotate(90 + self.direction)
90-
print(offset)
91+
offset.rotate_ip(90 + self.direction)
92+
self.image = pygame.transform.rotozoom(self.sprite, 90 - self.direction, 1)
93+
# offset = pygame.Vector2(0, 0)
9194
self.rect.x = scratch.WIDTH // 2 + self.x + offset.x
9295
self.rect.y = scratch.HEIGHT // 2 - self.y + offset.y
96+
print(self.rect.x, self.rect.y, "/", self.x, self.y, "/", offset.x, offset.y)
9397

9498
# Relatively set self position
9599
def setXyDelta(self, dx, dy):
@@ -101,9 +105,7 @@ def setXyDelta(self, dx, dy):
101105
def setRot(self, rot):
102106
self.direction = rot
103107
print(_("debug-prefix"), _("new-sprite-rotation", rot=rot, name=self.name), file=sys.stderr)
104-
image_rect = self.sprite.get_rect(topleft=(self.rect.x - self.target.costumes[self.target.currentCostume].rotationCenterX, self.rect.y - self.target.costumes[self.target.currentCostume].rotationCenterX))
105108

106-
self.image = pygame.transform.rotozoom(self.sprite, 90 - self.direction, 1)
107109
self.setXy(self.x, self.y)
108110

109111
# Relatively set self rotation (turn)

0 commit comments

Comments
 (0)