def update():
    gfw.world.update()
    global state
    if state != START_GAME:
        endgame()
        return

    global time, boss_die
    if boss_die:
        time += gfw.delta_time
    if time > 10:
        state = END_GAME
    dis_score.score += 10
    global boss_ox, boss_ap
    boss_ox += gfw.delta_time

    if boss_ox < 75:
        enemy_gen.update()
    else:
        if boss_ap > 0:
            music_bg.stop()
            wav_siren.play(5)
            music_bg2.repeat_play()
            boss.Boss().generate()
            boss_ap -= 1

    for e in gfw.world.objects_at(gfw.layer.enemy):
        check_enemy(e)
    for i in gfw.world.objects_at(gfw.layer.item):
        check_item(i)
    for e_b in gfw.world.objects_at(gfw.layer.boss):
        check_boss(e_b)
def enter():
    gfw.world.init([
        'bg', 'enemy', 'boss', 'bullet', 'player', 'boss_bullet', 'effect',
        'ui', 'item'
    ])
    global player, charnum
    player = Player()
    Player.player_type = charnum
    gfw.world.add(gfw.layer.player, player)

    global dis_score, score
    dis_score = Score(canvas_width - 20, canvas_height - 50)
    gfw.world.add(gfw.layer.ui, dis_score)
    score = Score(canvas_width - 20, canvas_height - 100)
    gfw.world.add(gfw.layer.ui, score)

    global font
    font = gfw.font.load(gobj.RES_DIR + '/BM.ttf', 40)

    life_gauge.load()

    bg = VertScrollBackground('/map_01.png')
    bg.speed = 100
    gfw.world.add(gfw.layer.bg, bg)

    global power_item, dual_item
    power_item = gfw.image.load(gobj.RES_DIR + '/powershot.png')
    dual_item = gfw.image.load(gobj.RES_DIR + '/dualshot.png')

    global music_bg, music_bg2, wav_mon_die, player_voice, player_hit_wav, wav_boss_dead, wav_siren, get_money, get_item
    music_bg = load_music(gobj.RES_DIR + '/bg_music.mp3')
    music_bg2 = load_music(gobj.RES_DIR + '/boss_stage_bg.mp3')
    wav_mon_die = load_wav(gobj.RES_DIR + '/enemy_die.wav')
    player_voice = load_wav(gobj.RES_DIR + '/go.wav')
    player_hit_wav = load_wav(gobj.RES_DIR + '/hit.wav')
    wav_siren = load_wav(gobj.RES_DIR + '/siren.wav')
    wav_boss_dead = load_wav(gobj.RES_DIR + '/boss_dead.wav')
    get_money = load_wav(gobj.RES_DIR + '/get_coin.wav')
    get_item = load_wav(gobj.RES_DIR + '/get_item.wav')

    music_bg.repeat_play()
    player_voice.play()

    global state
    state = START_GAME
    enemy_gen.reset()

    global boss_ox, boss_ap
    boss_ox, boss_ap = 0, 1
    boss.Boss().LASER_INTERVAL = 0.5

    global time, boss_die
    time = 0
    boss_die = False
    highscore.load()

    Gameover_state.num = charnum
Exemple #3
0
    def spawn_enemies(self):
        """Spawns enemies"""
        self.enemies.empty()
        self.shooters = []

        for i in self.sprites:
            if i[0] == "P":
                self.plat = platform.Platform((int(i[1]), int(i[2])),
                                              (int(i[3]), int(i[4])))
            elif i[0] == "B":
                self.plat = platform.Books((int(i[1]), int(i[2])), int(i[3]))
            elif i[0] == "PE":
                self.enemy = E.PlatformEnemy(self.plat)
                self.enemies.add(self.enemy)
            elif i[0] == "GE":
                self.enemy = E.GhostEnemy((int(i[1]), int(i[2])))
                self.enemies.add(self.enemy)
            elif i[0] == "TRFE":
                self.triggers.append(
                    trigger.Trigger("FE", (int(i[1]), int(i[2])),
                                    (int(i[3]), int(i[4]))))
            elif i[0] == "TRGE":
                self.triggers.append(
                    trigger.Trigger("GE", (int(i[1]), int(i[2])),
                                    (int(i[3]), int(i[4]))))
            elif i[0] == "TRPE":
                self.plat = platform.Platform((int(i[1]), int(i[2])),
                                              (int(i[3]), int(i[4])),
                                              (int(i[5]), int(i[6])))
                self.triggers.append(trigger.Trigger("PE", (-1, -1),
                                                     self.plat))
            elif i[0] == "SH":
                enemy = E.ShooterEnemy((int(i[1]), int(i[2])), float(i[3]))
                self.shooters.append(enemy)
            elif i[0] == "I":
                self.enemy = E.Spider((int(i[1]), int(i[2])))
                self.enemies.add(self.enemy)
            elif i[0] == "T":
                enemy = boss.Boss()
                self.bosses.add(enemy)
            elif i[0] == "BE":
                enemy = E.BookEnemy((int(i[1]), int(i[2])), i[3])
                self.enemies.add(enemy)
