diff --git a/__pycache__/settings.cpython-310.pyc b/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..77a5793 Binary files /dev/null and b/__pycache__/settings.cpython-310.pyc differ diff --git a/assets/road.jpeg b/assets/road.jpeg new file mode 100644 index 0000000..4782f39 Binary files /dev/null and b/assets/road.jpeg differ diff --git a/main2.py b/main2.py index e2a6666..f8538f7 100644 --- a/main2.py +++ b/main2.py @@ -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) diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..2fa0b41 --- /dev/null +++ b/settings.py @@ -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] + diff --git a/src/Plant.py b/src/Plant.py new file mode 100644 index 0000000..7fa7e1b --- /dev/null +++ b/src/Plant.py @@ -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] + \ No newline at end of file diff --git a/src/Tractor.py b/src/Tractor.py index 8604da1..39e2624 100644 --- a/src/Tractor.py +++ b/src/Tractor.py @@ -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") - - - diff --git a/src/__pycache__/Plant.cpython-310.pyc b/src/__pycache__/Plant.cpython-310.pyc new file mode 100644 index 0000000..f5e775c Binary files /dev/null and b/src/__pycache__/Plant.cpython-310.pyc differ diff --git a/src/__pycache__/Tractor.cpython-310.pyc b/src/__pycache__/Tractor.cpython-310.pyc index 54738c9..3b365b4 100644 Binary files a/src/__pycache__/Tractor.cpython-310.pyc and b/src/__pycache__/Tractor.cpython-310.pyc differ diff --git a/src/__pycache__/map.cpython-310.pyc b/src/__pycache__/map.cpython-310.pyc new file mode 100644 index 0000000..e89cdff Binary files /dev/null and b/src/__pycache__/map.cpython-310.pyc differ diff --git a/src/__pycache__/road.cpython-310.pyc b/src/__pycache__/road.cpython-310.pyc new file mode 100644 index 0000000..045fa03 Binary files /dev/null and b/src/__pycache__/road.cpython-310.pyc differ diff --git a/src/map.py b/src/map.py new file mode 100644 index 0000000..dc4e534 --- /dev/null +++ b/src/map.py @@ -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 diff --git a/src/plant.py b/src/plant.py index 997bc8d..80418a6 100644 --- a/src/plant.py +++ b/src/plant.py @@ -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" - \ No newline at end of file diff --git a/src/road.py b/src/road.py new file mode 100644 index 0000000..e69de29