void use_item( Player *p, Item *it, Level *l ) { DATAFILE *data; data = load_datafile( "dat/sprites.dat" ); if (!data) fatal("Error reading datafile 'dat/sprites.dat'\n"); V_clear( p->item_animation ); switch ( it->type ) { case ITEM_POTION: INC2MAX( p->life, 1, MAX_LIFE ); p->item_in_use = (4 * ANIMATION_RATE); p->item_timer = ANIMATION_RATE; p->cur_item_frame = 0; V_add( p->item_animation, copy_bitmap( (BITMAP *)data[9].dat ) ); V_add( p->item_animation, copy_bitmap( (BITMAP *)data[10].dat ) ); V_add( p->item_animation, copy_bitmap( (BITMAP *)data[11].dat ) ); V_add( p->item_animation, copy_bitmap( (BITMAP *)data[10].dat ) ); break; case ITEM_PIPE: /*tmp = V_length( l->sprite_images ); V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[12].dat ) ); V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[13].dat ) ); V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[14].dat ) ); V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[15].dat ) );*/ /*create_sprite( Level *l, int type, int x, int y, int dir, int speed, int jump_rate, int shot_rate, int life, int num_of_images, ... )*/ create_sprite( l, SPRITE_WALK, p->pos_x, 0, -1, 8, 0, 50, 2, 5, 0, 0, 1, 2, 1 ); break; default: break; } unload_datafile( data ); }
Player *load_player() { Player *p = (Player *)malloc( sizeof(Player) ); DATAFILE *data; BITMAP *t; memset( p, 0, sizeof(Player) ); data = load_datafile( "dat/sprites.dat" ); if (!data) fatal("Error reading datafile 'dat/sprites.dat'\n"); p->still_image = copy_bitmap( (BITMAP *)data[0].dat ); p->moving_images = V_new(); V_register_del_func( p->moving_images, (VectorFunc)destroy_bitmap ); t = copy_bitmap( (BITMAP *)data[0].dat ); V_add( p->moving_images, t ); t = copy_bitmap( (BITMAP *)data[1].dat ); V_add( p->moving_images, t ); t = copy_bitmap( (BITMAP *)data[2].dat ); V_add( p->moving_images, t ); t = copy_bitmap( (BITMAP *)data[1].dat ); V_add( p->moving_images, t ); p->ducking_image = copy_bitmap( (BITMAP *)data[a05_marioduck].dat ); p->jumping_image = copy_bitmap( (BITMAP *)data[a03_mariobat].dat ); p->attack_image = copy_bitmap( (BITMAP *)data[a04_mariobat].dat ); set_pallete( *((PALLETE *)data[Zpallete].dat) ); unload_datafile( data ); p->cur_image = p->still_image; p->width = p->cur_image->w; p->height = p->cur_image->h; p->invul = 0; p->life = MAX_LIFE; p->max_jump = MAX_JUMP; p->inventory = V_new(); p->quantity = IA_new(); p->inv_selection = 0; p->item_in_use = 0; p->cur_item_frame = 0; p->item_animation = V_new(); V_register_del_func( p->item_animation, (VectorFunc)destroy_bitmap ); p->weapon = 1; p->weapon_length = 20; p->weapon_timer = 0; p->weapon_speed = 15; p->weapon_delay = 10; return p; }
Vector V_rotate(Vector p, Vector centre, Vector v1, Vector v2) { // Now rotating around (0, 0, 0) p = V_substract(p, centre); // Coordinates to define Vector ux, uy, vx, vy; // Getting unit vectors so both bases have vectors with the same norm Vector v1_u = V_unit(v1); Vector v2_u = V_unit(v2); // Crafting the needed bases as described in the given file V_uxUyFromUz(v1_u, &ux, &uy); V_uxUyFromUz(v2_u, &vx, &vy); // Getting each coordinate of p in the basis (ux, uy, v1_u) and remaking it // in the basis (vx, vy, v2_u). // Adding "centre" to finish the rotation. This step is important. return V_add( centre, V_recompose( V_decompose(p, ux), V_decompose(p, uy), V_decompose(p, v1_u), vx, vy, v2_u ) ); }
Vector V_recompose(double x, double y, double z, Vector u, Vector v, Vector w) { return V_add(V_multiply(x, u), V_add(V_multiply(y, v), V_multiply(z, w))); }