Пример #1
0
BOOLEAN
InitSpace (void)
{
	if (space_ini_cnt++ == 0
			&& LOBYTE (GLOBAL (CurrentActivity)) <= IN_ENCOUNTER)
	{
		stars_in_space = CaptureDrawable (
				LoadGraphic (STAR_MASK_PMAP_ANIM));
		if (stars_in_space == NULL)
			return FALSE;

		if (!load_animation (explosion,
				BOOM_BIG_MASK_PMAP_ANIM,
				BOOM_MED_MASK_PMAP_ANIM,
				BOOM_SML_MASK_PMAP_ANIM))
			return FALSE;

		if (!load_animation (blast,
				BLAST_BIG_MASK_PMAP_ANIM,
				BLAST_MED_MASK_PMAP_ANIM,
				BLAST_SML_MASK_PMAP_ANIM))
			return FALSE;

		if (!load_animation (asteroid,
				ASTEROID_BIG_MASK_PMAP_ANIM,
				ASTEROID_MED_MASK_PMAP_ANIM,
				ASTEROID_SML_MASK_PMAP_ANIM))
			return FALSE;
	}

	return TRUE;
}
/**
 * Creates a speed belt on the map.
 * 
 * @param[in,out] world    A pointer to the world structure.
 * @param[in] type    	   The tile type.
 * @param[in] xPos    	   The tile xpos.
 * @param[in] yPos         The tile ypos.
 * @param[in] level        The level that the tile is on.
 *
 * @designer 
 * @author   
 */
unsigned int create_stile(World * world, int type, int xPos, int yPos, int level)
{
	if(type != 1 && type != 2)
	{
		return -1;
	}

	unsigned int speed_tile = create_entity(world, COMPONENT_RENDER_PLAYER | COMPONENT_POSITION | COMPONENT_ANIMATION | COMPONENT_COLLISION | COMPONENT_STILE);
	
	int x = xPos / TILE_WIDTH;
	int y = yPos / TILE_HEIGHT;
	
	world->position[speed_tile].x = (x * TILE_WIDTH) + (TILE_WIDTH / 2);
	world->position[speed_tile].y = (y * TILE_HEIGHT) + (TILE_HEIGHT / 2);
	world->position[speed_tile].level = level;
	
	world->position[speed_tile].width = TILE_WIDTH;
	world->position[speed_tile].height = TILE_HEIGHT;
	
	world->renderPlayer[speed_tile].width = TILE_WIDTH;
	world->renderPlayer[speed_tile].height = TILE_HEIGHT;
	
	world->collision[speed_tile].id = 0;
	world->collision[speed_tile].timer = 0;
	world->collision[speed_tile].timerMax = 0;
	world->collision[speed_tile].active = true;
	world->collision[speed_tile].radius = 0;
	
	switch(type)
	{
		case TILE_BELT_RIGHT:
			world->tile[speed_tile].type = TILE_BELT_RIGHT;
			world->collision[speed_tile].type = COLLISION_BELTRIGHT;
			load_animation("assets/Graphics/objects/tiles/speed_right/speed_right_animation.txt", world, speed_tile);
			play_animation(world, speed_tile, (char*)"speed_right");
			break;

		case TILE_BELT_LEFT:
			world->tile[speed_tile].type = TILE_BELT_RIGHT;
			world->collision[speed_tile].type = COLLISION_BELTLEFT;
			load_animation("assets/Graphics/objects/tiles/speed_left/speed_left_animation.txt", world, speed_tile);
			play_animation(world, speed_tile, (char*)"speed_left");
			break;

	}

	world->tile[speed_tile].start_time = SDL_GetTicks();
	return speed_tile;
}
Пример #3
0
static int load_object(scene_t *scene,FILE *file,char *path,int texture_mode) {
    char buffer[128],name[256];
    fscanf(file,"%s",buffer);
    while(fscanf(file,"%s",buffer) != EOF) {
        if(buffer[0] == '#') skeep_comment(file);
        else if(!strcmp(buffer,"mesh")) {
            load_name(file,path,name);
            scene->mesh = load_mesh(name,path,&scene->num_mesh,texture_mode);
            if(!scene->mesh) return 0;
        } else if(!strcmp(buffer,"thing")) {
            load_name(file,path,name);
            scene->thing = load_thing(name,scene->mesh,scene->num_mesh,&scene->num_thing);
            if(!scene->thing) return 0;
        } else if(!strcmp(buffer,"animation")) {
            load_name(file,path,name);
            scene->animation = load_animation(name,path,scene->mesh,scene->num_mesh,&scene->num_animation);
            if(!scene->animation) return 0;
        } else if(!strcmp(buffer,"particle")) {
            load_name(file,path,name);
            scene->particle = load_particle(name,path,&scene->num_particle,texture_mode);
            if(!scene->particle) return 0;
        } else if(!strcmp(buffer,"dynamiclight")) {
            load_name(file,path,name);
            scene->dynamiclight = load_dynamiclight(name,path,&scene->num_dynamiclight,texture_mode);
            if(!scene->dynamiclight) return 0;
        } else if(!strcmp(buffer,"}")) break;
        else return 0;
    }
    return 1;
}
Пример #4
0
/**
 * \brief Answer to a click on "Open animation".
 * \param event This event occured.
 */
