fix tractor movement, added function to tractor and plant
This commit is contained in:
parent
c9d145664f
commit
a88cb60fbd
Binary file not shown.
21
main.py
21
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)
|
12
src/Plant.py
12
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"
|
||||
|
||||
|
@ -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
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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()
|
33
tractor.py
33
tractor.py
@ -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
|
Loading…
Reference in New Issue
Block a user