Changing the way that farm is generating first corps on all fields

This commit is contained in:
JakubPaszke 2023-03-25 12:33:24 +01:00
parent f57cb07716
commit b869a5ade3
9 changed files with 77 additions and 127 deletions

Binary file not shown.

Binary file not shown.

71
main.py
View File

@ -1,35 +1,54 @@
import pygame
import sys
import tractor
import src.screen as screen
import src.plant as plant
from src.Tractor import Tractor as ractor2
#import src.tractor as tractor2
import random
from settings import screen_height, screen_width, SIZE, SPECIES, block_size, tile, road_coords
from src.map import drawRoads, seedForFirstTime
from src.Tractor import Tractor
from src.Plant import Plant
# pygame initialization
pygame.init()
clock = pygame.time.Clock()
pygame.mouse.set_visible(False)
# #new tractor sprite - todo
# tr=tractor2('oil','manual',36,36)
# tr_group = pygame.sprite.Group()
# tr_group.add()
#GAME SCREEN
screen = pygame.display.set_mode(SIZE)
pygame.display.set_caption("Traktor_interaktor")
background = pygame.image.load("assets/farmland.jpg")
background = pygame.transform.scale(background,SIZE)
screen.fill((90,50,20))
background.fill((90,50,20))
background = drawRoads(background)
# creating agent
myTractor = tractor.Tractor
for line in range(26):
pygame.draw.line(background, (0, 0, 0), (0, line * 36), (SIZE[0], line * 36))
pygame.draw.line(background, (0, 0, 0), (line * 36, 0), (line * 36, SIZE[1]))
#TRACTOR
tractor = Tractor('oil','manual')
tractor_group = pygame.sprite.Group()
tractor_group.add(tractor)
#PLANTS
plant_group = pygame.sprite.Group()
plant_group = seedForFirstTime()
if __name__ == "__main__":
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
tractor.collect(plant_group)
pygame.display.flip()
screen.blit(background,(0,0))
plant_group.draw(screen)
tractor_group.draw(screen)
tractor_group.update()
clock.tick(60)
#if __name__ == "__main__":
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
sys.exit()
# defines agent movement
tractor.movement(myTractor)
# screen visualisation
screen.set_screen(myTractor)
#pygame.quit()

View File

@ -1,57 +0,0 @@
import pygame
import sys
import random
from settings import screen_height, screen_width, SIZE, SPECIES, block_size, tile, road_coords_y, road_coords_x
from src.map import drawRoads
from src.Tractor import Tractor
from src.Plant import Plant
# pygame initialization
pygame.init()
clock = pygame.time.Clock()
pygame.mouse.set_visible(False)
#GAME SCREEN
screen = pygame.display.set_mode(SIZE)
pygame.display.set_caption("Traktor_interaktor")
background = pygame.image.load("assets/farmland.jpg")
background = pygame.transform.scale(background,SIZE)
screen.fill((90,50,20))
background.fill((90,50,20))
background = drawRoads(background)
for line in range(25):
pygame.draw.line(background, (0, 0, 0), (0, line * 36), (SIZE[0], line * 36))
pygame.draw.line(background, (0, 0, 0), (line * 36, 0), (line * 36, SIZE[1]))
#TRACTOR
tractor = Tractor('oil','manual')
tractor_group = pygame.sprite.Group()
tractor_group.add(tractor)
#PLANTS
plant_group = pygame.sprite.Group()
for plant in range(30):
new_plant = Plant(random.choice(SPECIES),0,random.randrange(0,25)*36+18,random.randrange(0,25)*36+18)
plant_group.add(new_plant)
if __name__ == "__main__":
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
tractor.collect(plant_group)
pygame.display.flip()
screen.blit(background,(0,0))
plant_group.draw(screen)
tractor_group.draw(screen)
tractor_group.update()
clock.tick(60)

View File

@ -1,10 +1,15 @@
screen_width=900
screen_height=900
from cmath import sqrt
screen_width=936
screen_height=936
SIZE = (screen_width, screen_height)
SPECIES=["carrot","potato","beetroot","wheat"]
# size in pixels of one tile = 36px/36px
tile = (36, 36)
block_size = 36
road_coords_x = [0, 5, 10, 15, 20]
road_coords_y = [4, 9, 14, 19, 24]
road_coords = [0, 5, 10, 15, 20, 25]
field_width = 4
field_height = 4
field_size = field_width*field_height
fields_amount = 25

Binary file not shown.

View File

@ -1,24 +1,40 @@
from cmath import sqrt
import pygame
from settings import screen_height, screen_width, SIZE, SPECIES, block_size, tile, road_coords_x, road_coords_y
from settings import screen_height, screen_width, SIZE, SPECIES, block_size, tile, road_coords, fields_amount, field_size, field_height, field_width
from src.Plant import Plant
import random
def drawRoads(screen):
#drawing roads:
road = pygame.image.load("assets/road.jpeg")
road = pygame.transform.scale(road, tile)
for x in road_coords_x:
for block in range(25):
for x in road_coords:
for block in range(26):
screen.blit(road, (x*block_size, block * 36))
for y in road_coords_y:
for block in range(25):
for y in road_coords:
for block in range(26):
screen.blit(road, (block * 36, y*block_size))
barn_img = pygame.image.load('assets/barn.png')
barn = pygame.transform.scale(barn_img, tile)
screen.blit(barn, (0, 864))
screen.blit(barn, (0, 900))
return screen
def seedForFirstTime():
plant_group = pygame.sprite.Group()
for field in range(fields_amount):
plant = random.choice(SPECIES)
blocks_seeded_in_field = 0
while (blocks_seeded_in_field < field_size):
x = (((field%5)*((block_size*(field_width+1)))) + ((blocks_seeded_in_field % field_width)*block_size) + ((3/2)*block_size))
y = ((int(field/5)*((block_size*(field_width+1)))) + ((int(blocks_seeded_in_field/field_height))*block_size) + ((3/2)*block_size))
new_plant = Plant(plant,0, x, y)
blocks_seeded_in_field = blocks_seeded_in_field + 1
plant_group.add(new_plant)
return plant_group
# to-be-done with minecraft farmland graphic xD
# maybe this function should be in drawRoads (ofc with changed name), not separated

View File

@ -1,33 +0,0 @@
from pygame.sprite import Sprite
class Plant(Sprite):
def __init__(self,species,location,is_ill,pic_path):
super.__init__()
self.species=species
self.location=location
self.is_ill=is_ill
if species=="carrot":
self.growth_time=100
self.weight=50
self.fertilizer="carrot_fertilizer"
self.pic_path="assets/Carrot.png"
elif species=="beetroot":
self.growth_time=200
self.weight=200
self.fertilizer="beetroot_fertilizer"
self.pic_path="assets/Beetroot.png"
elif species=="potato":
self.growth_time=100
self.weight=100
self.fertilizer="potatoe_fertilizer"
self.pic_path="assets/Potato.png"
elif species=="wheat":
self.growth_time=250
self.weight=75
self.fertilizer="wheat_fertilizer"
self.pic_path="assets/Wheat.png"