/* playerbackend_play */ void playerbackend_play(PlayerBackend * player) { char cmd[512]; size_t len; char * filename; if((filename = player_get_filename(player->player)) == NULL) return; /* FIXME escape double quotes in filename? */ if(player_get_paused(player->player)) len = snprintf(cmd, sizeof(cmd), "%s", "pause\n"); else len = snprintf(cmd, sizeof(cmd), "%s%s%s", "loadfile \"", filename, "\" 0\n"); if(len >= sizeof(cmd)) { fputs(PROGNAME ": String too long\n", stderr); return; } else player_reset(player->player, filename); free(filename); if(_playerbackend_command(player, cmd, len) != 0) return; player_set_paused(player->player, 0); if(player->read_id == 0) player->read_id = g_io_add_watch(player->channel[0], G_IO_IN, _command_read, player); if(player->timeout_id == 0) player->timeout_id = g_timeout_add(500, _command_timeout, player); }
/* * Resets the board struct (g->b) based on the ruleset. * * This is equivalent to "starting a new game". The function can't fail. */ enum HT_FR game_board_reset ( struct game * const g ) { const struct ruleset * const r = g->rules; memcpy (g->b->pieces, r->pieces, (size_t)g->rules->opt_blen); g->b->turn = (unsigned short)0; { unsigned short i; for (i = (unsigned short)0; i < g->playerc; i++) { const enum HT_FR fr = player_reset(g->players[i]); if (HT_FR_SUCCESS != fr) { return fr; } } } /* * Remove all history: */ g->movehist->elemc = 0; return HT_FR_SUCCESS; }
void player_init( ) { u8 idx = 0; loadFrame(0); subShip[idx].xOffset = 0; subShip[idx].yOffset = 0; subShip[idx].tileOffset = idx; idx++; subShip[idx].xOffset = 8; subShip[idx].yOffset = 0; subShip[idx].tileOffset = idx; idx++; subShip[idx].xOffset = 16; subShip[idx].yOffset = 0; subShip[idx].tileOffset = idx; #ifndef TARGET_GG idx++; subShip[idx].xOffset = 24; subShip[idx].yOffset = 0; subShip[idx].tileOffset = idx; #endif idx++; subShip[idx].xOffset = 0; subShip[idx].yOffset = 8; subShip[idx].tileOffset = idx; idx++; subShip[idx].xOffset = 8; subShip[idx].yOffset = 8; subShip[idx].tileOffset = idx; idx++; subShip[idx].xOffset = 16; subShip[idx].yOffset = 8; subShip[idx].tileOffset = idx; #ifndef TARGET_GG idx++; subShip[idx].xOffset = 24; subShip[idx].yOffset = 8; subShip[idx].tileOffset = idx; #endif idx++; shipSprite.tile = TILE_SHIP; shipSprite.nbSprites = idx; shipSprite.sprites =&subShip; //done in state_title, since player_init is called at each new level //player->score = 0; //player->lives = gameSetup.nbLives; player_reset( ); }
int main(int argc, char** argv) { int d,x; char *samps; //initialise AO ao_device *ao; ao_sample_format form; ao_initialize(); d=ao_default_driver_id(); form.bits=8; form.rate=DDS_FREQ; form.channels=1; form.byte_format=AO_FMT_NATIVE; #ifdef TO_FILE ao=ao_open_file(ao_driver_id("wav"),"music.wav",1,&form,NULL); #else ao=ao_open_live(d,&form,NULL); if (ao==NULL) { printf("Error opening device %d\n"); exit(0); } #endif //Libao is opened and initialised now. //allocate sample buffer samps=malloc(AO_BUFF); d=0; //reset player player_reset(); while(1) { //generate AO_BUFF samples, advance the player 60 times per second for (x=0; x<AO_BUFF; x++) { d++; if (d>(DDS_FREQ/PLAYER_FREQ)) { d=0; player_tick(); } samps[x]=dds_get_next_sample()<<5; } //let libao play the samples ao_play(ao,samps,AO_BUFF); } //never happens because the while() above ao_close(ao); ao_shutdown(); }
void reset_level_data() { // reload all data into RAM if (load_game_data(data)) { frame_handler = frame_error; return; } sprites_reset(); player_reset(); interpret_spritetypes(); // apply mapper just once uint8_t mapper = data[255*256]; switch (mapper) { case 0 : black_mapper(); break; case TRANSPARENT : // null mapper break; default: message("Unknown mapper ! "); frame_handler = frame_error; return; } // interpret level after mapper get_level_boundingbox(); get_level_start(); memcpy(hud,"B0 F0G0 C0 E000 D00 ",sizeof(hud)); hud[1]='0'+lives; hud[6]='0'+level+1; move_camera(); // avoid being negative play_song(); // start playing song vga_frame=0; coins=0; }
/** * Function that resets the data structs with invalid values * so that we can detect when we're using unitialized data members * * @return void * @date 2014-03-31 * @author Triplet VIOPE 2014 */ void reset_data_structs(void){ game_t *game_ptr; int i; game_ptr = get_current_game_ptr(); game_ptr->player_first = -1; game_ptr->board_columns = -1; game_ptr->board_rows = -1; game_ptr->game_mode = -1; /* Set the whole board as empty */ board_set_empty(); /* Deal with G_players */ for(i=0;i<2;i++){ player_reset(&(get_players_ptr()[i])); } }
void player_reload_with_str(object *obj, const char* custom_str) { // Free and reload parser sd_script_free(&obj->animation_state.parser); sd_script_create(&obj->animation_state.parser); int ret; int err_pos; ret = sd_script_decode(&obj->animation_state.parser, custom_str, &err_pos); if(ret != SD_SUCCESS) { PERROR("Decoder error %s at position %d in string \"%s\"", sd_get_error(ret), err_pos, custom_str); } // Set player state player_reset(obj); obj->animation_state.reverse = 0; obj->slide_state.timer = 0; obj->slide_state.vel = vec2f_create(0,0); obj->enemy_slide_state.timer = 0; obj->enemy_slide_state.dest = vec2i_create(0,0); obj->enemy_slide_state.duration = 0; obj->hit_frames = 0; obj->can_hit = 0; }
void player_run(object *obj) { // Some vars for easier life player_animation_state *state = &obj->animation_state; player_sprite_state *rstate = &obj->sprite_state; if(state->finished) return; // Handle slide operation if(obj->slide_state.timer > 0) { obj->pos.x += obj->slide_state.vel.x; obj->pos.y += obj->slide_state.vel.y; obj->slide_state.timer--; } // Not sure what this does int run_ret; if(state->end_frame == UINT32_MAX) { run_ret = sd_stringparser_run( state->parser, state->ticks - 1); } else { run_ret = sd_stringparser_run_frames( state->parser, state->ticks - 1, state->end_frame); } // Handle frame if(run_ret == 0) { // Handle frame switch sd_stringparser_frame *param = &state->parser->current_frame; sd_stringparser_frame n_param; sd_stringparser_frame *f = param; sd_stringparser_frame *n = &n_param; int real_frame = param->letter - 65; // Do something if animation is finished! if(param->is_animation_end) { if(state->repeat) { player_reset(obj); sd_stringparser_run(state->parser, state->ticks - 1); real_frame = param->letter - 65; } else if(obj->finish != NULL) { obj->cur_sprite = NULL; obj->finish(obj); return; } else { obj->cur_sprite = NULL; state->finished = 1; return; } } // If frame changed, do something if(param->id != state->previous) { player_clear_frame(obj); // Tick management if(isset(f, "d")) { cmd_tickjump(obj, get(f, "d")); sd_stringparser_reset(state->parser); } // Animation management if(isset(f, "m") && state->spawn != NULL) { int mx = isset(f, "mx") ? get(f, "mx") : 0; int my = isset(f, "my") ? get(f, "my") : 0; int mg = isset(f, "mg") ? get(f, "mg") : 0; DEBUG("Spawning %d, with g = %d, pos = (%d,%d)", get(f, "m"), mg, mx, my); state->spawn( obj, get(f, "m"), vec2i_create(mx, my), mg, state->spawn_userdata); } if(isset(f, "md") && state->destroy != NULL) { state->destroy(obj, get(f, "md"), state->destroy_userdata); } // Music playback if(isset(f, "smo")) { cmd_music_on(get(f, "smo")); } if(isset(f, "smf")) { cmd_music_off(); } // Sound playback if(isset(f, "s")) { float pitch = PITCH_DEFAULT; float volume = VOLUME_DEFAULT * (settings_get()->sound.sound_vol/10.0f); float panning = PANNING_DEFAULT; if(isset(f, "sf")) { int p = clamp(get(f, "sf"), -16, 239); pitch = clampf((p/239.0f)*3.0f + 1.0f, PITCH_MIN, PITCH_MAX); } if(isset(f, "l")) { int v = clamp(get(f, "l"), 0, 100); volume = (v / 100.0f) * (settings_get()->sound.sound_vol/10.0f); } if(isset(f, "sb")) { panning = clamp(get(f, "sb"), -100, 100) / 100.0f; } int sound_id = obj->sound_translation_table[get(f, "s")] - 1; sound_play(sound_id, volume, panning, pitch); } // Blend mode stuff if(isset(f, "b1")) { rstate->method_flags &= 0x2000; } if(isset(f, "b2")) { rstate->method_flags &= 0x4000; } if(isset(f, "bb")) { rstate->method_flags &= 0x0010; rstate->blend_finish = get(f, "bb"); } if(isset(f, "be")) { rstate->method_flags &= 0x0800; } if(isset(f, "bf")) { rstate->method_flags &= 0x0001; rstate->blend_finish = get(f, "bf"); } if(isset(f, "bh")) { rstate->method_flags &= 0x0040; } if(isset(f, "bl")) { rstate->method_flags &= 0x0008; rstate->blend_finish = get(f, "bl"); } if(isset(f, "bm")) { rstate->method_flags &= 0x0100; rstate->blend_finish = get(f, "bm"); } if(isset(f, "bj")) { rstate->method_flags &= 0x0400; rstate->blend_finish = get(f, "bj"); } if(isset(f, "bs")) { rstate->blend_start = get(f, "bs"); } if(isset(f, "bu")) { rstate->method_flags &= 0x8000; } if(isset(f, "bw")) { rstate->method_flags &= 0x0080; } if(isset(f, "bx")) { rstate->method_flags &= 0x0002; } // Palette tricks if(isset(f, "bpd")) { rstate->pal_ref_index = get(f, "bpd"); } if(isset(f, "bpn")) { rstate->pal_entry_count = get(f, "bpn"); } if(isset(f, "bps")) { rstate->pal_start_index = get(f, "bps"); } if(isset(f, "bpb")) { rstate->pal_begin = get(f, "bpb"); } if(isset(f, "bpd")) { rstate->pal_end = get(f, "bpd"); } if(isset(f, "bz")) { rstate->pal_tint = get(f, "bz"); } // Handle movement if (isset(f, "v")) { int x = 0, y = 0; if(isset(f, "y-")) { y = get(f, "y-") * -1; } else if(isset(f, "y+")) { y = get(f, "y+"); } if(isset(f, "x-")) { x = get(f, "x-") * -1 * object_get_direction(obj); } else if(isset(f, "x+")) { x = get(f, "x+") * object_get_direction(obj); } if (x || y) { obj->vel.x += x; obj->vel.y += y; } } // handle scaling on the Y axis if(isset(f, "y")) { obj->y_percent = get(f, "y") / 100.0f; } if (isset(f, "e")) { // x,y relative to *enemy's* position int x = 0, y = 0; if(isset(f, "y-")) { y = get(f, "y-") * -1; } else if(isset(f, "y+")) { y = get(f, "y+"); } if(isset(f, "x-")) { x = get(f, "x-") * -1 * object_get_direction(obj); } else if(isset(f, "x+")) { x = get(f, "x+") * object_get_direction(obj); } float x_dist = dist(obj->pos.x, state->enemy_x + x); float y_dist = dist(obj->pos.y, state->enemy_y + y); obj->slide_state.timer = param->duration; obj->slide_state.vel.x = x_dist / (float)param->duration; obj->slide_state.vel.y = y_dist / (float)param->duration; DEBUG("Slide object %d for (x,y) = (%f,%f) for %d ticks.", obj->cur_animation->id, obj->slide_state.vel.x, obj->slide_state.vel.y, param->duration); } if (isset(f, "v") == 0 && isset(f, "e") == 0 && (isset(f, "x+") || isset(f, "y+") || isset(f, "x-") || isset(f, "y-"))) { // check for relative X interleaving int x = 0, y = 0; if(isset(f, "y-")) { y = get(f, "y-") * -1; } else if(isset(f, "y+")) { y = get(f, "y+"); } if(isset(f, "x-")) { x = get(f, "x-") * -1 * object_get_direction(obj); } else if(isset(f, "x+")) { x = get(f, "x+") * object_get_direction(obj); } obj->slide_state.timer = param->duration; obj->slide_state.vel.x = (float)x / (float)param->duration; obj->slide_state.vel.y = (float)y / (float)param->duration; DEBUG("Slide object %d for (x,y) = (%f,%f) for %d ticks.", obj->cur_animation->id, obj->slide_state.vel.x, obj->slide_state.vel.y, param->duration); } // Check if next frame contains X=nnn or Y=nnn if(!param->is_final_frame) { sd_stringparser_peek(state->parser, param->id + 1, &n_param); int slide = 0; float xpos = obj->pos.x; float ypos = obj->pos.y; if(isset(n, "x=") || isset(n, "y=")) { obj->slide_state.vel = vec2f_create(0,0); } if(isset(n, "x=")) { slide = get(n, "x="); if(object_get_direction(obj) == OBJECT_FACE_LEFT) { // if the sprite is flipped horizontally, adjust the X coordinates slide = 320 - slide; } if(slide != xpos) { obj->slide_state.vel.x = dist(xpos, slide) / (float)param->duration; obj->slide_state.timer = param->duration; DEBUG("Slide object %d for X = %f for a total of %d ticks.", obj->cur_animation->id, obj->slide_state.vel.x, param->duration); } } if(isset(n, "y=")) { slide = get(n, "y="); if(slide != ypos) { obj->slide_state.vel.y = dist(ypos, slide) / (float)param->duration; obj->slide_state.timer = param->duration; DEBUG("Slide object %d for Y = %f for a total of %d ticks.", obj->cur_animation->id, obj->slide_state.vel.y, param->duration); } } } // Set render settings if(real_frame < 25) { object_select_sprite(obj, real_frame); if(obj->cur_sprite != NULL) { rstate->duration = param->duration; rstate->blendmode = isset(f, "br") ? BLEND_ADDITIVE : BLEND_ALPHA; if(isset(f, "r")) { rstate->flipmode ^= FLIP_HORIZONTAL; } if(isset(f, "f")) { rstate->flipmode ^= FLIP_VERTICAL; } } } else { obj->cur_sprite = NULL; } } state->previous = param->id; } // Animation ticks if(state->reverse) { state->ticks--; } else { state->ticks++; } // Sprite ticks rstate->timer++; // All done. return; }
void multi_change_state(struct game* game, game_state_t state_to) { switch(game_get_state(game)) { case PLAYING: case PAUSED: switch(state_to) { case SCORE: #ifdef USE_WIIMOTE //= 0) //wiimote_set_rumble(player->id, 0); #endif game_set_state(game, SCORE); if(player_get_nb_player_alive(game) == 1) game_inc_score(game, player_get_id_player_alive(game)); break; case CHOOSE_MAP: game_set_state(game, CHOOSE_MAP); game_reset_lvl_map(game); game_reset_scores(game); break; default: break; } break; case CHOOSE_MAP: switch(state_to) { case PLAYING: game_set_state(game, PLAYING); window_resize(map_get_width(level_get_curr_map(game_get_curr_level(game))) * SIZE_BLOC, map_get_height(level_get_curr_map(game_get_curr_level(game))) * SIZE_BLOC + BANNER_HEIGHT + LINE_HEIGHT); players_from_map(game, level_get_curr_map(game_get_curr_level(game))); player_reset(game, 1, 1, 2, 4, 0); break; default: break; } break; case SCORE: switch(state_to) { case PLAYING: game_set_state(game, PLAYING); game_reset_lvl_map(game); level_set_cur_map(game_get_curr_level(game), game_get_pos(game)); players_from_map(game, level_get_curr_map(game_get_curr_level(game))); player_reset(game, 1, 1, 2, 4, 0); break; case CHOOSE_MAP: game_set_state(game, CHOOSE_MAP); game_reset_lvl_map(game); game_reset_scores(game); break; default: break; } break; default: break; } }
void player_run(object *obj) { // Some vars for easier life player_animation_state *state = &obj->animation_state; player_sprite_state *rstate = &obj->sprite_state; if(state->finished) return; // Handle slide operation if(obj->slide_state.timer > 0) { obj->pos.x += obj->slide_state.vel.x; obj->pos.y += obj->slide_state.vel.y; obj->slide_state.timer--; } if(obj->enemy_slide_state.timer > 0) { obj->enemy_slide_state.duration++; obj->pos.x = state->enemy->pos.x + obj->enemy_slide_state.dest.x; obj->pos.y = state->enemy->pos.y + obj->enemy_slide_state.dest.y; obj->enemy_slide_state.timer--; } // Not sure what this does const sd_script_frame *frame = sd_script_get_frame_at(&state->parser, state->current_tick); // Animation has ended ? if(frame == NULL) { if(state->repeat) { player_reset(obj); frame = sd_script_get_frame_at(&state->parser, state->current_tick); } else if(obj->finish != NULL) { obj->cur_sprite = NULL; obj->finish(obj); return; } else { obj->cur_sprite = NULL; state->finished = 1; return; } } // Handle frame state->entered_frame = 0; if(frame == NULL) { DEBUG("Something went wery wrong!"); // We shouldn't really get here, unless stringparser messes something up badly } else { // If frame changed, do something if(sd_script_frame_changed(&state->parser, state->previous_tick, state->current_tick)) { state->entered_frame = 1; player_clear_frame(obj); // Tick management if(sd_script_isset(frame, "d")) { if(!obj->animation_state.disable_d) { state->previous_tick = sd_script_get(frame, "d")-1; state->current_tick = sd_script_get(frame, "d"); } } // Hover flag if(sd_script_isset(frame, "h")) { rstate->disable_gravity = 1; } else { rstate->disable_gravity = 0; } if(sd_script_isset(frame, "ua")) { obj->animation_state.enemy->sprite_state.disable_gravity = 1; } // Animation creation command if(sd_script_isset(frame, "m") && state->spawn != NULL) { int mx = 0; if (sd_script_isset(frame, "mrx")) { int mrx = sd_script_get(frame, "mrx"); int mm = sd_script_isset(frame, "mm") ? sd_script_get(frame, "mm") : mrx; mx = random_int(&obj->rand_state, 320 - 2*mm) + mrx; DEBUG("randomized mx as %d", mx); } else if(sd_script_isset(frame, "mx")) { mx = obj->start.x + (sd_script_get(frame, "mx") * object_get_direction(obj)); } int my = 0; if (sd_script_isset(frame, "mry")) { int mry = sd_script_get(frame, "mry"); int mm = sd_script_isset(frame, "mm") ? sd_script_get(frame, "mm") : mry; my = random_int(&obj->rand_state, 320 - 2*mm) + mry; DEBUG("randomized my as %d", my); } else if(sd_script_isset(frame, "my")) { my = obj->start.y + sd_script_get(frame, "my"); } int mg = sd_script_isset(frame, "mg") ? sd_script_get(frame, "mg") : 0; state->spawn( obj, sd_script_get(frame, "m"), vec2i_create(mx, my), mg, state->spawn_userdata); } // Animation deletion if(sd_script_isset(frame, "md") && state->destroy != NULL) { state->destroy(obj, sd_script_get(frame, "md"), state->destroy_userdata); } // Music playback if(sd_script_isset(frame, "smo")) { if(sd_script_get(frame, "smo") == 0) { music_stop(); return; } music_play(PSM_END + (sd_script_get(frame, "smo") - 1)); } if(sd_script_isset(frame, "smf")) { music_stop(); } // Sound playback if(sd_script_isset(frame, "s")) { float pitch = PITCH_DEFAULT; float volume = VOLUME_DEFAULT * (settings_get()->sound.sound_vol/10.0f); float panning = PANNING_DEFAULT; if(sd_script_isset(frame, "sf")) { int p = clamp(sd_script_get(frame, "sf"), -16, 239); pitch = clampf((p/239.0f)*3.0f + 1.0f, PITCH_MIN, PITCH_MAX); } if(sd_script_isset(frame, "l")) { int v = clamp(sd_script_get(frame, "l"), 0, 100); volume = (v / 100.0f) * (settings_get()->sound.sound_vol/10.0f); } if(sd_script_isset(frame, "sb")) { panning = clamp(sd_script_get(frame, "sb"), -100, 100) / 100.0f; } int sound_id = obj->sound_translation_table[sd_script_get(frame, "s")] - 1; sound_play(sound_id, volume, panning, pitch); } // Blend mode stuff if(sd_script_isset(frame, "b1")) { rstate->method_flags &= 0x2000; } if(sd_script_isset(frame, "b2")) { rstate->method_flags &= 0x4000; } if(sd_script_isset(frame, "bb")) { rstate->method_flags &= 0x0010; rstate->blend_finish = sd_script_get(frame, "bb"); rstate->screen_shake_vertical = sd_script_get(frame, "bb"); } if(sd_script_isset(frame, "be")) { rstate->method_flags &= 0x0800; } if(sd_script_isset(frame, "bf")) { rstate->method_flags &= 0x0001; rstate->blend_finish = sd_script_get(frame, "bf"); } if(sd_script_isset(frame, "bh")) { rstate->method_flags &= 0x0040; } if(sd_script_isset(frame, "bl")) { rstate->method_flags &= 0x0008; rstate->blend_finish = sd_script_get(frame, "bl"); rstate->screen_shake_horizontal = sd_script_get(frame, "bl"); } if(sd_script_isset(frame, "bm")) { rstate->method_flags &= 0x0100; rstate->blend_finish = sd_script_get(frame, "bm"); } if(sd_script_isset(frame, "bj")) { rstate->method_flags &= 0x0400; rstate->blend_finish = sd_script_get(frame, "bj"); } if(sd_script_isset(frame, "bs")) { rstate->blend_start = sd_script_get(frame, "bs"); } if(sd_script_isset(frame, "bu")) { rstate->method_flags &= 0x8000; } if(sd_script_isset(frame, "bw")) { rstate->method_flags &= 0x0080; } if(sd_script_isset(frame, "bx")) { rstate->method_flags &= 0x0002; } // Palette tricks if(sd_script_isset(frame, "bpd")) { rstate->pal_ref_index = sd_script_get(frame, "bpd"); } if(sd_script_isset(frame, "bpn")) { rstate->pal_entry_count = sd_script_get(frame, "bpn"); } if(sd_script_isset(frame, "bps")) { rstate->pal_start_index = sd_script_get(frame, "bps"); } if(sd_script_isset(frame, "bpf")) { // Exact values come from master.dat if(game_state_get_player(obj->gs, 0)->har == obj) { rstate->pal_start_index = 1; rstate->pal_entry_count = 47; } else { rstate->pal_start_index = 48; rstate->pal_entry_count = 48; } } if(sd_script_isset(frame, "bpp")) { rstate->pal_end = sd_script_get(frame, "bpp") * 4; rstate->pal_begin = sd_script_get(frame, "bpp") * 4; } if(sd_script_isset(frame, "bpb")) { rstate->pal_begin = sd_script_get(frame, "bpb") * 4; } if(sd_script_isset(frame, "bz")) { rstate->pal_tint = 1; } // The following is a hack. We don't REALLY know what these tags do. // However, they are only used in CREDITS.BK, so we can just interpret // then as we see fit, as long as stuff works. if(sd_script_isset(frame, "bc") && frame->tick_len >= 50) { rstate->blend_start = 0; } else if(sd_script_isset(frame, "bd") && frame->tick_len >= 30) { rstate->blend_finish = 0; } // Handle movement if(sd_script_isset(frame, "ox")) { DEBUG("changing X from %f to %f", obj->pos.x, obj->pos.x+sd_script_get(frame, "ox")); /*obj->pos.x += sd_script_get(frame, "ox");*/ } if(sd_script_isset(frame, "oy")) { DEBUG("changing Y from %f to %f", obj->pos.y, obj->pos.y+sd_script_get(frame, "oy")); /*obj->pos.y += sd_script_get(frame, "oy");*/ } if (sd_script_isset(frame, "bm")) { // hack because we don't have 'walk to other HAR' implemented obj->pos.x = state->enemy->pos.x; obj->pos.y = state->enemy->pos.y; player_next_frame(state->enemy); } if (sd_script_isset(frame, "v")) { int x = 0, y = 0; if(sd_script_isset(frame, "y-")) { y = sd_script_get(frame, "y-") * -1; } else if(sd_script_isset(frame, "y+")) { y = sd_script_get(frame, "y+"); } if(sd_script_isset(frame, "x-")) { x = sd_script_get(frame, "x-") * -1 * object_get_direction(obj); } else if(sd_script_isset(frame, "x+")) { x = sd_script_get(frame, "x+") * object_get_direction(obj); } if (x || y) { DEBUG("x vel %d, y vel %d", x, y); obj->vel.x += x; obj->vel.y += y; } } if (sd_script_isset(frame, "bu") && obj->vel.y < 0.0f) { float x_dist = dist(obj->pos.x, 160); // assume that bu is used in conjunction with 'vy-X' and that we want to land in the center of the arena obj->slide_state.vel.x = x_dist / (obj->vel.y*-2); obj->slide_state.timer = obj->vel.y*-2; } // handle scaling on the Y axis if(sd_script_isset(frame, "y")) { obj->y_percent = sd_script_get(frame, "y") / 100.0f; } if (sd_script_isset(frame, "e")) { // x,y relative to *enemy's* position int x = 0, y = 0; if(sd_script_isset(frame, "y-")) { y = sd_script_get(frame, "y-") * -1; } else if(sd_script_isset(frame, "y+")) { y = sd_script_get(frame, "y+"); } if(sd_script_isset(frame, "x-")) { x = sd_script_get(frame, "x-") * -1 * object_get_direction(obj); } else if(sd_script_isset(frame, "x+")) { x = sd_script_get(frame, "x+") * object_get_direction(obj); } if (x || y) { obj->enemy_slide_state.timer = frame->tick_len; obj->enemy_slide_state.duration = 0; obj->enemy_slide_state.dest.x = x; obj->enemy_slide_state.dest.y = y; /*DEBUG("ENEMY Slide object %d for (x,y) = (%f,%f) for %d ticks. (%d,%d)", obj->cur_animation->id, obj->enemy_slide_state.dest.x, obj->enemy_slide_state.dest.y, param->duration, x, y);*/ } } if (sd_script_isset(frame, "v") == 0 && sd_script_isset(frame, "e") == 0 && (sd_script_isset(frame, "x+") || sd_script_isset(frame, "y+") || sd_script_isset(frame, "x-") || sd_script_isset(frame, "y-"))) { // check for relative X interleaving int x = 0, y = 0; if(sd_script_isset(frame, "y-")) { y = sd_script_get(frame, "y-") * -1; } else if(sd_script_isset(frame, "y+")) { y = sd_script_get(frame, "y+"); } if(sd_script_isset(frame, "x-")) { x = sd_script_get(frame, "x-") * -1 * object_get_direction(obj); } else if(sd_script_isset(frame, "x+")) { x = sd_script_get(frame, "x+") * object_get_direction(obj); } obj->slide_state.timer = frame->tick_len; obj->slide_state.vel.x = (float)x; obj->slide_state.vel.y = (float)y; /*DEBUG("Slide object %d for (x,y) = (%f,%f) for %d ticks.",*/ /*obj->cur_animation->id,*/ /*obj->slide_state.vel.x, */ /*obj->slide_state.vel.y, */ /*param->duration);*/ } if(sd_script_isset(frame, "x=") || sd_script_isset(frame, "y=")) { obj->slide_state.vel = vec2f_create(0,0); } if(sd_script_isset(frame, "x=")) { obj->pos.x = obj->start.x + (sd_script_get(frame, "x=") * object_get_direction(obj)); // Find frame ID by tick int frame_id = sd_script_next_frame_with_tag(&state->parser, "x=", state->current_tick); // Handle it! if(frame_id >= 0) { int mr = sd_script_get_tick_pos_at_frame(&state->parser, frame_id); int r = mr - state->current_tick; int next_x = sd_script_get(sd_script_get_frame(&state->parser, frame_id), "x="); int slide = obj->start.x + (next_x * object_get_direction(obj)); if(slide != obj->pos.x) { obj->slide_state.vel.x = dist(obj->pos.x, slide) / (float)(frame->tick_len + r); obj->slide_state.timer = frame->tick_len + r; /*DEBUG("Slide object %d for X = %f for a total of %d ticks.",*/ /*obj->cur_animation->id,*/ /*obj->slide_state.vel.x,*/ /*param->duration + r);*/ } } } if(sd_script_isset(frame, "y=")) { obj->pos.y = obj->start.y + sd_script_get(frame, "y="); // Find frame ID by tick int frame_id = sd_script_next_frame_with_tag(&state->parser, "y=", state->current_tick); // handle it! if(frame_id >= 0) { int mr = sd_script_get_tick_pos_at_frame(&state->parser, frame_id); int r = mr - state->current_tick; int next_y = sd_script_get(sd_script_get_frame(&state->parser, frame_id), "y="); int slide = next_y + obj->start.y; if(slide != obj->pos.y) { obj->slide_state.vel.y = dist(obj->pos.y, slide) / (float)(frame->tick_len + r); obj->slide_state.timer = frame->tick_len + r; /*DEBUG("Slide object %d for Y = %f for a total of %d ticks.",*/ /*obj->cur_animation->id,*/ /*obj->slide_state.vel.y,*/ /*param->duration + r);*/ } } } if(sd_script_isset(frame, "as")) { // make the object move around the screen in a circular motion until end of frame obj->orbit = 1; } else { obj->orbit = 0; } if(sd_script_isset(frame, "q")) { // Enable hit on the current and the next n-1 frames. obj->hit_frames = sd_script_get(frame, "q"); } if(obj->hit_frames > 0) { obj->can_hit = 1; obj->hit_frames--; } if(sd_script_isset(frame, "at")) { // set the object's X position to be behind the opponent obj->pos.x = obj->animation_state.enemy->pos.x + (15 * object_get_direction(obj)); } if(sd_script_isset(frame, "ar")) { DEBUG("flipping direction %d -> %d", object_get_direction(obj), object_get_direction(obj) *-1); // reverse direction object_set_direction(obj, object_get_direction(obj) * -1); DEBUG("flipping direction now %d", object_get_direction(obj)); } // Set render settings if(frame->sprite < 25) { object_select_sprite(obj, frame->sprite); if(obj->cur_sprite != NULL) { rstate->duration = frame->tick_len; rstate->blendmode = sd_script_isset(frame, "br") ? BLEND_ADDITIVE : BLEND_ALPHA; if(sd_script_isset(frame, "r")) { rstate->flipmode ^= FLIP_HORIZONTAL; } if(sd_script_isset(frame, "f")) { rstate->flipmode ^= FLIP_VERTICAL; } } } else { object_select_sprite(obj, -1); } } } // Animation ticks state->previous_tick = state->current_tick; if(state->reverse) { state->current_tick--; } else { state->current_tick++; } // Sprite ticks rstate->timer++; // All done. return; }
/** * Handler to check user input, and see if it matches any avaible commands. * Will call the right methods for executing commands */ void handle_keyboard(sp_session *session, struct play_queue* node) { char buffer[1024]; fgets(buffer, sizeof(buffer), stdin); strtok(buffer, "\n"); if (strcmp(buffer, "search") == 0) { player_reset(); run_search(session); } else if ((strcmp(buffer, "list") == 0) || (strcmp(buffer, "ls") == 0 )) { print_playlists(session, pc); } else if(strcmp(buffer, "qshuffle") == 0) { queue_shuffle(); } else if (strcmp(buffer, "queueadd") == 0) { sp_playlist* pl = parse_play_command(session, buffer, node); printf("done finding playlist \n"); if(pl != NULL) printf("queueadd: %s\n", sp_playlist_name(pl)); else { printf("no playlist\n"); return; } int index; char input[10]; fputs("Song number: ", stdout); fgets(input, sizeof(input) - 1, stdin); sscanf(input, "%d", &index); if(sp_playlist_num_tracks(pl) < index) { printf("index too high!\n"); return; } sp_track* track = pl_find_song_by_id(pl, index); if(track != NULL) queue_add_first(track); } else if (strcmp(buffer, "list songs") == 0 ) { //release all threads sp_playlist* pl = playlist_find_by_num(session, pc); print_tracks_in_playlist(session, pl); } else if (strcmp(buffer, "help") == 0) { print_commands(); } else if (strcmp(buffer, "queue") == 0) { queue_print(node); } else if (strcmp(buffer, "shuffle mode") == 0) { print_commands(); } else if(strncmp(buffer, "play", strlen("play")) == 0) { player_reset(); sp_playlist* pl = parse_play_command(session, buffer, node); if(pl!=NULL) queue_add_playlist(pl); else { printf("ERROR playlist is null\n"); return; } queue_go_next(session); } else if(strncmp(buffer, "shuffle", strlen("shuffle")) == 0) { player_reset(); shuffle_mode = TRUE; sp_playlist* pl = parse_play_command(session, buffer, node); if(pl!=NULL) queue_add_playlist(pl); else { printf("ERROR playlist is null\n"); return; } queue_shuffle(); queue_go_next(session); } else if(strcmp(buffer, "pause") == 0 || strcmp(buffer, "p") == 0) { player_pause(session); play_info(); } else if (strcmp(buffer, "next") == 0 || strcmp(buffer, "n") == 0) { end_track(session); } else if (strcmp(buffer, "stop") == 0) { } else if (strcmp(buffer, "info") == 0) { play_info(); } else if (strcmp(buffer, "quit") == 0) { queue_free(); quit_program(session); } else { printf("Unkown command!\n"); } printf("> "); fflush(stdout); return; }