Przeniesienie zmiennych globalnych do osobnej klasy

This commit is contained in:
tonywesoly 2022-04-20 18:27:24 +02:00
parent e2924ae3c6
commit 592281ea2b
2 changed files with 9 additions and 13 deletions

View File

@ -1,17 +1,15 @@
import pygame
RECT_SIZE = 50
SHELF_COLOR = (143, 68, 33)
from Global_variables import Global_variables as G_var
class Shelf:
def __init__(self, window, x, y):
self.window = window
self.width = RECT_SIZE
self.length = 6*RECT_SIZE
self.width = G_var().RECT_SIZE
self.length = 6*G_var().RECT_SIZE
self.x = x
self.y = y
self.block = pygame.Rect(self.x, self.y, self.width, self.length)
def draw(self):
pygame.draw.rect(self.window, SHELF_COLOR, self.block)
pygame.draw.rect(self.window, G_var().SHELF_COLOR, self.block)
# pygame.draw.line(self.window, (255, 255, 255), (self.x, self.y), (self.x, self.y + self.length))

View File

@ -1,9 +1,7 @@
import pygame
from Environment import Environment
from Package import Package
RECT_SIZE = 50
from Global_variables import Global_variables as G_var
class Truck:
def __init__(self, window, ):
@ -25,19 +23,19 @@ class Truck:
# moving the truck
def move_right(self):
self.x += RECT_SIZE
self.x += G_var().RECT_SIZE
self.draw()
def move_left(self):
self.x -= RECT_SIZE
self.x -= G_var().RECT_SIZE
self.draw()
def move_up(self):
self.y -= RECT_SIZE
self.y -= G_var().RECT_SIZE
self.draw()
def move_down(self):
self.y += RECT_SIZE
self.y += G_var().RECT_SIZE
self.draw()
# def collision_with_shelves(self,x,y):