Exemplo n.º 1
0
Arquivo: RL.py Projeto: dealien/PyKroz
 def __init__(self):
     self.level = 0
     self.clock = pygame.time.Clock()
     self.surface = pygame.display.set_mode((WWIDTH, WHEIGHT), 0, 32)
     pygame.display.set_caption('Zero Trunk Rot')
     self.player = Player(os.path.join(IMGDIR, 'player.bmp'), 0, 0)
     self.level_map = RLmap.Map(1, self)  # int is level
     self.font = pygame.font.Font(os.path.join(RESDIR, 'visitor1.ttf'), 18)
     self.title_font = pygame.font.Font(os.path.join(RESDIR, 'visitor1.ttf'), 36)
     self.game_over = False
     self.setTimers()
     self.setSounds()
Exemplo n.º 2
0
def gameOver(game):
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                if event.key == K_y:
                    game.player = RLobject.Player(
                        os.path.join(IMGDIR, 'player.bmp'), 0, 0)
                    game.level_map = RLmap.Map(1, game.player)
                    return
                if event.key == K_n:
                    game.game_over = True
                    return
        game.surface.fill((0, 0, 0))
        game_over = game.font.render('GAME OVER!', True, DARKFLOOR)
        play_again = game.font.render('Play again? (y/n)', True, DARKFLOOR)
        game.surface.blit(game_over, (WWIDTH / 2, WHEIGHT / 2))
        game.surface.blit(play_again, (WWIDTH / 2, WHEIGHT / 2 + 20))
        pygame.display.update()
Exemplo n.º 3
0
Arquivo: RL.py Projeto: dealien/PyKroz
            if event.key == K_t:
                if game.player.teleports > 0:
                    game.player.teleports -= 1
                    game.player.rect = game.player.teleport(game)
            if event.key == K_x:
                game.player.keys += 10
                game.player.teleports += 10
                game.player.whips += 10
                game.player.gems += 10
            if event.key == K_m:
                game.player.findMovingWalls(game)
                game.changeTimer(lava, VERYSLOW)
            if event.key == K_n:
                game.level_map.level += 1
                game.level_map.clearLevel()
                RLmap.renderAll(game)
                game.clock.tick(2)
                game.level_map.makeMap(game)
                RLmap.renderAll(game)
                while not pygame.event.wait().type in (QUIT, KEYDOWN):
                    pass
            if event.key == K_SPACE:
                if game.player.whips > 0:
                    game.player.whipping = True
            if event.key == K_ESCAPE:
                pygame.quit()
                sys.exit()

        if event.type == slow:  # USEREVENT+1
            for a in game.level_map.mobs:
                if a.speed == 'slow':
Exemplo n.º 4
0
            if event.key == K_t:
                if game.player.teleports > 0:
                    game.player.teleports -= 1
                    game.player.rect = game.player.teleport(game)
            if event.key == K_x:
                game.player.keys += 10
                game.player.teleports += 10
                game.player.whips += 10
                game.player.gems += 10
            if event.key == K_m:
                game.player.findMovingWalls(game)
                game.changeTimer(lava, VERYSLOW)  
            if event.key == K_n:
                game.level_map.level += 1
                game.level_map.clearLevel()
                RLmap.renderAll(game)
                game.clock.tick(2)
                game.level_map.makeMap(game)
                RLmap.renderAll(game)
                while not pygame.event.wait().type in (QUIT, KEYDOWN):
                    pass
            if event.key == K_SPACE:
                if game.player.whips > 0:
                    game.player.whipping = True
            if event.key == K_ESCAPE:
                pygame.quit()
                sys.exit()


        if event.type == slow: #USEREVENT+1
            for a in game.level_map.mobs:
