I'm creating a game in PyGame where I need to pick up a plate and move it around the kitchen. so far I have managed to have the player collide and interact with the object but have not been able to pick up and move the object around the screen. I've been stuck on this issue for weeks and any help would be massively appreciated.
def new(self):
self.plate = pg.sprite.Group()
for tile_object in self.map.tmxdata.objects:
if tile_object.name == 'plate':
self.plate.x = tile_object.x
self.plate.y = tile_object.y
Plate(self, self.plate.x, self.plate.y)
touch=False
if (tx-32)<= x and (tx+32) >= x and (ty-64)<= y and (ty+64) >= y:
touch = True
elif (ty-32)<= y and (ty+32) >= y and (tx-64)<= x and (tx+64) >= x:
touch = True
return(touch)
def update(self):
self.all_sprites.update()
x = self.player.pos[0]
y = self.player.pos[1]
holding = 0
keys_pressed = self.get_pg_events()```
touch = self.grid_location(self.player.pos[0] ,self.player.pos[1] ,self.plate.x, self.plate.y)
if touch == True:
self.space_bar_plate.reposition(self.player.pos[0], self.player.pos[1]+64)
keys = pg.key.get_pressed()
if keys[pg.K_SPACE]:
now = pg.time.get_ticks()
if now - self.player.last_action > ACTION_RATE:
self.player.last_action = now
self.plate.x = math.cos(self.player.rot*math.pi/180)*80+self.player.pos[0]
self.plate.y = math.sin(self.player.rot*math.pi/180)*80+self.player.pos[1]
self.plate = Plate(self, self.plate.x , self.plate.y)
else:
self.space_bar_plate.reposition(-32, 0)```
in my sprites file
class Plate(pg.sprite.Sprite):
def __init__(self, game, x, y):
self.groups = game.all_sprites, game.plate
pg.sprite.Sprite.__init__(self, self.groups)
self.game = game
self.image = game.plate_img
self.rect = self.image.get_rect()
self.pos = (x, y)
self.rect.center = self.pos
def reposition(self, x, y):
self.pos = (x, y)
self.rect.center = self.pos
