diff --git a/program/__pycache__/tile.cpython-311.pyc b/program/__pycache__/tile.cpython-311.pyc index 0019ee06..4ef78271 100644 Binary files a/program/__pycache__/tile.cpython-311.pyc and b/program/__pycache__/tile.cpython-311.pyc differ diff --git a/program/__pycache__/tractor.cpython-311.pyc b/program/__pycache__/tractor.cpython-311.pyc index d9c02e21..8010a7d3 100644 Binary files a/program/__pycache__/tractor.cpython-311.pyc and b/program/__pycache__/tractor.cpython-311.pyc differ diff --git a/program/images/grass.png b/program/images/grass.png index a4975e53..407fe933 100644 Binary files a/program/images/grass.png and b/program/images/grass.png differ diff --git a/program/images/tractor.png b/program/images/tractor.png index 833d1762..0099f2fa 100644 Binary files a/program/images/tractor.png and b/program/images/tractor.png differ diff --git a/program/main.py b/program/main.py index 5b1aefab..59d010fd 100644 --- a/program/main.py +++ b/program/main.py @@ -13,9 +13,10 @@ if __name__ == "__main__": for event in pygame.event.get(): if event.type == pygame.QUIT: running = False - + + field.tractor.update() screen.fill(WHITE) field.draw(screen) pygame.display.flip() - pygame.time.Clock().tick(30) \ No newline at end of file + pygame.time.Clock().tick(10) \ No newline at end of file diff --git a/program/tile.py b/program/tile.py index bef04ae6..7a4e0b31 100644 --- a/program/tile.py +++ b/program/tile.py @@ -9,11 +9,17 @@ class Tile(pygame.sprite.Sprite): y = id//16 self.type = type self.field = field - if type=='grass': - self.image = pygame.image.load('images/grass.png').convert() - self.image = pygame.transform.scale(self.image, (64, 64)) + self.set_type(type) self.rect = self.image.get_rect() self.rect.topleft = (x * 64, y * 64) def draw(self, surface): - self.tiles.draw(surface) \ No newline at end of file + self.tiles.draw(surface) + + def set_type(self, type): + self.type = type + if self.type == 'grass': + self.image = pygame.image.load('images/grass.png').convert() + self.image = pygame.transform.scale(self.image, (64, 64)) + + diff --git a/program/tractor.py b/program/tractor.py index 2935fd9f..9cade46c 100644 --- a/program/tractor.py +++ b/program/tractor.py @@ -2,8 +2,7 @@ import pygame import os class Tractor(pygame.sprite.Sprite): def __init__(self, field): - super().__init__() - self.type = type + super().__init__ self.field = field self.image = pygame.image.load('images/tractor.png').convert_alpha() self.image = pygame.transform.scale(self.image, (64, 64)) @@ -13,3 +12,24 @@ class Tractor(pygame.sprite.Sprite): def draw(self, surface): surface.blit(self.image, self.rect) + + def move(self, direction): + if direction == "up": + self.rect.y -= 64 + elif direction == "down": + self.rect.y += 64 + elif direction == "left": + self.rect.x -= 64 + elif direction == "right": + self.rect.x += 64 + + def update(self): + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT]: + self.move('left') + if keys[pygame.K_RIGHT]: + self.move('right') + if keys[pygame.K_UP]: + self.move('up') + if keys[pygame.K_DOWN]: + self.move('down')