Trashmaster/agent.py

44 lines
875 B
Python
Raw Normal View History

2022-03-09 22:39:34 +01:00
import pygame.image
2022-04-07 19:40:39 +02:00
2022-03-09 22:39:34 +01:00
class trashmaster(pygame.sprite.Sprite):
2022-04-07 19:40:39 +02:00
def __init__(self, x, y, img):
2022-03-09 22:39:34 +01:00
super().__init__()
2022-04-07 19:40:39 +02:00
self.width = x
self.height = y
2022-03-22 11:55:01 +01:00
self.x = 0
self.y = 0
2022-04-07 19:40:39 +02:00
2022-03-11 13:00:11 +01:00
self.image = pygame.image.load(img)
2022-04-07 19:40:39 +02:00
self.image = pygame.transform.scale(self.image, (self.width, self.height))
2022-03-09 22:39:34 +01:00
self.rect = self.image.get_rect()
2022-03-22 11:55:01 +01:00
def movement(self, key, vel):
if key == pygame.K_LEFT:
self.x -= vel
2022-04-07 19:40:39 +02:00
2022-03-22 11:55:01 +01:00
if key == pygame.K_RIGHT:
self.x += vel
2022-04-07 19:40:39 +02:00
2022-03-22 11:55:01 +01:00
if key == pygame.K_UP:
self.y -= vel
2022-04-07 19:40:39 +02:00
2022-03-22 11:55:01 +01:00
if key == pygame.K_DOWN:
self.y += vel
2022-04-07 19:40:39 +02:00
return (self.x, self.y)
def move_up(self):
self.y -= 64
def move_down(self):
self.y += 64
def move_right(self):
self.x += 64
def move_left(self):
self.x -= 64