commit 2c1ff6c64c70c709b345de78fb5bbdff1dc4525d Author: Tomasz Adamczyk Date: Sat Mar 13 22:30:18 2021 +0100 dwuwymiarowe, dyskretne środowisko (krata) diff --git a/.idea/SmartTractor.iml b/.idea/SmartTractor.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/SmartTractor.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8656114 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..477f5bd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..bf7ab00 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1615670853142 + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/py.py b/py.py new file mode 100644 index 0000000..e6f5f04 --- /dev/null +++ b/py.py @@ -0,0 +1,39 @@ +import os +import pygame +WIDTH, HEIGHT = 1000, 1000 +WIN = pygame.display.set_mode((WIDTH, HEIGHT)) +pygame.display.set_caption("Smart Tractor") +WHITE = ((255, 255, 255)) +FPS = 13 +TRACTOR_WIDTH, TRACTOR_HEIGHT = 100, 100 +TRACTOR = pygame.image.load(os.path.join('resources', 'tractor.png')) +TRACTOR = pygame.transform.scale(TRACTOR, (TRACTOR_WIDTH, TRACTOR_HEIGHT)) +VEL = 100 +def draw_window(tractor_rectangle): + WIN.fill(WHITE) + WIN.blit(TRACTOR, (tractor_rectangle.x, tractor_rectangle.y)) + pygame.display.update() +def tractor_handle_movement(keys_pressed, tractor_rectangle): + if keys_pressed[pygame.K_DOWN] and tractor_rectangle.y + VEL + TRACTOR_HEIGHT <= HEIGHT: + tractor_rectangle.y += VEL + if keys_pressed[pygame.K_LEFT] and tractor_rectangle.x - VEL >= 0: + tractor_rectangle.x -= VEL + if keys_pressed[pygame.K_RIGHT] and tractor_rectangle.x + VEL + TRACTOR_WIDTH <= WIDTH: + tractor_rectangle.x += VEL + if keys_pressed[pygame.K_UP] and tractor_rectangle.y - VEL >= 0: + tractor_rectangle.y -= VEL +def main(): + tractor_rectangle = pygame.Rect(0, 0, TRACTOR_WIDTH, TRACTOR_HEIGHT) + clock = pygame.time.Clock() + run = True + while run: + clock.tick(FPS) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + run = False + keys_pressed = pygame.key.get_pressed() + tractor_handle_movement(keys_pressed, tractor_rectangle) + draw_window(tractor_rectangle) + pygame.quit() +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/resources/tractor.png b/resources/tractor.png new file mode 100644 index 0000000..1e720c6 Binary files /dev/null and b/resources/tractor.png differ