diff --git a/__pycache__/blocks.cpython-310.pyc b/__pycache__/blocks.cpython-310.pyc new file mode 100644 index 00000000..563ff56a Binary files /dev/null and b/__pycache__/blocks.cpython-310.pyc differ diff --git a/__pycache__/field.cpython-310.pyc b/__pycache__/field.cpython-310.pyc new file mode 100644 index 00000000..0f2ce160 Binary files /dev/null and b/__pycache__/field.cpython-310.pyc differ diff --git a/__pycache__/tractor.cpython-310.pyc b/__pycache__/tractor.cpython-310.pyc new file mode 100644 index 00000000..6783c0d0 Binary files /dev/null and b/__pycache__/tractor.cpython-310.pyc differ diff --git a/blocks.py b/blocks.py new file mode 100644 index 00000000..0a1e2261 --- /dev/null +++ b/blocks.py @@ -0,0 +1,43 @@ +import pygame +import random +from pygame.math import Vector2 + +class Blocks: + def __init__(self, parent_screen,cell_size): + self.parent_screen = parent_screen + self.vege_image = pygame.image.load(r'resources/flower.png').convert_alpha() + self.vege_image = pygame.transform.scale(self.vege_image, (cell_size, cell_size)) + + self.lief_image = pygame.image.load(r'resources/stone.png').convert_alpha() + self.lief_image = pygame.transform.scale(self.lief_image, (cell_size, cell_size)) + + self.carrot_image = pygame.image.load(r'resources/dead.png').convert_alpha() + self.carrot_image = pygame.transform.scale(self.carrot_image, (cell_size, cell_size)) + + + def locate_blocks(self, blocks_number, cell_number, body): + for i in range(blocks_number): + self.x = random.randint(0, cell_number-1) + self.y = random.randint(0, cell_number-1) + self.pos = Vector2(self.x, self.y) + body.append(self.pos) + #block_dict.update({self.x : 1}) # for now it may lay on each other, + print(body) + + def place_blocks(self, parent_screen, cell_size, body, color): #drawing blocks + for block in body: + x = int(block.x * cell_size) + y = int(block.y * cell_size) + if color == 'carrot': + self.parent_screen.blit(self.carrot_image, (x, y)) + if color == 'leaf': + self.parent_screen.blit(self.lief_image, (x, y)) + if color == 'vege': + self.parent_screen.blit(self.vege_image, (x, y)) + + + + def draw_lines(self, parent_screen, cell_size): # background lines + for i in range(1, 10): + pygame.draw.line(self.parent_screen, (228, 253, 227), (cell_size * i, 0), (cell_size * i, parent_screen), 1) + pygame.draw.line(self.parent_screen, (228, 253, 227), (0, cell_size * i), (parent_screen, cell_size * i), 1) diff --git a/field.py b/field.py index 245dedc7..9d78bfd8 100644 --- a/field.py +++ b/field.py @@ -4,8 +4,9 @@ class Field: def __init__(self, parent_screen): self.parent_screen = parent_screen self.block = pygame.image.load(r'resources/field.png').convert() + #def draw_blocks(): - def place_field(self, field_matrix, parent_screen, cell_size): + def place_field(self, field_matrix, parent_screen, cell_size): #drawing blocks for m, posY in enumerate(field_matrix): for n, posX in enumerate(posY): if field_matrix[m][n] == 1: diff --git a/main.py b/main.py index 50a6fdbd..f6192bdb 100644 --- a/main.py +++ b/main.py @@ -2,31 +2,42 @@ import pygame import random import tractor import field +import blocks from pygame.locals import * from datetime import datetime class Game: cell_size = 50 - screen_size = 500 - - field_matrix = [[0 for m in range(10)] for n in range(10)] - for i in range(10): - while True: - field_posX = random.randint(0, 9) - field_posY = random.randint(0, 9) - - if field_matrix[field_posY][field_posX] == 0: - field_matrix[field_posY][field_posX] = 1 - break + cell_number = 15 + blocks_number = 15 + block_dict = {} def __init__(self): + self.leaf_body = [] + self.vege_body = [] + self.carrot_body = [] + pygame.init() - self.surface = pygame.display.set_mode((self.screen_size, self.screen_size)) # initialize a window + self.surface = pygame.display.set_mode((self.cell_size*self.cell_number, self.cell_size*self.cell_number)) # initialize a window + + self.grass_image = pygame.image.load(r'resources/grass3.png').convert() + self.grass_image = pygame.transform.scale(self.grass_image, (self.cell_size, self.cell_size)) + + self.blocks = blocks.Blocks(self.surface,self.cell_size) + self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.leaf_body) + self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.vege_body) + self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.carrot_body) - self.field = field.Field(self.surface) - self.field.place_field(self.field_matrix, self.surface, self.cell_size) + self.blocks.place_blocks(self.surface, self.cell_size, self.leaf_body, 'leaf') + self.blocks.place_blocks(self.surface, self.cell_size, self.vege_body, 'vege') + self.blocks.place_blocks(self.surface, self.cell_size, self.carrot_body, 'carrot') + + for i in range(0, self.cell_number*self.cell_number): + x = int(i * self.cell_size) + y = int(i * self.cell_size) + self.surface.blit(self.grass_image, (x, y)) self.tractor = tractor.Tractor(self.surface, self.cell_size) self.tractor.draw() @@ -41,7 +52,6 @@ class Game: clock.tick(60) # manual fps control not to overwork the computer time_now = datetime.now() - for event in pygame.event.get(): if event.type == KEYDOWN: if pygame.key.get_pressed()[K_ESCAPE]: @@ -59,9 +69,21 @@ class Game: running = False self.surface.fill((140, 203, 97)) # background color - self.field.place_field(self.field_matrix, self.surface, self.cell_size) - self.field.draw_lines(self.screen_size, self.cell_size) + for i in range(0, self.cell_number): + for k in range(0, self.cell_number): + x = int(i * self.cell_size) + y = int(k * self.cell_size) + self.surface.blit(self.grass_image, (x, y)) + + + #self.blocks.draw_lines(self.cell_number*self.cell_size, self.cell_size) + + self.blocks.place_blocks(self.surface, self.cell_size, self.leaf_body, 'leaf') + self.blocks.place_blocks(self.surface, self.cell_size, self.vege_body, 'vege') + self.blocks.place_blocks(self.surface, self.cell_size, self.carrot_body, 'carrot') + + self.tractor.draw() pygame.display.update() diff --git a/resources/2ZAYDK.png b/resources/2ZAYDK.png new file mode 100644 index 00000000..d6d86b5b Binary files /dev/null and b/resources/2ZAYDK.png differ diff --git a/resources/3ZcPVQ.png b/resources/3ZcPVQ.png new file mode 100644 index 00000000..38bf602c Binary files /dev/null and b/resources/3ZcPVQ.png differ diff --git a/resources/4-gFH9.png b/resources/4-gFH9.png new file mode 100644 index 00000000..3ea15150 Binary files /dev/null and b/resources/4-gFH9.png differ diff --git a/resources/DJb-j3.png b/resources/DJb-j3.png new file mode 100644 index 00000000..7cf4e05d Binary files /dev/null and b/resources/DJb-j3.png differ diff --git a/resources/NfASJh.png b/resources/NfASJh.png new file mode 100644 index 00000000..a6dbe3f5 Binary files /dev/null and b/resources/NfASJh.png differ diff --git a/resources/b8H0jv.png b/resources/b8H0jv.png new file mode 100644 index 00000000..11f01c2e Binary files /dev/null and b/resources/b8H0jv.png differ diff --git a/resources/carrot.png b/resources/carrot.png new file mode 100644 index 00000000..47137552 Binary files /dev/null and b/resources/carrot.png differ diff --git a/resources/cldvYP.png b/resources/cldvYP.png new file mode 100644 index 00000000..c1923876 Binary files /dev/null and b/resources/cldvYP.png differ diff --git a/resources/cs5N6Z.png b/resources/cs5N6Z.png new file mode 100644 index 00000000..a58f51b4 Binary files /dev/null and b/resources/cs5N6Z.png differ diff --git a/resources/dXE2CG.png b/resources/dXE2CG.png new file mode 100644 index 00000000..f84fcf16 Binary files /dev/null and b/resources/dXE2CG.png differ diff --git a/resources/dead.png b/resources/dead.png new file mode 100644 index 00000000..1e730a0b Binary files /dev/null and b/resources/dead.png differ diff --git a/resources/flower.png b/resources/flower.png new file mode 100644 index 00000000..2341b87f Binary files /dev/null and b/resources/flower.png differ diff --git a/resources/grass.png b/resources/grass.png new file mode 100644 index 00000000..2862867e Binary files /dev/null and b/resources/grass.png differ diff --git a/resources/grass1.png b/resources/grass1.png new file mode 100644 index 00000000..42166233 Binary files /dev/null and b/resources/grass1.png differ diff --git a/resources/grass2.png b/resources/grass2.png new file mode 100644 index 00000000..dc56f5ed Binary files /dev/null and b/resources/grass2.png differ diff --git a/resources/grass3.png b/resources/grass3.png new file mode 100644 index 00000000..6b7ec3f9 Binary files /dev/null and b/resources/grass3.png differ diff --git a/resources/grass4.png b/resources/grass4.png new file mode 100644 index 00000000..b4c37e86 Binary files /dev/null and b/resources/grass4.png differ diff --git a/resources/jRdXIV.png b/resources/jRdXIV.png new file mode 100644 index 00000000..95e35e24 Binary files /dev/null and b/resources/jRdXIV.png differ diff --git a/resources/leaf.png b/resources/leaf.png new file mode 100644 index 00000000..b51d5861 Binary files /dev/null and b/resources/leaf.png differ diff --git a/resources/red.png b/resources/red.png new file mode 100644 index 00000000..ba538153 Binary files /dev/null and b/resources/red.png differ diff --git a/resources/robot2.png b/resources/robot2.png new file mode 100644 index 00000000..51503aa5 Binary files /dev/null and b/resources/robot2.png differ diff --git a/resources/sKlv-b.png b/resources/sKlv-b.png new file mode 100644 index 00000000..74b7fb77 Binary files /dev/null and b/resources/sKlv-b.png differ diff --git a/resources/stone.png b/resources/stone.png new file mode 100644 index 00000000..242e8bd6 Binary files /dev/null and b/resources/stone.png differ diff --git a/resources/tmxa28.png b/resources/tmxa28.png new file mode 100644 index 00000000..927997ac Binary files /dev/null and b/resources/tmxa28.png differ diff --git a/resources/vege.png b/resources/vege.png new file mode 100644 index 00000000..1568ab6f Binary files /dev/null and b/resources/vege.png differ diff --git a/tractor.py b/tractor.py index 645b759d..7e1b5d2e 100644 --- a/tractor.py +++ b/tractor.py @@ -1,13 +1,15 @@ import pygame import random +from pygame.math import Vector2 class Tractor: def __init__(self, parent_screen, cell_size): self.parent_screen = parent_screen - self.image = pygame.image.load(r'resources/tractor.png').convert_alpha() + self.image = pygame.image.load(r'resources/robot2.png').convert_alpha() self.image = pygame.transform.scale(self.image, (cell_size, cell_size+5)) self.x = cell_size*2 self.y = cell_size*2 + self.pos = Vector2(self.x, self.y) self.angle = 0 self.direction = 'up' @@ -17,16 +19,16 @@ class Tractor: def move(self, direction, cell_size): if direction == 'up': self.y -= cell_size - self.angle = 0 + #self.angle = 0 if direction == 'down': self.y += cell_size - self.angle = 180 + #self.angle = 180 if direction == 'left': self.x -= cell_size - self.angle = 90 + #self.angle = 90 if direction == 'right': self.x += cell_size - self.angle = 270 + #self.angle = 270 def walk(self): choice = ['up', 'down', 'left', 'right']