I am making a game. In the
def update(self):bit I have the code
player_hitbox = Rect(self.player.position-12, self.player.position-12, 24, 24) if self.enemy1.frame.intersects(player_hitbox): self.gameOver()
However, when I run the game, there is this error:
Traceback (most recent call last): File "/var/containers/Bundle/Application/D2B5AEDE-2A6F-4263-8217-08037B4C2570/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/scene.py", line 199, in _draw self.update() File "/private/var/mobile/Containers/Shared/AppGroup/6311A336-2012-414A-9433-E66D7EBF131D/Pythonista3/Documents/impossibleGame.py", line 147, in update player_hitbox = Rect(self.player.position-12, self.player.position-12, 24, 24) TypeError: Unsupported operand type(s)
How can I get it so when the player’s hit box intersects enemy1’s frame, it runs
@rex_noctis I don't know your code but is self.player.position a number or a couple of coordinates? It has to be a single number/integer/float.
I just realised the error. It’s meant to be
Rect(self.player.position.x-12, self.player.position.y-12, 24, 24)I forgot the
.xon the end of position. Thanks for making me notice it!