move agent_movement to agent class #4
28
agent.py
28
agent.py
@ -1,14 +1,30 @@
|
|||||||
import pygame.image
|
import pygame.image
|
||||||
|
|
||||||
class trashmaster(pygame.sprite.Sprite):
|
class trashmaster(pygame.sprite.Sprite):
|
||||||
def __init__(self,x,y,img,vel):
|
|
||||||
|
def __init__(self,x,y,img):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.x=x
|
self.width=x
|
||||||
self.y=y
|
self.height=y
|
||||||
self.img = img
|
|
||||||
self.velocity = vel
|
self.x = 0
|
||||||
|
self.y = 0
|
||||||
|
|
||||||
self.image = pygame.image.load(img)
|
self.image = pygame.image.load(img)
|
||||||
self.image = pygame.transform.scale(self.image, (self.x,self.y))
|
self.image = pygame.transform.scale(self.image, (self.width,self.height))
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
|
|
||||||
|
def movement(self, key, vel):
|
||||||
|
if key == pygame.K_LEFT:
|
||||||
|
self.x -= vel
|
||||||
|
|
||||||
|
if key == pygame.K_RIGHT:
|
||||||
|
self.x += vel
|
||||||
|
|
||||||
|
if key == pygame.K_UP:
|
||||||
|
self.y -= vel
|
||||||
|
|
||||||
|
if key == pygame.K_DOWN:
|
||||||
|
self.y += vel
|
||||||
|
return (self.x, self.y)
|
23
main.py
23
main.py
@ -23,19 +23,20 @@ class WalleGame():
|
|||||||
def update_window(self):
|
def update_window(self):
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
def draw_trashmaster(self, smieciara: trashmaster):
|
def draw_trashmaster(self, smieciara: trashmaster, pos):
|
||||||
smieciara_list = pygame.sprite.Group()
|
# pos => (x, y)
|
||||||
smieciara_list.add(smieciara)
|
self.screen.blit(smieciara.image, pos )
|
||||||
smieciara_list.draw(self.screen)
|
|
||||||
|
def reloadMap(self):
|
||||||
|
self.screen.fill(pygame.Color(self.BACKGROUND_COLOR))
|
||||||
|
self.screen.blit(self.map, (0,0))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
game = WalleGame()
|
game = WalleGame()
|
||||||
game.update_window()
|
game.update_window()
|
||||||
|
|
||||||
smieciara_object = trashmaster(16,16,"resources/textures/trashmaster_blu.png",16)
|
smieciara_object = trashmaster(16,16,"resources/textures/trashmaster_blu.png")
|
||||||
game.draw_trashmaster(smieciara_object)
|
game.draw_trashmaster(smieciara_object, (0, 0))
|
||||||
|
|
||||||
game.update_window()
|
game.update_window()
|
||||||
|
|
||||||
@ -45,7 +46,11 @@ def main():
|
|||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
running = False
|
||||||
pygame.quit()
|
if event.type == pygame.KEYDOWN:
|
||||||
|
game.reloadMap()
|
||||||
|
game.draw_trashmaster(smieciara_object,
|
||||||
|
smieciara_object.movement(event.key, 16))
|
||||||
|
game.update_window()
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user