void cb_vs_spawn_object(object *parent, int id, vec2i pos, int g, void *userdata) { scene *s = (scene*)userdata; // Get next animation bk_info *info = bk_get_info(&s->bk_data, id); if(info != NULL) { object *obj = malloc(sizeof(object)); object_create(obj, parent->gs, vec2i_add(pos, vec2f_to_i(parent->pos)), vec2f_create(0,0)); object_set_stl(obj, object_get_stl(parent)); object_set_animation(obj, &info->ani); object_set_spawn_cb(obj, cb_vs_spawn_object, userdata); object_set_destroy_cb(obj, cb_vs_destroy_object, userdata); game_state_add_object(parent->gs, obj, RENDER_LAYER_MIDDLE, 0, 0); } }
int projectile_unserialize(object *obj, serial *ser, int animation_id, game_state *gs) { uint8_t har_id = serial_read_int8(ser); game_player *player; object *o; har *h; for(int i = 0; i < 2; i++) { player = game_state_get_player(gs, i); o = game_player_get_har(player); h = object_get_userdata(o); if (h->af_data->id == har_id) { af_move *move = af_get_move(h->af_data, animation_id); object_set_animation(obj, &move->ani); object_set_userdata(obj, h); object_set_stl(obj, object_get_stl(o)); projectile_create(obj); return 0; } } DEBUG("COULD NOT FIND HAR ID %d", har_id); // could not find the right HAR... return 1; }