Zmiana akcji agenta - obrót prawo/lewo, ruch do przodu
This commit is contained in:
parent
ceafb6b12c
commit
86bd4e7973
@ -210,6 +210,9 @@ class Waiter(object):
|
||||
self.dirny = 1
|
||||
self.plates = [] #lista niesionych przez agenta talerzy, planowo lista par: (talerz, klient)
|
||||
self.direction = direction #kierunek, w ktory jest skierowany bot
|
||||
self.currentRotation = 0
|
||||
self.rotate = "forward"
|
||||
self.rotationNumber = 0
|
||||
|
||||
def moveRandomly(self, noWalkable):
|
||||
rand = random.randrange(1, 5, 1) #losuje w zakresie 1-4
|
||||
@ -316,16 +319,29 @@ class Waiter(object):
|
||||
plate = self.plates.pop(0)
|
||||
client.takePlateAndEat(plate)
|
||||
|
||||
def rotateRight(self):
|
||||
self.currentRotation += 90
|
||||
|
||||
def rotateLeft(self):
|
||||
self.currentRotation -= 90
|
||||
|
||||
def goForward(self, movex, movey):
|
||||
self.posx += movex
|
||||
self.posy += movey
|
||||
self.pos = (self.posx, self.posy)
|
||||
|
||||
def draw(self, surface):
|
||||
image = pygame.image.load(r'waiter_right.png')
|
||||
image = pygame.transform.scale(image, (sizeBetween - 1, sizeBetween - 1))
|
||||
|
||||
if self.direction == "right":
|
||||
image = pygame.transform.rotate(image, 270)
|
||||
elif self.direction == "left":
|
||||
image = pygame.transform.rotate(image, 90)
|
||||
elif self.direction == "up":
|
||||
image = pygame.transform.rotate(image, 180)
|
||||
if self.rotate == "right":
|
||||
self.rotateRight()
|
||||
elif self.rotate == "left":
|
||||
self.rotateLeft()
|
||||
elif self.direction == "forward":
|
||||
pass
|
||||
|
||||
image = pygame.transform.rotate(image, self.currentRotation)
|
||||
|
||||
i = self.pos[0]
|
||||
j = self.pos[1]
|
||||
@ -338,19 +354,41 @@ class Waiter(object):
|
||||
for i in range(lenght):
|
||||
movex = positionList[i + 1][0] - positionList[i][0]
|
||||
movey = positionList[i + 1][1] - positionList[i][1]
|
||||
self.posx += movex
|
||||
self.posy += movey
|
||||
self.pos = (self.posx, self.posy)
|
||||
|
||||
prevDirection = self.direction
|
||||
if movex == -1 and movey == 0:
|
||||
self.direction = "left"
|
||||
self.direction = 1 #"left"
|
||||
elif movex == 1 and movey == 0:
|
||||
self.direction = "right"
|
||||
elif movey == -1 and movex == 0:
|
||||
self.direction = "down"
|
||||
self.direction = 3 #"right"
|
||||
elif movey == 1 and movex == 0:
|
||||
self.direction = 4 #"down"
|
||||
else:
|
||||
self.direction = "up"
|
||||
self.direction = 2 #"up"
|
||||
|
||||
howToRotate = prevDirection - self.direction #działa!
|
||||
|
||||
print(prevDirection)
|
||||
print(self.direction)
|
||||
print(howToRotate)
|
||||
if howToRotate < 0:
|
||||
self.rotate = "left"
|
||||
self.rotationNumber = abs(howToRotate)
|
||||
elif howToRotate > 0:
|
||||
self.rotate = "right"
|
||||
self.rotationNumber = abs(howToRotate)
|
||||
elif howToRotate == 0:
|
||||
self.rotate = "forward"
|
||||
self.rotationNumber = 0
|
||||
|
||||
print(self.rotate)
|
||||
|
||||
for i in range(self.rotationNumber):
|
||||
redrawWindow(window)
|
||||
time.sleep(0.5)
|
||||
self.rotate = "forward"
|
||||
self.rotationNumber -= 0
|
||||
|
||||
self.goForward(movex, movey)
|
||||
redrawWindow(window)
|
||||
time.sleep(0.5)
|
||||
|
||||
@ -398,7 +436,7 @@ def main():
|
||||
rows = 15
|
||||
sizeBetween = width // rows #wielkość pojedynczej kratki
|
||||
window = pygame.display.set_mode((width, width))
|
||||
bot = Waiter((255, 0, 0), (12, 8), "right")
|
||||
bot = Waiter((255, 0, 0), (12, 8), 2)
|
||||
|
||||
tables = []
|
||||
tables.append(Table((0, 3), 1))
|
||||
@ -432,10 +470,10 @@ def main():
|
||||
pygame.time.delay(100)
|
||||
clock.tick(60)
|
||||
redrawWindow(window)
|
||||
#bot.moveRandomly(list)
|
||||
goal = (1,5)
|
||||
#bot.moveRandomly()
|
||||
goal = (1, 5)
|
||||
bot.goByAStar(goal)
|
||||
time.sleep(120)
|
||||
time.sleep(60)
|
||||
flag = False
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user