diff --git a/__pycache__/settings.cpython-310.pyc b/__pycache__/settings.cpython-310.pyc index 534c1bf..4d2d62e 100644 Binary files a/__pycache__/settings.cpython-310.pyc and b/__pycache__/settings.cpython-310.pyc differ diff --git a/main.py b/main.py index 6b262b8..26bbac1 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ from src.Plant import Plant # pygame initialization pygame.init() clock = pygame.time.Clock() -pygame.mouse.set_visible(False) +#pygame.mouse.set_visible(False) #GAME SCREEN screen = pygame.display.set_mode(SIZE) @@ -25,8 +25,10 @@ for line in range(26): pygame.draw.line(background, (0, 0, 0), (line * 36, 0), (line * 36, SIZE[1])) #TRACTOR -tractor = Tractor('oil','manual') +tractor = Tractor('oil','manual', 'fuel', 'fertilizer1') tractor_group = pygame.sprite.Group() +tractor.rect.x = 0 +tractor.rect.y = 0 tractor_group.add(tractor) #PLANTS @@ -42,13 +44,16 @@ if __name__ == "__main__": running = False pygame.quit() sys.exit() - if event.type == pygame.MOUSEBUTTONDOWN: - tractor.collect(plant_group) - - pygame.display.flip() + if event.type == pygame.KEYDOWN: + if event.key==pygame.K_RETURN: + tractor.collect(plant_group) + if event.key == pygame.K_ESCAPE: + running = False + + Tractor.movement(tractor) screen.blit(background,(0,0)) plant_group.draw(screen) tractor_group.draw(screen) tractor_group.update() - clock.tick(60) - + pygame.display.flip() + clock.tick(60) \ No newline at end of file diff --git a/src/Field.py b/src/Field.py new file mode 100644 index 0000000..77b78d6 --- /dev/null +++ b/src/Field.py @@ -0,0 +1,21 @@ +from pygame.sprite import Sprite + +class Field(Sprite): + def __init__(self, type, row_id, col_id, image, cost, hydration_level , soil, + fertilizer_degree, development_degree, plant_type, fertilizer_type, to_water): + + self.type = type + self.row_id = row_id + self.col_id = col_id + self.position = (row_id, col_id) + self.image = image + self.cost = cost + + self.hydration_level = hydration_level + self.soil = soil + self.fertilizer_degree = fertilizer_degree + self.development_degree = development_degree + self.plant_type = plant_type + self.fertilizer_type = fertilizer_type + self.to_water = to_water + diff --git a/src/Plant.py b/src/Plant.py index 7fa7e1b..4702979 100644 --- a/src/Plant.py +++ b/src/Plant.py @@ -9,24 +9,36 @@ class Plant(pygame.sprite.Sprite): if species=="carrot": self.growth_time=100 self.weight=50 + self.min_hydration = 30 + self.max_hydration = 60 + self.soil_type = "torf" self.fertilizer="carrot_fertilizer" self.pic_path="assets/Carrot.png" elif species=="beetroot": self.growth_time=200 self.weight=200 + self.min_hydration = 20 + self.max_hydration = 60 + self.soil_type = "piaszczyste" self.fertilizer="beetroot_fertilizer" self.pic_path="assets/Beetroot.png" elif species=="potato": self.growth_time=100 self.weight=100 + self.min_hydration = 10 + self.max_hydration = 30 + self.soil_type = "ilaste" self.fertilizer="potatoe_fertilizer" self.pic_path="assets/Potato.png" else: self.growth_time=250 self.weight=75 + self.min_hydration = 10 + self.max_hydration = 65 + self.soil_type = "gliniaste" self.fertilizer="wheat_fertilizer" self.pic_path="assets/Wheat.png" diff --git a/src/Tractor.py b/src/Tractor.py index 39e2624..3cfc78e 100644 --- a/src/Tractor.py +++ b/src/Tractor.py @@ -1,23 +1,60 @@ import pygame + class Tractor(pygame.sprite.Sprite): - def __init__(self,engine,transmission): + def __init__(self,engine,transmission,fuel,fertilizer): super().__init__() self.image=pygame.image.load("assets/tractor/tractor.png") self.image=pygame.transform.scale(self.image,(36,36)) + self.UP = pygame.transform.rotate(self.image, 0) + self.DOWN = pygame.transform.rotate(self.image, 180) + self.LEFT = pygame.transform.rotate(self.image, 90) + self.RIGHT = pygame.transform.rotate(self.image, -90) self.rect = self.image.get_rect() self.engine=engine self.transmission=transmission - self.fuel=100 - + self.fuel=fuel + self.fertilizer=fertilizer + + def movement(self): + keys = pygame.key.get_pressed() + + if keys[pygame.K_LEFT] and self.rect.x>0: + self.image = self.LEFT + self.rect.x -= 36 + if keys[pygame.K_RIGHT] and self.rect.x<900: + self.image = self.RIGHT + self.rect.x += 36 + if keys[pygame.K_UP] and self.rect.y>0: + self.image = self.UP + self.rect.y -= 36 + if keys[pygame.K_DOWN] and self.rect.y<900: + self.image = self.DOWN + self.rect.y += 36 + def collect(self,plant_group): - self.plant_group=plant_group - print("collected plant") - pygame.sprite.spritecollide(self,self.plant_group,True) + 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() + + def water_plant(self,plant_group): + self.plant_group=plant_group + print("watered plant") + # def update(self): + # self.rect.center=pygame.mouse.get_pos() + + def fertilize(self, plant_group): + self.plant_group=plant_group + print("fertilize") + + def plant(self, plant_group): + self.plant_group=plant_group + print("new plant") + + def find_nearest_plant(self,plant_group): + self.plant_group=plant_group + \ No newline at end of file diff --git a/src/__pycache__/map.cpython-310.pyc b/src/__pycache__/map.cpython-310.pyc index efd55d6..9d06a5f 100644 Binary files a/src/__pycache__/map.cpython-310.pyc and b/src/__pycache__/map.cpython-310.pyc differ diff --git a/src/__pycache__/plant.cpython-310.pyc b/src/__pycache__/plant.cpython-310.pyc index 4605e26..21fa799 100644 Binary files a/src/__pycache__/plant.cpython-310.pyc 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 1a4249d..7bb4d92 100644 Binary files a/src/__pycache__/tractor.cpython-310.pyc and b/src/__pycache__/tractor.cpython-310.pyc differ diff --git a/src/screen.py b/src/screen.py deleted file mode 100644 index 35d197a..0000000 --- a/src/screen.py +++ /dev/null @@ -1,29 +0,0 @@ -import pygame - -# 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) - -# screen settings -SIZE = (900, 900) -SCREEN = pygame.display.set_mode(SIZE) -pygame.display.set_caption("Traktor_interaktor") - -# screen dispaly -def set_screen(myTractor): - # setting background color - SCREEN.fill((90,50,20)) - - # dispaly agent icon - TRACTOR = SCREEN.blit(myTractor.IMG, (myTractor.x, myTractor.y)) - # display barn - SCREEN.blit(barn, (0, 863)) - # draw lines(horizontal, vertical) on the screen - for line in range(25): - pygame.draw.line(SCREEN, (0, 0, 0), (0, line * 36), (SIZE[0], line * 36)) - pygame.draw.line(SCREEN, (0, 0, 0), (line * 36, 0), (line * 36, SIZE[1])) - - pygame.display.update() \ No newline at end of file diff --git a/tractor.py b/tractor.py deleted file mode 100644 index 44b5d9c..0000000 --- a/tractor.py +++ /dev/null @@ -1,33 +0,0 @@ -import pygame - -class Tractor: - # this is where tractor spawns when program starts (center) - x=432 - y=432 - # it's speed -> pixels it moves after pressing arrow - speed = 36 - # tractor image - tractor_img = pygame.image.load('assets/tractor/tractor.png') - IMG = pygame.transform.scale(tractor_img, (36, 36)) - # tractor image rotation - UP = pygame.transform.rotate(IMG, 0) - DOWN = pygame.transform.rotate(IMG, 180) - LEFT = pygame.transform.rotate(IMG, 90) - RIGHT = pygame.transform.rotate(IMG, -90) - - -def movement(myTractor): - keys = pygame.key.get_pressed() - - if keys[pygame.K_LEFT] and myTractor.x>0: - myTractor.IMG = myTractor.LEFT - myTractor.x -= myTractor.speed - if keys[pygame.K_RIGHT] and myTractor.x<900-myTractor.speed: - myTractor.IMG = myTractor.RIGHT - myTractor.x += myTractor.speed - if keys[pygame.K_UP] and myTractor.y>0: - myTractor.IMG = myTractor.UP - myTractor.y -= myTractor.speed - if keys[pygame.K_DOWN] and myTractor.y<900-myTractor.speed: - myTractor.IMG = myTractor.DOWN - myTractor.y += myTractor.speed