Compare commits

..

No commits in common. "7a03e2f25401de754d3ea7838bf1d80ff880dc21" and "4e98ae6e87d1587d15d581bc78010ff141704d0a" have entirely different histories.

4 changed files with 29 additions and 37 deletions

View File

@ -1,6 +1,8 @@
import pygame
import displayControler as dCon
CUBE_SIZE=128
WIDTH = 1024
HEIGHT = 512
BLACK=(0,0,0)
BORDER_COLOR=BLACK
BORDER_THICKNESS=1 #Has to be INT value
@ -10,7 +12,7 @@ class Slot:
self.y_axis=y_axis
self.color=color
self.screen=screen
self.field=pygame.Rect(self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE,dCon.CUBE_SIZE,dCon.CUBE_SIZE)
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

View File

@ -1,37 +1,39 @@
import pygame
import random
import displayControler as dCon
import Slot
import random
CUBE_SIZE=128
WIDTH = 1024
HEIGHT = 512
class Tractor:
def __init__(self,x_axis,y_axis,screen):
self.x_axis=x_axis
self.y_axis=y_axis
self.tractor_image = pygame.image.load('images/traktor.png')
self.tractor_image = pygame.transform.scale(self.tractor_image, (dCon.CUBE_SIZE, dCon.CUBE_SIZE))
self.tractor_image = pygame.transform.scale(self.tractor_image, (CUBE_SIZE, CUBE_SIZE))
self.screen=screen
self.slot=None
def draw_tractor(self):
self.screen.blit(self.tractor_image, (self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE))
self.screen.blit(self.tractor_image, (self.x_axis*CUBE_SIZE,self.y_axis*CUBE_SIZE))
pygame.display.update()
def move_tractor(self,x):
if(x==0):
if(dCon.isValidMove(self.x_axis + 1, self.y_axis)):
if(self.x_axis+1<=7):
print("Ruch w prawo")
self.x_axis=self.x_axis+1
elif(x==1):
if(dCon.isValidMove(self.x_axis - 1, self.y_axis)):
if(x==1):
if(self.x_axis-1>=0):
print("Ruch w lewo")
self.x_axis=self.x_axis-1
elif(x==2):
if(dCon.isValidMove(self.x_axis, self.y_axis + 1)):
print("Ruch w dol")
self.y_axis=self.y_axis+1
elif(x==3):
if(dCon.isValidMove(self.x_axis, self.y_axis - 1)):
if(x==2):
if(self.y_axis+1<=3):
print("Ruch w gore")
self.y_axis=self.y_axis+1
if(x==3):
if(self.y_axis-1>=0):
print("Ruch w dol")
self.y_axis=self.y_axis-1
self.draw_tractor()

View File

@ -1,17 +0,0 @@
CUBE_SIZE = 64
NUM_X = 20
NUM_Y = 12
#returns true if tractor can move to specified slot
def isValidMove(x, y):
if x < 0 or y < 0:
return False
if x > NUM_X - 1 or y > NUM_Y - 1:
return False
return True
def getScreenWidth():
return NUM_X * CUBE_SIZE
def getScreenHeihgt():
return NUM_Y * CUBE_SIZE

15
main.py
View File

@ -3,18 +3,23 @@ import Slot
import Tractor
import random
import time
import displayControler as dCon
pygame.init()
BLACK = (0, 0, 0)
BROWN = (139, 69, 19)
WHITE = (255, 255, 255)
RED=(255,0,0)
GREEN=(0,255,0)
screen = pygame.display.set_mode((dCon.getScreenWidth(), dCon.getScreenHeihgt()))
CUBE_SIZE = 128
NUM_X = 8
NUM_Y = 4
WIDTH = 1024
HEIGHT = 512
screen = pygame.display.set_mode((WIDTH, HEIGHT))
screen.fill(WHITE)
pygame.display.update()
@ -42,8 +47,8 @@ def draw_grid():
#Draw grid and tractor (new one)
def draw_grid():
for x in range(0,dCon.NUM_X): #We got 8 cubes in X axis so we use for from 0 to 7 do draw them all
for y in range(0,dCon.NUM_Y): #We got 4 cubes in Y axis so we use for from 0 to 3 to draw them all
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,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) #Creation of empty slot
SLOT_DICT[(x,y)]=new_slot #Adding slots to dict
for entity in SLOT_DICT:
@ -66,7 +71,7 @@ def randomize_colors():
font=pygame.font.Font('freesansbold.ttf',32)
text=font.render('Randomizing crops',True,BLACK,WHITE)
textRect=text.get_rect()
textRect.center=(dCon.getScreenWidth() // 2,dCon.getScreenHeihgt() // 2)
textRect.center=(WIDTH//2,HEIGHT//2)
screen.blit(text,textRect)
pygame.display.update()
time.sleep(3)