def __init__(self, raw_image, position, _dir): OnBoard.__init__(self, raw_image, position) self.__coinAnimState = 0 # Initialize animation state to 0 self.IMAGES = { "coin1": pygame.transform.scale( pygame.image.load(os.path.join(_dir, 'assets/coin1.png')), (15, 15)).convert_alpha(), "coin2": pygame.transform.scale( pygame.image.load(os.path.join(_dir, 'assets/coin2.png')), (15, 15)).convert_alpha(), "coin3": pygame.transform.scale( pygame.image.load(os.path.join(_dir, 'assets/coin3.png')), (15, 15)).convert_alpha(), "coin4": pygame.transform.scale( pygame.image.load(os.path.join(_dir, 'assets/coin4.png')), (15, 15)).convert_alpha(), "coin5": pygame.transform.scale( pygame.image.load(os.path.join(_dir, 'assets/coin5.png')), (15, 15)).convert_alpha() }
def populateMap(self): for x in range(len(self.map)): for y in range(len(self.map[x])): if self.map[x][y] == 1: # Add a wall at that position self.Walls.append(OnBoard(self.IMAGES["wood_block"], (y * 15 + 15 / 2, x * 15 + 15 / 2))) elif self.map[x][y] == 2: # Add a ladder at that position self.Ladders.append(OnBoard(self.IMAGES["ladder"], (y * 15 + 15 / 2, x * 15 + 15 / 2)))
def __init__(self, raw_image, position, _dir): OnBoard.__init__(self, raw_image, position) self.__coinAnimState = 0 # Initialize animation state to 0 self.IMAGES = { "coin1": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/coin1.png')), (15, 15)).convert_alpha(), "coin2": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/coin2.png')), (15, 15)).convert_alpha(), "coin3": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/coin3.png')), (15, 15)).convert_alpha(), "coin4": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/coin4.png')), (15, 15)).convert_alpha(), "coin5": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/coin5.png')), (15, 15)).convert_alpha() }
def __init__(self, raw_image, position, _dir): OnBoard.__init__(self, raw_image, position) self.__enemyAnimState = 0 # Initialize animation state to 0 self.IMAGES = { "enemy1": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/enemy1.png')), (15, 15)).convert_alpha(), "enemy2": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/enemy1.png')), (15, 15)).convert_alpha(), "enemy3": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/enemy1.png')), (15, 15)).convert_alpha(), "enemy4": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/enemy1.png')), (15, 15)).convert_alpha(), "enemy5": pygame.transform.scale(pygame.image.load(os.path.join(_dir, 'assets/enemy1.png')), (15, 15)).convert_alpha() }
def resetGroups(self): self.score = 0 self.lives = 3 self.map = [] # We will create the map again when we reset the game self.Players = [Player(self.IMAGES["still"], (self.__width/2, 435), 15, 15)] self.Enemies = [MonsterPerson(self.IMAGES["monster0"], (100, 117), self.rng, self._dir)] self.Allies = [Person(self.IMAGES["princess"], (50, 48), 18, 25)] self.Allies[0].updateWH(self.Allies[0].image, "H", 0, 25, 25) self.Coins = [] self.Walls = [] self.Ladders = [] self.Fireballs = [] self.FireballEndpoints = [OnBoard(self.IMAGES["still"], (50, 440))] self.initializeGame() # This initializes the game and generates our map self.createGroups() # This creates the instance groups
def populateMap(self): self.map = np.loadtxt(os.path.join(self._dir, 'map1.txt'), dtype='i', delimiter=',') #use numpy for python3 for x in range(len(self.map)): for y in range(len(self.map[x])): if self.map[x][y] == 1: # Add a wall at that position self.Walls.append( OnBoard( self.IMAGES["wood_block"], (y * 15 + 15 / 2, x * 15 + 15 / 2))) elif self.map[x][y] == 2: # Add a ladder at that position self.Ladders.append( OnBoard( self.IMAGES["ladder"], (y * 15 + 15 / 2, x * 15 + 15 / 2))) elif self.map[x][y] == 11: # Add the enemy to our enemy list self.enemys.append( enemy( self.IMAGES["enemy1"], (y * 15 + 15 / 2, x * 15 + 15 / 2), self._dir)) elif self.map[x][y] == 12: # Add the enemy to our enemy list self.enemys2.append( enemy( self.IMAGES["enemy2"], (y * 15 + 15 / 2, x * 15 + 15 / 2), self._dir)) # Add a wall at that position elif self.map[x][y] == 4: self.Walls.append( OnBoard( self.IMAGES["wood_block2"], (y * 15 + 15 / 2, x * 15 + 15 / 2))) elif self.map[x][y] == 5: self.Walls.append( OnBoard( self.IMAGES["wood_block3"], (y * 15 + 15 / 2, x * 15 + 15 / 2))) elif self.map[x][y] == 6: self.Walls.append( OnBoard( self.IMAGES["wood_block4"], (y * 15 + 15 / 2, x * 15 + 15 / 2))) elif self.map[x][y] == 7: self.Walls.append( OnBoard( self.IMAGES["wood_block5"], (y * 15 + 15 / 2, x * 15 + 15 / 2))) elif self.map[x][y] == 9: self.Walls.append( OnBoard( self.IMAGES["boundary"], #9 is to create boundary walls so that player doesn't cross over the game (y * 15 + 15 / 2, x * 15 + 15 / 2)))