Add simple game enviroment

This commit is contained in:
s473580 2023-03-16 22:23:42 +01:00
parent 96ddbfc821
commit bf90f35c0a

View File

@ -0,0 +1,65 @@
import pygame
pygame.init()
white = (255, 255, 255)
black = (0, 0, 0)
red = (255, 0, 0)
dis = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Intelegentny Pszczelarz')
game_over = False
x1 = 300
y1 = 300
x1_change = 0
y1_change = 0
block_xy = [[100, 20], [100, 500], [700, 20], [700, 500]]
block1 = block_xy[0]
block2 = block_xy[1]
block3 = block_xy[2]
block4 = block_xy[3]
clock = pygame.time.Clock()
while not game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x1_change = -10
y1_change = 0
elif event.key == pygame.K_RIGHT:
x1_change = 10
y1_change = 0
elif event.key == pygame.K_UP:
y1_change = -10
x1_change = 0
elif event.key == pygame.K_DOWN:
y1_change = 10
x1_change = 0
x1 += x1_change
y1 += y1_change
dis.fill(white)
pygame.draw.rect(dis, black, [x1, y1, 10, 10])
if [x1,y1] in block_xy:
game_over = True
pygame.draw.rect(dis, red, [block1[0], block1[1], 20, 20])
pygame.draw.rect(dis, red, [block2[0], block2[1], 20, 20])
pygame.draw.rect(dis, red, [block3[0], block3[1], 20, 20])
pygame.draw.rect(dis, red, [block4[0], block4[1], 20, 20])
pygame.display.update()
clock.tick(30)
pygame.quit()
quit()