Here I have 2 classes; Player
and Obstacle
. Player
has some basic movement with input from keys. I change Player.rect.x
to change the position of player. In Obstacle
I have a code that detects if the Player.rect.x
reaches the same x postion as Obstacle.rect.x
, if so print "test".
Code:
import pygame
pygame.init()
class Player(pygame.sprite.Sprite):
def __init__(self):
#initializing code
def movement(self):
#code for movement
def update(self):
self.movement()
class Obstacle(pygame.sprite.Sprite):
def __init__(self):
#intitializing code
def test(self):
player_char = Player()
if self.rect.x == player_char.rect.x :
print("test")
def update(self):
self.test()
I used print statements to figure out that player_char.rect.x
changes in the Player
class but not in the Obstacle
class. Hence player_char.rect.x
stays the same as it was when we did move it. player_char.rect.x
simply doesn't update so the if statement will never become true. How can I update player_char.rect.x
in Obstacle
class also?
I am pretty new to python so this might turn out to be a stupid mistake.