Ejemplo n.º 1
0
void vs_input_tick(scene *scene) {
    vs_local *local = scene->userdata;
    ctrl_event *p1=NULL, *i;
    game_player *player1 = game_state_get_player(scene->gs, 0);
    controller_poll(player1->ctrl, &p1);
    i = p1;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                if (i->event_data.action == ACT_ESC) {
                    if(dialog_is_visible(&local->too_pathetic_dialog)) {
                        dialog_event(&local->too_pathetic_dialog, i->event_data.action);
                    } else if(dialog_is_visible(&local->quit_dialog)) {
                        dialog_event(&local->quit_dialog, i->event_data.action);
                    } else if(vs_is_singleplayer(scene) && player1->sp_wins != 0) {
                        // there's an active singleplayer campaign, confirm quitting
                        dialog_show(&local->quit_dialog, 1);
                    } else {
                        game_state_set_next(scene->gs, SCENE_MELEE);
                    }
                } else {
                    vs_handle_action(scene, i->event_data.action);
                }
            } else if (i->type == EVENT_TYPE_CLOSE) {
                game_state_set_next(scene->gs, SCENE_MENU);
            }
        } while((i = i->next));
    }
    controller_free_chain(p1);
}
Ejemplo n.º 2
0
void melee_tick(scene *scene, int paused) {
    melee_local *local = scene_get_userdata(scene);
    game_player *player1 = game_state_get_player(scene->gs, 0);
    game_player *player2 = game_state_get_player(scene->gs, 1);
    ctrl_event *i = NULL;

    // Handle extra controller inputs
    i = player1->ctrl->extra_events;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                handle_action(scene, 1, i->event_data.action);
            } else if (i->type == EVENT_TYPE_CLOSE) {
                game_state_set_next(scene->gs, SCENE_MENU);
                return;
            }
        } while((i = i->next));
    }
    i = player2->ctrl->extra_events;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                handle_action(scene, 2, i->event_data.action);
            } else if (i->type == EVENT_TYPE_CLOSE) {
                game_state_set_next(scene->gs, SCENE_MENU);
                return;
            }
        } while((i = i->next));
    }

    if(!local->pulsedir) {
        local->ticks++;
    } else {
        local->ticks--;
    }
    if(local->ticks > 120) {
        local->pulsedir = 1;
    }
    if(local->ticks == 0) {
        local->pulsedir = 0;
    }
    local->hartick++;
    if (local->selection == 1) {
        if(local->hartick > 10) {
            local->hartick = 0;
            object_dynamic_tick(&local->har_player1[5*local->row_a + local->column_a]);
            if (player2->selectable) {
                object_dynamic_tick(&local->har_player2[5*local->row_b + local->column_b]);
            }
        }
    }

}
Ejemplo n.º 3
0
void newsroom_continue_dialog_clicked(dialog *dlg, dialog_result result){
    scene *sc = dlg->userdata;
    if(result == DIALOG_RESULT_NO) {
        game_state_set_next(sc->gs, SCENE_MENU);
    } else if (result == DIALOG_RESULT_YES_OK) {
        // Resetting p2->sp_wins here allows the game to progress,
        // otherwise you get stuck with the same opponent
        game_player *p1 = game_state_get_player(sc->gs, 0);
        game_player *p2 = game_state_get_player(sc->gs, 1);
        p2->sp_wins = 0;
        chr_score_reset(game_player_get_score(p1), 1);
        chr_score_reset_wins(game_player_get_score(p1));
        game_state_set_next(sc->gs, SCENE_VS);
    }
}
Ejemplo n.º 4
0
void vs_handle_action(scene *scene, int action) {
    vs_local *local = scene_get_userdata(scene);
    if(dialog_is_visible(&local->too_pathetic_dialog)) {
        dialog_event(&local->too_pathetic_dialog, action);
    } else if(dialog_is_visible(&local->quit_dialog)) {
        dialog_event(&local->quit_dialog, action);
    } else {
        switch (action) {
            case ACT_KICK:
            case ACT_PUNCH:
                game_state_set_next(scene->gs, SCENE_ARENA0+local->arena);
                break;
            case ACT_UP:
            case ACT_LEFT:
                if(game_state_get_player(scene->gs, 1)->selectable) {
                    local->arena--;
                    if (local->arena < 0) {
                        local->arena =4;
                    }
                    object_select_sprite(&local->arena_select, local->arena);
                }
                break;
            case ACT_DOWN:
            case ACT_RIGHT:
                if(game_state_get_player(scene->gs, 1)->selectable) {
                    local->arena++;
                    if (local->arena > 4) {
                        local->arena = 0;
                    }
                    object_select_sprite(&local->arena_select, local->arena);
                }
                break;
        }
    }
}
Ejemplo n.º 5
0
void intro_tick(scene *scene, int paused) {
    intro_local *local = scene_get_userdata(scene);
    local->ticks++;
    if(local->ticks > 2500) {
        game_state_set_next(scene->gs, SCENE_MENU);
    }
}
Ejemplo n.º 6
0
int cutscene_event(scene *scene, SDL_Event *event) {
    cutscene_local *local = scene_get_userdata(scene);
    game_player *player1 = game_state_get_player(scene->gs, 0);
    ctrl_event *p1=NULL, *i;
    controller_event(player1->ctrl, event, &p1);
    i = p1;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                if (
                        i->event_data.action == ACT_KICK ||
                        i->event_data.action == ACT_PUNCH) {

                    if (strlen(local->current) + local->pos < local->len) {
                        local->pos += strlen(local->current)+1;
                        local->current += strlen(local->current)+1;
                        char * p;
                        if ((p = strchr(local->current, '\n'))) {
                            // null out the byte
                            *p = '\0';
                        }
                    } else {
                        game_state_set_next(scene->gs, cutscene_next_scene(scene));
                    }
                    return 1;
                }
            }
        } while((i = i->next));
    }
    controller_free_chain(p1);
    return 1;
}
Ejemplo n.º 7
0
void melee_input_tick(scene *scene) {
    melee_local *local = scene_get_userdata(scene);
    game_player *player1 = game_state_get_player(scene->gs, 0);
    game_player *player2 = game_state_get_player(scene->gs, 1);
    ctrl_event *p1=NULL, *p2 = NULL, *i;
    controller_poll(player1->ctrl, &p1);
    controller_poll(player2->ctrl, &p2);
    i = p1;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                if (i->event_data.action == ACT_ESC) {
                    sound_play(20, 0.5f, 0.0f, 2.0f);
                    if (local->selection == 1) {
                        // restore the player selection
                        local->column_a = local->pilot_id_a % 5;
                        local->row_a = local->pilot_id_a / 5;
                        local->column_b = local->pilot_id_b % 5;
                        local->row_b = local->pilot_id_b / 5;

                        local->selection = 0;
                        local->done_a = 0;
                        local->done_b = 0;
                    } else {
                        game_state_set_next(scene->gs, SCENE_MENU);
                    }
                } else {
                    handle_action(scene, 1, i->event_data.action);
                }
            } else if (i->type == EVENT_TYPE_CLOSE) {
                game_state_set_next(scene->gs, SCENE_MENU);
            }
        } while((i = i->next));
    }
    controller_free_chain(p1);
    i = p2;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                handle_action(scene, 2, i->event_data.action);
            } else if (i->type == EVENT_TYPE_CLOSE) {
                game_state_set_next(scene->gs, SCENE_MENU);
            }
        } while((i = i->next));
    }
    controller_free_chain(p2);
}
Ejemplo n.º 8
0
void menu_listen_tick(component *c) {
    listen_menu_data *local = menu_get_userdata(c);
    game_state *gs = local->s->gs;
    if(local->host) {
        ENetEvent event;
        if(enet_host_service(local->host, &event, 0) > 0 && event.type == ENET_EVENT_TYPE_CONNECT) {
            ENetPacket * packet = enet_packet_create("0", 2,  ENET_PACKET_FLAG_RELIABLE);
            enet_peer_send(event.peer, 0, packet);
            enet_host_flush(local->host);

            DEBUG("client connected!");
            controller *player1_ctrl, *player2_ctrl;
            keyboard_keys *keys;
            game_player *p1 = game_state_get_player(gs, 0);
            game_player *p2 = game_state_get_player(gs, 1);

            // force the speed to 3
            game_state_set_speed(gs, 5);

            p1->har_id = HAR_JAGUAR;
            p1->pilot_id = 0;
            p2->har_id = HAR_JAGUAR;
            p2->pilot_id = 0;

            player1_ctrl = malloc(sizeof(controller));
            controller_init(player1_ctrl);
            player1_ctrl->har = p1->har;
            player2_ctrl = malloc(sizeof(controller));
            controller_init(player2_ctrl);
            player2_ctrl->har = p2->har;

            // Player 1 controller -- Keyboard
            settings_keyboard *k = &settings_get()->keys;
            keys = malloc(sizeof(keyboard_keys));
            keys->up = SDL_GetScancodeFromName(k->key1_up);
            keys->down = SDL_GetScancodeFromName(k->key1_down);
            keys->left = SDL_GetScancodeFromName(k->key1_left);
            keys->right = SDL_GetScancodeFromName(k->key1_right);
            keys->punch = SDL_GetScancodeFromName(k->key1_punch);
            keys->kick = SDL_GetScancodeFromName(k->key1_kick);
            keys->escape = SDL_GetScancodeFromName(k->key1_escape);
            keyboard_create(player1_ctrl, keys, 0);
            game_player_set_ctrl(p1, player1_ctrl);

            // Player 2 controller -- Network
            net_controller_create(player2_ctrl, local->host, event.peer, ROLE_SERVER);
            game_player_set_ctrl(p2, player2_ctrl);
            local->host = NULL;
            game_player_set_selectable(p2, 1);

            chr_score_set_difficulty(game_player_get_score(game_state_get_player(gs, 0)), AI_DIFFICULTY_CHAMPION);
            chr_score_set_difficulty(game_player_get_score(game_state_get_player(gs, 1)), AI_DIFFICULTY_CHAMPION);

            game_state_set_next(gs, SCENE_MELEE);
        }
    }
}
Ejemplo n.º 9
0
int console_cmd_scene(game_state *gs, int argc, char **argv) {
    // change scene
    if(argc == 2) {
        int i;
        if(strtoint(argv[1], &i)) {
            if(is_scene(i)) {
                game_state_set_next(gs, i);
                return 0;
            }
        }
    }
    return 1;
}
Ejemplo n.º 10
0
void vs_dynamic_tick(scene *scene, int paused) {
    game_player *player1 = game_state_get_player(scene->gs, 0);
    ctrl_event *i = NULL;
    // Handle extra controller inputs
    i = player1->ctrl->extra_events;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                vs_handle_action(scene, i->event_data.action);
            } else if (i->type == EVENT_TYPE_CLOSE) {
                game_state_set_next(scene->gs, SCENE_MENU);
                return;
            }
        } while((i = i->next));
    }
}
Ejemplo n.º 11
0
void scoreboard_input_tick(scene*scene) {
    scoreboard_local *local = scene_get_userdata(scene);
    game_player *player1 = game_state_get_player(scene->gs, 0);
    ctrl_event *p1 = NULL, *i;
    controller_poll(player1->ctrl, &p1);
    i = p1;
    if(i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                // If there is pending data, and name has been given, save
                if(local->has_pending_data
                        && strlen(local->pending_data.name) > 0
                        && (i->event_data.action == ACT_KICK || i->event_data.action == ACT_PUNCH)) {

                    handle_scoreboard_save(local);
                    local->has_pending_data = 0;

                // If there is no data, and confirm is clicked, don't save
                } else if (local->has_pending_data == 1
                        && strlen(local->pending_data.name) == 0
                        && (i->event_data.action == ACT_KICK || i->event_data.action == ACT_PUNCH)) {

                    local->has_pending_data = 0;

                // Normal exit routine
                // Only allow if there is no pending data.
                } else if(!local->has_pending_data && 
                    (i->event_data.action == ACT_ESC ||
                     i->event_data.action == ACT_KICK ||
                     i->event_data.action == ACT_PUNCH)) {

                    game_state_set_next(scene->gs, scene->gs->next_next_id);

                // If left or right button is pressed, change page
                // but only if we are not in input mode.
                } else if(!local->has_pending_data && i->event_data.action == ACT_LEFT) {
                    local->page = (local->page > 0) ? local->page-1 : 0;
                } else if(!local->has_pending_data && i->event_data.action == ACT_RIGHT) {
                    local->page = (local->page < MAX_PAGES) ? local->page+1 : MAX_PAGES;
                }
            } 
        } while((i = i->next));
    }
    controller_free_chain(p1);
}
Ejemplo n.º 12
0
int intro_event(scene *scene, SDL_Event *event) {
    game_player *player1 = game_state_get_player(scene->gs, 0);
    ctrl_event *p1=NULL, *i;
    controller_event(player1->ctrl, event, &p1);
    i = p1;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                if(i->event_data.action == ACT_ESC ||
                    i->event_data.action == ACT_KICK ||
                    i->event_data.action == ACT_PUNCH) {

                    game_state_set_next(scene->gs, SCENE_MENU);
                }
            }
        } while((i = i->next));
    }
    controller_free_chain(p1);
    return 1;
}
Ejemplo n.º 13
0
void mechlab_tick(scene *scene, int paused) {
    mechlab_local *local = scene_get_userdata(scene);

    guiframe_tick(local->frame);
    guiframe_tick(local->dashboard);
    object_dynamic_tick(local->mech);

    // Check if root is finished
    component *root = guiframe_get_root(local->frame);
    if(trnmenu_is_finished(root)) {
        if(local->dashtype == DASHBOARD_SELECT_NEW_PIC) {
            guiframe_free(local->frame);
            local->frame = guiframe_create(0, 0, 320, 200);
            guiframe_set_root(local->frame, lab_menu_pilotselect_create(scene, &local->dw));
            guiframe_layout(local->frame);
        } else {
            game_state_set_next(scene->gs, SCENE_MENU);
        }
    }
}
Ejemplo n.º 14
0
void vs_too_pathetic_dialog_clicked(dialog *dlg, dialog_result result){
    scene *sc = dlg->userdata;
    game_state_set_next(sc->gs, SCENE_MENU);
}
Ejemplo n.º 15
0
void vs_quit_dialog_clicked(dialog *dlg, dialog_result result){
    scene *sc = dlg->userdata;
    if(result == DIALOG_RESULT_YES_OK) {
        game_state_set_next(sc->gs, SCENE_MELEE);
    }
}
Ejemplo n.º 16
0
int console_cmd_quit(game_state *gs, int argc, char **argv) {
    game_state_set_next(gs, SCENE_CREDITS);
    return 0;
}
Ejemplo n.º 17
0
void handle_action(scene *scene, int player, int action) {
    game_player *player1 = game_state_get_player(scene->gs, 0);
    game_player *player2 = game_state_get_player(scene->gs, 1);
    melee_local *local = scene_get_userdata(scene);
    int *row, *column, *done;
    if (player == 1) {
        row = &local->row_a;
        column = &local->column_a;
        done = &local->done_a;
    } else {
        row = &local->row_b;
        column = &local->column_b;
        done = &local->done_b;
    }

    if (*done) {
        return;
    }

    switch (action) {
        case ACT_LEFT:
            (*column)--;
            if (*column < 0) {
                *column = 4;
            }
            sound_play(19, 0.5f, 0.0f, 2.0f);
            break;
        case ACT_RIGHT:
            (*column)++;
            if (*column > 4) {
                *column = 0;
            }
            sound_play(19, 0.5f, 0.0f, 2.0f);
            break;
        case ACT_UP:
            if(*row == 1) {
                *row = 0;
            }
            sound_play(19, 0.5f, 0.0f, 2.0f);
            break;
        case ACT_DOWN:
            if(*row == 0) {
                *row = 1;
            }
            // nova selection cheat
            if(*row == 1 && *column == 0) {
                local->katana_down_count[player-1]++;
                if(local->katana_down_count[player-1] > 11) {
                    local->katana_down_count[player-1] = 11;
                }
            }
            sound_play(19, 0.5f, 0.0f, 2.0f);
            break;
        case ACT_KICK:
        case ACT_PUNCH:
            *done = 1;
            sound_play(20, 0.5f, 0.0f, 2.0f);
            if (local->done_a && (local->done_b || !player2->selectable)) {
                local->done_a = 0;
                local->done_b = 0;
                if (local->selection == 0) {
                    local->selection = 1;
                    local->pilot_id_a = 5*local->row_a + local->column_a;
                    local->pilot_id_b = 5*local->row_b + local->column_b;

                    // nova selection cheat
                    local->har_selected[0][local->pilot_id_a] = 1;
                    local->har_selected[1][local->pilot_id_b] = 1;

                    object_select_sprite(&local->bigportrait1, local->pilot_id_a);
                    // update the player palette
                    palette *base_pal = video_get_base_palette();
                    pilot p_a;
                    pilot_get_info(&p_a, local->pilot_id_a);
                    palette_set_player_color(base_pal, 0, p_a.colors[0], 2);
                    palette_set_player_color(base_pal, 0, p_a.colors[1], 1);
                    palette_set_player_color(base_pal, 0, p_a.colors[2], 0);
                    video_force_pal_refresh();
                    player1->colors[0] = p_a.colors[0];
                    player1->colors[1] = p_a.colors[1];
                    player1->colors[2] = p_a.colors[2];

                    if (player2->selectable) {
                        object_select_sprite(&local->bigportrait2, local->pilot_id_b);
                        // update the player palette
                        pilot_get_info(&p_a, local->pilot_id_b);
                        palette_set_player_color(base_pal, 1, p_a.colors[0], 2);
                        palette_set_player_color(base_pal, 1, p_a.colors[1], 1);
                        palette_set_player_color(base_pal, 1, p_a.colors[2], 0);
                        video_force_pal_refresh();
                        player2->colors[0] = p_a.colors[0];
                        player2->colors[1] = p_a.colors[1];
                        player2->colors[2] = p_a.colors[2];
                    }
                } else {
                    int nova_activated[2] = {1, 1};
                    for(int i = 0;i < 2;i++) {
                        for(int j = 0;j < 10;j++) {
                            if(local->har_selected[i][j] == 0) {
                                nova_activated[i] = 0;
                                break;
                            }
                        }
                        if(local->katana_down_count[i] < 11) {
                            nova_activated[i] = 0;
                        }
                    }
                    if(nova_activated[0] && local->row_a == 1 && local->column_a == 2) {
                        player1->har_id = HAR_NOVA;
                    } else {
                        player1->har_id = 5*local->row_a+local->column_a;
                    }
                    player1->pilot_id = local->pilot_id_a;
                    if (player2->selectable) {
                        if(nova_activated[1] && local->row_b == 1 && local->column_b == 2) {
                            player2->har_id = HAR_NOVA;
                        } else {
                            player2->har_id = 5*local->row_b+local->column_b;
                        }
                        player2->pilot_id = local->pilot_id_b;
                    } else {
                        if (player1->sp_wins == (2046 ^ (2 << player1->pilot_id))) {
                            // everyone but kriessack
                            player2->pilot_id = 10;
                            player2->har_id = HAR_NOVA;
                        } else {
                            // pick an opponent we have not yet beaten
                            while(1) {
                                int i = rand_int(10);
                                if ((2 << i) & player1->sp_wins || i == player1->pilot_id) {
                                    continue;
                                }
                                player2->pilot_id = i;
                                player2->har_id = rand_int(10);
                                break;
                            }
                        }

                        pilot p_a;
                        pilot_get_info(&p_a, player2->pilot_id);
                        player2->colors[0] = p_a.colors[0];
                        player2->colors[1] = p_a.colors[1];
                        player2->colors[2] = p_a.colors[2];
                    }
                    game_state_set_next(scene->gs, SCENE_VS);
                }
            }
            break;
    }

    if(local->selection == 0) {
        object_select_sprite(&local->bigportrait1, 5*local->row_a + local->column_a);
        if (player2->selectable) {
            object_select_sprite(&local->bigportrait2, 5*local->row_b + local->column_b);
        }
    }

    // nova selection cheat
    if(local->selection == 1) {
        local->har_selected[player-1][5 * (*row) + *column] = 1;
    }

    refresh_pilot_stats(local);
}
Ejemplo n.º 18
0
void newsroom_input_tick(scene *scene) {
    newsroom_local *local = scene_get_userdata(scene);

    game_player *player1 = game_state_get_player(scene->gs, 0);
    ctrl_event *p1=NULL, *i;
    controller_poll(player1->ctrl, &p1);
    i = p1;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                if(dialog_is_visible(&local->continue_dialog)) {
                    dialog_event(&local->continue_dialog, i->event_data.action);
                } else if (
                        i->event_data.action == ACT_ESC ||
                        i->event_data.action == ACT_KICK ||
                        i->event_data.action == ACT_PUNCH) {
                    local->screen++;
                    newsroom_fixup_str(local);
                    if(local->screen >= 2) {
                        if (local->won) {
                            // pick a new player
                            game_player *p1 = game_state_get_player(scene->gs, 0);
                            game_player *p2 = game_state_get_player(scene->gs, 1);
                            DEBUG("wins are %d", p1->sp_wins);
                            if (p1->sp_wins == (4094 ^ (2 << p1->pilot_id)))  {
                                // won the game
                                game_state_set_next(scene->gs, SCENE_END);
                            } else {
                                if (p1->sp_wins == (2046 ^ (2 << p1->pilot_id))) {
                                    // everyone but kriessack
                                    p2->pilot_id = 10;
                                    p2->har_id = HAR_NOVA;
                                } else {
                                    // pick an opponent we have not yet beaten
                                    while(1) {
                                        int i = rand_int(10);
                                        if ((2 << i) & p1->sp_wins || i == p1->pilot_id) {
                                            continue;
                                        }
                                        p2->pilot_id = i;
                                        p2->har_id = rand_int(10);
                                        break;
                                    }
                                }
                                pilot p;
                                pilot_get_info(&p, p2->pilot_id);
                                p2->colors[0] = p.colors[0];
                                p2->colors[1] = p.colors[1];
                                p2->colors[2] = p.colors[2];

                                // make a new AI controller
                                controller *ctrl = malloc(sizeof(controller));
                                controller_init(ctrl);
                                ai_controller_create(ctrl, settings_get()->gameplay.difficulty);
                                game_player_set_ctrl(p2, ctrl);
                                game_state_set_next(scene->gs, SCENE_VS);
                            }
                        } else {
                            dialog_show(&local->continue_dialog, 1);
                        }
                    }
                }
            }
        } while((i = i->next));
    }
    controller_free_chain(p1);
}