Add new method to soil. Working on a new type of items.
This commit is contained in:
parent
24497254d7
commit
0793deb2cd
20
blocks.py
20
blocks.py
@ -1,6 +1,8 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import random
|
import random
|
||||||
from pygame.math import Vector2
|
from pygame.math import Vector2
|
||||||
|
import soil
|
||||||
|
|
||||||
|
|
||||||
class Blocks:
|
class Blocks:
|
||||||
def __init__(self, parent_screen,cell_size):
|
def __init__(self, parent_screen,cell_size):
|
||||||
@ -17,6 +19,8 @@ class Blocks:
|
|||||||
self.alive_leaf_image = pygame.image.load(r'resources/alive.png').convert_alpha()
|
self.alive_leaf_image = pygame.image.load(r'resources/alive.png').convert_alpha()
|
||||||
self.alive_leaf_image = pygame.transform.scale(self.alive_leaf_image, (cell_size, cell_size))
|
self.alive_leaf_image = pygame.transform.scale(self.alive_leaf_image, (cell_size, cell_size))
|
||||||
|
|
||||||
|
self.soil = soil.Soil()
|
||||||
|
|
||||||
|
|
||||||
def locate_blocks(self, blocks_number, cell_number, body):
|
def locate_blocks(self, blocks_number, cell_number, body):
|
||||||
for i in range(blocks_number):
|
for i in range(blocks_number):
|
||||||
@ -41,8 +45,24 @@ class Blocks:
|
|||||||
if color == 'flower':
|
if color == 'flower':
|
||||||
self.parent_screen.blit(self.flower_image, (x, y))
|
self.parent_screen.blit(self.flower_image, (x, y))
|
||||||
|
|
||||||
|
# if color == 'potato':
|
||||||
|
# pass
|
||||||
|
|
||||||
|
def locate_soil(self, name, acidity, irrigation, blocks_number):
|
||||||
|
# for block in blocks_number:
|
||||||
|
self.soil.set_name(name)
|
||||||
|
self.soil.set_irrigation(irrigation)
|
||||||
|
self.soil.set_acidity(acidity)
|
||||||
|
|
||||||
|
def get_soil_info(self):
|
||||||
|
return self.soil
|
||||||
|
|
||||||
def draw_lines(self, parent_screen, cell_size): # background lines
|
def draw_lines(self, parent_screen, cell_size): # background lines
|
||||||
for i in range(1, 10):
|
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), (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)
|
pygame.draw.line(self.parent_screen, (228, 253, 227), (0, cell_size * i), (parent_screen, cell_size * i), 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
2
land.py
2
land.py
@ -19,7 +19,7 @@ class Land:
|
|||||||
x = int(body[0] * cell_size)
|
x = int(body[0] * cell_size)
|
||||||
y = int(body[1] * cell_size)
|
y = int(body[1] * cell_size)
|
||||||
if(name == 'good'):
|
if(name == 'good'):
|
||||||
parent_screen.blit(self.grass_image, (x, y))
|
parent_screen.blit(self.grass_image, (x, y)) # to-check: () redundant parentheses
|
||||||
if(name == 'bad'):
|
if(name == 'bad'):
|
||||||
parent_screen.blit(self.bad_grass_image, (x, y))
|
parent_screen.blit(self.bad_grass_image, (x, y))
|
||||||
|
|
12
main.py
12
main.py
@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
import random
|
import random
|
||||||
import land
|
import land
|
||||||
@ -10,7 +12,7 @@ from datetime import datetime
|
|||||||
class Game:
|
class Game:
|
||||||
cell_size = 50
|
cell_size = 50
|
||||||
cell_number = 15 #horizontally
|
cell_number = 15 #horizontally
|
||||||
blocks_number = 15
|
blocks_number = 15 # to-check sth is wrong: duplicate(?) and overlap
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.dead_leaf_body = []
|
self.dead_leaf_body = []
|
||||||
@ -20,6 +22,8 @@ class Game:
|
|||||||
self.dead_grass_body = []
|
self.dead_grass_body = []
|
||||||
self.grass_body = []
|
self.grass_body = []
|
||||||
|
|
||||||
|
self.potato_field = []
|
||||||
|
|
||||||
|
|
||||||
self.entire_block = {}
|
self.entire_block = {}
|
||||||
|
|
||||||
@ -34,10 +38,16 @@ class Game:
|
|||||||
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.stone_body)
|
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.stone_body)
|
||||||
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.flower_body)
|
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.flower_body)
|
||||||
|
|
||||||
|
self.potato = blocks.Blocks(self.surface, self.cell_size)
|
||||||
|
self.potato.locate_soil('black earth', 6, 1, [])
|
||||||
|
|
||||||
self.tractor = tractor.Tractor(self.surface, self.cell_size)
|
self.tractor = tractor.Tractor(self.surface, self.cell_size)
|
||||||
self.tractor.draw()
|
self.tractor.draw()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
print(self.potato.get_soil_info().get_name())
|
||||||
|
print(self.potato.get_soil_info().get_acidity())
|
||||||
|
print(self.potato.get_soil_info().get_irrigation())
|
||||||
running = True
|
running = True
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
last_time = datetime.now()
|
last_time = datetime.now()
|
||||||
|
23
soil.py
Normal file
23
soil.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
class Soil:
|
||||||
|
def __init__(self, name='', irrigation=-1, acidity=-1):
|
||||||
|
self._name = name
|
||||||
|
self._irrigation = irrigation
|
||||||
|
self._acidity = acidity
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
def set_name(self, name):
|
||||||
|
self._name = name
|
||||||
|
|
||||||
|
def get_acidity(self):
|
||||||
|
return self._acidity
|
||||||
|
|
||||||
|
def set_acidity(self, acidity):
|
||||||
|
self._acidity = acidity
|
||||||
|
|
||||||
|
def get_irrigation(self):
|
||||||
|
return self._irrigation
|
||||||
|
|
||||||
|
def set_irrigation(self, irrigation):
|
||||||
|
self._irrigation = irrigation
|
@ -15,7 +15,7 @@ class Tractor:
|
|||||||
self.left = pygame.transform.scale(self.left, (cell_size+2, cell_size+2))
|
self.left = pygame.transform.scale(self.left, (cell_size+2, cell_size+2))
|
||||||
self.right = pygame.transform.scale(self.right, (cell_size+4, cell_size+1))
|
self.right = pygame.transform.scale(self.right, (cell_size+4, cell_size+1))
|
||||||
|
|
||||||
self.x = cell_size*2
|
self.x = cell_size*2 # to-check: start pos may be written explicit
|
||||||
self.y = cell_size*2
|
self.y = cell_size*2
|
||||||
#self.pos = Vector2(self.x, self.y)
|
#self.pos = Vector2(self.x, self.y)
|
||||||
self.angle = 0
|
self.angle = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user