Example #1
0
    def fire_ball(self, big):
        mag = 1.5 if self.dir == 1 else -1.5
        mag *= random.uniform(0.5, 1.0)
        #ballSpeed = mag * self.speed + self.dx

        #ballSpeed = math.sqrt((Boy.MouseX - self.x) ** 2 + (Boy.MouseY - self.y) ** 2) / 2

        #ySpeed = 2 * self.speed * (1 + random.random())
        ballSpeed = abs(Boy.MouseX -
                        self.x) / 25 if self.dir == 1 else -1 * abs(
                            Boy.MouseX - self.x) / 25
        ySpeed = abs(Boy.MouseY -
                     self.y) / 25 if self.dir == 1 else -1 * abs(Boy.MouseY -
                                                                 self.y) / 25
        if big: ySpeed *= 0.75
        ball = Ball(big, self.x, self.y + 70, ballSpeed, ySpeed)
        game_world.add_object(ball, game_world.layer_obstacle)
Example #2
0
 def update(self):
     global t, i, r
     self.frame = (self.frame + FRAMES_PER_ACTION * ACTION_PER_TIME *
                   game_framework.frame_time) % 6
     self.bullet_draw_time += 0.01 * FRAMES_PER_ACTION * ACTION_PER_TIME * game_framework.frame_time
     i += 1
     t = i / 100
     if (i > 101):
         r = (r + 1) % 10
         i = 0
     if self.bullet_draw_time > 2.0:
         while self.bullet_count < 360:
             self.bullet_count += 30
             bullets = Bullet(self.x, self.y, 5, self.bullet_count)
             game_world.add_object(bullets, 1)
         self.bullet_draw_time = 0
         self.bullet_count = 0
Example #3
0
def update():
    for game_object in game_world.all_objects():
        game_object.update()
    # 마리오와 적이 충돌하면 하트 1개 없어짐
    if collide(mario, enemy):
        game_world.remove_object(mario_life)

    # 마리오가 점프로 적을 죽이면 적 없어짐
    if collide(mario, enemy) and mario.is_jump:
        game_world.remove_object(enemy)

    global item
    if collide(mario, item_box):
        print("collide")
        item_box.collide_to_mario = True
        item = Item()
        game_world.add_object(item, 0)
Example #4
0
    def update(self):
        front_monster_x = 0  # 맨앞 몬스터 좌표
        front_monster_y = 720  # 맨앞 몬스터 좌표
        front_monster_move = 0 # 맨앞 몬스터 어디경로 이동
        for game_object in game_world.all_objects(): #맨앞 몬스터 위치
            if str(game_object).find("monster1") != -1:
                if math.sqrt((game_object.x - self.x)**2 + (game_object.y - self.y)**2) < 450:
                    if game_object.move > front_monster_move:
                        front_monster_x = game_object.x
                        front_monster_y = game_object.y

        if get_time() >= self.time + 0.5: #화살발사
            if front_monster_y != 720: #없으면 화살 발사 x
                vector = (abs(front_monster_x - self.x) + abs(self.y - front_monster_y)) / 25
                shot_arrow = Shot_arrow(self.x, self.y, (front_monster_x - self.x) / vector, (front_monster_y - self.y) / vector)
                game_world.add_object(shot_arrow, 2)
            self.time = get_time()
Example #5
0
def enter():
    global CharacterMeiMei,Stage1screen,Stage2screen,Stage3screen,Stage4screen,\
        Cloud,Chicken,Sword
    CharacterMeiMei = MeiMei()
    Stage1screen = Stage1()
    Stage2screen = Stage2()
    Stage3screen = Stage3()
    Stage4screen = Stage4()
    Stage1_enemy_Cloud = Cloud()
    Stage1_enemy_Chicken = Chicken()
    Stage1_enemy_Sword = Sword()

    game_world.add_object(Stage1screen, 0)
    game_world.add_object(CharacterMeiMei, 1)
    game_world.add_object(Stage1_enemy_Cloud, 2)
    game_world.add_object(Stage1_enemy_Chicken, 3)
    game_world.add_object(Stage1_enemy_Sword, 4)