Exemplo n.º 5
0
    def checkCollision(self, game, old_position, new_position):
        position = old_position
        if new_position.collidelist(
                game.level_map.walls
        ) == -1:  # check to see if colliding with walls -1 is False
            if new_position.collidelist(
                    game.level_map.items
            ) == -1:  # check to see if colliding with items
                pass
            else:
                for item in game.level_map.items:  # iterate through items and remove them from the map and the list
                    if item.rect == new_position:
                        game.level_map.items.remove(item)
                        if item.kind == 'gem' and self.gems < self.maxGems:
                            self.gems += 1
                            self.score += 10
                            game.level_map.panel.messages.append(
                                'You pick up a gem. Points and Life!')
                        if item.kind == 'whip':
                            self.whips += 1
                            self.score = +10
                            game.level_map.panel.messages.append(
                                'You pick up a Whip.')
                        if item.kind == 'gold':
                            game.gold.play()
                            self.score += 500
                            game.level_map.panel.messages.append(
                                'You pick up a pile of gold.')
                        if item.kind == 'teleport':
                            self.teleports += 1
                            self.score += 10
                            game.level_map.panel.messages.append(
                                'A teleport scroll.')
                        if item.kind == 'key':
                            self.keys += 1
                            self.score += 10
                            game.level_map.panel.messages.append('A key.')
                        if item.kind == 'chest':
                            gem = random.randint(0, 3)
                            whip = random.randint(0, 3)
                            game.level_map.panel.messages.append(
                                'You open a treasure chest and find {0} gems and {1} whips.'
                                .format(gem, whip))
                            self.gems += gem
                            self.whips += whip
                            self.score += 50
                        if item.kind == 'whip_ring':
                            self.weapon.power += 1
                            self.score += 1000
                            game.level_map.panel.messages.append(
                                'You find a ring of Whip Power!')
                        if item.kind == 'gem_sack':
                            self.gems += 25
                            self.score += 125
                            game.level_map.panel.messages.append(
                                'You found a pouch with 25 Gems')
                        if item.kind == 'bomb':
                            game.bomb.play()
                            self.score += 500
                            center_x = item.rect.centerx
                            center_y = item.rect.centery
                            radius = IMGSIZE * 5
                            for wall in game.level_map.breakable:
                                x = wall.rect.centerx
                                y = wall.rect.centery
                                if game.isInRange(center_x, center_y, radius,
                                                  x, y):
                                    game.level_map.breakable.remove(wall)
                                    game.level_map.moveable_walls.remove(wall)
                        if item.kind == 'k' or item.kind == 'r' or item.kind == 'o' or item.kind == 'z':
                            game.level_map.kroz.append(item.kind)
                            if len(game.level_map.kroz) == 4:
                                if game.level_map.kroz[0] == 'k' and game.level_map.kroz[1] == 'r' and \
                                        game.level_map.kroz[2] == 'o' and game.level_map.kroz[3] == 'z':
                                    game.player.score += 10000
                                    # play a sound
                                    game.level_map.panel.messages.append(
                                        'You get the KROZ 10,000 point bonus!')
                        if item.kind == 'tele_trap':
                            position = self.teleport(game)
                            return position
                        # ---SPELLS-----------------------------------------
                        if item.kind == 'freeze':
                            game.stopTimers()
                            self.score += 10
                            game.changeTimer(check_things, ETERNITY)
                            game.level_map.panel.messages.append(
                                'You trigger a freeze monster spell!')
                        if item.kind == 'slow':
                            game.slowTimers()
                            self.score += 10
                            game.changeTimer(check_things, ETERNITY)
                            game.level_map.panel.messages.append(
                                'You trigger a slow monster spell!')
                        if item.kind == 'fast':
                            game.speedTimers()
                            self.score += 10
                            game.changeTimer(check_things, ETERNITY)
                            game.level_map.panel.messages.append(
                                'You trigger a speed monster spell!')
                        if item.kind == 'invisibility':
                            game.player.invisible = True
                            self.score += 100
                            game.changeTimer(check_things, ETERNITY)
                            game.level_map.panel.messages.append(
                                'You trigger an invisibiltiy spell!')
                        if item.kind == 'more_monsters':
                            for a in range(20, 50):
                                space = random.choice(game.level_map.floors)
                                x = space.left
                                y = space.top
                                mob = Mob(os.path.join(IMGDIR, 'gnome.bmp'), x,
                                          y, 1, 'slow')
                                game.level_map.mobs.append(mob)

                        if item.kind == 'tablet':
                            game.player.score += 10000
                            game.level_map.panel.messages.append(item.message)
                        # TRIGGERS-----------------------------------------------------------------------------------------------------------------------------------
            if new_position.collidelistall(
                    game.level_map.triggers
            ):  # triggers that set of special events etc
                for trigger in game.level_map.triggers:
                    if trigger.rect == new_position:
                        trigger.trigger(game)

            if new_position.collidelistall(
                    game.level_map.doors):  # locked doors
                for item in game.level_map.doors:
                    if item.rect == new_position:
                        if self.keys > 0:
                            self.keys -= 1
                            game.level_map.doors.remove(item)
                        else:
                            game.hit_wall.play()
                            new_position = old_position

            if new_position.collidelistall(
                    game.level_map.mobs):  # collision with mobs
                for mob in game.level_map.mobs:
                    if mob.rect == new_position:
                        game.mob_hit_player.play()
                        self.gems -= mob.damage
                        self.score += 10
                        game.level_map.mobs.remove(mob)

            if new_position.collidelistall(
                    game.level_map.breakable
            ):  # breakable is a list of breakable walls, needed to seperate from regular walls
                for wall in game.level_map.breakable:
                    if wall.rect == new_position:
                        game.hit_wall.play()
                        new_position = old_position

            if new_position.collidelistall(
                    game.level_map.hidden_walls
            ):  # this is the hidden walls, maybe only level 1? when bumped it appears
                for wall in game.level_map.hidden_walls:
                    if wall == new_position:
                        game.hit_wall.play()
                        new_position = old_position
                        game.level_map.walls.append(wall)

            if new_position.collidelistall(
                    game.level_map.exits):  # did they get to the level exit?
                for level_exit in game.level_map.exits:
                    if level_exit == new_position:
                        self.score += 50
                        game.level_map.level += 1
                        game.level_map.clearLevel()
                        RLmap.renderAll(game)
                        game.clock.tick(2)
                        game.level_map.makeMap(game)
                        game.level_map.panel.messages = []
                        RLmap.renderAll(game)
                        '''while not pygame.event.wait().type in (QUIT, KEYDOWN):
                            pass'''
                        return
            if new_position.collidelistall(game.level_map.pits):
                anim.pitFall(game)

            if new_position.collidelistall(
                    game.level_map.lava):  # lava collision
                for lava in game.level_map.lava:
                    if lava.rect == new_position:
                        game.lava.play()
                        self.gems -= 10
                        game.level_map.lava.remove(lava)
                        game.level_map.floors.append(lava.rect)
            '''
             THIS SHOULD TAKE points away if player hits mobtile, however it only works if hitting a 
             space they used to be in. not working right obviosuly
             
            if new_position.collidelistall(game.level_map.moveable_walls):
                self.score -= 10
                new_position = old_position
                return'''
            '''
            take this out to try and return position instwead
            self.rect = new_position

        else:
            game.hit_wall.play()
            self.rect = old_position'''

            position = new_position

        else:
            game.hit_wall.play()
            position = old_position

        return position
