inteligenty-traktor/program/tractor.py
2024-03-09 20:02:19 +01:00

36 lines
1.0 KiB
Python

import pygame
import os
class Tractor(pygame.sprite.Sprite):
def __init__(self, field):
super().__init__
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)
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')