#πŸ”’ Pygame Tutorial help

24 messages Β· Page 1 of 1 (latest)

elder quarry
#

I'm watching a pygame tutorial and there's an update function they use. Can someone explain what it does please, when I search online it's talking about dictionaries only

boreal wharfBOT
#

@elder quarry

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

iron tapir
#

open scripts.entities

#

it might be custom and not a native pygame class

elder quarry
#
import pygame

class PhysicsEntity:
    def __init__(self, game, e_type, position, size):
        self.game = game
        self.type = e_type
        self.position = list(position)
        self.size = size
        self.velocity = [0, 0]
   
    def update(self, movement=(0, 0)):
        frame_movement = (movement[0] + self.velocity[0], movement[1] + self.velocity[1])

        self.position[0] += frame_movement[0]
        self.position[1] += frame_movement[1]

    def render(self, surface):
        surface.blit(self.game.assets['player'], self.position)
#

This is entities file

alpine fjord
#

Is there a specific part you're confused about?

#

Are you familiar with OOP?

iron tapir
elder quarry
#

I'm just wondering what ```py
self.player.update((self.movement[1] - self.movement[0], 0))

#

does

elder quarry
#

sorry I made a silly error

#

I didn't see that

elder quarry
#

thanks guys

alpine fjord
iron tapir
#
def update(self, movement=(0, 0)):
    frame_movement = (movement[0] + self.velocity[0], movement[1] + self.velocity[1])

    self.position[0] += frame_movement[0]
    self.position[1] += frame_movement[1]
#

this is what self.player.update will call

elder quarry
boreal wharfBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.