Esempio n. 1
0
def update():
    game_world.update()
    for ball in game_world.objects_at_layer(game_world.layer_obstacle):
        if collides(boy, ball):
            print("Collision:", ball)
            game_world.remove_object(ball)
    delay(0.03)
Esempio n. 2
0
def update():
    global player, gameState, wav_bomb, wav_item

    if gameState != GAMESTATE_INPLAY:
        delay(0.01)
        return

    ui.update()
    game_world.update()
    global wall, ball
    wall.didBounce(ball)
    player.didBounce(ball)

    global stage, stage_number
    for b in game_world.objects_at_layer(game_world.layer_obstacle):
        if b.didBounce(ball):
            if stage != None and 'scores' in stage:
                score = stage['scores'][b.type]
                # print(b.type, score)
            else:
                score = b.score
            if b.life == 0:
                player.score += score
                update_score()
                count = game_world.count_at_layer(game_world.layer_obstacle)
                if count == 0:
                    goto_next_stage()
            break

    delay(0.01)
Esempio n. 3
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)
Esempio n. 4
0
def save():
    global stage, saved, stage_number, max_stage_number
    bricks = list(game_world.objects_at_layer(game_world.layer_obstacle))
    stage['bricks'] = list(map(Brick.dict, bricks))
    print(stage)
    f = open('stage_' + str(stage_number) + '.json', 'w')
    json.dump(stage, f, indent=2)
    f.close()
    saved = True
    if max_stage_number <= stage_number:
        max_stage_number = stage_number + 1

    update_stage_label()
Esempio n. 5
0
    def update(self):
        Player_ob = game_world.objects_at_layer(game_world.layer_player)
        Player_ob = next(Player_ob, None)

        lengthX = Player_ob.x - self.x
        lengthY = Player_ob.y - self.y
        dist = math.sqrt(lengthX**2 + lengthY**2)

        if Player_ob.state >= 2:
            if (dist < Player_ob.wepon.range):
                self.speed = self.Maxspeed * -5
                self.health -= Player_ob.wepon.damage

        if dist > 0:
            self.x += self.speed * lengthX / dist
            self.y += self.speed * lengthY / dist
        if (Player_ob.x < self.x):
            self.dir = RIGHT
        else:
            self.dir = LEFT

        #colide
        if (Player_ob.state < 2):
            if (self.dir == LEFT):
                left, right = (self.x - self.right), (self.x + self.left)
            else:
                left, right = (self.x - self.left), (self.x + self.right)
            if (Player_ob.state == player.IDLE_LEFT):
                Tleft, Tright = (Player_ob.x -
                                 Player_ob.right), (Player_ob.x +
                                                    Player_ob.left)
            elif (Player_ob.state == player.IDLE_RIGHT):
                Tleft, Tright = (Player_ob.x -
                                 Player_ob.left), (Player_ob.x +
                                                   Player_ob.right)

            if (left < Tright and right > Tleft and (self.y + self.top) >
                (Player_ob.y - Player_ob.bottom) and (self.y - self.bottom) <
                (Player_ob.y + Player_ob.top)):
                self.speed = self.Maxspeed * -5
                Player_ob.health -= self.damage

        if (self.speed != self.Maxspeed):
            self.speed += 1
        if self.health <= 0:
            game_world.remove_object(self)
Esempio n. 6
0
def add_brick(x, y):
    global saved, brick
    ord_val = brick.orderValue()
    index = 0
    at = -1
    for b in game_world.objects_at_layer(game_world.layer_obstacle):
        if GameObject.intersection(b, brick) != None:
            game_world.remove_object(b)
            return
        if at < 0:
            if b.orderValue() > ord_val:
                at = index
        index += 1
    print('at:', at, 'ord_val:', ord_val)
    if at >= 0:
        game_world.add_object_at(brick, at, game_world.layer_obstacle)
    else:
        game_world.add_object(brick, game_world.layer_obstacle)
    mark_edited()
    brick = Brick(x, y, brick.type, True)