52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import pygame
|
|
from Environment import Environment
|
|
from Package import Package
|
|
from Global_variables import Global_variables as G_var
|
|
|
|
class Truck:
|
|
def __init__(self, window, ):
|
|
self.window = window
|
|
self.image = pygame.image.load("resources/truck.jpeg").convert()
|
|
self.x = 701 # (x,y) - position of the truck
|
|
self.y = 401
|
|
self.has_package = False
|
|
self.environment = Environment(window)
|
|
self.package = Package(self.window)
|
|
# self.speed
|
|
|
|
# drawing the truck
|
|
def draw(self):
|
|
self.environment.draw_itself()
|
|
self.package.draw()
|
|
self.window.blit(self.image, (self.x, self.y))
|
|
pygame.display.flip()
|
|
|
|
# moving the truck
|
|
def move_right(self):
|
|
self.x += G_var().RECT_SIZE
|
|
self.draw()
|
|
|
|
def move_left(self):
|
|
self.x -= G_var().RECT_SIZE
|
|
self.draw()
|
|
|
|
def move_up(self):
|
|
self.y -= G_var().RECT_SIZE
|
|
self.draw()
|
|
|
|
def move_down(self):
|
|
self.y += G_var().RECT_SIZE
|
|
self.draw()
|
|
|
|
# def collision_with_shelves(self,x,y):
|
|
# for row in self.environment.compute_coordinates_of_shelves():
|
|
# if self.is_collision(x, y,row[0],row[1]):
|
|
# return True
|
|
# return False
|
|
#
|
|
# def is_collision(self, x1, y1, x2, y2):
|
|
# if x1 >= x2 and x1 <= x2 + RECT_SIZE:
|
|
# if y1 >= y2 and y1 <= y2 + 6*RECT_SIZE:
|
|
# return True
|
|
#
|