Exemple #4
0
    def new(self):
        ''' Scanning the tmx map and assign elems to Classes'''
        self.obj_poss_loc = []

        for tile_object in self.map.tmxdata.objects:
            if tile_object.name == 'player':
                self.player = player.Player(self, tile_object.x, tile_object.y)
            if tile_object.name == 'wall':
                self.wall = obstacles.Obstacle(self, tile_object.x,
                                               tile_object.y,
                                               tile_object.width,
                                               tile_object.height)
            if tile_object.name == 'boss':
                self.boss = boss.Boss(self, tile_object.x, tile_object.y,
                                      tile_object.width, tile_object.height)
            if tile_object.name == 'end':
                self.end = end.End(self, tile_object.x, tile_object.y,
                                   tile_object.width, tile_object.height)
            if tile_object.name == 'object':
                self.obj_poss_loc.append((tile_object.x, tile_object.y))

        self.place_objects(['tube', 'ether', 'needle'])
Exemple #5
0
def Reset():
    gfw.world.clear()
    gfw.world.init([
        'bg', 'bossbullet', 'boss', 'zombiebullet', 'bullet', 'zombie', 'p',
        'obj_dead'
    ])

    global bg
    bg.init()
    gfw.world.add(gfw.layer.bg, bg)

    global p
    p = player.Player()
    gfw.world.add(gfw.layer.p, p)

    global zombie, zombies
    for i in range(0, 20):
        zombie = Enemy(random.randint(500, 1600), 115, random.randint(1, 2))
        gfw.world.add(gfw.layer.zombie, zombie)

    global boss
    boss = bs.Boss()
    gfw.world.add(gfw.layer.boss, boss)
Exemple #6
0
import location, player, item, boss
import random
from datetime import datetime

seed = input(" Enter a seed: ")

tile = location.Location(seed + "0,0")

user = player.Player(input("Hello Space Ranger! What is your Ranger name ? "))

boss = boss.Boss()

bossLocationX = random.randint(6, 12)
bossLocationY = random.randint(6, 12)

x = 0
y = 0
tiles = {}
searched_tiles = []

# print("{}, {}".format(bossLocationX, bossLocationY))

def bossFight():
    print("You have descovered a boss!")
    while boss.isAlive() and user.isAlive():
        print("You have {} health!".format(user.health))
        command = input("FIGHT CLUB > ")
        if command == "punch":
            if random.randint(1,5) < 5:
                print("You punched the enemy!")
                boss.health -= 3
Exemple #7
0
import member
import boss
import hentai

GRP_MSG_PARSE_INIT_FLAG = True

BOSS = boss.Boss()
MEMBER = member.Member()

def help():
    ret = '''ENE です,兰德索尔排刀助手
    (✪ω✪)
    boss/王
    出刀/申请出刀
    报刀/提交伤害
    队列
    已出刀
    未出刀
    统计
    修正/数据修正'''
    return ret

## 完成内容解析后,构造该结构用于发送到群里
def new_ret_dict(data):
    ret = { "toUser":data['FromGroupId'], 
            "sendToType":2,       
            "sendMsgType":"TextMsg",     
            "content":"",     
            "groupid":0,       
            "atUser":0,      
            "replayInfo":'null'
Exemple #8
0
def game_loop():
    menu_object = menu.Menu()
    # ----------- INIT MENU ####
    while menu_object.menu_loop:
        menu_object.update()
        menu_object.draw(FONT, FONT_SMALL)
        for event in pg.event.get():
            menu_object.get_event(event)
        pg.display.update()
        clock.tick(fps)

    # ----------- INIT ####
    pg.mixer.music.play(-1)
    player = pl.Player(pl.PLAYER_UP_DOWN, start_lives, start_score, 1)
    player.rect.center = display_width * 0.5 - 33, display_height * 0.8
    enemies = enemy.Enemies()
    enemies_pro = enemy.Projectiles()
    boss_obj = boss.Boss(0, -300, -1)
    boss_pro = boss.Projectiles()
    projectiles_objects = projectiles.Projectiles()
    particles_objects = particle.Particle()
    particles_objects.add_particles()
    comets_objects = comet.Comet()
    _thread.start_new_thread(comets_objects.add_comets, (10, 1))
    level_transition = lt.LevelTransition(0, -400, game_display, white, 3, FONT, display_width, display_height + 400)
    scraps_objects = scraps.Scraps(0, 0, 0, 0)
    scraps_objects_enemies = enemy.Scraps(0, 0, 0, 0)
    particles = []
    sparkles = []
    exit_ = False

    while not player.is_dead:
        constans.player_dead = True

        # ----------- HANDLING EVENTS ####
        for event in pg.event.get():
            if event.type == pg.QUIT:
                player.is_dead = True
                exit_ = True
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_ESCAPE:
                    exit_ = True
                    player.is_dead = True
            if event.type == pg.KEYUP:
                pass
            player.get_event(event)
            projectiles_objects.get_event(event, player.rect, PEW_SOUND, particles, sparkles)

        # ----------- UPDATES ####
        # ----------- ENEMY SPAWN INIT ####
        if player.level == 3 and len(enemies.enemies) < 50:
            enemies.add_enemy()
        elif player.level == 3:
            player.level += 1
        if player.level == 10:
            _thread.start_new_thread(boss_obj.create_boss, (5, ))
            player.level += 1

        projectiles_objects.update()
        particles_objects.update(player.level)
        comet_pos = comets_objects.update(pg.Rect(player.rect.x + 10, player.rect.y, 45, 85),
                                          player, projectiles_objects, scraps_objects, EXPLOSIONS)
        enemies.update(enemies_pro, projectiles_objects, player, PEW_ENEMY_SOUND, HURTS, EXPLOSIONS,
                       scraps_objects_enemies)
        enemies_pro.update(player)
        boss_pos = boss_obj.update(EXPLOSIONS, projectiles_objects, boss_pro, PEW_ENEMY_SOUND, player, comets_objects, UP_SOUND)
        boss_pro.update(player)
        scraps_objects_enemies.update()
        player.update(enemies, comets_objects)
        scrap_pos = scraps_objects.update(pg.Rect(player.rect.x + 10, player.rect.y, 45, 85),
                                          player, projectiles_objects)
        if comet_pos is not None:
            for i in range(3):
                particles.append(se.ParticleBall(game_display, comet_pos, (0, -1), gravity, particles, sparkles, 20))
        if boss_pos is not None:
            particles.append(se.ParticleBall(game_display, boss_pos, (0, -1), gravity, particles, sparkles, 20))
        if scrap_pos is not None:
            particles.append(se.ParticleBall(game_display, scrap_pos, (0, -1), gravity, particles, sparkles, 12))
        for p in particles:
            p.update()
            try:
                if clock.get_fps() + 1 < fps: particles.remove(p)
            except ValueError:
                pass
        for s in sparkles: s.update()

        # ----------- DRAW ####
        game_display.fill(black)
        projectiles_objects.draw()
        particles_objects.draw(game_display)
        enemies.draw(game_display)
        scraps_objects_enemies.draw(game_display)
        comets_objects.draw(game_display)
        boss_obj.draw(game_display)
        player.draw(game_display)
        pl.draw_points(player.score, FONT_SMALL, game_display)
        scraps_objects.draw(game_display)
        enemies_pro.draw(game_display)
        boss_pro.draw(game_display)
        level_transition.update(player.level)
        for p in particles: p.draw()
        for s in sparkles: s.draw()

        pg.display.update()
        clock.tick(fps)

    if not exit_:
        game_loop()
Exemple #9
0
def main():
    # Main Program
    pygame.init()
 
    # Define altura, largura e posição inicial da janela
    size = [constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT]
    screen = pygame.display.set_mode(size)
    os.environ["SDL_VIDEO_WINDOW_POS"] = '200,50'
    screen = pygame.display.set_mode((1, 1))
    
    # Define ícone e label da janela
    icon = pygame.image.load("images/triforceicon.png")
    pygame.display.set_caption("The Legend Of Souls")
    pygame.display.set_icon(icon)
    
    # Esconde o cursor do mouse
    pygame.mouse.set_visible(0)
 
    # Cria o player
    player1 = player.Player()
    
    # Cria os inimigos
    boss1 = boss.Boss()
 
    # Cria todos os levels
    level_list = []
    level_list.append(levels.Level_01(player1, boss1))
    level_list.append(levels.Level_02(player1, boss1))
 
    # Define o level atual
    current_level_no = 0
    current_level = level_list[current_level_no]
 
    active_sprite_list = pygame.sprite.Group()
    player1.level = current_level
    boss1.level = current_level
    
    
    # Define posição inicial do player
    player1.rect.x = 150
    player1.rect.y = constants.SCREEN_HEIGHT - player1.rect.height - 12
    active_sprite_list.add(player1)
    
    # Define posição inicial do enemy
    boss1.rect.x = 550
    boss1.rect.y = constants.SCREEN_HEIGHT - boss1.rect.height - 32
    active_sprite_list.add(boss1)
 
    #Loop até o usuário fechar o jogo
    ingame = True
 
    # Controla quão rápido a janela atualiza
    clock = pygame.time.Clock()
    
    # Mostra a tela de início
    levels.start_screen()
 
    # -------- Main Program Loop -----------
    while ingame:
        
        for event in pygame.event.get():
            pressed = pygame.key.get_pressed()
            
            # Fecha a janela se o usuário clicar em fechar
            if event.type == pygame.QUIT:
                ingame = False               
                
            if event.type == pygame.KEYDOWN:
                
                # Fecha a janela se o usuário pressionar ALT+F4
                if ((pressed[pygame.K_LALT] and pressed[pygame.K_F4]) or (pressed[pygame.K_RALT] and pressed[pygame.K_F4])):
                    ingame = False 
                    
                # Move o player para a esquerda
                if event.key == pygame.K_a:
                    player1.go_left()
                if event.key == pygame.K_LEFT:
                    boss1.go_left()
                    
                # Move o player para a direita
                if event.key == pygame.K_d:
                    player1.go_right()
                if event.key == pygame.K_RIGHT:
                    boss1.go_right()
                    
                # Faz o player pular
                if event.key == pygame.K_w:
                    player1.jump()
                if event.key == pygame.K_UP:
                    boss1.jump()
                    
                # Faz o player recuperar vida
                if event.key == pygame.K_e:
                    player1.use_estus()
                    
                # Calcula o dano recebido pelo player
                if event.key == pygame.K_q:
                    player1.calc_damage(40, player1.defending)
                if event.key == pygame.K_p:
                    boss1.calc_damage(200)
                    
                # Calcula a stamina gasta pelo player
                if event.key == pygame.K_r:
                    player1.calc_stamina(15)
                    
                # Regenera a stamina gasta pelo player
                if event.key == pygame.K_f:
                    pygame.time.set_timer(pygame.USEREVENT+1, 5)
                    
                # Coloca o player em posição de defesa
                if event.key == pygame.K_z:
                    player1.defending = True                    
                    player1.defend()
            
            # Calcula a regeneração de stamina do player
            if event.type == pygame.USEREVENT+1:
                player1.stamina_regen()                
                    
            if event.type == pygame.KEYUP:
                
                # Para o movimento do player
                if event.key == pygame.K_a and player1.change_x < 0:
                    player1.stop()
                if event.key == pygame.K_LEFT and boss1.change_x < 0:
                    boss1.stop()
                if event.key == pygame.K_d and player1.change_x > 0:
                    player1.stop()
                if event.key == pygame.K_RIGHT and boss1.change_x > 0:
                    boss1.stop()
                    
                # Para a regeneração de stamina
                if event.key == pygame.K_f:
                    pygame.time.set_timer(pygame.USEREVENT+1, 0)
                    
                # Tira o player da posição de defesa
                if event.key == pygame.K_z:
                    player1.defending = False
 
        # Atualiza o player
        active_sprite_list.update()
 
        # Atualiza os itens no level
        current_level.update()
 
        # Se o player chegar perto do lado direito, muda o world para a esquerda (-x)
        if player1.rect.right >= 500:
            diff = player1.rect.right - 500
            player1.rect.right = 500
            current_level.shift_world(-diff)
  
        # Se o player chegar perto do lado esquerdo, muda o world para a direita (+x)
        if player1.rect.left <= 120:
            diff = 120 - player1.rect.left
            player1.rect.left = 120
            current_level.shift_world(diff)
 
        # Se o player chegar ao fim do level, vai para o próximo level
        current_position = player1.rect.x + current_level.world_shift
        if (current_position < current_level.level_limit) and current_level_no != 0:
            player1.rect.x = 120
            if current_level_no < len(level_list)-1:
                current_level_no += 1
                current_level = level_list[current_level_no]
                player1.level = current_level
 
        # Todo código de desenhar
        current_level.draw(screen)
        active_sprite_list.draw(screen)
        player.player_hud(screen, player1.health, player1.stamina, player1.estus_rn)
        boss.boss_hud(screen, boss1.health)
        
        # Limita os frames por segundo
        clock.tick(constants.FPS)
 
        # Atualiza a janela com o que foi desenhado
        pygame.display.update()
 
    pygame.quit() #Termina o jogo
Exemple #10
0
def Game(screen, mute):
    global backgrounds_all, backgrounds

    # Source: https://www.soundsnap.com/search/audio
    gameover_sound = pygame.mixer.Sound("sound/music for game/gameover.wav")
    lifeup_sound = pygame.mixer.Sound("sound/music for game/lifeupsound.wav")
    mobgothit_sound = pygame.mixer.Sound("sound/music for game/mobgothit.wav")
    playergothit_sound = pygame.mixer.Sound(
        "sound/music for game/playergothit.wav")
    spookyplayershoot_sound = pygame.mixer.Sound(
        "sound/music for game/spookyplayershoot.wav")
    starbulletpickup_sound = pygame.mixer.Sound(
        "sound/music for game/starbulletpickup.wav")

    # Initialise clock
    clock = pygame.time.Clock()
    offset = pygame.time.get_ticks() // 1000

    # Initialise screen
    screen = pygame.display.set_mode((WIDTH, HEIGHT))
    screen.fill(pygame.Color("White"))
    pygame.display.flip()

    # Set screen title
    pygame.display.set_caption("Bone Voyage")

    pygame.mouse.set_visible(False)  # Hide mouse

    # Player group
    player_loop, player_frame = 0, 0
    player = eng.Player(player_animations[player_frame])
    player_group = pygame.sprite.Group()
    player_group.add(player)

    #Player bullet group
    bullet_group = pygame.sprite.Group()

    # Bullet group one group for each bullet direction
    rightbullet_group = pygame.sprite.Group()
    leftbullet_group = pygame.sprite.Group()
    downbullet_group = pygame.sprite.Group()
    upbullet_group = pygame.sprite.Group()

    #boss bullet group
    boss_bullet_group = pygame.sprite.Group()

    # Mob group
    # With adjustable number of mobs using mob_number
    mob = pygame.sprite.Group()
    mob_number = 5
    for i in range(mob_number):  #no of mobs
        m = eng.Mob(mob_animations, 1)
        mob.add(m)

    # Heart group
    # With adjustable number of hearts
    heart = pygame.sprite.Group()
    heart_number = 1
    for i in range(heart_number):
        h = eng.Heart(heart_img)
        heart.add(h)

    # Bullet star group
    # With adjustable number of bullet stars
    starbullet = pygame.sprite.Group()
    for i in range(1):
        s = eng.StarBullet(starbullet_img)
        starbullet.add(s)

    # Score and a separate variable for kill counter
    # Level used for speed and level screen
    score = 0
    kills = 0
    level = 1
    """ Display Level Screen """
    # Draws cover level screen
    eng.DrawLevelScreen(screen, WIDTH, HEIGHT, level_img, level)
    # Set offset for game timer
    offset = pygame.time.get_ticks() // 1000

    # init background
    scroll_bg = [0, WIDTH]
    bg = [0, 0]
    for i in range(2):
        index = random.randint(0, len(backgrounds) - 1)
        bg[i] = backgrounds[index]

    speed = 2

    # Pausing element added here
    # Theory for the pausing is taken from another person
    # Source: https://stackoverflow.com/questions/30744237/how-to-create-a-pause-button-in-pygame
    pause = False
    game_running = True
    state = game_running
    while game_running:

        # Event loop
        mouse_xpos, mouse_ypos = pygame.mouse.get_pos()  # Get mouse location
        left_click = False
        for event in pygame.event.get():
            if event.type == pygame.QUIT:  # Window close event
                eng.Shutdown()
            if event.type == pygame.KEYDOWN:  # Key down events
                if event.key == pygame.K_ESCAPE:
                    game_running = False
                if event.key == pygame.K_p:
                    if state == pause:
                        state = game_running
                    elif state == game_running:
                        state = pause
            if event.type == pygame.MOUSEBUTTONDOWN:  # Mouse click down
                if event.button == 1:
                    left_click = True

        if state == game_running:
            """ SCROLL BACKGROUND """
            for i in range(2):
                scroll_bg[i] = eng.DrawScrollBackground(
                    screen, WIDTH, speed, bg[i], FRAMERATE, scroll_bg[i])

            # reset background loop
            # This code is overcomplicated for current use
            # It was intended to take n backgrounds
            # and display them in a random sequence
            # Currently it only used one background on an infinite loop
            if scroll_bg[1] < 0:
                scroll_bg = [0, WIDTH]
                bg[0] = bg[1]
                index = random.randint(0, len(backgrounds) - 1)
                bg[1] = backgrounds[index]
            """ TIMER AND SCORE """
            # Calculates the total number of seconds at current point in time
            # Code is built from http://programarcadegames.com/python_examples/f.php?file=timer.py
            # Also calculates score based on time spent in game and number of kills
            total_seconds = (pygame.time.get_ticks() // 1000) - offset

            if total_seconds >= 30:
                level += 1
                eng.DrawLevelScreen(screen, WIDTH, HEIGHT, level_img, level)
                offset = pygame.time.get_ticks(
                ) // 1000  # set offset for game timer
                backgrounds = backgrounds_all[level % 2]

            seconds = total_seconds % 60
            if kills > 1 or kills == 1:
                score = seconds + (kills * 5)
            else:
                score = seconds
            """ PLAYER MECHANICS """
            # increment player frame
            player_loop += 1
            if player_loop >= FRAMERATE // (
                    len(player_animations) *
                    speed):  # Sync player roll to background
                player_loop = 0
                player_frame += 1
            if player_frame >= len(player_animations):
                player_frame = 0

            # Shoots bullet on left click
            if left_click:
                if mute == False:
                    pygame.mixer.Sound.play(spookyplayershoot_sound)
                bullet_group.add(player.create_bullet(bullet_img))

            # If player life is 0 game stops
            if player.life == 0:
                if mute == False:
                    pygame.mixer.Sound.play(gameover_sound)
                eng.DrawStaticBackground(
                    screen, WIDTH, HEIGHT,
                    gameover_img)  # Set game over background
                pygame.display.flip()  # update display
                pygame.time.wait(
                    5000)  # wait for 5 seconds i.e. display game over screen
                game_running = False  #if player is hit by mob, loop stops and game exits
            """ COLLISIONS """
            # Check to see if a bullet hits a mob
            # Bullet needs to run into mob and vice versa so 2 Trues
            # inspiration drawn from https://www.youtube.com/watch?v=1_H7InPMjaY&t=64s 8:00
            bullet_groups = [
                leftbullet_group, rightbullet_group, upbullet_group,
                downbullet_group
            ]
            for bullet in bullet_groups:
                mob_hit = pygame.sprite.groupcollide(mob, bullet, True, True)
                #This loop adds a mob if a mob dies
                for hit in mob_hit:
                    if mute == False:
                        pygame.mixer.Sound.play(mobgothit_sound)
                    m = eng.Mob(mob_animations, level)
                    mob.add(m)
                    kills += 1

            mob_player_hit = pygame.sprite.groupcollide(
                mob, bullet_group, True, True
            )  #didnt work when I added it to the above loop for some reason so making a separate loop for now for player bullet.
            # This loop adds a mob if a mob dies
            for hit in mob_player_hit:
                if mute == False:
                    pygame.mixer.Sound.play(mobgothit_sound)

                m = eng.Mob(mob_animations, level)
                mob.add(m)
                kills += 1

            # If the player is hit by a mob the player loses a life
            # Mob is removed to prevent too many collisions and loss of multiple lives
            player_hit = pygame.sprite.spritecollide(player, mob, True)
            if player_hit:
                if mute == False:
                    pygame.mixer.Sound.play(playergothit_sound)
                player.life -= 1
                mob.remove(m)
                m = eng.Mob(mob_animations, level)
                mob.add(m)
            """ BOOSTS """
            # If the player is touches heart gains a life
            # Heart is removed to prevent too many collisions and gaining of multiple lives
            life_up = pygame.sprite.spritecollide(player, heart, True)
            if life_up:
                if mute == False:
                    pygame.mixer.Sound.play(lifeup_sound)
                player.life += 1
                heart.remove(h)

            # Caps the amount of lives the player can gain
            # Spawns a new life every 20 to 30 seconds
            if player.life < 5:
                if seconds % 25 == 0:
                    h.rect.y = random.randrange(
                        HEIGHT - h.rect.height
                    )  # spanwns them on x axis outside of screen to the right
                    h.rect.x = random.randrange(
                        WIDTH + 100, WIDTH + 500
                    )  # spawn in a random place to the right of the screen
                    heart.add(h)

            # If the player is touches bullet, cause bullets to shoot in 4 directions
            # Bullet is removed to prevent too many collisions and gaining of multiple, multiple bullets
            bullet_up = pygame.sprite.spritecollide(player, starbullet, True)
            if bullet_up:
                if mute == False:
                    pygame.mixer.Sound.play(starbulletpickup_sound)
                    pygame.mixer.Sound.play(spookyplayershoot_sound)
                leftbullet_group.add(player.create_leftbullet(bullet_img))
                downbullet_group.add(player.create_downbullet(bullet_img))
                rightbullet_group.add(player.create_rightbullet(bullet_img))
                upbullet_group.add(player.create_upbullet(bullet_img))
                starbullet.remove(s)

            # Spawns a new star bullet every 30 seconds
            if seconds % 20 == 0:
                s.rect.y = random.randrange(
                    HEIGHT - s.rect.height
                )  # spanwns them on x axis outside of screen to the right
                s.rect.x = random.randrange(
                    WIDTH + 100, WIDTH +
                    500)  # spawn in a random place to the right of the screen
                starbullet.add(s)

            # Updates and draws everything to screen
            mob.update()
            player_group.update(player_animations[player_frame])
            heart.update()
            starbullet.update()

            mob.draw(screen)
            heart.draw(screen)
            rightbullet_group.draw(screen)
            leftbullet_group.draw(screen)
            downbullet_group.draw(screen)
            upbullet_group.draw(screen)
            player_group.draw(screen)
            starbullet.draw(screen)
            bullet_group.draw(screen)
            bullet_group.update()
            rightbullet_group.update()
            leftbullet_group.update()
            downbullet_group.update()
            upbullet_group.update()

            # Section to write score and lives to screen
            myfont = pygame.font.SysFont(pygame.font.get_default_font(), 50)
            str_lives = str(player.life)
            str_score = str(score)

            lives = myfont.render("Lives: " + str_lives, False, (153, 0, 153))
            score_total = myfont.render("Score: " + str_score, False,
                                        (153, 0, 153))

            screen.blit(lives, (0, 20))
            screen.blit(score_total, (0, 80))

            lives = player.life

            # If level is 5 boss screen will be shown
            if level == 5:
                game_running = boss.Boss(screen, mute, score, level, lives)

        # If the game is paused the instructions are shown on screen
        elif state == pause:
            screen.blit(cheatsheet_img,
                        ((WIDTH / 2 - 400), (HEIGHT / 2 - 300)))

        # Add to frame count for the timer
        clock.tick(FRAMERATE)
        pygame.display.flip()
Exemple #11
0
def update(frame_time):
    global current_time, creating, score, create_next_time, background, monster_number, stage, total_time, bossi, player
    # handle_events(frame_time)

    # frame_time = get_time() - current_time
    total_time += frame_time

    if stage == 1 or stage == 2:

        for monsteri in monster:
            for p_arrow in player_arrow:
                if collide(p_arrow, monsteri):
                    monsteri.hp -= 1
                    score += 100
                    player_arrow.remove(p_arrow)
            if monsteri.hp == 0:
                if random.randint(0, 2) == 0:
                    items.append(Player_item.Item(monsteri.x, monsteri.y))
                # print("item creat")
                monster.remove(monsteri)

            if collide(player, monsteri):
                monsteri.hp -= 1
                player.hp -= 1
                #print("crash")

            if monsteri.detecting(player) and monsteri.sense == False:
                monsteri.sense = True
                monsteri.change_state()
            elif monsteri.detecting(
                    player) == False and monsteri.sense == True:
                monsteri.sense = False
                monsteri.change_state()

        for arrow in monster_arrow:
            if collide(player, arrow):
                monster_arrow.remove(arrow)
                player.hp -= 1
            # print("mon aro crash")

        if total_time >= 100:
            create_time = 0.5
        elif total_time >= 80:
            create_time = 0.8
        elif total_time >= 60:
            create_time = 1.2
        elif total_time >= 40:
            create_time = 0.8
        elif total_time >= 20:
            create_time = 1.0
        elif total_time >= 0:
            create_time = 1.5

        if total_time % create_time < 0.05 and creating == False:
            creating = True
            temp = random.randint(1, monster_number)
            if temp == 1:
                monster.append(monsterpy.Monster_Lion())
            elif temp == 2:
                monster.append(monsterpy.Monster_Sheep())
            else:
                monster.append(monsterpy.Monster_Ghost())
            create_next_time = total_time + create_time

        if total_time > create_next_time:
            creating = False

        for item in items:
            if item.x < -100:
                items.remove(item)

    # clear_canvas()

        for monsteri in monster:
            monsteri.update(frame_time)
        for arrow in monster_arrow:
            arrow.update(frame_time)
            if arrow.x < -150:
                monster_arrow.remove(arrow)
                #print("arrow remove")
    for p_arrow in player_arrow:
        p_arrow.update(frame_time)
        if p_arrow.x > 900 or p_arrow.x < -50:
            player_arrow.remove(p_arrow)
    for item in items:
        if collide(player, item):
            #item.eat()
            if item.item_num < 3:
                score += 20
            elif item.item_num == 3:
                player.skill_gauge += 1
            elif item.item_num == 4:
                player.hp += 2
            items.remove(item)
            #background.bgm_call(stage)
        else:
            item.update(frame_time)
    background.update(frame_time, stage)
    player.update(frame_time, stage)
    if total_time >= 40 and stage == 1:
        background.potal = True
        if player.x > background.potal_x:
            stage = 2
            background.bgm2.repeat_play()
            #game_framework.reset_time()
            player.hp = 10
            player.skill_gauge = 2
            creating = False
            create_time = 0.0
            monster_number = 3
            create_next_time = 0.0
            for monsteri in monster:
                monster.remove(monsteri)
            #reset_time()
    if total_time >= 80 and stage == 2:
        background.potal = True
        if player.x > background.potal_x:
            background.potal = False
            stage = 3
            background.bgm3.repeat_play()
            player.hp = 10
            player.skill_gauge = 0
            create_time = 5.0
            creating = False
            for monsteri in monster:
                monster.remove(monsteri)
            bossi = boss.Boss()
            next_time = 0
    if stage == 3:
        global next_time
        create_time = 5.0
        bossi.update(frame_time, player.x, player.y)
        if total_time >= next_time:
            if collide(player, bossi):
                bossi.hp -= 1
                player.hp -= 2
                #print("crash")
                next_time = total_time + 2
        for p_arrow in player_arrow:
            if collide(p_arrow, bossi):
                bossi.hp -= 1
                score += 100
                player_arrow.remove(p_arrow)

        for boss_a in boss_arrow:
            boss_a.update(frame_time)
        if total_time % create_time < 0.05 and creating == False:
            creating = True
            temp = random.randint(1, 5)
            if temp == 1:
                bossi.state = 0
            elif temp == 2:
                bossi.state = 1
            elif temp == 3:
                bossi.state = 3
            create_next_time = total_time + create_time

        if total_time > create_next_time:
            creating = False
        if bossi.hp == 0:
            game_framework.change_state(end_state)
    global player, bossi
    if player.hp <= 0:
        game_framework.change_state(end_state)
Exemple #12
0
 def __init__(self):
     self.boss = boss.Boss()
     self.is_running = True
     self.player_character = character.Character()
     self.UI = ui.GameUI(self)
Exemple #13
0
    def load_room(self):

        if self.cur_room >= len(Game.ROOMS):
            self.playing = False
            return
        self.downgrades[self.cur_room].apply()
        if self.cur_room == 3:
            # Boss room
            self.boss = boss.Boss(self)
            pygame.mixer.music.load("snd/boss theme.ogg")
            pygame.mixer.music.play(-1)
        self.player.bullets.clear()
        self.tiles = []
        self.obstacles = []
        y = 0
        for cur_row in Game.ROOMS[self.cur_room]:
            x = 0
            for cur_tile in cur_row:
                rect = Rect(x * Game.TILE_SIZE, y * Game.TILE_SIZE,
                            Game.TILE_SIZE, Game.TILE_SIZE)
                if cur_tile == "@":
                    type = "wall"
                    if y == 0:
                        if x == 0:
                            img = self.room_tiles["wall_top_left"]
                        elif x == Game.WIN_WIDTH_T - 1:
                            img = self.room_tiles["wall_top_right"]
                        else:
                            img = self.room_tiles["wall_top"]
                    elif y == Game.WIN_HEIGHT_T - 1:
                        if x == 0:
                            img = self.room_tiles["wall_bottom_left"]
                        elif x == Game.WIN_WIDTH_T - 1:
                            img = self.room_tiles["wall_bottom_right"]
                        else:
                            img = self.room_tiles["wall_bottom"]
                    else:
                        if x == 0:
                            img = self.room_tiles["wall_left"]
                        elif x == Game.WIN_WIDTH_T - 1:
                            img = self.room_tiles["wall_right"]
                        else:
                            img = self.room_tiles["wall_square"]
                elif cur_tile == "_":
                    type = "door"
                    if y == 0:
                        img = self.room_tiles["door_closed"]
                    elif y == Game.WIN_HEIGHT_T - 1:
                        img = pygame.transform.flip(
                            self.room_tiles["door_closed"], False, True)
                elif cur_tile == ".":
                    type = "floor"
                    img = self.room_tiles["floor"]
                elif cur_tile == "E":
                    self.enemies.append(enemy.Enemy(self, (x, y)))
                    type = "floor"
                    img = self.room_tiles["floor"]
                elif cur_tile == "T":
                    self.enemies.append(enemy.Enemy(self, (x, y), True))
                    type = "floor"
                    img = self.room_tiles["floor"]
                self.tiles.append(tile.Tile(self, type, rect, img))
                x += 1
            y += 1
        self.obstacles[:] = [
            t for t in self.tiles if t.type == "wall" or t.type == "door"
        ]
        self.player.pos = pygame.math.Vector2(Game.PLAYER_SPAWN)
        self.doors_open = False
Exemple #14
0
 def setBoss(self):
     self.boss = boss.Boss('EndBoss')
     self.bossGroup.add(self.boss)