Compare commits

..

No commits in common. "2a1c9bedf29671cea0ebaac5bc16d6ba74047b58" and "d61d507bf4e26b5aad8b0d9f08296a46da10b749" have entirely different histories.

4 changed files with 13 additions and 16 deletions

29
main.py
View File

@ -19,26 +19,23 @@ 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.image = pygame.image.load(r'resources/tractor.png').convert_alpha() self.block = pygame.image.load(r'resources/arrow.png').convert()
self.image = pygame.transform.scale(self.image, (conf.cell_size, conf.cell_size+5)) self.x = 100
#self.block = pygame.Rect(int(conf.cell_size), int(conf.cell_size), conf.cell_size, conf.cell_size) self.y = 100
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.image, self.angle), (self.x, self.y)) # rotate tractor self.parent_screen.blit(pygame.transform.rotate(self.block, 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()
@ -84,7 +81,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:
@ -125,7 +122,8 @@ class Game:
clock.tick(60) # manual fps control not to overwork the computer clock.tick(60) # manual fps control not to overwork the computer
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]:
@ -142,15 +140,14 @@ class Game:
elif event.type == QUIT: elif event.type == QUIT:
running = False running = False
self.surface.fill((140, 203, 97)) # background color self.surface.fill((120, 120, 0)) # 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

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB