89 lines
2.6 KiB
Python
89 lines
2.6 KiB
Python
import arcade
|
|
from tank import Tank
|
|
from bonus import Bonus
|
|
from random import randint
|
|
|
|
class Map():
|
|
ground_tiles = arcade.SpriteList()
|
|
object_tiles = arcade.SpriteList()
|
|
block_list = arcade.SpriteList()
|
|
def __init__(self,width,height,tw,th):
|
|
self.height = height
|
|
self.width = width
|
|
self.tilew = tw
|
|
self.tileh = th
|
|
self.ground = [
|
|
' ........ ',
|
|
' . ',
|
|
' . ',
|
|
' . ',
|
|
' . ',
|
|
' . ',
|
|
' . ',
|
|
' . ',
|
|
' ',
|
|
]
|
|
self.objects = [
|
|
' ',
|
|
' e e ',
|
|
' s ',
|
|
' ',
|
|
' s p ',
|
|
' ',
|
|
' e s ',
|
|
' ',
|
|
' s e ',
|
|
]
|
|
self.setup()
|
|
def init_ground(self):
|
|
for i in range(len(self.ground)):
|
|
for j in range(len(self.ground[i])):
|
|
if self.ground[i][j] == ' ':
|
|
tile = arcade.Sprite(
|
|
'./assets/tileGrass1.png',
|
|
scale=1
|
|
)
|
|
elif self.ground[i][j] == '.':
|
|
tile = arcade.Sprite(
|
|
'./assets/tileSand1.png',
|
|
scale=1
|
|
)
|
|
tile.center_x = self.tilew//2 + j * self.tilew
|
|
tile.center_y = self.height - (self.tileh//2 + i * self.tileh)
|
|
Map.ground_tiles.append(tile)
|
|
def init_objects(self):
|
|
for i in range(len(self.objects)):
|
|
for j in range(len(self.objects[i])):
|
|
if self.objects[i][j] == 'p':
|
|
Tank(
|
|
self.tilew//2 + j * self.tilew,
|
|
self.height - (self.tileh//2 + i * self.tileh),
|
|
'player')
|
|
elif self.objects[i][j] == 'e':
|
|
tank = Tank(
|
|
self.tilew//2 + j * self.tilew,
|
|
self.height - (self.tileh//2 + i * self.tileh)
|
|
)
|
|
Map.block_list.append(tank.get_sprite())
|
|
elif self.objects[i][j] == 's':
|
|
Bonus(
|
|
self.tilew//2 + j * self.tilew,
|
|
self.height - (self.tileh//2 + i * self.tileh)
|
|
)
|
|
#tile.center_x = self.tilew//2 + j * self.tilew
|
|
#tile.center_y = self.height - (self.tileh//2 + i * self.tileh)
|
|
#Map.object_tiles.append(tile)
|
|
def setup(self):
|
|
self.init_ground()
|
|
self.init_objects()
|
|
def update(self):
|
|
if self.coin_timer >= 1:
|
|
for i in range(len(self.objects)):
|
|
for j in range(len(self.objects[i])):
|
|
if self.objects[i][j] == ' ' and randint(0,1) == 1:
|
|
self.objects[i][j] = 's'
|
|
|
|
def draw(self):
|
|
Map.ground_tiles.draw()
|
|
#Map.object_tiles.draw()
|