Merge pull request 'Roads added. Settings file added. Creation of roads and fields moved into map.py file' (#7) from roads_created into main

Reviewed-on: s473634/TurboTraktor#7
This commit is contained in:
Jakub Paszke 2023-03-25 12:25:00 +01:00
commit f57cb07716
13 changed files with 109 additions and 105 deletions

Binary file not shown.

BIN
assets/road.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -1,76 +1,10 @@
import pygame
import sys
import random
#import tractor
#import src.screen as screen
import src.plant as plant
screen_width=900
screen_height=900
SIZE = (screen_width, screen_height)
SPECIES=["carrot","potatoe","beetroot","wheat"]
# collected=0
#agent class
class Tractor(pygame.sprite.Sprite):
def __init__(self,engine,transmission):
super().__init__()
self.image=pygame.image.load("assets/tractor/tractor.png")
self.image=pygame.transform.scale(self.image,(36,36))
self.rect = self.image.get_rect()
self.engine=engine
self.transmission=transmission
self.fuel=100
def collect(self):
print("collected plant")
pygame.sprite.spritecollide(tractor,plant_grup,True)
# collected=collected+1
# print("plants in trunk "+collected)
def update(self):
self.rect.center=pygame.mouse.get_pos()
#plant class
class Plant(pygame.sprite.Sprite):
def __init__(self,species,is_ill,pos_x,pos_y):
super().__init__()
self.species=species
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"
if species=="beetroot":
self.growth_time=200
self.weight=200
self.fertilizer="beetroot_fertilizer"
self.pic_path="assets/Beetroot.png"
if species=="potato":
self.growth_time=100
self.weight=100
self.fertilizer="potatoe_fertilizer"
self.pic_path="assets/Potato.png"
else:
self.growth_time=250
self.weight=75
self.fertilizer="wheat_fertilizer"
self.pic_path="assets/Wheat.png"
self.image = pygame.image.load(self.pic_path) #zmienic
self.image = pygame.transform.scale(self.image,(36,36))
self.rect = self.image.get_rect()
self.rect.center = [pos_x,pos_y]
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()
@ -84,28 +18,23 @@ 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]))
# size in pixels of one tile = 36px/36px
tile = (36, 36)
# later move it to another class "barn"?
barn_img = pygame.image.load('assets/barn.png')
barn = pygame.transform.scale(barn_img, tile)
#Tractor
#TRACTOR
tractor = Tractor('oil','manual')
tractor_group = pygame.sprite.Group()
tractor_group.add(tractor)
#PLANTS
plant_grup = pygame.sprite.Group()
plant_group = pygame.sprite.Group()
for plant in range(30):
new_plant = Plant(random.choice(SPECIES),0,random.randrange(0,screen_width),random.randrange(0,screen_height))
plant_grup.add(new_plant)
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
@ -117,11 +46,11 @@ if __name__ == "__main__":
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
tractor.collect()
tractor.collect(plant_group)
pygame.display.flip()
screen.blit(background,(0,0))
plant_grup.draw(screen)
plant_group.draw(screen)
tractor_group.draw(screen)
tractor_group.update()
clock.tick(60)

10
settings.py Normal file
View File

@ -0,0 +1,10 @@
screen_width=900
screen_height=900
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]

37
src/Plant.py Normal file
View File

@ -0,0 +1,37 @@
import pygame
class Plant(pygame.sprite.Sprite):
def __init__(self,species,is_ill,pos_x,pos_y):
super().__init__()
self.species=species
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"
else:
self.growth_time=250
self.weight=75
self.fertilizer="wheat_fertilizer"
self.pic_path="assets/Wheat.png"
self.image = pygame.image.load(self.pic_path) #zmienic
self.image = pygame.transform.scale(self.image,(36,36))
self.rect = self.image.get_rect()
self.rect.center = [pos_x,pos_y]

View File

@ -1,30 +1,23 @@
from pygame.sprite import Sprite
import pygame
class Tractor(pygame.sprite.Sprite):
def __init__(self,engine,transmission,pos_x,pos_y):
super.__init__()
self.image=pygame.image.load("../assets/tractor/tractor.png")
self.image=pygame.transform.scale(self,(36,36))
def __init__(self,engine,transmission):
super().__init__()
self.image=pygame.image.load("assets/tractor/tractor.png")
self.image=pygame.transform.scale(self.image,(36,36))
self.rect = self.image.get_rect()
self.engine=engine
self.transmission=transmission
self.pos_x=pos_x
self.pos_y=pos_y
self.fuel=100
def collect(self,plant_group):
self.plant_group=plant_group
print("collected plant")
pygame.sprite.spritecollide(self,self.plant_group,True)
# collected=collected+1
# print("plants in trunk "+collected)
def update(self):
self.rect.center=pygame.mouse.get_pos()
# self.pos_x=pos_x
# self.pos_y=pos_y
def movement(self):
print("todo")
def rotation(self,direction):
print("todo")

Binary file not shown.

Binary file not shown.

Binary file not shown.

36
src/map.py Normal file
View File

@ -0,0 +1,36 @@
import pygame
from settings import screen_height, screen_width, SIZE, SPECIES, block_size, tile, road_coords_x, road_coords_y
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):
screen.blit(road, (x*block_size, block * 36))
for y in road_coords_y:
for block in range(25):
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))
return screen
# to-be-done with minecraft farmland graphic xD
# maybe this function should be in drawRoads (ofc with changed name), not separated
#def drawFields(background):
#field = pygame.image.load()
#field = pygame.transform.scale(field, tile)
#for x in range(25):
#if block not in road_coords_x:
#screen.blit(field, (x*block_size, block * 36))
#for y in range(25):
#if block not in road_coords_y:
#screen.blit(field, (block*36, y*block_size))
#return screen

View File

@ -13,22 +13,21 @@ class Plant(Sprite):
self.fertilizer="carrot_fertilizer"
self.pic_path="assets/Carrot.png"
if species=="beetroot":
elif species=="beetroot":
self.growth_time=200
self.weight=200
self.fertilizer="beetroot_fertilizer"
self.pic_path="assets/Beetroot.png"
if species=="potato":
elif species=="potato":
self.growth_time=100
self.weight=100
self.fertilizer="potatoe_fertilizer"
self.pic_path="assets/Potato.png"
if species=="wheat":
elif species=="wheat":
self.growth_time=250
self.weight=75
self.fertilizer="wheat_fertilizer"
self.pic_path="assets/Wheat.png"

0
src/road.py Normal file
View File