-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBlack.py
More file actions
71 lines (55 loc) · 1.96 KB
/
Black.py
File metadata and controls
71 lines (55 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from Setting import *
from helper import *
from math import ceil
from Algorithms import Astar, Pair, BFS
import pygame
import random
class Black:
def __init__(self, App, x, y):
self.App = App
self.currPos = Pair(x, y)
self.nextPos = self.currPos
self.dir = Pair(0, 0)
self.deadCount = 0
self.turn = 0
self.bestPath = Path([], OO)
self.AstarTick = 3
self.load()
def load(self):
self.image_left = []
self.image_right = []
for i in range(4):
self.image_left.append(Get("blackleft_" + str(i + 1)))
for i in range(4):
self.image_right.append(Get("blackright_" + str(i + 1)))
def updateBestPath(self, curr, target):
astar = Astar(self.App.grid, curr, target)
maybe = astar.optimalPath()
if(self.bestPath.isEmpty() or self.AstarTick == 0):
self.bestPath = maybe
self.AstarTick = 3
else :
self.AstarTick -= 1
def Update(self):
if(self.currPos == self.nextPos):
here = Pair(int (self.currPos.x), int (self.currPos.y))
self.updateBestPath(here, self.App.retPlayerPos())
self.nextPos = (self.bestPath.pop())
self.nextPos = self.nextPos
self.dir = self.nextPos - self.currPos
print(self.bestPath)
self.currPos = self.currPos + self.dir / 8.0
self.turn = (self.turn + 1)%12
def draw(self):
INDEX = self.turn // 3
if(self.dir == EAST or self.dir == NORTH):
self.App.screen.blit(
self.image_right[INDEX],
(self.currPos.x * CELL_WIDTH, self.currPos.y * CELL_HEIGHT)
)
else :
self.App.screen.blit(
self.image_left[INDEX],
(self.currPos.x * CELL_WIDTH, self.currPos.y * CELL_WIDTH)
)
pygame.display.update()