2024-03-07 21:25:05 +01:00
|
|
|
import pygame
|
|
|
|
import os
|
|
|
|
class Tractor(pygame.sprite.Sprite):
|
|
|
|
def __init__(self, field):
|
2024-03-09 20:02:19 +01:00
|
|
|
super().__init__
|
2024-03-07 21:25:05 +01:00
|
|
|
self.field = field
|
|
|
|
self.image = pygame.image.load('images/tractor.png').convert_alpha()
|
|
|
|
self.image = pygame.transform.scale(self.image, (64, 64))
|
|
|
|
self.rect = self.image.get_rect()
|
|
|
|
x, y = 0, 0
|
|
|
|
self.rect.topleft = (x, y)
|
|
|
|
|
|
|
|
def draw(self, surface):
|
|
|
|
surface.blit(self.image, self.rect)
|
2024-03-09 20:02:19 +01:00
|
|
|
|
|
|
|
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')
|