omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Hitbox error

    Pythonista
    frame error intersect scene
    2
    3
    3205
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • rex_noctis
      rex_noctis last edited by rex_noctis

      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 self.gameOver()?

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @rex_noctis last edited by cvp

        @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.

        1 Reply Last reply Reply Quote 0
        • rex_noctis
          rex_noctis last edited by

          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 .x on the end of position. Thanks for making me notice it!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors