master #1
@ -17,16 +17,19 @@ from colors import *
|
|||||||
from sprites import *
|
from sprites import *
|
||||||
|
|
||||||
class Tractor(pygame.sprite.Sprite):
|
class Tractor(pygame.sprite.Sprite):
|
||||||
def __init__(self, field):
|
def __init__(self, field, position):
|
||||||
super(Tractor, self).__init__()
|
super(Tractor, self).__init__()
|
||||||
self.surf = pygame.Surface((WIDTH, HEIGHT))
|
self.surf = pygame.Surface((WIDTH, HEIGHT))
|
||||||
self.surf = tractor_img_0
|
self.surf = tractor_img_0
|
||||||
self.position = field.position
|
self.position = position
|
||||||
|
self.field = field
|
||||||
self.rect = self.surf.get_rect(
|
self.rect = self.surf.get_rect(
|
||||||
topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN))
|
topleft=((MARGIN + WIDTH) * self.position[0] + MARGIN, (MARGIN + HEIGHT) * self.position[1] + MARGIN))
|
||||||
self.direction = [1, 0]
|
self.direction = [1, 0]
|
||||||
|
self.field[self.position[0]][self.position[1]].tractor_there = True
|
||||||
|
|
||||||
def move(self):
|
def move(self):
|
||||||
|
self.field[self.position[0]][self.position[1]].tractor_there = False
|
||||||
self.rect.move_ip(self.direction[0]*(WIDTH + MARGIN), self.direction[1]*(HEIGHT + MARGIN))
|
self.rect.move_ip(self.direction[0]*(WIDTH + MARGIN), self.direction[1]*(HEIGHT + MARGIN))
|
||||||
self.position[0] += self.direction[0]
|
self.position[0] += self.direction[0]
|
||||||
self.position[1] += self.direction[1]
|
self.position[1] += self.direction[1]
|
||||||
@ -48,6 +51,8 @@ class Tractor(pygame.sprite.Sprite):
|
|||||||
if self.rect.right > SCREEN_WIDTH-MARGIN:
|
if self.rect.right > SCREEN_WIDTH-MARGIN:
|
||||||
self.rect.right = SCREEN_WIDTH-MARGIN
|
self.rect.right = SCREEN_WIDTH-MARGIN
|
||||||
|
|
||||||
|
self.field[self.position[0]][self.position[1]].tractor_there = True
|
||||||
|
|
||||||
|
|
||||||
def rotate_right(self):
|
def rotate_right(self):
|
||||||
if self.direction == [1, 0]:
|
if self.direction == [1, 0]:
|
||||||
|
Loading…
Reference in New Issue
Block a user