void bf::main_frame::on_open_animation( wxCommandEvent& WXUNUSED(event) )
{
  const wxFileName path(m_animation_file);

  wxFileDialog dlg
    ( this, _("Choose an animation"), path.GetPath(), wxEmptyString,
      _("Animation files (*.anim)|*.anim"), wxFD_OPEN | wxFD_FILE_MUST_EXIST );

  if ( dlg.ShowModal() == wxID_OK )
    {
      std::string w = 
        path_configuration::get_instance().search_workspace
        ( wx_to_std_string(dlg.GetPath()) );
      
      if ( ! w.empty() )
        {
          if ( is_changed() || !m_animation_file.empty() )
            {
              main_frame* frm = new main_frame( workspace_environment(w) );
              frm->load_animation( dlg.GetPath() );
              frm->Show();
            }
          else
            load_animation( dlg.GetPath() );
        }
    }
} // main_frame::on_open_animation()
Пример #5
0
animation_t * render_manager_get_animation(render_manager_t *r_manager, const char * name) {
    MAYBE(animation_t *) maybe_anim = asset_cache_get(&(r_manager->animations), name);
    if (UNMAYBE(maybe_anim) != NULL) {
        return (animation_t *) UNMAYBE(maybe_anim);
    }
    return load_animation(r_manager, name);
}
Пример #6
0
int
main(int argc, char** argv)
{
  HGE_loop_t loop;
  HGE_anim_t* anim;

  HGE_initialize_video();
  HGE_initialize_timer();

  anim = HGE_new(HGE_anim);

  HGE_loop_init(&loop);
  HGE_loop_set_data(&loop, anim);
  HGE_loop_set_framefunc(&loop, frame_func);
  
  load_animation(anim);
  anim->speed = 2.0f;
  HGE_anim_set_attr(anim, HGE_ANIM_REPEAT|HGE_ANIM_BOUNCE);

  HGE_loop_run(&loop);

  HGE_unref(anim);

  HGE_quit();

  return 0;
}
Пример #7
0
    bool init(mhe::game::Engine& engine, const mhe::game::GameSceneDesc& /*desc*/) override
    {
        mhe::NodeInstance& node = engine.scene().create_node();
        mhe::load_node<mhe::GBufferFillMaterialSystem>(node, mhe::string("rainbow_dash.bin"), engine.context(), engine.scene_context());
        engine.scene_context().transform_pool.get(node.transform_id).transform.rotate_by(mhe::quatf(-mhe::pi_2, mhe::pi, 0.0f));
        engine.scene_context().transform_pool.get(node.transform_id).transform.scale_by(mhe::vec3(1.0f, 1.0f, 1.0f));

        engine.scene_context().aabb_pool.get(node.aabb_id).aabb.extents *= 1.0f;

        node_ = node.id;

        load_animation(engine);
        controller_.set_animation(&animation_, node.mesh.mesh.skeleton);

        mhe::TextureInstance texture;
        engine.context().texture_manager.get(texture, mhe::string("rainbow-dash/rainbow_dash.tga"));
        mhe::Material& material = engine.context().materials[node.mesh.instance_parts[0].material.material_system].get(
            node.mesh.instance_parts[0].material.id);
        material.textures[mhe::albedo_texture_unit] = texture;

        mhe::GBufferFillMaterialSystem* material_system = engine.context().material_systems.get<mhe::GBufferFillMaterialSystem>();
        mhe::NodeInstance& plane = engine.scene().create_node();
        mhe::utils::create_plane(plane, engine.context());
        mhe::MaterialInitializationData material_initialization_data;
        material_initialization_data.textures[0] = mhe::string("test.tga");
        mhe::setup_node(plane, material_system, engine.context(), engine.scene_context(), material_initialization_data);
        mhe::set_node_transform(engine.scene_context(), plane, mhe::vec3::zero(), mhe::quatf(mhe::pi_2, 0.0f, 0.0f),
            mhe::vec3(5.0f, 5.0f, 5.0f));

        mhe::LightInstance& light_instance = engine.scene().create_light();
        mhe::Light& light = light_instance.light;
        light.shading().diffuse = mhe::vec4(240.0f / 255.0f, 150.0f / 255.0f, 80.0f / 255.0f, 1.0f);
        light.shading().specular = mhe::vec4(1.0f, 1.0f, 1.0f, 1.0f);
        light.shading().intensity = 5.0f;
        mhe::set_light_position(engine.scene_context(), light_instance.id, mhe::vec3(0, 1.0f, 0));
        mhe::set_light_rotation(engine.scene_context(), light_instance.id, mhe::quatf(mhe::pi_2, 0.0f, 0.0f));
        light.set_type(mhe::Light::directional);
        light.desc().cast_shadows = true;
        light.desc().shadowmap_bias = 0.005f;
        light_instance.enabled = true;
        return true;
    }
