61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
|
import pygame
|
||
|
import sys
|
||
|
|
||
|
BLACK = (0, 0, 0)
|
||
|
|
||
|
GRID_SIZE = 100
|
||
|
GRID_WIDTH = 20
|
||
|
GRID_HEIGHT = 10
|
||
|
|
||
|
pygame.init()
|
||
|
|
||
|
WINDOW_SIZE = (GRID_WIDTH * GRID_SIZE, GRID_HEIGHT * GRID_SIZE)
|
||
|
screen = pygame.display.set_mode(WINDOW_SIZE)
|
||
|
pygame.display.set_caption("Mini Zoo")
|
||
|
|
||
|
agent_pos = [0,0]
|
||
|
agent_image = pygame.image.load('avatar.png')
|
||
|
agent_image = pygame.transform.scale(agent_image, (GRID_SIZE,GRID_SIZE))
|
||
|
|
||
|
background_image = pygame.image.load('tło.jpg')
|
||
|
background_image = pygame.transform.scale(background_image, WINDOW_SIZE)
|
||
|
|
||
|
def draw_grid():
|
||
|
for y in range(0, GRID_HEIGHT * GRID_SIZE, GRID_SIZE):
|
||
|
for x in range(0, GRID_WIDTH * GRID_SIZE, GRID_SIZE):
|
||
|
rect = pygame.Rect(x, y, GRID_SIZE, GRID_SIZE)
|
||
|
pygame.draw.rect(screen, BLACK, rect, 1)
|
||
|
|
||
|
def draw_agent(agent_pos):
|
||
|
x, y = agent_pos
|
||
|
screen.blit(agent_image, (x*GRID_SIZE,y*GRID_SIZE))
|
||
|
|
||
|
def main():
|
||
|
global agent_pos
|
||
|
clock = pygame.time.Clock()
|
||
|
|
||
|
while True:
|
||
|
for event in pygame.event.get():
|
||
|
if event.type == pygame.QUIT:
|
||
|
pygame.quit()
|
||
|
sys.exit()
|
||
|
elif event.type ==pygame.KEYDOWN:
|
||
|
if event.key == pygame.K_UP and agent_pos[1] > 0:
|
||
|
agent_pos[1] -= 1
|
||
|
elif event.key == pygame.K_DOWN and agent_pos[1] < GRID_HEIGHT - 1:
|
||
|
agent_pos[1] += 1
|
||
|
elif event.key == pygame.K_LEFT and agent_pos[0] > 0:
|
||
|
agent_pos[0] -= 1
|
||
|
elif event.key == pygame.K_RIGHT and agent_pos[0] < GRID_WIDTH - 1:
|
||
|
agent_pos[0] += 1
|
||
|
|
||
|
|
||
|
screen.blit(background_image,(0,0))
|
||
|
draw_grid()
|
||
|
draw_agent(agent_pos)
|
||
|
pygame.display.flip()
|
||
|
clock.tick(10)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|