Exemplo n.º 6
0
    def checkCollision(self, game, old_position, new_position):
        position = old_position
        if new_position.collidelist(game.level_map.walls) == -1: #check to see if colliding with walls -1 is False
            if new_position.collidelist(game.level_map.items) == -1: #check to see if colliding with items
                pass
            else:
                for item in game.level_map.items: #iterate through items and remove them from the map and the list
                    if item.rect == new_position:
                        game.level_map.items.remove(item)
                        if item.kind == 'gem' and self.gems < self.maxGems:
                            self.gems += 1
                            self.score += 10
                            game.level_map.panel.messages.append('You pick up a gem. Points and Life!')
                        if item.kind == 'whip':
                            self.whips += 1
                            self.score =+ 10
                            game.level_map.panel.messages.append('You pick up a Whip.')
                        if item.kind == 'gold':
                            game.gold.play()
                            self.score += 500
                            game.level_map.panel.messages.append('You pick up a pile of gold.')
                        if item.kind == 'teleport':
                            self.teleports +=1
                            self.score += 10
                            game.level_map.panel.messages.append('A teleport scroll.')
                        if item.kind == 'key':
                            self.keys +=1
                            self.score += 10
                            game.level_map.panel.messages.append('A key.')
                        if item.kind == 'chest':
                            gem = random.randint(0,3)
                            whip = random.randint(0,3)
                            game.level_map.panel.messages.append('You open a treasure chest and find {0} gems and {1} whips.'.format(gem,whip))
                            self.gems += gem
                            self.whips += whip
                            self.score += 50 
                        if item.kind == 'whip_ring':
                            self.weapon.power += 1
                            self.score += 1000
                            game.level_map.panel.messages.append('You find a ring of Whip Power!')
                        if item.kind == 'gem_sack':
                            self.gems += 25
                            self.score += 125
                            game.level_map.panel.messages.append('You found a pouch with 25 Gems')
                        if item.kind == 'bomb':
                            game.bomb.play()
                            self.score += 500
                            center_x = item.rect.centerx
                            center_y = item.rect.centery
                            radius = IMGSIZE * 5
                            for wall in game.level_map.breakable:
                                x = wall.rect.centerx
                                y = wall.rect.centery
                                if game.isInRange(center_x, center_y, radius, x,y):
                                    game.level_map.breakable.remove(wall)
                                    game.level_map.moveable_walls.remove(wall)
                        if item.kind == 'k' or item.kind =='r' or item.kind == 'o' or item.kind == 'z':
                            game.level_map.kroz.append(item.kind)
                            if len(game.level_map.kroz) == 4: 
                                if game.level_map.kroz[0] == 'k' and game.level_map.kroz[1] == 'r' and game.level_map.kroz[2] == 'o' and game.level_map.kroz[3] == 'z':
                                    game.player.score += 10000
                                    #play a sound
                                    game.level_map.panel.messages.append('You get the KROZ 10,000 point bonus!')
                        if item.kind == 'tele_trap':
                            position = self.teleport(game)
                            return position
