commit 569d790144871859edce86e3a417efa104a45e06 Author: s464923 Date: Sun Mar 10 02:46:14 2024 +0100 push diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..26d33521a --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /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 000000000..e5c1b90a2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..70e6f2032 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/traktor.iml b/.idea/traktor.iml new file mode 100644 index 000000000..74d515a02 --- /dev/null +++ b/.idea/traktor.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/__pycache__/board.cpython-39.pyc b/__pycache__/board.cpython-39.pyc new file mode 100644 index 000000000..1473b2b04 Binary files /dev/null and b/__pycache__/board.cpython-39.pyc differ diff --git a/__pycache__/constant.cpython-39.pyc b/__pycache__/constant.cpython-39.pyc new file mode 100644 index 000000000..7212d8c7c Binary files /dev/null and b/__pycache__/constant.cpython-39.pyc differ diff --git a/__pycache__/tractor.cpython-39.pyc b/__pycache__/tractor.cpython-39.pyc new file mode 100644 index 000000000..444aa7dd1 Binary files /dev/null and b/__pycache__/tractor.cpython-39.pyc differ diff --git a/board.py b/board.py new file mode 100644 index 000000000..190f1a035 --- /dev/null +++ b/board.py @@ -0,0 +1,25 @@ +import pygame +from constant import size, rows, cols + + + +class Board: + def __init__(self): + self.board = [] + + + def load_images(self): + self.grass = pygame.image.load("grass.png") + self.dirt = pygame.image.load("dirt.png") + + def draw_cubes(self, win): + + for row in range(rows): + for col in range(cols): + cube_rect = pygame.Rect(row * size, col * size, size, size) + + if (row + col) % 2 == 0: + win.blit(self.grass, cube_rect) + else: + win.blit(self.dirt, cube_rect) + diff --git a/constant.py b/constant.py new file mode 100644 index 000000000..c64d704e1 --- /dev/null +++ b/constant.py @@ -0,0 +1,7 @@ +import pygame +width, height = 640, 640 +rows, cols = 8, 8 +size = width//cols +yellow = (216,178,0) +green= (103,178,0) +red = (255,0,0) \ No newline at end of file diff --git a/dirt.png b/dirt.png new file mode 100644 index 000000000..53cda07b9 Binary files /dev/null and b/dirt.png differ diff --git a/down.png b/down.png new file mode 100644 index 000000000..19f8ed025 Binary files /dev/null and b/down.png differ diff --git a/grass.png b/grass.png new file mode 100644 index 000000000..0ac777dd3 Binary files /dev/null and b/grass.png differ diff --git a/left.png b/left.png new file mode 100644 index 000000000..ae80eb346 Binary files /dev/null and b/left.png differ diff --git a/main.py b/main.py new file mode 100644 index 000000000..04bd0e56d --- /dev/null +++ b/main.py @@ -0,0 +1,46 @@ +import pygame +from board import Board +from constant import width, height, rows, cols +from tractor import Tractor + + + + +fps = 5 +WIN = pygame.display.set_mode((width, height)) + +pygame.display.set_caption('Inteligenty Traktor') + +def main(): + run = True + clock = pygame.time.Clock() + board = Board() + board.load_images() + tractor = Tractor(4, 4) + while run: + clock.tick(fps) + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + run = False + + keys = pygame.key.get_pressed() + if keys[pygame.K_UP] and tractor.row > 0: + tractor.row -= 1 + tractor.direction = "up" + if keys[pygame.K_DOWN] and tractor.row < rows-1: + tractor.row += 1 + tractor.direction = "down" + if keys[pygame.K_LEFT] and tractor.col > 0: + tractor.col -= 1 + tractor.direction = "left" + if keys[pygame.K_RIGHT] and tractor.col < cols -1: + tractor.col += 1 + tractor.direction = "right" + + board.draw_cubes(WIN) + tractor.draw(WIN) + pygame.display.update() + pygame.quit() + +main() \ No newline at end of file diff --git a/right.png b/right.png new file mode 100644 index 000000000..426fb2514 Binary files /dev/null and b/right.png differ diff --git a/tractor.py b/tractor.py new file mode 100644 index 000000000..7938d94b4 --- /dev/null +++ b/tractor.py @@ -0,0 +1,16 @@ +import pygame +from constant import size +class Tractor: + def __init__(self, row, col): + self.row = row + self.col = col + self.images = { + "up": pygame.image.load("up.png"), + "down": pygame.image.load("down.png"), + "left":pygame.image.load("left.png"), + "right":pygame.image.load("right.png") + } + self.direction = "down" + def draw(self, win): + tractor_image = self.images[self.direction] + win.blit(tractor_image, (self.col*size, self.row*size)) \ No newline at end of file diff --git a/up.png b/up.png new file mode 100644 index 000000000..e914e184e Binary files /dev/null and b/up.png differ