def enter():
    global balls, ball
    balls = [Ball() for i in range(100)]
    game_world.add_objects(balls, 1)

    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    global background
    background = Background()
    game_world.add_object(background, 0)

    background.set_center_object(boy)
    for ball in balls:
        ball.set_background(background)
    boy.set_background(background)
Example #7
0
def update():
    global time, monster1, stage_time, stage1_time, stage

    for game_object in game_world.all_objects():
        game_object.update()
    ui.update()

    if get_time() - time >= 10 and stage == 0:
        stage = 1
        stage_time = get_time()
        stage1_time = get_time()

    if stage == 1:
        if get_time() - stage1_time >= 2:
            monster1 = Monster1()
            game_world.add_object(monster1, 0)
            stage1_time += 2
Example #8
0
    def update(self):
        self.bt.run()
       #self.frame = (self.frame + FRAMES_PER_ACTION * ACTION_PER_TIME * game_framework.frame_time) % FRAMES_PER_ACTION
        self.x += self.speed * math.cos(self.dir)* game_framework.frame_time
        self.y += self.speed * math.sin(self.dir)* game_framework.frame_time
        self.x = clamp(50, self.x, get_canvas_width() - 50)
        self.y = clamp(50, self.y, get_canvas_height() - 50)
        self.survive_timer-=1

        if self.survive_timer==0 :
            global bubble_destroys
            bubble_destroys=Bubble_destroy(self.x,self.y)
            game_world.add_object(bubble_destroys,4)
            game_world.remove_object(self)

            bubble_destroyList = game_world.get_layer(4)
            boyList = game_world.get_layer(1)
Example #9
0
    def initPlayerUI(self):
        uiHpCheck = 0
        uiScoreCheck = 0
        uiMoneyCheck = 0
        uiBombCheck = 0
        uiLayer = game_world.get_layer(UIINGAME)

        uiStage = 0

        for ui in uiLayer:
            if ui.uiID == 'hpbar':
                self.hpBar = ui
                uiHpCheck = 1
            elif ui.uiID == 'score':
                self.scoreBar = ui
                uiScoreCheck = 1
            elif ui.uiID == 'money':
                self.moneyBar = ui
                uiMoneyCheck = 1
            elif ui.uiID == 'bomb':
                self.bombBar = ui
                uiBombCheck = 1
            elif ui.uiID == 'numbers':
                self.stage_number = ui
                uiStage = 1

        if uiHpCheck == 0:
            self.hpBar = HPBar(470, 30, self.hp)
            game_world.add_object(self.hpBar, UIINGAME)

        if uiBombCheck == 0:
            self.bombBar = BombBar(470, 80, self.bombCount)
            game_world.add_object(self.bombBar, UIINGAME)

        if uiScoreCheck == 0:
            self.scoreBar = Score(120, 680, self.score)
            game_world.add_object(self.scoreBar, UIINGAME)

        if uiMoneyCheck == 0:
            self.moneyBar = Money(480, 680, 1, 120, 2, 17, self.money)
            game_world.add_object(self.moneyBar, UIINGAME)

        if uiStage == 0:
            self.stage_number = Numbers(120, 650, 2, 2, 17, stage_scene.stage)
            game_world.add_object(self.stage_number, UIINGAME)
Example #10
0
    def update(self):
        self.frame = (self.frame + FRAMES_PER_ACTION * ACTION_PER_TIME *
                      game_framework.frame_time) % 8

        if collide(self,
                   self.ground[0]) or collide(self, self.ground[1]) or collide(
                       self, self.ground[4]) or collide(
                           self, self.ground[6]):  # 모든 땅에 작용하게 하기
            self.stop()
            if collide(self, self.boy):
                self.pickUpEffect = pick_up_effect.Pick_up_effect(
                    self.x, self.y, self.bg)
                game_world.add_object(self.pickUpEffect, 2)
                self.boy.coinCount += 1
                game_world.remove_object(self)
                self.y -= 1000

        self.y -= self.fall_speed * game_framework.frame_time
