-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.py
128 lines (121 loc) · 4.66 KB
/
level.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import pygame, random, geom
from path import Path
from path import squareToTank
from soldier import SoldierAgent
from turret import TurretAgent
from hunter import HunterAgent
from bomber import BomberAgent
from sniper import SniperAgent
from sentry import SentryAgent
from rover import RoverAgent
NULL = 0
WALL = 1
BLOCK = 2
HOLE = 3
wallColour = pygame.Color(130, 61, 30)
blockColour = pygame.Color(91, 36, 0)
class Level:
pv = [squareToTank((4, 4)), squareToTank((4, 10)), squareToTank((4, 16)), squareToTank((9, 16)),
squareToTank((9, 9)), squareToTank((9, 4)), squareToTank((18, 4)), squareToTank((26, 4)),
squareToTank((18, 16)), squareToTank((26, 16)), squareToTank((21, 10))]
ev = [(pv[0], pv[1], None), (pv[1], pv[2], None), (pv[2], pv[3], None), (pv[3], pv[4], None),
(pv[4], pv[5], None), (pv[5], pv[6], None), (pv[6], pv[7], None), (pv[6], pv[8], None),
(pv[6], pv[10], None), (pv[7], pv[9], None), (pv[8], pv[10], None)]
p = Path(pv, ev)
def __init__(self, surface):
self.walls = []
self.blocks = []
self.holes = []
image = surface
self.level = []
self.spawnPoints = []
self.innerWalls = []
tr = (30, 30)
tl = (870, 30)
br = (870, 570)
bl = (30, 570)
self.outerWalls = [geom.Line(tl, tr), geom.Line(bl, br), geom.Line(tr, br), geom.Line(tl, bl)]
for y in range(0, 20):
temp = []
for x in range(0, 30):
colour = image.get_at((x, y))
if colour == (255, 127, 0):
temp.append(WALL)
if x < 29 and x > 0 and y < 19 and y > 0:
self.innerWalls.append((x, y))
self.walls.append((x, y))
elif colour == (255, 0, 0):
temp.append(BLOCK)
if x < 29 and x > 0 and y < 19 and y > 0:
self.innerWalls.append((x, y))
self.blocks.append((x, y))
elif colour == (0,0,0):
temp.append(HOLE)
self.holes.append((x, y))
else:
if colour == (0, 255, 0):
self.spawnPoints.append((x, y))
elif colour == (0, 0, 255):
self.playerSpawn = (x*30+15, y*30+15)
temp.append(0)
self.level.append(temp)
def draw(self, surface):
y = 0
for i in self.level:
x = 0
for j in i:
if j == 0:
x+=1
continue
elif j == 1:
pygame.draw.rect(surface, wallColour, pygame.Rect(x*30, y*30, 30, 30))
elif j == 2:
pygame.draw.rect(surface, blockColour, pygame.Rect(x*30, y*30, 30, 30))
elif j == 3:
pygame.draw.circle(surface, pygame.Color(25,25,25), (x*30+15, y*30+14), 14)
x += 1
y += 1
def spawnList(player, level, list):
j = 0
for i in list:
x = level.spawnPoints[j][0]*30 + 15
y = level.spawnPoints[j][1]*30 + 15
if i == 1:
TurretAgent((x, y))
elif i == 2:
SoldierAgent((x, y))
elif i == 3:
HunterAgent((x, y))
elif i == 4:
BomberAgent((x, y))
elif i == 5:
RoverAgent((x, y))
elif i == 6:
SniperAgent((x, y))
elif i == 8:
SentryAgent((x, y))
j+=1
#All the levels:
game = (
#1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5
(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0),
(0, 0, 2, 0, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 0),
(2, 0, 0, 0, 0, 0, 1, 2, 0, 1, 2, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 0),
(0, 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