Merge pull request 'dev2_0' (#1) from dev2_0 into master

Reviewed-on: #1
This commit is contained in:
Szymon Szczubkowski 2023-03-13 16:56:44 +01:00
commit 2a1c9bedf2
4 changed files with 16 additions and 13 deletions

27
main.py
View File

@ -19,23 +19,26 @@ class Lines:
for i in range(1, 10): for i in range(1, 10):
pygame.draw.line(self.parent_scr, (228, 253, 227), (conf.cell_size * i, 0), (conf.cell_size * i, conf.screen_size), 1) pygame.draw.line(self.parent_scr, (228, 253, 227), (conf.cell_size * i, 0), (conf.cell_size * i, conf.screen_size), 1)
pygame.draw.line(self.parent_scr, (228, 253, 227), (0, conf.cell_size * i), (conf.screen_size, conf.cell_size * i), 1) pygame.draw.line(self.parent_scr, (228, 253, 227), (0, conf.cell_size * i), (conf.screen_size, conf.cell_size * i), 1)
pygame.display.flip() #pygame.display.flip()
class Tractor: class Tractor:
def __init__(self, parent_screen): def __init__(self, parent_screen):
conf = Configurations()
self.parent_screen = parent_screen self.parent_screen = parent_screen
self.block = pygame.image.load(r'resources/arrow.png').convert() self.image = pygame.image.load(r'resources/tractor.png').convert_alpha()
self.x = 100 self.image = pygame.transform.scale(self.image, (conf.cell_size, conf.cell_size+5))
self.y = 100 #self.block = pygame.Rect(int(conf.cell_size), int(conf.cell_size), conf.cell_size, conf.cell_size)
self.x = conf.cell_size*2
self.y = conf.cell_size*2
self.angle = 0 self.angle = 0
self.direction = 'up' self.direction = 'up'
def draw(self): def draw(self):
#self.parent_screen.fill((120, 120, 0)) # background color #self.parent_screen.fill((120, 120, 0)) # background color
self.parent_screen.blit(self.block, (self.x, self.y)) #self.parent_screen.blit(self.block, (self.x, self.y))
self.parent_screen.blit(pygame.transform.rotate(self.block, self.angle), (self.x, self.y)) # rotate tractor self.parent_screen.blit(pygame.transform.rotate(self.image, self.angle), (self.x, self.y)) # rotate tractor
pygame.display.flip() # updating screen #pygame.display.flip() # updating screen
def move(self, direction): def move(self, direction):
conf = Configurations() conf = Configurations()
@ -81,7 +84,7 @@ class Field:
if field_matrix[m][n] == 1: if field_matrix[m][n] == 1:
self.parent_screen.blit(self.block, (n * conf.cell_size, m * conf.cell_size)) self.parent_screen.blit(self.block, (n * conf.cell_size, m * conf.cell_size))
pygame.display.flip() #pygame.display.flip()
class Game: class Game:
@ -123,7 +126,6 @@ class Game:
time_now = datetime.now() time_now = datetime.now()
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == KEYDOWN: if event.type == KEYDOWN:
if pygame.key.get_pressed()[K_ESCAPE]: if pygame.key.get_pressed()[K_ESCAPE]:
@ -140,14 +142,15 @@ class Game:
elif event.type == QUIT: elif event.type == QUIT:
running = False running = False
self.surface.fill((120, 120, 0)) # background color self.surface.fill((140, 203, 97)) # background color
self.field.place_field(self.field_matrix) self.field.place_field(self.field_matrix)
self.lines.draw_lines() self.lines.draw_lines()
self.tractor.draw() self.tractor.draw()
pygame.display.update()
if (time_now - last_time).total_seconds() > 1: # tractor moves every 1 sec # if (time_now - last_time).total_seconds() > 1: # tractor moves every 1 sec
last_time = datetime.now() # last_time = datetime.now()
#self.tractor.walk() #self.tractor.walk()
#print(f'x, y = ({int(self.tractor.x / 50)}, {int(self.tractor.y / 50)})') #print(f'x, y = ({int(self.tractor.x / 50)}, {int(self.tractor.y / 50)})')

BIN
resources/.DS_Store vendored Normal file

Binary file not shown.

BIN
resources/robot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

BIN
resources/tractor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB