Esempio n. 1
0
File: RL.py Progetto: 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':
Esempio n. 2
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
Esempio n. 3
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:
Esempio n. 4
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