Пример #8
0
int demo_initialize(int argc, char * argv[])
{
	if(!t3f_initialize(640, 480, 60.0, "Paintball Party 2 Tech Demo 2", demo_logic, demo_render, T3F_DEFAULT | T3F_USE_MOUSE | T3F_USE_JOYSTICK))
	{
		return 0;
	}
	demo_font = al_load_bitmap_font("demo_font.png");
	if(!demo_font)
	{
		printf("Failed to load font!\n");
		return 0;
	}
	
	t3f_3d_set_projection(&demo_camera.projection, 1.0, 1.0, 320.0, 240.0, 640, 640);
	t3f_3d_select_projection(&demo_camera.projection);
	
	demo_camera.x = 0.0;
	demo_camera.y = 0.0;
	demo_camera.z = 0.0;
	demo_camera.vx = 0;
	demo_camera.vy = 0;
	demo_camera.vw = al_get_display_width() / 2;
	demo_camera.vh = al_get_display_height() / 2;
	demo_camera.flags = 0;
	t3f_3d_set_projection(&demo_camera.projection, 0.5, 0.5, 320.0, 240.0, 640, 640);
	t3f_3d_select_projection(&demo_camera.projection);
	
	demo_tileset = t3f_load_tileset("export.ots");
	if(!demo_tileset)
	{
		return 0;
	}
	demo_tilemap = t3f_load_tilemap("export.otm");
	if(!demo_tilemap)
	{
		return 0;
	}
	demo_tilemap->tileset = demo_tileset;
	
	demo_collision_tilemap = t3f_load_collision_tilemap("export.ocm");
	if(!demo_collision_tilemap)
	{
		return 0;
	}
	
	sprite_ani[DEMO_SPRITE_STATE_STAND_RIGHT] = load_animation("mario_sr.ani");
	sprite_ani[DEMO_SPRITE_STATE_WALK_RIGHT] = load_animation("mario_wr.ani");
	sprite_ani[DEMO_SPRITE_STATE_JUMP_RIGHT] = load_animation("mario_jr.ani");
	sprite_ani[DEMO_SPRITE_STATE_FALL_RIGHT] = load_animation("mario_fr.ani");
	sprite_ani[DEMO_SPRITE_STATE_DUCK_RIGHT] = load_animation("mario_dr.ani");
	sprite_ani[DEMO_SPRITE_STATE_STAND_LEFT] = load_animation("mario_sl.ani");
	sprite_ani[DEMO_SPRITE_STATE_WALK_LEFT] = load_animation("mario_wl.ani");
	sprite_ani[DEMO_SPRITE_STATE_JUMP_LEFT] = load_animation("mario_jl.ani");
	sprite_ani[DEMO_SPRITE_STATE_FALL_LEFT] = load_animation("mario_fl.ani");
	sprite_ani[DEMO_SPRITE_STATE_DUCK_LEFT] = load_animation("mario_dl.ani");
	if(!sprite_ani)
	{
		return 0;
	}
	platform_ani = load_animation("platform.ani");
	if(!sprite_ani)
	{
		return 0;
	}
	
	platform.angle = 0.0;
	platform.x = 320 + cos(platform.angle) * 48.0;
	platform.y = 240 + sin(platform.angle) * 48.0;
	platform.cp = t3f_create_collision_object(0, 0, al_get_bitmap_width(platform_ani->bitmap[0]) * 2, al_get_bitmap_height(platform_ani->bitmap[0]) * 2, 32, 32, 0);
	platform.sticky = NULL;
/*	player.x = 0.0;
	player.y = 0.0;
	player.cp = t3f_create_collision_object(0, 0, 32, 32, 32, 32, 0);
	player.sticky = NULL;
	player.floor = 0; */
	
	player.cp = t3f_create_collision_object(5, 0, 22, 56, 32, 32, 0);
	player.x = 64.0;
	player.y = 64.0;
	player.vx = 0.0;
	player.vy = 0.0;
	player.sticky = NULL;
	player.floor = false;
	player.state = DEMO_SPRITE_STATE_STAND_RIGHT;
	player.frame = 0;
	
	controller = t3f_create_controller(4);
	if(!controller)
	{
		return 0;
	}
	al_clear_to_color(al_map_rgb(255, 0, 0));
	al_flip_display();
	t3f_bind_controller(controller, DEMO_CONTROLLER_UP);
	al_clear_to_color(al_map_rgb(0, 255, 0));
	al_flip_display();
	t3f_bind_controller(controller, DEMO_CONTROLLER_DOWN);
	al_clear_to_color(al_map_rgb(0, 0, 255));
	al_flip_display();
	t3f_bind_controller(controller, DEMO_CONTROLLER_LEFT);
	al_clear_to_color(al_map_rgb(0, 0, 0));
	al_flip_display();
	t3f_bind_controller(controller, DEMO_CONTROLLER_RIGHT);
	
	return 1;
}
Пример #9
0
int map_init(World* world, const char *file_map, const char *file_tiles) {
	
	FILE *fp_map;
	FILE *fp_tiles;
	
	int width, height;
	int x, y, i;
	int **collision_map;
	int **map;

	char *entity_type = (char*)malloc(sizeof(char) * 128);
	int entity_count;
	
	
	SDL_Surface **tiles;
	int *collision;
	int num_tiles;
	int pos = 0;
	char *tile_filename = (char*)malloc(sizeof(char) * 128);
	
	SDL_Rect tile_rect;
	
	if (map_surface != 0) {
		SDL_FreeSurface(map_surface);
	}
	
	//load tiles
	if ((fp_tiles = fopen(file_tiles, "r")) == 0) {
		printf("Error opening tile set %s\n", file_tiles);
		return -1;
	}
	
	if (fscanf(fp_tiles, "%d", &num_tiles) != 1) {
		printf("Cannot find tile number\n");
		return -1;
	}
	
	if ((tiles = (SDL_Surface**)malloc(sizeof(SDL_Surface*) * num_tiles)) == 0) {
		printf("Error mallocing tile surfaces\n");
		return -1;
	}
	if ((collision = (int*)malloc(sizeof(int) * num_tiles)) == 0) {
		printf("Error mallocing tile surfaces\n");
		return -1;
	}
	
	for(i = 0; i < num_tiles; i++) {
		
		if (fscanf(fp_tiles, "%d", &pos) != 1) {
			printf("Error reading tile map index.\n");
			return -1;
		}
		
		if (pos >= num_tiles) {
			printf("Trying to write to tiles outside of memory\n");
			return -1;
		}
		
		if (fscanf(fp_tiles, "%s", (char*)tile_filename) != 1) {
			printf("Error reading tile map filename.\n");
			return -1;
		}
		if (fscanf(fp_tiles, "%d", &collision[pos]) != 1){
			printf("Error reading tile map collision.\n");
			return -1;	
		}
		
		tiles[pos] = IMG_Load(tile_filename);
		
		if (tiles[pos] == NULL) {
			printf("Error loading tile: %s\n", tile_filename);
			return -1;
		}
	}
	
	fclose(fp_tiles);
	
	//LOAD MAP
	
	if ((fp_map = fopen(file_map, "r")) == 0) {
		printf("Error opening map %s\n", file_map);
		return -1;
	}
	
	if (fscanf(fp_map, "%d %d %d", &level, &width, &height) != 3) {
		return -1;
	}
	
	if ((map = (int**)malloc(sizeof(int*) * width)) == NULL) {
		printf("malloc failed\n");
	}
	if ((collision_map = (int**)malloc(sizeof(int*) * width)) == NULL) {
		printf("malloc failed\n");
	}
	
	for (i = 0; i < width; i++) {
		if ((map[i] = (int*)malloc(sizeof(int) * height)) == NULL) {
			printf("malloc failed\n");
		}
		if ((collision_map[i] = (int*)malloc(sizeof(int) * height)) == NULL) {
			printf("malloc failed\n");
		}
	}
	
	printf("Map load size %d %d\n", width, height);
	
	for(y = 0; y < height; y++) {
		for(x = 0; x < width; x++) {
			
			if (fscanf(fp_map, "%d", &map[x][y]) != 1) {
				printf("Expected more map.\n");
				return -1;
			}
			
			if (map[x][y] >= num_tiles) {
				printf("Using tile %u that is bigger than %d\n", map[x][y], num_tiles);
			}
			
			collision_map[x][y] = collision[map[x][y]];
		}
	}
	
	if (fscanf(fp_map, "%d", &entity_count) == 1) {
		
		for(i = 0; i < entity_count; i++) {
			
			if (fscanf(fp_map, "%s", (char*)entity_type) != 1) {
				printf("Entity type error: %s\n", file_map);
				return -1;
			}
			
			//printf("Found entity: %s\n", entity_type);
			
			if (strcmp(entity_type, "stair") == 0 || strcmp(entity_type, "stairs") == 0) { //stairs
				
				//stair x y targetX targetY 2
				int x, y, floor;
				float targetX, targetY;
				char dir;

				if (fscanf(fp_map, "%d %d %f %f %d %c", &x, &y, &targetX, &targetY, &floor, &dir) != 6) {
					printf("Error loading stair\n");
					return -1;
				}
				switch (dir) { // make the hitboxes for the stairs
					case 'l':
						create_stair(world, floor, targetX * TILE_WIDTH + TILE_WIDTH / 2, targetY * TILE_HEIGHT + TILE_HEIGHT / 2, x * TILE_WIDTH + TILE_WIDTH / 2 - 5, y * TILE_HEIGHT + TILE_HEIGHT / 2, 4, 4, level);
						create_block(world, x * TILE_WIDTH + 7, y * TILE_HEIGHT + TILE_HEIGHT / 2, 10, TILE_HEIGHT - 4, floor);
						break;
					case 'r':
						create_stair(world, floor, targetX * TILE_WIDTH + TILE_WIDTH / 2, targetY * TILE_HEIGHT + TILE_HEIGHT / 2, x * TILE_WIDTH + TILE_WIDTH / 2 + 5, y * TILE_HEIGHT + TILE_HEIGHT / 2, 4, 4, level);
						create_block(world, x * TILE_WIDTH + TILE_WIDTH - 7, y * TILE_HEIGHT + TILE_HEIGHT / 2, 10, TILE_HEIGHT - 4, floor);
						break;
					case 'u':
						create_stair(world, floor, targetX * TILE_WIDTH + TILE_WIDTH / 2, targetY * TILE_HEIGHT + TILE_HEIGHT / 2, x * TILE_WIDTH + TILE_WIDTH / 2, y * TILE_HEIGHT + TILE_HEIGHT / 2 - 5, 4, 4, level);
						create_block(world, x * TILE_WIDTH + TILE_WIDTH / 2, y * TILE_HEIGHT + 7, TILE_WIDTH - 4, 10, floor);
						break;
					case 'd':
						create_stair(world, floor, targetX * TILE_WIDTH + TILE_WIDTH / 2, targetY * TILE_HEIGHT + TILE_HEIGHT / 2, x * TILE_WIDTH + TILE_WIDTH / 2, y * TILE_HEIGHT + TILE_HEIGHT / 2 + 5, 4, 4, level);
						create_block(world, x * TILE_WIDTH + TILE_WIDTH / 2, y * TILE_HEIGHT + TILE_HEIGHT - 7, TILE_WIDTH - 4, 10, floor);
						break;
				}
			}
			else if (strcmp(entity_type, "object") == 0) { //animated objects
				
				unsigned int entity;
				float x, y;
				int w, h;
				char *animation_name = (char*)malloc(sizeof(char) * 64);
				char *animation_filename = (char*)malloc(sizeof(char) * 64);
				
				if (fscanf(fp_map, "%f %f %d %d %s %s", &x, &y, &w, &h, animation_filename, animation_name) != 6) {
					printf("Error loading object!\n");
					return -1;
				}
				
				entity = create_entity(world, COMPONENT_RENDER_PLAYER | COMPONENT_POSITION | COMPONENT_ANIMATION | COMPONENT_COLLISION);
				
				//printf("Loading object %d (%f, %f) [%s] %s\n", entity, x, y, animation_name, animation_filename);
				
				world->position[entity].x = x * TILE_WIDTH + TILE_WIDTH / 2;
				world->position[entity].y = y * TILE_HEIGHT + TILE_HEIGHT / 2;
				
				world->position[entity].width = w;
				world->position[entity].height = h;
				
				world->renderPlayer[entity].width = w;
				world->renderPlayer[entity].height = h;
				
				world->collision[entity].id = 0;
				world->collision[entity].type = COLLISION_SOLID;
				world->collision[entity].timer = 0;
				world->collision[entity].timerMax = 0;
				world->collision[entity].active = true;
				world->collision[entity].radius = 0;
				
				load_animation(animation_filename, world, entity);
				play_animation(world, entity, animation_name);
				
				free(animation_name);
				free(animation_filename);
				
			}
			else if (strcmp(entity_type, "sound") == 0) {
				
				int sound_id;
				
				if (fscanf(fp_map, "%d", &sound_id) != 1) {
					printf("Error loading sound!\n");
					return -1;
				}
				
				play_music(sound_id);
				
				//printf("Playing sound %d\n", sound_id);
				
			}
			else if (strcmp(entity_type, "objective") == 0) {
				
				float x, y;
				int w, h;
				unsigned int id, entity = -1;
				char *animation_filename = (char*)malloc(sizeof(char) * 64);
				
				if (fscanf(fp_map, "%f %f %d %d %u %s", &x, &y, &w, &h, &id, animation_filename) != 6) {
					printf("Error loading objective!\n");
					return -1;
				}
				
				entity = create_objective(world, x * TILE_WIDTH + TILE_WIDTH / 2, y * TILE_HEIGHT + TILE_HEIGHT / 2, w, h, id, level);
				
				if (entity >= MAX_ENTITIES) {
					printf("exceeded max entities.\n");
					return -1;
				}
				
				world->mask[entity] |= COMPONENT_ANIMATION | COMPONENT_RENDER_PLAYER;
				
				world->renderPlayer[entity].width = w;
				world->renderPlayer[entity].height = h;
				
				load_animation(animation_filename, world, entity);
				play_animation(world, entity, "not_captured");
				
				//printf("Loaded objective: %u\n", entity);
				
				free(animation_filename);
			}
			else if (strcmp(entity_type, "powerup") == 0) {
				float x, y;
				int w, h, type;
				unsigned int entity = -1;
				char *animation_filename = (char*)malloc(sizeof(char) * 128);
				
				if (fscanf(fp_map, "%f %f %d %d %d %s", &x, &y, &w, &h, &type, animation_filename) != 6) {
					printf("Error loading powerup!\n");
					return -1;
				}
				entity = create_powerup(world, x * TILE_WIDTH + TILE_WIDTH / 2, y * TILE_HEIGHT + TILE_HEIGHT / 2, w, h, type, level);
				
				if (entity >= MAX_ENTITIES) {
					printf("exceeded max entities.\n");
					return -1;
				}
				world->mask[entity] |= COMPONENT_ANIMATION | COMPONENT_RENDER_PLAYER;
				world->renderPlayer[entity].width = w;
				world->renderPlayer[entity].height = h;
				
				load_animation(animation_filename, world, entity);
				play_animation(world, entity, "bounce");
				
				free(animation_filename);
			}
			else if (strcmp(entity_type, "chair") == 0) { //animated objects
				
				unsigned int entity;
				float x, y;
				int w, h;
				char *animation_name = (char*)malloc(sizeof(char) * 64);
				char *animation_filename = (char*)malloc(sizeof(char) * 64);
				
				if (fscanf(fp_map, "%f %f %d %d %s %s", &x, &y, &w, &h, animation_filename, animation_name) != 6) {
					printf("Error loading chair!\n");
					return -1;
				}
				
				entity = create_entity(world, COMPONENT_RENDER_PLAYER | COMPONENT_POSITION | COMPONENT_ANIMATION);
				
				//printf("Loading object %d (%f, %f) [%s] %s\n", entity, x, y, animation_name, animation_filename);
				
				world->position[entity].x = x * TILE_WIDTH;
				world->position[entity].y = y * TILE_HEIGHT;
				
				world->position[entity].width = w;
				world->position[entity].height = h;
				
				world->renderPlayer[entity].width = w;
				world->renderPlayer[entity].height = h;
				
				load_animation(animation_filename, world, entity);
				play_animation(world, entity, animation_name);
				
				free(animation_name);
				free(animation_filename);
				
			}
			else {
				printf("Did not deal with the entity type: %s\n", entity_type);
				break;
			}
		}
	}
	
	fclose(fp_map);
	//cleanup_map();

	map_surface = SDL_CreateRGBSurface(0, width * TILE_WIDTH, height * TILE_HEIGHT, 32, 0, 0, 0, 0);
	
	if (map_surface == 0) {
		printf("error making map surface.\n");
		return -1;
	}
	
	SDL_FillRect(map_surface, NULL, 0xFF0000);
	
	tile_rect.w = TILE_WIDTH;
	tile_rect.h = TILE_HEIGHT;
	
	for(y = 0; y < height; y++) {
		for(x = 0; x < width; x++) {
			tile_rect.x = x * TILE_WIDTH;
			tile_rect.y = y * TILE_HEIGHT;
			
			SDL_BlitSurface(tiles[map[x][y]], NULL, map_surface, &tile_rect);
		}
	}
	
	for(i = 0; i < num_tiles; i++) {
		SDL_FreeSurface(tiles[i]);
	}
	
	map_rect.x = 0;
	map_rect.y = 0;
	w = map_rect.w = width * TILE_WIDTH;
	h = map_rect.h = height * TILE_HEIGHT;
	
	
	create_level(world, collision_map, width, height, TILE_WIDTH, level);

	for (i = 0; i < width; i++) {
		free(map[i]);
		free(collision_map[i]);
	}
	free(map);
	free(collision_map);
	
	
	free(tiles);
	free(collision);
	
	free(entity_type);
	free(tile_filename);

	return 0;
}
Пример #10
0
RACE_DESC *
load_ship (SPECIES_ID SpeciesID, BOOLEAN LoadBattleData)
{
    RACE_DESC *RDPtr = 0;
    void *CodeRef;

    if (SpeciesID >= NUM_SPECIES_ID)
        return NULL;

    CodeRef = CaptureCodeRes (LoadCodeRes (code_resources[SpeciesID]),
                              &GlobData, (void **)(&RDPtr));

    if (!CodeRef)
        goto BadLoad;
    RDPtr->CodeRef = CodeRef;

    if (RDPtr->ship_info.icons_rsc != NULL_RESOURCE)
    {
        RDPtr->ship_info.icons = CaptureDrawable (LoadGraphic (
                                     RDPtr->ship_info.icons_rsc));
        if (!RDPtr->ship_info.icons)
        {
            /* goto BadLoad */
        }
    }

    if (RDPtr->ship_info.melee_icon_rsc != NULL_RESOURCE)
    {
        RDPtr->ship_info.melee_icon = CaptureDrawable (LoadGraphic (
                                          RDPtr->ship_info.melee_icon_rsc));
        if (!RDPtr->ship_info.melee_icon)
        {
            /* goto BadLoad */
        }
    }

    if (RDPtr->ship_info.race_strings_rsc != NULL_RESOURCE)
    {
        RDPtr->ship_info.race_strings =	CaptureStringTable (LoadStringTable (
                                            RDPtr->ship_info.race_strings_rsc));
        if (!RDPtr->ship_info.race_strings)
        {
            /* goto BadLoad */
        }
    }

    if (LoadBattleData)
    {
        DATA_STUFF *RawPtr = &RDPtr->ship_data;
        if (!load_animation (RawPtr->ship,
                             RawPtr->ship_rsc[0],
                             RawPtr->ship_rsc[1],
                             RawPtr->ship_rsc[2]))
            goto BadLoad;

        if (RawPtr->weapon_rsc[0] != NULL_RESOURCE)
        {
            if (!load_animation (RawPtr->weapon,
                                 RawPtr->weapon_rsc[0],
                                 RawPtr->weapon_rsc[1],
                                 RawPtr->weapon_rsc[2]))
                goto BadLoad;
        }

        if (RawPtr->special_rsc[0] != NULL_RESOURCE)
        {
            if (!load_animation (RawPtr->special,
                                 RawPtr->special_rsc[0],
                                 RawPtr->special_rsc[1],
                                 RawPtr->special_rsc[2]))
                goto BadLoad;
        }

        if (RawPtr->captain_control.captain_rsc != NULL_RESOURCE)
        {
            RawPtr->captain_control.background = CaptureDrawable (LoadGraphic (
                    RawPtr->captain_control.captain_rsc));
            if (!RawPtr->captain_control.background)
                goto BadLoad;
        }

        if (RawPtr->victory_ditty_rsc != NULL_RESOURCE)
        {
            RawPtr->victory_ditty =
                LoadMusic (RawPtr->victory_ditty_rsc);
            if (!RawPtr->victory_ditty)
                goto BadLoad;
        }

        if (RawPtr->ship_sounds_rsc != NULL_RESOURCE)
        {
            RawPtr->ship_sounds = CaptureSound (
                                      LoadSound (RawPtr->ship_sounds_rsc));
            if (!RawPtr->ship_sounds)
                goto BadLoad;
        }
    }

ExitFunc:
    return RDPtr;

    // TODO: We should really free the resources that did load here
BadLoad:
    if (CodeRef)
        DestroyCodeRes (ReleaseCodeRes (CodeRef));

    RDPtr = 0; /* failed */

    goto ExitFunc;
}
Пример #11
0
/**
 * Plays the specified animation. Loads it if necessary.
 */
