diff --git a/__pycache__/settings.cpython-310.pyc b/__pycache__/settings.cpython-310.pyc index 77a5793..534c1bf 100644 Binary files a/__pycache__/settings.cpython-310.pyc and b/__pycache__/settings.cpython-310.pyc differ diff --git a/__pycache__/tractor.cpython-310.pyc b/__pycache__/tractor.cpython-310.pyc index 5a6779d..4faba8f 100644 Binary files a/__pycache__/tractor.cpython-310.pyc and b/__pycache__/tractor.cpython-310.pyc differ diff --git a/main.py b/main.py index 881adbc..6b262b8 100644 --- a/main.py +++ b/main.py @@ -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() \ No newline at end of file diff --git a/main2.py b/main2.py deleted file mode 100644 index f8538f7..0000000 --- a/main2.py +++ /dev/null @@ -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) - diff --git a/settings.py b/settings.py index 2fa0b41..f807018 100644 --- a/settings.py +++ b/settings.py @@ -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 diff --git a/src/__pycache__/map.cpython-310.pyc b/src/__pycache__/map.cpython-310.pyc index e89cdff..efd55d6 100644 Binary files a/src/__pycache__/map.cpython-310.pyc and b/src/__pycache__/map.cpython-310.pyc differ diff --git a/src/__pycache__/screen.cpython-310.pyc b/src/__pycache__/screen.cpython-310.pyc index de53c8c..905b9ab 100644 Binary files a/src/__pycache__/screen.cpython-310.pyc and b/src/__pycache__/screen.cpython-310.pyc differ diff --git a/src/map.py b/src/map.py index dc4e534..34aed87 100644 --- a/src/map.py +++ b/src/map.py @@ -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 diff --git a/src/plant.py b/src/plant.py deleted file mode 100644 index 80418a6..0000000 --- a/src/plant.py +++ /dev/null @@ -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" -