I recently downloaded a game and under level.py this is the code. Im lost with this code can someone please help!
import pygame, os
from pygame.locals import *
from sprites import *
def load_level(file):
img = pygame.image.load(os.path.join("data", file))
return img.convert()
class Level:
def __init__(self, level=1):
self.level = load_level("level.png")
platform_color = (0, 0, 0, 255)
collidables = [platform_color]
self.x = self.y = 0
while self.y < self.level.get_height():
color = self.level.get_at((self.x, self.y))
if color == (0, 255, 0, 255):
Monster((self.x*24, self.y*24))
if color == (255, 0, 0, 255):
HealthUp((self.x*24 + 4, self.y*24 + 4))
if color == (255, 255, 0, 255):
Chemical((self.x*24, self.y*24))
if color == (255, 0, 255, 255):
AmmoUp((self.x*24, self.y*24))
if color in collidables:
top = bottom = left = right = False
if self.get_tile_above() not in collidables:
top = True
if self.get_tile_under() not in collidables:
bottom = True
if self.get_tile_left() not in collidables:
left = True
if self.get_tile_right() not in collidables:
right = True
Block((self.x*24, self.y*24), top, bottom, left, right)
self.x += 1
if self.x >= self.level.get_width():
self.x = 0
self.y += 1
def get_size(self):
return [self.level.get_size()[0]*24, self.level.get_size()[1]*24]
def get_tile_above(self):
try:
return self.level.get_at((self.x, self.y-1))
except:
pass
def get_tile_under(self):
try:
return self.level.get_at((self.x, self.y+1))
except:
pass
def get_tile_left(self):
try:
return self.level.get_at((self.x-1, self.y))
except:
pass
def get_tile_right(self):
try:
return self.level.get_at((self.x+1, self.y))
except:
pass