Example #11
0
    def handle_event(self, event):
        if (event.type, event.key) in key_event_table:
            key_event = key_event_table[(event.type, event.key)]
            self.add_event(key_event)

        if event.type == SDL_KEYDOWN and event.key == SDLK_SPACE:
            if get_time() >= self.time + 0.3:  # 화살발사
                if self.look_vector == 0:
                    elf_arrow = Elf_arrow(self.x, self.y, 0, 10)
                elif self.look_vector == 1:
                    elf_arrow = Elf_arrow(self.x, self.y, 0, -10)
                elif self.look_vector == 2:
                    elf_arrow = Elf_arrow(self.x, self.y, -10, 0)
                elif self.look_vector == 3:
                    elf_arrow = Elf_arrow(self.x, self.y, 10, 0)

                game_world.add_object(elf_arrow, 2)
                self.time = get_time()
Example #12
0
def enter():
    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    global background
    background = Background()
    game_world.add_object(background, 0)

    global balls
    balls = [FixedBall() for i in range(100)]
    game_world.add_objects(balls, 1)

    background.set_center_object(boy)  # 백그라운드에 boy를 알려줌
    boy.set_background(background)  # boy에 백그라운드를 알려줌

    for ball in balls:
        ball.set_background(background)
Example #13
0
def enter():
    global map, heroine, blue_enemy, blue_enemys1, black_enemys1, bose_enemy, red_enemy, green_enemy, special_enemy
    map = Map()
    heroine = Heroine()
    blue_enemy = Blue_enemy(600, 400)
    game_world.add_object(heroine, 1)
    #global summontime
    #summontime = get_time()
    blue_enemys1 = [
        Blue_enemy(i, j) for (i, j) in [(600, 700), (650, 700), (700, 700)]
    ]
    black_enemys1 = [
        Black_enemy(i, j) for (i, j) in [(0, 700), (-50, 700), (-100, 700)]
    ]
    bose_enemy = Bose_enemy(300, 800)
    red_enemy = Red_enemy(0, 700)
    green_enemy = Green_enemy(600, 700)
    special_enemy = Special_enemy(300, 810)
Example #14
0
def enter():
    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    global grass
    grass = Grass()
    game_world.add_object(grass, 0)

    #global bird
    #Birds = [Bird() for i in range(5)]
    #for bird in Birds:
    #    bird = Bird()
    #    game_world.add_object(bird,2)

    global balls
    balls=[Ball() for i in range(10)]+[BigBall() for i in range(10)]
    game_world.add_objects(balls,1)
Example #15
0
def enter():
    global Sound2
    Sound2 = load_wav('pickup.wav')
    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    global background
    background = Background()
    game_world.add_object(background, 0)

    global ba
    ba = [Ball() for i in range(100)]

    game_world.add_objects(ba, 1)

    background.set_center_object(boy)
    boy.set_background(background)
Example #16
0
    def do(character):

        if character.frame == 15:
            find_wall = False

            for sw in game_world.layer_objects(game_world.snow_wall_layer):
                if sw.check_existence(character.x, character.x + 60):
                    sw.strengthen_wall(character.shovel_power)
                    find_wall = True

            if find_wall == False:
                game_world.add_object(snow_wall.SnowWall(character.x, False, character.snow_wall_level, character.shovel_power), game_world.snow_wall_layer)

            character.frame = 0
        else:
            if character.frame == 0:
                character.make_wall_sound.play()
            character.frame += 1
