Exemplo n.º 1
0
void init_target()
{
	//Textures loading
	target_scientist = spLoadSurface( "./data/science_guy_frames01.png" );
	target_garfield = spLoadSurface( "./data/garfield.png" );
	target_texture = spCreateSurface(256,256);
	target_graph = spCreateSurface(GRAPH_SIZE,GRAPH_SIZE);


	//Sprite Creating
	target_sprite = spNewSprite( NULL );
	int i;
	for ( i = 0; i < 9; i++ )
		spNewSubSpriteWithTiling( target_sprite, target_scientist, i * 24 + 1, 1, 22, 46, 100 );
}
Exemplo n.º 2
0
PREFIX void spNewSubSpriteTilingRow( spSpritePointer sprite, SDL_Surface* surface, Sint32 sx, Sint32 sy, Sint32 sw, Sint32 sh, Sint32 hopw,Sint32 hoph, Sint32 count,Sint32 duration )
{
  int i;
  for (i = 0; i < count; i++)
  {
    spNewSubSpriteWithTiling(sprite,surface,sx,sy,sw,sh,duration);
    sx+=hopw;
    if (sx >= surface->w)
    {
      sx = sx % hopw;
      sy += hoph;
      if (sy+sh > surface->h)
        return;
    }
  }
}
Exemplo n.º 3
0
int main( int argc, char **argv )
{
	//sparrow3D Init
	spSetDefaultWindowSize( 640, 480 ); //Creates a 640x480 window at PC instead of 320x240
	spInitCore();

	//Setup
	screen = spCreateDefaultWindow();
	spSelectRenderTarget(screen);

	//Tile map loading
	tile_map = spLoadSurface( "./data/science_guy_frames01.png" );

	//Creating an empty sprite
	sprite = spNewSprite();
	//Filling it with it subsprites.
	int i;
	for ( i = 0; i < 9; i++ )
		spNewSubSpriteWithTiling( sprite, tile_map, i * 24 + 1, 1, 22, 46, 100 );

	//We don't want to use the zBuffer in any way
	spSetZSet(0);
	spSetZTest(0);

	//All glory the main loop
	//every frame the draw_function is called
	//every frame the calc_function is called with the past time as argument
	//at least 10 ms have to be between to frames (max 100 fps)
	//if the window is resized, the resize feedback-function is called (again)
	spLoop( draw_function, calc_function, 10, NULL, NULL );

	//Winter Wrap up, Winter Wrap up
	spDeleteSprite( sprite );
	spDeleteSurface( tile_map );
	spQuitCore();
	return 0;
}
Exemplo n.º 4
0
PREFIX spSubSpritePointer spNewSubSpriteNoTiling( spSpritePointer sprite, SDL_Surface* surface, Sint32 duration )
{
	return spNewSubSpriteWithTiling( sprite, surface, -1, -1, surface->w, surface->h, duration );
}
Exemplo n.º 5
0
PREFIX spSpriteCollectionPointer spLoadSpriteCollection(char* filename,SDL_Surface* fallback_surface)
{
	SDL_RWops *file = SDL_RWFromFile(filename, "rt");
	if (!file)
		return NULL;
	spSpriteCollectionPointer collection = spNewSpriteCollection();
	
	//Loading the file line by line
	int end = 0;
	spSpritePointer sprite = NULL;
	char surface_d[1024] = "";
	//border default
	int bw_d = 0;
	int bh_d = 0;
	//frame default
	int fw_d = 0;
	int fh_d = 0;
	int fps_d = 0;
	char sprite_d[1024] = "";
	char surface[1024] = "";
	int bw = bw_d;
	int bh = bh_d;
	int fw = fw_d;
	int fh = fh_d;
	int fps = fps_d;
	while (!end) 
	{
		char line[512];
		end = spReadOneLine(file,line,512);
		//parsing the line
		if (line[0] == '#' || line[0] == ';') {} //comment
		else
		if (line[0] == '[') //new sprite
		{
			int i;
			for (i = 1; line[i]!=']' && line[i]!=0; i++);
			line[i] = 0;
			sprite = spNewSprite(&(line[1]));
			spAddSpriteToCollection(collection,sprite);
			sprintf(surface,"%s",surface_d);
			bw = bw_d;
			bh = bh_d;
			fw = fw_d;
			fh = fh_d;
			fps = fps_d;
		}
		else //some keywords
		{
			//searching the '=', ' ' or \0.
			int i;
			for (i = 1; line[i]!='=' && line[i]!=' ' && line[i]!=0; i++);
			if (line[i]==0) //hm, not good...
				continue;
			int keyword = 0;
			if (line[i]=='=')
			{
				line[i] = 0;
				keyword = spSpriteCollectionGetKeyword(line);
				line[i] = '=';
			}
			else // ' '
			{
				line[i] = 0;
				keyword = spSpriteCollectionGetKeyword(line);
				line[i] =' ';
				for (i++;line[i]!='=' && line[i]!=0; i++);
				if (line[i]==0) //hm, not good...
					continue;
			}
			for (i++;line[i]==' '; i++);
			char* value = &(line[i]);
			int j;
			for (j = strlen(value)-1;value[j]==' ' && j>=0;j--);
			value[j+1] = 0;
			int x,y,n;
			switch (keyword)
			{
				case 1: //"default"
					sprintf(sprite_d,"%s",value);
					break;
				case 2: //"image"
					if (sprite)
						sprintf(surface,"%s",value);
					else
						sprintf(surface_d,"%s",value);
					break;
				case 3: //fps
					if (sprite)
						fps = atoi(value);
					else
						fps_d = atoi(value);
					break;
				case 4: //framesize
					if (sprite)
						fw = atoi(value);
					else
						fw_d = atoi(value);
					for (i++;line[i]!=',' && line[i]!=0; i++);
					if (line[i] == 0)
						continue;
					value = &(line[i+1]);
					if (sprite)
						fh = atoi(value);
					else
						fh_d = atoi(value);
					break;
				case 5: //bordersize
					if (sprite)
						bw = atoi(value);
					else
						bw_d = atoi(value);
					for (i++;line[i]!=',' && line[i]!=0; i++);
					if (line[i] == 0)
						continue;
					value = &(line[i+1]);
					if (sprite)
						bh = atoi(value);
					else
						bh_d = atoi(value);
					break;
				case 6: //frame
					if (!sprite)
						break;
					x = atoi(value);
					for (i++;line[i]!=',' && line[i]!=0; i++);
					if (line[i] == 0)
						continue;
					value = &(line[i+1]);
					y = atoi(value);
					for (i++;line[i]!=',' && line[i]!=0; i++);
					
					SDL_Surface* s = spLoadSurface( surface );
					if (s == NULL)
						s = fallback_surface;
					if (line[i] == 0)
						spNewSubSpriteWithTiling(sprite,s,x+(bw-fw)/2,y+(bh-fh)/2,fw,fh,1000/(fps>0?fps:1));
					else
					{
						value = &(line[i+1]);
						n = atoi(value);						
						if (n > 0)
							spNewSubSpriteTilingRow(sprite,s,x+(bw-fw)/2,y+(bh-fh)/2,fw,fh,bw,bh,n,1000/(fps>0?fps:1));
					}
					//We loaded the surface one time more, than we will it delete later, so lets decrease the ref counter:
					spDeleteSurface( s );
					break;
			}
		}
	}
	spSelectSprite(collection,sprite_d);
	SDL_RWclose(file);
	return collection;
}