void play_animation
(Animation *anim, char *subtitle, bool press_key_to_continue, bool hold_at_end)
{
  static WINDOW *animation_window = NULL;
  static PANEL  *animation_panel = NULL;
  static int    anim_width;
  static int    anim_height;
  char msg[500];
  (void)msg;
  char *hold_message = "\n(Press any key to continue)";

  if (!anim->isLoaded) load_animation(anim);

  anim_width = anim->width;
  anim_height = anim->height;

  if (subtitle != NULL)
    anim_height++;



  for (int i=0; i < anim->numFrames; ++i) {
    char *theframe = anim->frames[i];
    if (subtitle != NULL) {
      theframe = (char *) malloc(strlen(anim->frames[i]) + strlen(subtitle) + 2); /* +2 for extra null and newline */
      KINDLY_DIE_IF_NULL(theframe);
      strcpy(theframe, anim->frames[i]);
      strcat(theframe, "\n");
      strcat(theframe, subtitle);
    }

    show_message_box_win(&animation_window, &animation_panel,
			 theframe, &anim_width, &anim_height);

    if (subtitle != NULL)
      free(theframe);

    if (press_key_to_continue) {
      /* no delay if press_key_to_continue is set: */
      nodelay(animation_window, true);
      if (ERR != wgetch(animation_window)) {
	nodelay(animation_window, false);
	return;
      }
      nodelay(animation_window, false);
    }

    /* we assume the show_message_box_win takes 0 time */
    usleep( (1/(float)anim->fps) * 1000000 );
  }

  if (hold_at_end) {
    char *hold_frame = (char *) malloc(strlen(anim->frames[anim->numFrames-1]) + strlen(hold_message) + 1);
    KINDLY_DIE_IF_NULL(hold_frame);
    strcpy(hold_frame, anim->frames[anim->numFrames-1]);
    strcat(hold_frame, hold_message);
    show_message_box_win(&animation_window, &animation_panel,
             hold_frame, &anim_width, &anim_height);
    getch();
    free(hold_frame);
  }

  hide_message_box_win(&animation_window, &animation_panel);
}
Пример #12
0
static void
cb_media_downloader_load_threaded (CbMediaDownloader *downloader,
                                   CbMedia           *media)
{
  const char *url;
  SoupMessage *msg;
  GInputStream *input_stream;

  g_return_if_fail (CB_IS_MEDIA_DOWNLOADER (downloader));
  g_return_if_fail (CB_IS_MEDIA (media));
  g_return_if_fail (media->url != NULL);

  g_object_ref (media);

  url = canonicalize_url (media->url);

  /* For these, we first need to download some html and get the real
     URL of the image we want to display */
  if (g_str_has_prefix (url, "instagr.am") ||
      g_str_has_prefix (url, "instagram.com/p/"))
    {
      cb_media_downloader_get_instagram_url (downloader, media);
    }
  else if (g_str_has_prefix (url, "ow.ly/i/") ||
           g_str_has_prefix (url, "flickr.com/photos/") ||
           g_str_has_prefix (url, "flic.kr/p/") ||
           g_str_has_prefix (url, "flic.kr/s/") ||
           g_str_has_prefix (url, "vine.co/v/"))
    {
      cb_media_downloader_load_real_url (downloader, media,
                                         "<meta property=\"og:image\" content=\"(.*?)\"", 1);
    }
  else if (g_str_has_prefix (url, "twitpic.com/"))
    {
      cb_media_downloader_load_real_url (downloader, media,
                                         "<meta name=\"twitter:image\" value=\"(.*?)\"", 1);
    }
  else if (g_str_has_suffix (url, "/photo/1"))
    {
      cb_media_downloader_load_twitter_video (downloader, media);
    }
  else if (g_str_has_prefix (url, "d.pr/i/"))
    {
      cb_media_downloader_load_real_url (downloader, media,
                                         "<meta property=\"og:image\"\\s+content=\"(.*?)\"", 1);
    }

  if (media->url == NULL)
    {
      g_warning ("Media is invalid.");
      mark_invalid (media);
      return;
    }


  msg = soup_message_new ("GET", media->thumb_url ? media->thumb_url : media->url);
  if (msg == NULL)
    {
      mark_invalid (media);
      g_warning ("soup_message_new failed for URI '%s'",
                 media->thumb_url ? media->thumb_url : media->url);
      return;
    }
  g_signal_connect (msg, "got-chunk", G_CALLBACK (update_media_progress), media);
  soup_session_send_message (downloader->soup_session, msg);

  if (msg->status_code != SOUP_STATUS_OK)
    {
      g_debug ("Request on '%s' returned status '%s'",
               media->thumb_url ? media->thumb_url : media->url,
               soup_status_get_phrase (msg->status_code));

      mark_invalid (media);
      g_object_unref (msg);
      return;
    }

  input_stream = g_memory_input_stream_new_from_data (msg->response_body->data,
                                                      msg->response_body->length,
                                                      NULL);

  load_animation (input_stream, media);
  g_input_stream_close (input_stream, NULL, NULL);
  g_object_unref (input_stream);
  g_object_unref (msg);
}
Пример #13
0
/**
 * Loads a model from a file.
 * Returns a pointer to the bone struct containing the data loaded.
 */