def enter():
    global isaac, background, is_key_pressed, is_attack_key_pressing, bullet_dir, gushers, is_bullet_create
    global BackGround_Width, BackGround_Height, invincibility_time, shot_term, bullets, door,  monster_count
    global  flies, big_flies, enemy_bullets, is_enemy_bullet_create, is_bullet_upgrade, is_black_bullet_create
    global duke,is_monster_create


    game_world.objects = [[],[]]
    BackGround_Width = 1280
    BackGround_Height = 960
    isaac = Isaac()
    isaac.x = 200
    isaac.y = BackGround_Height//2
    isaac.body_x, isaac.body_y = isaac.x - 5, isaac.y - 50
    isaac.now_health = main_state_4.hp
    isaac.body_is_move = False
    duke = Duke()
    monster_count = 0
    background = BackGround(1)
    entrance_door = Door()
    entrance_door.x = door_position[0]
    entrance_indoor = InDoor()
    entrance_indoor.x = door_position[0]

    game_world.add_object(background,0)
    game_world.add_object(isaac, 1)
    game_world.add_object(duke,1)
    game_world.add_object(entrance_door, 1)
    game_world.add_object(entrance_indoor, 1)
    is_key_pressed = 0
    is_attack_key_pressing = 0
    bullet_dir = 0
    is_bullet_create = False
    is_enemy_bullet_create = False
    is_bullet_upgrade = main_state_4.is_bullet_upgrade
    is_black_bullet_create = False
    is_monster_create = False
    invincibility_time = 100
    shot_term = 0
    flies = []
    big_flies = []
    bullets = []
    enemy_bullets = []
    pass
def updateStage():
    global stage
    global stage_time
    global stageCount
    global stageCountMax
    global monsterSpawnCheck
    global bossCheck
    # stage
    if stageCount > stageCountMax:
        monsterSpawnCheck = False

    # monster spawn
    if monsterSpawnCheck == True:
        spawnCheck = monsterpattern.update()
        if spawnCheck == True:
            stageCount += 1
    else:
        # 몬스터를 모두 잡았으면?
        monsterLayer = game_world.get_layer(MONSTER)

        if len(monsterLayer) == 0 and bossCheck == False:
            # 보스 등장
            boss = BossHead()
            boss.modify_difficulty(Monster_Pattern.difficulty + 1)
            game_world.add_object(boss, BOSS)
            #
            bgm.stop()
            bossbgm.repeat_play()
            bossCheck = True

        elif bossCheck == True:
            # if 보스를 잡으면
            bossLayer = game_world.get_layer(BOSS)
            if len(bossLayer) == 0:
                # 코인이 쏟아지며
                # 코인이 없어지면
                coinLayer = game_world.get_layer(COIN)
                # 상점 등장
                if len(coinLayer) == 0:
                    stage_time += mainframe.frame_time
                    if stage_time > 1.5:
                        bossCheck = False
                        mainframe.push_state(shop_state)
                        stage_time = 0.0
Example #19
0
def update():
    global player, gameState, wav_bomb, wav_item
    ui.update()
    game_world.update()

    if gameState == GAMESTATE_INPLAY:
        if random.random() < 0.01:
            if (random.random() < 0.5):
                item = Item(*gen_random())
            else:
                item = CoinItem(*gen_random())
            game_world.add_object(item, game_world.layer_item)
            print("Items:", game_world.count_at_layer(game_world.layer_item))
        for m in game_world.objects_at_layer(game_world.layer_obstacle):
            collides = collides_distance(player, m)
            if collides:
                wav_bomb.play()
                player.life -= 1
                print("Player Life = ", player.life)
                if player.life > 0:
                    game_world.remove_object(m)
                else:
                    end_game()
                break
        for m in game_world.objects_at_layer(game_world.layer_item):
            collides = collides_distance(player, m)
            if collides:
                wav_item.play()
                game_world.remove_object(m)
                if player.life < Life.LIFE_AT_START:
                    player.life += 1
                else:
                    player.score += m.score
                break

        player.score += game_framework.frame_time
        update_score()

    obstacle_count = game_world.count_at_layer(game_world.layer_obstacle)
    # print(obstacle_count)
    if obstacle_count < BULLETS_AT_START + player.score // 10:
        # print("Missiles:", (obstacle_count + 1))
        createMissle()
    delay(0.03)
Example #20
0
def enter():
    global normal_zombie, fast_zombie, map, tower1
    normal_zombie = Normal_Zombie()
    fast_zombie = Fast_Zombie()
    tower1 = tower.Tower1()
    map = Map()
    game_world.add_object(map, 0)
    game_world.add_object(normal_zombie, 1)

    game_world.add_object(fast_zombie, 1)
    game_world.add_object(tower1, 1)
