2023-03-30 15:51:20 +02:00
|
|
|
import pygame
|
|
|
|
from config import *
|
|
|
|
|
|
|
|
class Agent(pygame.sprite.Sprite):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, game, x, y):
|
|
|
|
self.game = game
|
|
|
|
self.groups = self.game.all_sprites
|
|
|
|
pygame.sprite.Sprite.__init__(self, self.groups)
|
|
|
|
|
|
|
|
self.x = x * TILE_SIZE
|
|
|
|
self.y = y * TILE_SIZE
|
|
|
|
self.width = TILE_SIZE
|
|
|
|
self.height = TILE_SIZE
|
|
|
|
|
|
|
|
self.x_change = 0
|
|
|
|
self.y_change = 0
|
|
|
|
|
|
|
|
self.AGENT_IMG = pygame.image.load("./zdjecia/gandalf.png")
|
|
|
|
self.AGENT = pygame.transform.scale(self.AGENT_IMG,(64,64))
|
|
|
|
|
|
|
|
self.image = pygame.Surface([self.width, self.height])
|
|
|
|
self.image.blit(self.AGENT, (0,0))
|
|
|
|
self.image.set_colorkey((0, 0, 0))
|
|
|
|
|
|
|
|
self.rect = self.image.get_rect()
|
|
|
|
self.rect.x = self.x
|
|
|
|
self.rect.y = self.y
|
|
|
|
|
2023-03-30 19:54:48 +02:00
|
|
|
self.level = 1
|
2023-03-30 15:51:20 +02:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self.movement()
|
|
|
|
|
|
|
|
self.rect.x += self.x_change
|
|
|
|
self.rect.y += self.y_change
|
|
|
|
|
|
|
|
self.x_change = 0
|
|
|
|
self.y_change = 0
|
|
|
|
|
|
|
|
def movement(self):
|
|
|
|
keys = pygame.key.get_pressed()
|
|
|
|
if keys[pygame.K_LEFT] and self.rect.x > 0:
|
|
|
|
self.x_change -= TILE_SIZE
|
|
|
|
if keys[pygame.K_RIGHT] and self.rect.x < 832 - 64:
|
|
|
|
self.x_change += TILE_SIZE
|
|
|
|
if keys[pygame.K_UP] and self.rect.y > 0:
|
|
|
|
self.y_change -= TILE_SIZE
|
|
|
|
if keys[pygame.K_DOWN] and self.rect.y < 832 - 64:
|
|
|
|
self.y_change += TILE_SIZE
|