Naprawiono blad polegajacy na rysowaniu jednej linijki, drobne usprawnienia komentarzy #3
21
main.py
21
main.py
@ -33,8 +33,8 @@ SLOT_DICT={} #Slot are stored in dictionary with key being a Tuple of x and y co
|
|||||||
def draw_grid():
|
def draw_grid():
|
||||||
for x in range(0, 8):
|
for x in range(0, 8):
|
||||||
pygame.draw.line(screen, BLACK, (x*CUBE_SIZE, 0), (x*CUBE_SIZE, HEIGHT)) #We got 8 lines in Y axis so to draw them we use x from range <0,7) to make slot manage easier
|
pygame.draw.line(screen, BLACK, (x*CUBE_SIZE, 0), (x*CUBE_SIZE, HEIGHT)) #We got 8 lines in Y axis so to draw them we use x from range <0,7) to make slot manage easier
|
||||||
for y in range(0, 5):
|
for y in range(0, 4):
|
||||||
pygame.draw.line(screen, BLACK, (0, y*CUBE_SIZE), (WIDTH, y*CUBE_SIZE)) #We got 4 lines in X axis so to draw them we use y from range <0,5) to make slot manage easier
|
pygame.draw.line(screen, BLACK, (0, y*CUBE_SIZE), (WIDTH, y*CUBE_SIZE)) #We got 4 lines in X axis so to draw them we use y from range <0,4) to make slot manage easier
|
||||||
|
|
||||||
# Draw tractor
|
# Draw tractor
|
||||||
tractor_image = pygame.image.load('images/traktor.png')
|
tractor_image = pygame.image.load('images/traktor.png')
|
||||||
@ -48,15 +48,15 @@ def draw_tractor(): #TODO? I think we should move draw_tractor to tractor class
|
|||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
#Draw grid and tractor (new one)
|
#Draw grid and tractor (new one)
|
||||||
def draw_grid():
|
def draw_grid():
|
||||||
for x in range(0,8):
|
for x in range(0,WIDTH//CUBE_SIZE): #We got 8 cubes in X axis so we use for from 0 to 7 do draw them all
|
||||||
for y in range(0,5):
|
for y in range(0,HEIGHT//CUBE_SIZE): #We got 4 cubes in Y axis so we use for from 0 to 3 to draw them all
|
||||||
new_slot=Slot.Slot(x,y,BROWN,screen)
|
new_slot=Slot.Slot(x,y,BROWN,screen) #Creation of empty slot
|
||||||
SLOT_DICT[(x,y)]=new_slot
|
SLOT_DICT[(x,y)]=new_slot #Adding slots to dict
|
||||||
for entity in SLOT_DICT:
|
for entity in SLOT_DICT:
|
||||||
SLOT_DICT[entity].draw()
|
SLOT_DICT[entity].draw() #For each slot in dictionary draw it on the screen
|
||||||
draw_tractor()
|
draw_tractor()
|
||||||
|
|
||||||
def change_color_of_slot(coordinates,color):
|
def change_color_of_slot(coordinates,color): #Coordinates must be tuple (x,y) x from range 0,7 and y in range 0,3 (left top slot has cord (0,0) ), color has to be from defined or custom in RGB value (R,G,B)
|
||||||
SLOT_DICT[coordinates].color_change(color)
|
SLOT_DICT[coordinates].color_change(color)
|
||||||
|
|
||||||
def random_color():
|
def random_color():
|
||||||
@ -67,6 +67,7 @@ def random_color():
|
|||||||
3:WHITE}
|
3:WHITE}
|
||||||
return switcher[x]
|
return switcher[x]
|
||||||
|
|
||||||
|
#Demo purpose, can be reused for photos of crops in the future(?)
|
||||||
def randomize_colors():
|
def randomize_colors():
|
||||||
font=pygame.font.Font('freesansbold.ttf',32)
|
font=pygame.font.Font('freesansbold.ttf',32)
|
||||||
text=font.render('Randomizing crops',True,BLACK,WHITE)
|
text=font.render('Randomizing crops',True,BLACK,WHITE)
|
||||||
@ -79,10 +80,12 @@ def randomize_colors():
|
|||||||
SLOT_DICT[coordinates].color_change(random_color())
|
SLOT_DICT[coordinates].color_change(random_color())
|
||||||
draw_tractor()
|
draw_tractor()
|
||||||
|
|
||||||
def init_demo():
|
def init_demo(): #Demo purpose
|
||||||
draw_grid()
|
draw_grid()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
randomize_colors()
|
randomize_colors()
|
||||||
|
|
||||||
|
#Main program
|
||||||
init_demo()
|
init_demo()
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
|
Loading…
Reference in New Issue
Block a user