Example #21
0
 def phase3(self):
     if int(self.spawntimer) % 150 == 0:  # type1 spawn
         if self.type1_counter < 4 and self.spawntimer < 500:
             enemy = Enemy_1(1200, 1000, 500, -200, 0, -200)
             game_world.add_object(enemy, 1)
             enemy = Enemy_1(1200, -200, 500, 200, 0, 800)
             game_world.add_object(enemy, 1)
             self.type1_counter += 2
         elif self.type1_counter < 4 and self.spawntimer > 500:
             enemy = Enemy_1(1800, 200, 500, 200, 0, 0)
             game_world.add_object(enemy, 1)
             enemy = Enemy_1(1800, 600, 0, -500, 0,
                             600)  # 시작위치, 꺾이는 정도, 끝 위치
             game_world.add_object(enemy, 1)
             self.type1_counter += 2
     if self.type3_counter < 1 and int(self.spawntimer) % 350 == 0:
         enemy = Enemy_3(1700, 200, -500, 0, 1400, 350)
         game_world.add_object(enemy, 1)
         self.type3_counter += 1
def enter():
    global boy
    boy = Boy()
    game_world.add_object(boy, 1)

    global background
    background = Background()
    game_world.add_object(background, 0)

    global balls;
    balls = [Ball() for i in range(0, 100)];
    game_world.add_objects(balls, 1)

    for ball in balls:
        ball.set_background(background);

    # fill here
    background.set_center_object(boy);
    boy.set_background(background);
Example #23
0
def enter():
    global stage2_map, ingame_word, screen_timer, screen_timer_2, cursor, gameover_timer, bgm
    global bazzi, block, enemy
    global block_y, block_x

    screen_timer = 0
    screen_timer_2 = 0

    stage2_map = load_image('resource/stage2.png')
    ingame_word = load_image('resource/InGame_Image_Word.png')
    cursor = load_image('resource/hand_arrow.png')
    bgm = load_music('sound/piratebgm.mp3')
    bgm.set_volume(80)
    bgm.repeat_play()

    bazzi = Bazzi()
    bazzi.stage = 3
    bazzi.x, bazzi.y = 180, 140
    game_world.add_object(bazzi, 3)

    enemy = Boss()
    game_world.add_object(enemy, 2)

    block = []
    for i in range(195):
        if block_x > 610:
            block_y -= 40
            block_x = 39
        # no broken1
        if i == 82:
            box_color = 4
            box_broken = 1
        # no broken2
        elif i == 16 or i == 28 or i == 166 or i == 178:
            box_color = 5
            box_broken = 1
        else:
            box_color = 0
            box_broken = 0
        block.append(Block(block_x, block_y, box_color, box_broken))
        block_x += 40.2
    game_world.add_objects(block, 0)
    pass
Example #24
0
def enter():
    global mainstage
    mainstage = title_state.stage
    global player
    player = Player()
    global sky
    if stageload.stage == 2:
        sky = Sky(stageload.stage)
    else:
        sky = Sky(mainstage)

    global map_counter
    if stageload.stage == 2:
        map_counter = Mapcounter(stageload.stage)
    else:
        map_counter = Mapcounter(mainstage)

    game_world.add_object(sky, 0)
    game_world.add_object(player, 1)
Example #25
0
    def update(self):
        if self.upgrade >= 1:
            self.damage = 10
        if self.upgrade == 2:
            self.delays = 0.7

        for game_object in game_world.all_objects():  #맨앞 몬스터 위치
            if str(game_object).find("monster1") != -1 or str(
                    game_object).find("monster2") != -1 or str(
                        game_object).find("monster3") != -1 or str(
                            game_object).find("monster4") != -1 or str(
                                game_object).find("boss") != -1 or str(
                                    game_object).find("teemo") != -1:
                if math.sqrt((game_object.x - self.x)**2 +
                             (game_object.y - self.y)**2) < 250:
                    if get_time() >= self.time + 1.5:  # 마법 사용
                        magic = Magic(self.x, self.y, self.damage, self.delays)
                        game_world.add_object(magic, 2)
                        self.time = get_time()
