Python-project/build/exe.win-amd64-3.7/maps.py

47 lines
1.1 KiB
Python
Raw Normal View History

2019-02-07 14:26:48 +01:00
from os import path
import pygame
walls=pygame.sprite.Group()
bwalls=pygame.sprite.Group()
class Hitbox(pygame.sprite.Sprite):
def __init__(self, x, y, instance):
if instance=='player':
self.groups=walls
elif instance=='bullet':
self.groups=bwalls
pygame.sprite.Sprite.__init__(self, self.groups)
self.image=pygame.Surface((20,20))
self.rect=self.image.get_rect()
self.x=x
self.y=y
self.rect.x=x*20
self.rect.y=y*20
game_folder=path.dirname(__file__)
map_pdata=[]
map_bdata=[]
# player collison map
with open(path.join(game_folder, 'map_player_collision.txt')) as f:
for line in f:
map_pdata.append(line)
for row, tiles in enumerate(map_pdata):
for col, tile in enumerate(tiles):
if tile=='1':
Hitbox(col, row, 'player')
# bullet collision map
with open(path.join(game_folder, 'map_bullet_collision.txt')) as f:
for line in f:
map_bdata.append(line)
for row, tiles in enumerate(map_bdata):
for col, tile in enumerate(tiles):
if tile=='1':
Hitbox(col, row, 'bullet')