Skip to content

Commit f10bf03

Browse files
committed
Update
1 parent 7fd6898 commit f10bf03

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
# Enable debug messages
4242
# Set whether debug messages (messages to stderr) should be allowed.
43-
enableDebugMessages: bool = False
43+
enableDebugMessages: bool = True
4444

4545
# Enable pygame welcome message
4646
# Enable or disable the "

targetSprite.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(self, target):
4545
self.sprite = sprite
4646
self.image = self.sprite.copy()
4747
self.rect = self.image.get_rect()
48+
self.spriteRect = self.sprite.get_rect()
4849
self.isStage = target.isStage
4950
self.imageSize = sprite.get_size()
5051
if self.target.name == "Stage":
@@ -84,13 +85,8 @@ def setXy(self, x, y):
8485
self.x = x
8586
self.y = y
8687
print(_("debug-prefix"), _("new-sprite-position", x=x, y=y, name=self.name), file=sys.stderr)
87-
# Scratch really is weird.
88-
if self.isBitmap:
89-
self.rect.x = self.x + scratch.WIDTH // 2 - round(self.target.costumes[self.target.currentCostume].rotationCenterX) + round(self.imageSize[0] / 2)
90-
self.rect.y = scratch.HEIGHT // 2 - self.y - round(self.target.costumes[self.target.currentCostume].rotationCenterY) + round(self.imageSize[1] / 2)
91-
else:
92-
self.rect.x = self.x + scratch.WIDTH // 2 - round(self.target.costumes[self.target.currentCostume].rotationCenterX)
93-
self.rect.y = scratch.HEIGHT // 2 - self.y - round(self.target.costumes[self.target.currentCostume].rotationCenterY)
88+
self.rect.x = self.x + scratch.WIDTH // 2 - round(self.target.costumes[self.target.currentCostume].rotationCenterX) + (self.spriteRect.width - self.rect.width) / 2
89+
self.rect.y = scratch.HEIGHT // 2 - self.y - round(self.target.costumes[self.target.currentCostume].rotationCenterY) + (self.spriteRect.height - self.rect.height) / 2
9490

9591
# Relatively set self position
9692
def setXyDelta(self, dx, dy):
@@ -103,10 +99,19 @@ def setRot(self, rot):
10399
self.direction = rot
104100
print(_("debug-prefix"), _("new-sprite-rotation", rot=rot, name=self.name), file=sys.stderr)
105101
center = self.sprite.get_rect().center # TODO get correct rotation centre of sprite
106-
print(center, (self.rect.x + center[0], self.rect.y - center[1]), (self.rect.x, self.rect.y), (self.x, self.y), self.direction)
102+
# self.image = pygame.transform.rotate(self.sprite, 90 - self.direction)
103+
# self.rect = self.image.get_rect(center=(self.rect.x + center[0], self.rect.y - center[1]))
104+
# # TODO calculate correct rotation centre
105+
# self.setXy(self.x, self.y)
106+
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))
107+
#offset_center_to_pivot = pygame.math.Vector2((self.rect.x, self.rect.y)) - image_rect.center
108+
offset_center_to_pivot = pygame.math.Vector2((134, 36))
109+
print(offset_center_to_pivot)
110+
rotated_offset = offset_center_to_pivot.rotate(90 - self.direction)
111+
rotated_image_center = (self.rect.x - rotated_offset.x, self.rect.y - rotated_offset.y)
112+
107113
self.image = pygame.transform.rotate(self.sprite, 90 - self.direction)
108-
self.rect = self.image.get_rect(center=(self.rect.x + center[0], self.rect.y - center[1]))
109-
# TODO calculate correct rotation centre
114+
self.rect = self.image.get_rect(center=rotated_image_center)
110115
self.setXy(self.x, self.y)
111116

112117
# Relatively set self rotation (turn)

0 commit comments

Comments
 (0)