2023-03-21 23:55:52 +01:00
|
|
|
import pygame
|
|
|
|
import random
|
|
|
|
|
2023-06-15 19:33:40 +02:00
|
|
|
class Chicken:
|
|
|
|
def __init__(self, surface, cell_size, cell_number):
|
|
|
|
self.surface = surface
|
|
|
|
self.lastVisitedBlocks = [] # Chicken stores last 3 visited blocks
|
2023-03-22 17:57:33 +01:00
|
|
|
|
2023-06-17 11:49:38 +02:00
|
|
|
self.up = pygame.image.load(r'resources/chicken/up.png').convert_alpha()
|
|
|
|
self.down = pygame.image.load(r'resources/chicken/down.png').convert_alpha()
|
|
|
|
self.left = pygame.image.load(r'resources/chicken/left.png').convert_alpha()
|
|
|
|
self.right = pygame.image.load(r'resources/chicken/right.png').convert_alpha()
|
2023-03-22 17:57:33 +01:00
|
|
|
|
2023-06-18 01:59:54 +02:00
|
|
|
self.cell_size = cell_size
|
|
|
|
self.cell_number = cell_number
|
|
|
|
|
|
|
|
self.up = pygame.transform.scale(self.up, (self.cell_size+2, self.cell_size))
|
|
|
|
self.down = pygame.transform.scale(self.down, (self.cell_size, self.cell_size+2))
|
|
|
|
self.left = pygame.transform.scale(self.left, (self.cell_size+2, self.cell_size+2))
|
|
|
|
self.right = pygame.transform.scale(self.right, (self.cell_size+4, self.cell_size+1))
|
2023-03-22 17:57:33 +01:00
|
|
|
|
2023-06-15 19:33:40 +02:00
|
|
|
self.x = 1 # to-check: start pos may be written explicit
|
|
|
|
self.y = 1
|
2023-04-16 13:07:46 +02:00
|
|
|
self.angle = 180
|
2023-03-21 23:55:52 +01:00
|
|
|
self.direction = 'up'
|
2023-03-22 17:57:33 +01:00
|
|
|
self.image = self.down
|
2023-03-27 15:29:06 +02:00
|
|
|
self.step = 0
|
2023-06-15 19:33:40 +02:00
|
|
|
|
|
|
|
def move(self, direction):
|
|
|
|
print('MOVE')
|
2023-04-16 13:07:46 +02:00
|
|
|
if direction == 'move':
|
|
|
|
if self.angle == 0 and self.y != 0:
|
2023-06-15 19:33:40 +02:00
|
|
|
self.y -= 1
|
|
|
|
if self.angle == 90 and self.x != (self.cell_number-1):
|
|
|
|
self.x += 1
|
|
|
|
if self.angle == 180 and self.y != (self.cell_number-1):
|
|
|
|
self.y += 1
|
2023-04-16 13:07:46 +02:00
|
|
|
if self.angle == 270 and self.x != 0:
|
2023-06-15 19:33:40 +02:00
|
|
|
self.x -= 1
|
2023-03-21 23:55:52 +01:00
|
|
|
if direction == 'right':
|
2023-04-16 13:07:46 +02:00
|
|
|
self.angle += 90
|
|
|
|
if self.angle == 360:
|
|
|
|
self.angle = 0
|
|
|
|
if direction == 'left':
|
|
|
|
self.angle -= 90
|
|
|
|
if self.angle == -90:
|
|
|
|
self.angle = 270
|
|
|
|
|
|
|
|
if self.angle == 0:
|
|
|
|
self.image = self.up
|
|
|
|
if self.angle == 90:
|
2023-03-22 17:57:33 +01:00
|
|
|
self.image = self.right
|
2023-04-16 13:07:46 +02:00
|
|
|
if self.angle == 180:
|
|
|
|
self.image = self.down
|
|
|
|
if self.angle == 270:
|
|
|
|
self.image = self.left
|
|
|
|
|
2023-03-27 15:29:06 +02:00
|
|
|
self.step = self.step + 1
|
2023-03-22 21:09:00 +01:00
|
|
|
print(self.x, self.y)
|
2023-06-17 11:49:38 +02:00
|
|
|
print('step: ', self.step)
|
2023-03-27 15:29:06 +02:00
|
|
|
|
2023-06-15 19:33:40 +02:00
|
|
|
def water(self, xy , plant_list):
|
|
|
|
for obj in plant_list:
|
|
|
|
if obj.xy == xy:
|
|
|
|
obj.state = 1
|
2023-03-27 15:29:06 +02:00
|
|
|
|
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)
|
2023-06-15 19:33:40 +02:00
|
|
|
self.move(self.direction)
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
self.surface.blit(self.image, (self.x * self.cell_size, self.y * self.cell_size)) # rotate tractor
|