srodowisko agenta

This commit is contained in:
SaluSL 2021-03-15 16:53:00 +01:00
parent 9cf11c2f0b
commit 5bd1105bab
4 changed files with 63 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

62
src/app.py Normal file
View File

@ -0,0 +1,62 @@
import pygame
pygame.init()
IMAGE = pygame.image.load('forklift2.jpg')
BACKGROUND = pygame.image.load('magazyn2.jpg')
WIDTH = 675
HEIGHT = 675
size = 75
class Agent:
def __init__(self, pos):
self.pos = pos
self.image = IMAGE
self.rect = self.image.get_rect(center=pos)
def move(self, key):
if key == pygame.K_UP and self.rect.y - size > 0:
self.rect.move_ip(0, -size)
if key == pygame.K_DOWN and self.rect.y + size < HEIGHT:
self.rect.move_ip(0, size)
if key == pygame.K_RIGHT and self.rect.x + size < WIDTH:
self.rect.move_ip(size, 0)
if key == pygame.K_LEFT and self.rect.x - size > 0:
self.rect.move_ip(-size, 0)
board = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA) # transparentny surface
for x in range(9):
for y in range(9):
pygame.draw.rect(board, (0, 0, 0), (x * size, y * size, size, size), 3)
agent = Agent((40, 40))
screen = pygame.display.set_mode([WIDTH, HEIGHT])
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
agent.move(event.key)
#screen.fill((0, 0, 0))
screen.blit(BACKGROUND, [0, 0])
screen.blit(board, board.get_rect())
screen.blit(agent.image, agent.rect)
pygame.display.update()
pygame.quit()

BIN
src/forklift2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
src/magazyn2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 KiB