model *load_model(const char *file_name)
{
  FILE *fp;
  char buffer[BUFF_LEN], *arg_list[MAX_ARGS];
  int i, line = 0, arg_count;
  mesh *geo;
  bone *b_new;
  model *new_mdl = NULL;


  /* Attempt to open the requested file. Prints error message on error. */
  if((fp = fopen(file_name, "r")) == NULL)
  {
    fprintf(stderr, "ERROR(load_model): Unable to open file '%s'.\n",
      file_name);
    return NULL;
  }

  while(fgets(buffer, BUFF_LEN - 1, fp) != NULL)
  {
    line++;

    /* No lines should be more then the max buffer size in length. If any
     * lines do breach this contraint, then the file is corrupt and will
     * not be loaded. */
    if(buffer[strlen(buffer) - 1] != '\n')
    {
      fprintf(stderr,
        "ERROR(load_model): Buffer overflow in file '%s' line %d\n", file_name,
        line);
      return NULL;
    }
    buffer[strlen(buffer) - 1] = '\0';

    arg_count = makeargs(buffer, SEPERATOR, arg_list, MAX_ARGS);
    if(arg_count == 0)
      continue;


    /* If there's an m as the first character (which there should be at the
     * head of each model file) then we prepare the model.  */
    if(buffer[0] == 'm')
    {
      if(arg_count != 4)
        continue;

      /* Create a new model struct. */
      new_mdl = new_model(arg_list[1], atoi(arg_list[2]));
      if(new_mdl == NULL) return NULL;

      /* Initialise all the new models variables. */
      new_mdl->texture = loadTexture(arg_list[3]);

      printf("New model '%s' created. Loading Model...\n", arg_list[1]);
    }


    /* If we have a bone, indicated by a b as the first character. Note that
     * bones can only be added if a model line has been read in. */
    else if(buffer[0] == 'b')
    {
      if(new_mdl == NULL)
      {
        fprintf(stderr,
          "ERROR(load_mdl): Attempted load bone without model decl.\n");
        continue;
      }
      if(arg_count < 7) continue;

      printf("Loading bone '%s' into model '%s'.\n", arg_list[1],
          new_mdl->name);

      new_mdl->n_bones++;
      /* Allocate memory for the bone object and various chores that need
       * to be done to the bone to keep it healthy. */
      b_new = malloc(sizeof(bone));
      if(b_new == NULL)
      {
        fprintf(stderr, "ERROR(load_model): Cannot allocate memory.\n");
        exit(1);
      }
      b_new->child = NULL;
      b_new->sibling = NULL;
      b_new->child_count = 0;

      /**
       * Allocate memory for the bone name and copy the string accross.
       */
      b_new->name = malloc(strlen(arg_list[1]));
      strcpy(b_new->name, arg_list[1]);

      /* Parse translations from the strings and put them into the bone's
       * translation struct. */
      for(i = 0; i < TRANS_SIZE; i++)
        b_new->rot[i] = atof(arg_list[i + 2]);

      b_new->length = atof(arg_list[5]);

      /* Attempt to load a new mesh into the current bone.  */
      if(strlen(arg_list[7]) > 0)
      {
        geo = load_obj(arg_list[7]);
        if(geo == NULL)
        {
          fprintf(stderr, "Error loading obj %s\n", arg_list[7]);
          exit(1);
        }

        /* Create a vertex array out of the loaded obj and free the mesh
         * struct that was temporarily created. */
        if(strlen(arg_list[8]) > 0 && arg_list[8][0] == 'F')
          b_new->geometry = mesh_to_array(geo, NORM_FLAT);
        else
          b_new->geometry = mesh_to_array(geo, NORM_SMOOTH);
        b_new->tri_count = geo->n_elements;
        free_mesh(geo);
      }
      else
        b_new->geometry = NULL;

      /* If the root bone has not been set then this is obviously the root
       * bone, or a file format error. */
      if(new_mdl->root == NULL)
      {
        if(strlen(arg_list[6]) == 0)
          new_mdl->root = b_new;
        else
        {
          fprintf(stderr,
            "ERROR(load_model): Error, root bone must not have parent.\n");
          free_model(new_mdl);
          return NULL;
        }
      }
      else
      {
        if(!skel_add_child(arg_list[6], new_mdl->root, b_new))
        {
          printf("Cannot add child %s.\n", b_new->name);
          free_model(new_mdl);
          return NULL;
        }
      }
    }


    /* Start of an animation. */
    else if(buffer[0] == 'a')
    {
      if(new_mdl == NULL)
      {
        fprintf(stderr,
          "ERROR(load_mdl): Attempted load animation without model decl.\n");
        continue;
      }
      if(arg_count != 2) continue;

      load_animation(new_mdl, atoi(arg_list[1]), fp);
    }
  }

  if(new_mdl != NULL)
    new_mdl->bone_array = skel_make_array(new_mdl->root, new_mdl->n_bones);

  printf("New model '%s' successfully loaded.\n", new_mdl->name);
  printf("%d bones loaded.\n", new_mdl->n_bones);
  printf("%d animations loaded.\n", new_mdl->n_anims);

  return new_mdl;
}
Пример #14
0
  network_module::network_module(const bar_settings& bar, string name_)
      : timer_module<network_module>(bar, move(name_)) {
    // Load configuration values
    m_interface = m_conf.get(name(), "interface", m_interface);
    m_ping_nth_update = m_conf.get(name(), "ping-interval", m_ping_nth_update);
    m_udspeed_minwidth = m_conf.get(name(), "udspeed-minwidth", m_udspeed_minwidth);
    m_accumulate = m_conf.get(name(), "accumulate-stats", m_accumulate);
    m_interval = m_conf.get<decltype(m_interval)>(name(), "interval", 1s);
    m_unknown_up = m_conf.get<bool>(name(), "unknown-as-up", false);

    m_conf.warn_deprecated(name(), "udspeed-minwidth", "%downspeed:min:max% and %upspeed:min:max%");

    // Add formats
    m_formatter->add(FORMAT_CONNECTED, TAG_LABEL_CONNECTED, {TAG_RAMP_SIGNAL, TAG_RAMP_QUALITY, TAG_LABEL_CONNECTED});
    m_formatter->add(FORMAT_DISCONNECTED, TAG_LABEL_DISCONNECTED, {TAG_LABEL_DISCONNECTED});

    // Create elements for format-connected
    if (m_formatter->has(TAG_RAMP_SIGNAL, FORMAT_CONNECTED)) {
      m_ramp_signal = load_ramp(m_conf, name(), TAG_RAMP_SIGNAL);
    }
    if (m_formatter->has(TAG_RAMP_QUALITY, FORMAT_CONNECTED)) {
      m_ramp_quality = load_ramp(m_conf, name(), TAG_RAMP_QUALITY);
    }
    if (m_formatter->has(TAG_LABEL_CONNECTED, FORMAT_CONNECTED)) {
      m_label[connection_state::CONNECTED] =
          load_optional_label(m_conf, name(), TAG_LABEL_CONNECTED, "%ifname% %local_ip%");
    }

    // Create elements for format-disconnected
    if (m_formatter->has(TAG_LABEL_DISCONNECTED, FORMAT_DISCONNECTED)) {
      m_label[connection_state::DISCONNECTED] = load_optional_label(m_conf, name(), TAG_LABEL_DISCONNECTED, "");
      m_label[connection_state::DISCONNECTED]->reset_tokens();
      m_label[connection_state::DISCONNECTED]->replace_token("%ifname%", m_interface);
    }

    // Create elements for format-packetloss if we are told to test connectivity
    if (m_ping_nth_update > 0) {
      m_formatter->add(FORMAT_PACKETLOSS, TAG_LABEL_CONNECTED,
          {TAG_ANIMATION_PACKETLOSS, TAG_LABEL_PACKETLOSS, TAG_LABEL_CONNECTED});

      if (m_formatter->has(TAG_LABEL_PACKETLOSS, FORMAT_PACKETLOSS)) {
        m_label[connection_state::PACKETLOSS] = load_optional_label(m_conf, name(), TAG_LABEL_PACKETLOSS, "");
      }
      if (m_formatter->has(TAG_ANIMATION_PACKETLOSS, FORMAT_PACKETLOSS)) {
        m_animation_packetloss = load_animation(m_conf, name(), TAG_ANIMATION_PACKETLOSS);
      }
    }

    // Get an intstance of the network interface
    if (net::is_wireless_interface(m_interface)) {
      m_wireless = factory_util::unique<net::wireless_network>(m_interface);
      m_wireless->set_unknown_up(m_unknown_up);
    } else {
      m_wired = factory_util::unique<net::wired_network>(m_interface);
      m_wired->set_unknown_up(m_unknown_up);
    };

    // We only need to start the subthread if the packetloss animation is used
    if (m_animation_packetloss) {
      m_threads.emplace_back(thread(&network_module::subthread_routine, this));
    }
  }