Merge pull request 'zarzadzanie_slotami' (#2) from zarzadzanie_slotami into master
Reviewed-on: #2
This commit is contained in:
commit
7fe9a458ba
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__/
|
22
Slot.py
Normal file
22
Slot.py
Normal file
@ -0,0 +1,22 @@
|
||||
import pygame
|
||||
|
||||
CUBE_SIZE=128
|
||||
WIDTH = 1024
|
||||
HEIGHT = 512
|
||||
BLACK=(0,0,0)
|
||||
BORDER_COLOR=BLACK
|
||||
BORDER_THICKNESS=1 #Has to be INT value
|
||||
class Slot:
|
||||
def __init__(self,x_axis,y_axis,color,screen): #TODO crop and related to it things handling. for now as a place holder crop=>color
|
||||
self.x_axis=x_axis
|
||||
self.y_axis=y_axis
|
||||
self.color=color
|
||||
self.screen=screen
|
||||
self.field=pygame.Rect(self.x_axis*CUBE_SIZE,self.y_axis*CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
|
||||
def draw(self):
|
||||
pygame.draw.rect(self.screen,self.color,self.field,0) #Draw field
|
||||
pygame.draw.rect(self.screen,BLACK,self.field,BORDER_THICKNESS) #Draw border
|
||||
pygame.display.update()
|
||||
def color_change(self,color):
|
||||
self.color=color
|
||||
self.draw()
|
79
main.py
79
main.py
@ -1,40 +1,91 @@
|
||||
import pygame
|
||||
import Slot
|
||||
import random
|
||||
import time
|
||||
|
||||
pygame.init()
|
||||
|
||||
|
||||
BLACK = (0, 0, 0)
|
||||
BROWN = (139, 69, 19)
|
||||
WHITE = (255, 255, 255)
|
||||
RED=(255,0,0)
|
||||
GREEN=(0,255,0)
|
||||
|
||||
CUBE_SIZE = 128
|
||||
NUM_X = 8
|
||||
NUM_Y = 4
|
||||
WIDTH = 1024
|
||||
HEIGHT = 512
|
||||
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
WHITE = (255, 255, 255)
|
||||
screen.fill(WHITE)
|
||||
pygame.display.update()
|
||||
BLACK = (0, 0, 0)
|
||||
BROWN = (139, 69, 19)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SLOT_DICT={} #Slot are stored in dictionary with key being a Tuple of x and y coordinates so top left slot key is (0,0) and value is slot object
|
||||
"""#Draw grid and tractor (old one)
|
||||
def draw_grid():
|
||||
for x in range(NUM_X):
|
||||
for y in range(NUM_Y):
|
||||
pygame.draw.rect(screen, BROWN, (x * CUBE_SIZE, y * CUBE_SIZE, CUBE_SIZE, CUBE_SIZE))
|
||||
|
||||
for x in range(0, WIDTH, CUBE_SIZE):
|
||||
pygame.draw.line(screen, BLACK, (x, 0), (x, HEIGHT))
|
||||
for y in range(0, HEIGHT, CUBE_SIZE):
|
||||
pygame.draw.line(screen, BLACK, (0, y), (WIDTH, y))
|
||||
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
|
||||
for y in range(0, 5):
|
||||
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
|
||||
|
||||
# Draw tractor
|
||||
tractor_image = pygame.image.load('images/traktor.png')
|
||||
tractor_image = pygame.transform.scale(tractor_image, (CUBE_SIZE, CUBE_SIZE))
|
||||
screen.blit(tractor_image, (CUBE_SIZE - 128, CUBE_SIZE - 128))"""
|
||||
|
||||
def draw_tractor(): #TODO? I think we should move draw_tractor to tractor class in the future
|
||||
tractor_image = pygame.image.load('images/traktor.png')
|
||||
tractor_image = pygame.transform.scale(tractor_image, (CUBE_SIZE, CUBE_SIZE))
|
||||
screen.blit(tractor_image, (CUBE_SIZE - 128, CUBE_SIZE - 128))
|
||||
pygame.display.update()
|
||||
#Draw grid and tractor (new one)
|
||||
def draw_grid():
|
||||
for x in range(0,8):
|
||||
for y in range(0,5):
|
||||
new_slot=Slot.Slot(x,y,BROWN,screen)
|
||||
SLOT_DICT[(x,y)]=new_slot
|
||||
for entity in SLOT_DICT:
|
||||
SLOT_DICT[entity].draw()
|
||||
draw_tractor()
|
||||
|
||||
def change_color_of_slot(coordinates,color):
|
||||
SLOT_DICT[coordinates].color_change(color)
|
||||
|
||||
def random_color():
|
||||
x=random.randint(0,3)
|
||||
switcher={0:BROWN,
|
||||
1:GREEN,
|
||||
2:RED,
|
||||
3:WHITE}
|
||||
return switcher[x]
|
||||
|
||||
def randomize_colors():
|
||||
font=pygame.font.Font('freesansbold.ttf',32)
|
||||
text=font.render('Randomizing crops',True,BLACK,WHITE)
|
||||
textRect=text.get_rect()
|
||||
textRect.center=(WIDTH//2,HEIGHT//2)
|
||||
screen.blit(text,textRect)
|
||||
pygame.display.update()
|
||||
time.sleep(3)
|
||||
for coordinates in SLOT_DICT:
|
||||
SLOT_DICT[coordinates].color_change(random_color())
|
||||
draw_tractor()
|
||||
|
||||
def init_demo():
|
||||
draw_grid()
|
||||
time.sleep(2)
|
||||
randomize_colors()
|
||||
init_demo()
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
quit()
|
||||
|
||||
draw_grid()
|
||||
|
||||
pygame.display.update()
|
Loading…
Reference in New Issue
Block a user