From 2bd79b6e7163b96c943797988a5547a2eee45ce0 Mon Sep 17 00:00:00 2001 From: Wojciech Medenecki Date: Fri, 10 Mar 2023 23:21:14 +0100 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wozek object moves with arrow keys --- main.py | 57 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index 47ed5f8..10f1cd9 100644 --- a/main.py +++ b/main.py @@ -1,19 +1,38 @@ -import pygame -import sys - -pygame.init() -screen = pygame.display.set_mode((1280, 720)) - -c = (0, 150, 0) - -while True: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - sys.exit(0) - elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: - sys.exit(0) - - for x in range(0, 1280, 80): - pygame.draw.line(screen, c, (1, x), (1280, x), 2) - pygame.draw.line(screen, c, (x, 1), (x, 720), 2) - pygame.display.update() +import pygame +import sys + +pygame.init() +screen = pygame.display.set_mode((1280, 720)) +wozek = pygame.Rect(55,55,50,50) +c = (0, 150, 0) + +while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + sys.exit(0) + elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: + sys.exit(0) + elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: + if wozek.y <= 600: + wozek.y += 80 + elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: + if wozek.y >= 100: + wozek.y -= 80 + elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT: + if wozek.x <= 1170: + wozek.x += 80 + elif event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT: + if wozek.x >= 100: + wozek.x -= 80 + + + for x in range(0, 1280, 80): + pygame.draw.line(screen, c, (1, x), (1280, x), 2) + pygame.draw.line(screen, c, (x, 1), (x, 720), 2) + pygame.display.update() + + + #Drawing + screen.fill((0,0,0)) #removes object trail + pygame.draw.rect(screen, (0,150,255), wozek) #resolution, color, object + pygame.display.flip() #updating frames