Example #26
0
    def __init__(self, x, y, is_foe):
        self.IMAGE_SIZE = 150

        self.WAITING_TIME_PER_ACTION = 10
        self.WAITING_ACTION_PER_TIME = 1.0 / self.WAITING_TIME_PER_ACTION
        self.WAITING_FRAMES_PER_ACTION = 3

        self.HATCH_TIME_PER_ACTION = 1
        self.HATCH_ACTION_PER_TIME = 1.0 / self.HATCH_TIME_PER_ACTION
        self.HATCH_FRAMES_PER_ACTION = 0

        self.DYING_TIME_PER_ACTION = 2
        self.DYING_ACTION_PER_TIME = 1.0 / self.DYING_TIME_PER_ACTION
        self.DYING_FRAMES_PER_ACTION = 1
        self.dying_init_time = 0

        self.is_air_unit = False
        self.is_foe = is_foe

        self.is_hatching = False
        self.max_hp = 1
        self.hp = 1

        self.frame = 0
        self.x, self.y = x, y
        self.opacity = 1

        self.event_que = []
        self.cur_state = WaitingState
        self.waiting_init_time = self.WAITING_TIME_PER_ACTION

        self.hatch_init_time = 0
        self.dying_init_time = 0

        hp_bar = HpBar(self.x, self.y, self.max_hp, self.max_hp, self.is_foe,
                       self)
        self.hp_bar = hp_bar
        game_world.add_object(hp_bar, 4)

        if SunBloom.image is None:
            SunBloom.image = load_image('resource\\image\\unit\\sunbloom.png')

        self.add_self()
Example #27
0
def enter():
    global cursor, background, sad, happy, selected_character
    cursor = Cursor()
    background = Background()
    sad = Choose_sadness300()
    happy = Choose_happiness300()
    selected_character = 'none'

    game_world.add_object(background, 0)
    game_world.add_object(happy, 1)
    game_world.add_object(sad, 1)
    game_world.add_object(cursor, 2)
Example #28
0
def enter():
    global mario, map, enemy, object
    mario = Mario()
    map = Map()
    enemy = Enemy()
    object = Object()

    game_world.add_object(map, 0)
    game_world.add_object(object, 1)
    game_world.add_object(mario, 2)
    game_world.add_object(enemy, 3)
    pass
Example #29
0
 def stage2_phase4(self):
     if int(self.spawntimer) % 30 == 0:  # type1 spawn
         if self.type1_counter < 4 and self.spawntimer < 500:
             enemy = Enemy_4(1200, 1000, 500, -200, 0, -200)
             game_world.add_object(enemy, 1)
             enemy = Enemy_4(1200, -200, 500, 200, 0, 800)
             game_world.add_object(enemy, 1)
             self.type1_counter += 2
         elif self.type1_counter < 4 and self.spawntimer > 500:
             enemy = Enemy_4(1800, 200, 500, 200, 0, 0)
             game_world.add_object(enemy, 1)
             enemy = Enemy_4(1800, 600, 0, -500, 0,
                             600)  # 시작위치, 꺾이는 정도, 끝 위치
             game_world.add_object(enemy, 1)
             self.type1_counter += 2
     if self.type4_counter < 1 and int(self.spawntimer) % 350 == 0:
         enemy = Enemy_7(1900, 200, -500, 0, 1500, 350)
         game_world.add_object(enemy, 1)
         self.type4_counter += 1
 def drop_item(self):
     for i in range(self.dropItemCount):
         if 1 <= self.dropItemSort + i <= 5:
             game_world.add_object(Coin(self.x, self.y, self.bg),
                                   2)  # update()에서 현재 좌표 해서 해결
         elif 6 <= self.dropItemSort + i <= 8:
             game_world.add_object(Potion(self.x, self.y, self.bg), 2)
         elif self.dropItemSort + i == 9:
             game_world.add_object(Lightning_Book(self.x, self.y, self.bg),
                                   2)
         else:
             game_world.add_object(Fire_Book(self.x, self.y, self.bg), 2)