added tractor rotation and movement
This commit is contained in:
parent
1f08e350d8
commit
53603120bc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -12,6 +12,9 @@ GROUND = ""
|
|||||||
# path to ground image
|
# path to ground image
|
||||||
GREY = (20, 17, 17, 255)
|
GREY = (20, 17, 17, 255)
|
||||||
|
|
||||||
|
DIRECTION_NORTH = 1
|
||||||
|
DIRECTION_EAST = 2
|
||||||
|
DIRECTION_SOUTH = 3
|
||||||
|
DIRECTION_WEST = 4
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
from crop_protection_product import CropProtectionProduct
|
from crop_protection_product import CropProtectionProduct
|
||||||
|
from area.constants import TILE_SIZE, DIRECTION_EAST, DIRECTION_SOUTH, DIRECTION_WEST, DIRECTION_NORTH
|
||||||
|
from area.field import fieldX,fieldY
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
class Tractor:
|
class Tractor:
|
||||||
x = None
|
x = None
|
||||||
y = None
|
y = None
|
||||||
|
direction = None #direction takes values in the range of 1 to 4
|
||||||
image = None
|
image = None
|
||||||
cypermetryna = CropProtectionProduct("pests", "cereal")
|
cypermetryna = CropProtectionProduct("pests", "cereal")
|
||||||
diflufenikan = CropProtectionProduct("weeds", "cereal")
|
diflufenikan = CropProtectionProduct("weeds", "cereal")
|
||||||
@ -13,10 +17,12 @@ class Tractor:
|
|||||||
metazachlor = CropProtectionProduct("weeds", "vegetable")
|
metazachlor = CropProtectionProduct("weeds", "vegetable")
|
||||||
# etc
|
# etc
|
||||||
|
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y, direction):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.image = 'resources/images/tractor.png'
|
self.direction = direction
|
||||||
|
self.image = pygame.image.load('resources/images/tractor.png').convert_alpha()
|
||||||
|
|
||||||
|
|
||||||
def work_on_field(self, tile, ground, plant1):
|
def work_on_field(self, tile, ground, plant1):
|
||||||
if plant1 is None:
|
if plant1 is None:
|
||||||
@ -58,3 +64,43 @@ class Tractor:
|
|||||||
if ground.nutrients_level < plant1.nutrients_requirements:
|
if ground.nutrients_level < plant1.nutrients_requirements:
|
||||||
ground.nutrients_level += 20
|
ground.nutrients_level += 20
|
||||||
print("Tractor added some nutrients")
|
print("Tractor added some nutrients")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def move(self):
|
||||||
|
if self.direction == DIRECTION_EAST:
|
||||||
|
self.x = self.x + TILE_SIZE
|
||||||
|
|
||||||
|
elif self.direction == DIRECTION_WEST:
|
||||||
|
self.x = self.x - TILE_SIZE
|
||||||
|
|
||||||
|
elif self.direction == DIRECTION_NORTH:
|
||||||
|
self.y = self.y - TILE_SIZE
|
||||||
|
|
||||||
|
elif self.direction == DIRECTION_SOUTH:
|
||||||
|
self.y = self.y + TILE_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
def rotate_to_right(self):
|
||||||
|
if self.direction == 4:
|
||||||
|
self.direction = 1
|
||||||
|
else:
|
||||||
|
self.direction += 1
|
||||||
|
self.image = pygame.transform.rotate(self.image, -90)
|
||||||
|
|
||||||
|
|
||||||
|
def rotate_to_left(self):
|
||||||
|
if self.direction == 1:
|
||||||
|
self.direction = 4
|
||||||
|
else:
|
||||||
|
self.direction -= 1
|
||||||
|
self.image = pygame.transform.rotate(self.image, 90)
|
||||||
|
|
||||||
|
|
||||||
|
def draw_tractor(self, win):
|
||||||
|
|
||||||
|
imageTractor = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||||
|
self.x += fieldX
|
||||||
|
self.y += fieldY
|
||||||
|
win.blit(imageTractor, (self.x, self.y))
|
||||||
|
pygame.display.flip()
|
@ -2,7 +2,7 @@ import pygame
|
|||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from area.constants import WIDTH, HEIGHT
|
from area.constants import WIDTH, HEIGHT, TILE_SIZE
|
||||||
from area.field import drawWindow
|
from area.field import drawWindow
|
||||||
from area.tractor import Tractor
|
from area.tractor import Tractor
|
||||||
from area.field import tiles
|
from area.field import tiles
|
||||||
@ -16,6 +16,8 @@ def main():
|
|||||||
run = True
|
run = True
|
||||||
window = drawWindow(WIN)
|
window = drawWindow(WIN)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
|
||||||
while run:
|
while run:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
@ -28,12 +30,19 @@ def main():
|
|||||||
d1 = Dirt(random.randint(1, 100), random.randint(1,100))
|
d1 = Dirt(random.randint(1, 100), random.randint(1,100))
|
||||||
d1.pests_and_weeds()
|
d1.pests_and_weeds()
|
||||||
tile1.ground=d1
|
tile1.ground=d1
|
||||||
t1 = Tractor(10, 10)
|
|
||||||
t1.work_on_field(tile1, d1, p1)
|
tractor = Tractor(0*TILE_SIZE, 0*TILE_SIZE, 2)
|
||||||
|
tractor.rotate_to_right()
|
||||||
|
tractor.move()
|
||||||
|
tractor.draw_tractor(WIN)
|
||||||
|
|
||||||
|
pygame.display.update()
|
||||||
|
tractor.work_on_field(tile1, d1, p1)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
|
|
||||||
# in loop move tractor
|
# in loop move tractor:
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user