Merge pull request 'plant_class_added' (#6) from plant_class_added into main

Reviewed-on: s473634/TurboTraktor#6
This commit is contained in:
Michał Wujec 2023-03-20 13:49:21 +01:00
commit 9eefaad350
15 changed files with 217 additions and 13 deletions

Binary file not shown.

BIN
assets/Beetroot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/Carrot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

BIN
assets/Potato.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

BIN
assets/Wheat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

BIN
assets/farmland.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

38
main.py
View File

@ -1,23 +1,35 @@
import pygame
import sys
import tractor
import screen
import src.screen as screen
import src.plant as plant
from src.Tractor import Tractor as ractor2
#import src.tractor as tractor2
# pygame initialization
pygame.init()
pygame.mouse.set_visible(False)
# #new tractor sprite - todo
# tr=tractor2('oil','manual',36,36)
# tr_group = pygame.sprite.Group()
# tr_group.add()
# creating agent
myTractor = tractor.Tractor
if __name__ == "__main__":
running = True
#if __name__ == "__main__":
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# defines agent movement
tractor.movement(myTractor)
# screen visualisation
screen.set_screen(myTractor)
pygame.quit()
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()

128
main2.py Normal file
View File

@ -0,0 +1,128 @@
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]
# 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))
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('oil','manual')
tractor_group = pygame.sprite.Group()
tractor_group.add(tractor)
#PLANTS
plant_grup = 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)
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()
pygame.display.flip()
screen.blit(background,(0,0))
plant_grup.draw(screen)
tractor_group.draw(screen)
tractor_group.update()
clock.tick(60)

30
src/Tractor.py Normal file
View File

@ -0,0 +1,30 @@
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))
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 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.

Binary file not shown.

34
src/plant.py Normal file
View File

@ -0,0 +1,34 @@
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"
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"
if species=="wheat":
self.growth_time=250
self.weight=75
self.fertilizer="wheat_fertilizer"
self.pic_path="assets/Wheat.png"