2023-03-21 23:55:52 +01:00
|
|
|
import pygame
|
|
|
|
import random
|
|
|
|
|
|
|
|
class Tractor:
|
|
|
|
def __init__(self, parent_screen, cell_size):
|
2023-03-22 21:09:00 +01:00
|
|
|
self.parent_screen = parent_screen
|
2023-03-22 17:57:33 +01:00
|
|
|
|
|
|
|
self.up = pygame.image.load(r'resources/up.png').convert_alpha()
|
|
|
|
self.down = pygame.image.load(r'resources/down.png').convert_alpha()
|
|
|
|
self.left = pygame.image.load(r'resources/left.png').convert_alpha()
|
|
|
|
self.right = pygame.image.load(r'resources/right.png').convert_alpha()
|
|
|
|
|
2023-03-22 21:09:00 +01:00
|
|
|
self.up = pygame.transform.scale(self.up, (cell_size+2, cell_size))
|
2023-03-22 17:57:33 +01:00
|
|
|
self.down = pygame.transform.scale(self.down, (cell_size, cell_size+2))
|
|
|
|
self.left = pygame.transform.scale(self.left, (cell_size+2, cell_size+2))
|
2023-03-22 21:09:00 +01:00
|
|
|
self.right = pygame.transform.scale(self.right, (cell_size+4, cell_size+1))
|
2023-03-22 17:57:33 +01:00
|
|
|
|
2023-03-21 23:55:52 +01:00
|
|
|
self.x = cell_size*2
|
|
|
|
self.y = cell_size*2
|
2023-03-22 21:09:00 +01:00
|
|
|
#self.pos = Vector2(self.x, self.y)
|
2023-03-21 23:55:52 +01:00
|
|
|
self.angle = 0
|
|
|
|
self.direction = 'up'
|
2023-03-22 17:57:33 +01:00
|
|
|
self.image = self.down
|
|
|
|
|
2023-03-21 23:55:52 +01:00
|
|
|
|
|
|
|
def draw(self):
|
2023-03-22 17:57:33 +01:00
|
|
|
self.parent_screen.blit(self.image, (self.x, self.y)) # rotate tractor
|
2023-03-21 23:55:52 +01:00
|
|
|
|
2023-03-22 21:09:00 +01:00
|
|
|
|
|
|
|
def move(self, direction, cell_size, cell_number):
|
2023-03-21 23:55:52 +01:00
|
|
|
if direction == 'up':
|
2023-03-22 21:09:00 +01:00
|
|
|
if self.y != 0:
|
|
|
|
self.y -= cell_size
|
2023-03-22 17:57:33 +01:00
|
|
|
self.image = self.up
|
2023-03-21 23:55:52 +01:00
|
|
|
if direction == 'down':
|
2023-03-22 21:09:00 +01:00
|
|
|
if self.y != (cell_number-1)*cell_size:
|
|
|
|
self.y += cell_size
|
2023-03-22 17:57:33 +01:00
|
|
|
self.image = self.down
|
2023-03-21 23:55:52 +01:00
|
|
|
if direction == 'left':
|
2023-03-22 21:09:00 +01:00
|
|
|
if self.x != 0:
|
|
|
|
self.x -= cell_size
|
2023-03-22 17:57:33 +01:00
|
|
|
self.image = self.left
|
2023-03-21 23:55:52 +01:00
|
|
|
if direction == 'right':
|
2023-03-22 21:09:00 +01:00
|
|
|
if self.x != (cell_number-1)*cell_size:
|
|
|
|
self.x += cell_size
|
2023-03-22 17:57:33 +01:00
|
|
|
self.image = self.right
|
2023-03-22 21:09:00 +01:00
|
|
|
print(self.x, self.y)
|
|
|
|
|
|
|
|
def water(self, body_before, body_after, cell_size):
|
|
|
|
self.pos = [self.x/cell_size, self.y/cell_size]
|
|
|
|
if self.pos in body_before:
|
|
|
|
body_before.remove(self.pos)
|
|
|
|
body_after.append(self.pos)
|
|
|
|
print('HERE!')
|
|
|
|
#print(body)
|
2023-03-21 23:55:52 +01:00
|
|
|
|
|
|
|
def walk(self):
|
|
|
|
choice = ['up', 'down', 'left', 'right']
|
|
|
|
|
|
|
|
if self.x == 450:
|
|
|
|
choice.pop(3)
|
|
|
|
if self.x == 0:
|
|
|
|
choice.pop(2)
|
|
|
|
if self.y == 0:
|
|
|
|
choice.pop(0)
|
|
|
|
if self.y == 450:
|
|
|
|
choice.pop(1)
|
|
|
|
|
|
|
|
self.direction = random.choice(choice)
|
|
|
|
self.move(self.direction)
|