#---SPELLS-----------------------------------------                        
                        if item.kind == 'freeze':
                            game.stopTimers()
                            self.score += 10
                            game.changeTimer(check_things,ETERNITY)
                            game.level_map.panel.messages.append('You trigger a freeze monster spell!')
                        if item.kind == 'slow':
                            game.slowTimers()
                            self.score += 10
                            game.changeTimer(check_things,ETERNITY)
                            game.level_map.panel.messages.append('You trigger a slow monster spell!')
                        if item.kind == 'fast':
                            game.speedTimers()
                            self.score += 10
                            game.changeTimer(check_things,ETERNITY)
                            game.level_map.panel.messages.append('You trigger a speed monster spell!')
                        if item.kind == 'invisibility':
                            game.player.invisible = True
                            self.score += 100
                            game.changeTimer(check_things,ETERNITY)
                            game.level_map.panel.messages.append('You trigger an invisibiltiy spell!')
                        if item.kind == 'more_monsters':
                            for a in range(20,50):
                                space = random.choice(game.level_map.floors)
                                x = space.left
                                y = space.top
                                mob = Mob(os.path.join(IMGDIR,'gnome.bmp'), x , y, 1, 'slow')
                                game.level_map.mobs.append(mob)
                        
                        if item.kind == 'tablet':
                            game.player.score += 10000
                            game.level_map.panel.messages.append(item.message)                  
#TRIGGERS-----------------------------------------------------------------------------------------------------------------------------------
            if new_position.collidelistall(game.level_map.triggers): #triggers that set of special events etc
                for trigger in game.level_map.triggers:
                    if trigger.rect == new_position:
                        trigger.trigger(game)
                       
                
            if new_position.collidelistall(game.level_map.doors): #locked doors
                for item in game.level_map.doors:
                    if item.rect == new_position:
                        if self.keys > 0:
                            self.keys -= 1
                            game.level_map.doors.remove(item)
                        else:
                            game.hit_wall.play()
                            new_position = old_position
                            
            if new_position.collidelistall(game.level_map.mobs): #collision with mobs
                for mob in game.level_map.mobs:
                    if mob.rect == new_position:
                        game.mob_hit_player.play()
                        self.gems -= mob.damage
                        self.score += 10
                        game.level_map.mobs.remove(mob)
                        
            
            if new_position.collidelistall(game.level_map.breakable): #breakable is a list of breakable walls, needed to seperate from regular walls
                for wall in game.level_map.breakable:
                    if wall.rect == new_position:
                        game.hit_wall.play()
                        new_position = old_position
                        
            if new_position.collidelistall(game.level_map.hidden_walls): # this is the hidden walls, maybe only level 1? when bumped it appears
                for wall in game.level_map.hidden_walls: 
                    if wall == new_position:
                        game.hit_wall.play()
                        new_position = old_position
                        game.level_map.walls.append(wall)
                
                
            if new_position.collidelistall(game.level_map.exits): #did they get to the level exit?
                for level_exit in game.level_map.exits:
                    if level_exit == new_position:
                        self.score += 50
                        game.level_map.level += 1
                        game.level_map.clearLevel()
                        RLmap.renderAll(game)
                        game.clock.tick(2)
                        game.level_map.makeMap(game)
                        game.level_map.panel.messages = []
                        RLmap.renderAll(game)
                        
                        '''while not pygame.event.wait().type in (QUIT, KEYDOWN):
                            pass'''
                        return
            if new_position.collidelistall(game.level_map.pits):
                anim.pitFall(game)
                
            if new_position.collidelistall(game.level_map.lava): #lava collision
                for lava in game.level_map.lava:
                    if lava.rect == new_position:
                        game.lava.play()
                        self.gems -= 10
                        game.level_map.lava.remove(lava)
                        game.level_map.floors.append(lava.rect)
            '''
             THIS SHOULD TAKE points away if player hits mobtile, however it only works if hitting a 
             space they used to be in. not working right obviosuly
             
            if new_position.collidelistall(game.level_map.moveable_walls):
                self.score -= 10
                new_position = old_position
                return'''
                        
            '''
            take this out to try and return position instwead
            self.rect = new_position

        else:
            game.hit_wall.play()
            self.rect = old_position'''
            
            position = new_position
        
        else:
            game.hit_wall.play()
            position = old_position
            
        return position