SI_projekt_smieciarka/truck.py
Michal Zmudzinski 5289c48fe2 Game
2021-06-13 15:14:55 +02:00

33 lines
1.1 KiB
Python

import pygame
from house import is_house
class Truck:
def __init__(self, grid_w, grid_h, grid_size):
self.grid_w = grid_w
self.grid_h = grid_h
self.size = grid_size
self.pos = [self.grid_w // 2, self.grid_h // 2]
self.direction = [1, 0]
self.dir_control = 0
self.image = pygame.image.load('./img/truck.png')
def move(self):
self.pos[0] += self.direction[0] * self.size
self.pos[1] += self.direction[1] * self.size
def test_crash(self, houses):
new_pos = []
new_pos.append(self.pos[0] + (self.direction[0]*self.size))
new_pos.append(self.pos[1] + (self.direction[1]*self.size))
return is_house(new_pos, houses)
def rotate(self, direction):
all_dir = [[1, 0], [0, 1], [-1, 0], [0, -1]]
self.dir_control = (direction + self.dir_control) % 4
self.direction = all_dir[self.dir_control]
def rotate_image(self, angle):
rotated_image = pygame.transform.rotate(self.image, angle)
self.image = rotated_image