Пример #1
0
void resize( Uint16 w, Uint16 h )
{
	#if defined ZOOMUP || defined ZOOMDOWN
		#if defined ZOOMUP && defined ZOOMDOWN
			if (dummy_screen)
				spDeleteSurface(dummy_screen);
			#ifdef FIRSTUP
				dummy_screen = spCreateSurface(screen->w*2,screen->h*2);
			#else
				dummy_screen = spCreateSurface(screen->w/2,screen->h/2);
			#endif
		#else
			if (screen)
				spDeleteSurface(screen);
			#ifdef ZOOMUP
				screen = spCreateSurface(real_screen->w/2,real_screen->h/2);
			#else
				screen = spCreateSurface(real_screen->w*2,real_screen->h*2);
			#endif
		#endif
	#endif
	spSelectRenderTarget(screen);
	//Font Loading
	if ( font )
		spFontDelete( font );
	int zoom = spMin( ( screen->w << SP_ACCURACY ) / 320, ( screen->h << SP_ACCURACY ) / 240 ); //at 320x240 == 1.0
	font = spFontLoad( "./font/LiberationMono-Regular.ttf", 10 * zoom >> SP_ACCURACY );
	spFontAdd( font,SP_FONT_GROUP_ASCII, 0 ); //Just for debug stuff
	spFontAddBorder( font, spGetFastRGB(127,127,127) );
}
Пример #2
0
StateScore::StateScore( StateLevel *level ) :
	StateBase(),
	file( FOLDER_DATA "/" FILE_HIGHSCORE_NORMAL )
{
	SDL_Surface *temp = spCreateSurface( APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT );
	killFrame = spCreateSurface( APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT );
	spSelectRenderTarget( temp );
	level->render( temp );
	spUnlockRenderTarget();
	SDL_SetAlpha( temp, SDL_SRCALPHA, 128 );
	SDL_BlitSurface( temp, NULL, killFrame, NULL );
	spLockRenderTarget();
	spSelectRenderTarget( spGetWindowSurface() );
	spDeleteSurface( temp );
	if ( level->player->toBeRemoved )
		playerDead = true;
	else
		playerDead = false;

	score = level->scoreKeeper->getScore();
	scoreText = spFontLoad( FONT_GENERAL, SCORE_FONT_SIZE );
	if ( scoreText )
	{
		spFontAdd( scoreText, SP_FONT_GROUP_ALPHABET SP_FONT_GROUP_GERMAN ".:!\"_", -1 );
		spFontAdd( scoreText, SP_FONT_GROUP_NUMBERS, spGetRGB( 255, 128, 0 ) );
	}

	nameBkup[0] = 0;
	if ( level->run->playing )
	{
		state = 1;
		caret = false;
		strcpy( nameBkup, name );
		strcpy( name, level->run->info.name.c_str() );
		run = level->run;
		level->run = NULL;
	}
	else
	{
		caret = true;
		state = 0;
		spPollKeyboardInput( name, SCORE_MAX_NAME_LENGTH, NULL );
		run = level->run;
		level->run = NULL;
	}

	caretTimer.start( SCORE_CARET_BLINK_TIME );
	timers.push_back( &caretTimer );

	type = stScore;
}
Пример #3
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 );
}
Пример #4
0
StateMenu::StateMenu() : StateBase()
{
	fontDark = spFontLoad( FONT_GENERAL, MENU_FONT_SIZE );
	if ( fontDark )
	{
		spFontAdd( fontDark, SP_FONT_GROUP_ASCII, spGetFastRGB( 0, 0, 0 ) );
		spFontAdd( fontDark, SP_FONT_GROUP_GERMAN, spGetFastRGB( 0, 0, 0 ) );
	}
	fontBright = spFontLoad( FONT_GENERAL, MENU_FONT_SIZE );
	if ( fontBright )
		spFontAdd( fontBright, SP_FONT_GROUP_ASCII, spGetFastRGB( 255, 255, 255 ) );

	addMenuEntry( "start game", stLevel );
	addMenuEntry( "show scores", stHighscores );
	addMenuEntry( "load replay", stReplayLoader );
#ifdef _DEBUG
	addMenuEntry( "collision test", stCollision );
#endif
	addMenuEntry( "exit", -1 );
	timers.push_back( &inputLag );

	text = spCreateSurface( APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT / 2 );
	textMode = 1;
	textIndex = -1;
	timers.push_back( &textTimer );
	lines.push_back( std::make_pair( "A game by", "Janek Schäfer" ) );
	lines.push_back( std::make_pair( "Press \""SP_BUTTON_B_NAME"\" or \""SP_BUTTON_START_NAME"\"", "to select an item" ) );
	lines.push_back( std::make_pair( "This is a WIP", "A lot left to do" ) );
	lines.push_back( std::make_pair( "Use the arrow keys", "to navigate" ) );
	lines.push_back( std::make_pair( "Hint: Bombs explode,", "Spikes and Lasers don't" ) );
	lines.push_back( std::make_pair( "Hint: Not entering a name,", "will not add a highscore or replay" ) );
	lines.push_back( std::make_pair( "Hint: Waves may exceed,", "the max unit limit" ) );

	type = stMenu;
}
Пример #5
0
void UnitLaser::generateIdleImage()
{
	idle = spCreateSurface( LASER_RADIUS * 2, LASER_RADIUS * 2 );
	SDL_FillRect( idle, NULL, SP_ALPHA_COLOR );
	spSelectRenderTarget( idle );
	spEllipse( LASER_RADIUS, LASER_RADIUS, -1, LASER_RADIUS, LASER_RADIUS, 0 );
	spSelectRenderTarget( spGetWindowSurface() );
}
Пример #6
0
void UnitBomb::generateFlashingImage()
{
    flashing = spCreateSurface( BOMB_RADIUS * 2, BOMB_RADIUS * 2 );
    SDL_FillRect( flashing, NULL, SP_ALPHA_COLOR );
    spSelectRenderTarget( flashing );
    spEllipse( BOMB_RADIUS ,BOMB_RADIUS, -1, BOMB_RADIUS, BOMB_RADIUS, spGetFastRGB( 255, 255, 255 ) );
    spSelectRenderTarget( spGetWindowSurface() );
}
Пример #7
0
void ItemSlowmo::generateIdleImage()
{
	idle = spCreateSurface( ITEM_SLOWMO_RADIUS * 2, ITEM_SLOWMO_RADIUS * 2 );
	SDL_FillRect( idle, NULL, SP_ALPHA_COLOR );
	spSelectRenderTarget( idle );
	Uint16 col = spGetRGB( 0, 192, 0 );
	spEllipse( ITEM_SLOWMO_RADIUS, ITEM_SLOWMO_RADIUS, -1, ITEM_SLOWMO_RADIUS, ITEM_SLOWMO_RADIUS, -1);
	spEllipse( ITEM_SLOWMO_RADIUS, ITEM_SLOWMO_RADIUS, -1, ITEM_SLOWMO_RADIUS * 0.9, ITEM_SLOWMO_RADIUS * 0.9, col );
	spEllipse( ITEM_SLOWMO_RADIUS, ITEM_SLOWMO_RADIUS, -1, ITEM_SLOWMO_RADIUS * 0.65, ITEM_SLOWMO_RADIUS * 0.65, -1);
	spEllipse( ITEM_SLOWMO_RADIUS, ITEM_SLOWMO_RADIUS, -1, ITEM_SLOWMO_RADIUS * 0.55, ITEM_SLOWMO_RADIUS * 0.55, col );
	spRectangle( ITEM_SLOWMO_RADIUS, ITEM_SLOWMO_RADIUS * 0.8, -1, ITEM_SLOWMO_RADIUS * 0.1, ITEM_SLOWMO_RADIUS * 0.4, -1 );
	spRectangle( ITEM_SLOWMO_RADIUS * 1.2, ITEM_SLOWMO_RADIUS, -1, ITEM_SLOWMO_RADIUS * 0.4, ITEM_SLOWMO_RADIUS * 0.1, -1 );
	spSelectRenderTarget( spGetWindowSurface() );
}
Пример #8
0
void ItemVortex::generateIdleImage()
{
	idle = spCreateSurface( ITEM_VORTEX_RADIUS * 2, ITEM_VORTEX_RADIUS * 2 );
	SDL_FillRect( idle, NULL, SP_ALPHA_COLOR );
	spSelectRenderTarget( idle );
	Uint16 col = spGetRGB( 0, 192, 0 );
	spEllipse( ITEM_VORTEX_RADIUS, ITEM_VORTEX_RADIUS, -1, ITEM_VORTEX_RADIUS, ITEM_VORTEX_RADIUS, -1 );
	spEllipse( ITEM_VORTEX_RADIUS, ITEM_VORTEX_RADIUS, -1, ITEM_VORTEX_RADIUS * 0.9, ITEM_VORTEX_RADIUS * 0.9, col );
	spEllipse( ITEM_VORTEX_RADIUS, ITEM_VORTEX_RADIUS, -1, ITEM_VORTEX_RADIUS * 0.65, ITEM_VORTEX_RADIUS * 0.65, -1 );
	spEllipse( ITEM_VORTEX_RADIUS, ITEM_VORTEX_RADIUS, -1, ITEM_VORTEX_RADIUS * 0.55, ITEM_VORTEX_RADIUS * 0.55, col );
	spEllipse( ITEM_VORTEX_RADIUS, ITEM_VORTEX_RADIUS, -1, ITEM_VORTEX_RADIUS * 0.45, ITEM_VORTEX_RADIUS * 0.45, -1 );
	spEllipse( ITEM_VORTEX_RADIUS, ITEM_VORTEX_RADIUS, -1, ITEM_VORTEX_RADIUS * 0.35, ITEM_VORTEX_RADIUS * 0.35, col );
	spEllipse( ITEM_VORTEX_RADIUS, ITEM_VORTEX_RADIUS, -1, ITEM_VORTEX_RADIUS * 0.25, ITEM_VORTEX_RADIUS * 0.25, -1 );
	spEllipse( ITEM_VORTEX_RADIUS, ITEM_VORTEX_RADIUS, -1, ITEM_VORTEX_RADIUS * 0.15, ITEM_VORTEX_RADIUS * 0.15, col );
	spSelectRenderTarget( spGetWindowSurface() );
}
Пример #9
0
PREFIX void spFontChangeLetter( spFontPointer font, spLetterPointer letter, Uint32 character, Uint16 color )
{
	letter->color = color;
	char buffer[5];
	buffer[0] = character;
	buffer[1] = 0; //TODO: utf8
	SDL_Color sdlcolor = {( color >> 11 ) << 3, ( ( color << 5 ) >> 10 ) << 2, ( ( color & 31 ) << 3 )};
	SDL_Surface* surface = TTF_RenderUTF8_Solid( font->font, buffer, sdlcolor );
	int width = surface->w + SP_FONT_EXTRASPACE * 2;
	if ( width & 1 )
		width++;
	letter->surface = spCreateSurface(width, surface->h + SP_FONT_EXTRASPACE * 2);
	SDL_FillRect( letter->surface, NULL, SP_ALPHA_COLOR );

	SDL_Rect DestR;
	DestR.x = SP_FONT_EXTRASPACE;
	DestR.y = SP_FONT_EXTRASPACE;
	DestR.w = surface->w;
	DestR.h = surface->h;
	SDL_BlitSurface( surface, NULL, letter->surface, &DestR );

	SDL_FreeSurface( surface );

	TTF_SizeUTF8( font->font, buffer, &( letter->width ), &( letter->height ) );
	if ( font->maxheight < letter->height )
		font->maxheight = letter->height;
}

PREFIX void spFontAdd( spFontPointer font, Uint32 character, Uint16 color )
{
	spLetterPointer letter = ( spLetterPointer )malloc( sizeof( spLetterStruct ) );

	spFontChangeLetter( font, letter, character, color );
	letter->character = character;

	//tree insert
	font->root = spFontInsert( letter, font->root );
}
Пример #10
0
void resize_particle(int winX,int winY)
{
  //smallParticle 2% of y
  if (smallParticle)
    SDL_FreeSurface(smallParticle);
  int w = winY*2/100;
  if (w&1)
    w++;
  SDL_Surface* dummy = spCreateSurface(w,w);
  SDL_LockSurface(dummy);
  Uint16* pixel = dummy->pixels;
  int x,y;
  for (x = 0; x < dummy->w; x++)
    for (y = 0; y < dummy->h; y++)
    {
      int X = dummy->w/2-x;
      int Y = dummy->h/2-y;
      int R = dummy->w/2;
      if (X*X+Y*Y < R*R)
        pixel[x+y*dummy->w] = 65535;
      else
        pixel[x+y*dummy->w] = SP_ALPHA_COLOR;
    }
  SDL_UnlockSurface(dummy);
  smallParticle = dummy;
  //middleParticle 3.5% of y
  if (middleParticle)
    SDL_FreeSurface(middleParticle);
  w = winY*7/200;
  if (w&1)
    w++;
  dummy = spCreateSurface(w,w);
  SDL_LockSurface(dummy);
  pixel = dummy->pixels;
  for (x = 0; x < dummy->w; x++)
    for (y = 0; y < dummy->h; y++)
    {
      int X = dummy->w/2-x;
      int Y = dummy->h/2-y;
      int R = dummy->w/2;
      if (X*X+Y*Y < R*R)
        pixel[x+y*dummy->w] = 65535;
      else
        pixel[x+y*dummy->w] = SP_ALPHA_COLOR;
    }
  SDL_UnlockSurface(dummy);
  middleParticle = dummy;
  //bigParticle 5% of y
  if (bigParticle)
    SDL_FreeSurface(bigParticle);
  w = winY*5/100;
  if (w&1)
    w++;
  dummy = spCreateSurface(w,w);
  SDL_LockSurface(dummy);
  pixel = dummy->pixels;
  for (x = 0; x < dummy->w; x++)
    for (y = 0; y < dummy->h; y++)
    {
      int X = dummy->w/2-x;
      int Y = dummy->h/2-y;
      int R = dummy->w/2;
      if (X*X+Y*Y < R*R)
        pixel[x+y*dummy->w] = 65535;
      else
        pixel[x+y*dummy->w] = SP_ALPHA_COLOR;
    }
  SDL_UnlockSurface(dummy);
  bigParticle = dummy;
  //timeSurface
  if (timeSurface)
    SDL_FreeSurface(timeSurface);
  w = winY*2/6;
  if (w&1)
    w++;
  dummy = spCreateSurface(w,w/8);
  SDL_LockSurface(dummy);
  pixel = dummy->pixels;
  //memset(pixel,255,dummy->w*dummy->h*4);
  for (x = 0; x < dummy->w; x++)
    for (y = 0; y < dummy->h; y++)
    {
      /*pixel[(x+y*dummy->w)*4+0] = 255;
      if (x < dummy->w/2)
        pixel[(x+y*dummy->w)*4+1] = 2*x*192/dummy->w;
      else
        pixel[(x+y*dummy->w)*4+1] = 2*(dummy->w-x)*192/dummy->w;
      pixel[(x+y*dummy->w)*4+2] = x*255/dummy->w;
      pixel[(x+y*dummy->w)*4+3] = 255-x*255/dummy->w;      */
      if ((x == 0) ^ (y == 0) ^ (x == dummy->w-1) ^ (y == dummy->h-1))
        pixel[x+y*dummy->w] = 65535;
      else
      if ((x == 0) || (y == 0) || (x == dummy->w-1) || (y == dummy->h-1))
        pixel[x+y*dummy->w] = SP_ALPHA_COLOR;
      else
      {
        int g = (x*255/dummy->w)>>2;
        int r = (255-x*255/dummy->w)>>3;
        pixel[x+y*dummy->w] = (r<<11)+(g<<5);
      }
    }
  SDL_UnlockSurface(dummy);
  timeSurface = dummy;
}
Пример #11
0
PREFIX void spFontChangeLetter( spFontPointer font, spLetterPointer letter, Uint32 character, Uint16 color )
{
	letter->color = color;
	Uint16 buffer[2];
	buffer[0] = character;
	buffer[1] = 0;
	SDL_Color sdlcolor = {( color >> 11 ) << 3, ( ( color << 5 ) >> 10 ) << 2, ( ( color & 31 ) << 3 )};
	SDL_Surface* surface;
	if (spFontBackgroundColor == SP_FONT_NO_BORDER)
		surface = TTF_RenderUNICODE_Solid( font->font, buffer, sdlcolor );
	else
	{
		SDL_Color background =	{( spFontBackgroundColor >> 11 ) << 3, ( ( spFontBackgroundColor << 5 ) >> 10 ) << 2, ( ( spFontBackgroundColor & 31 ) << 3 )};
		surface = TTF_RenderUNICODE_Shaded( font->font, buffer, sdlcolor ,background );
	}
	if (!surface)
		surface = spCreateSurface(0,font->maxheight);
	int width = surface->w + SP_FONT_EXTRASPACE * 2;
	if ( width & 1 )
		width++;
	letter->surface = spCreateSurface(width, surface->h + SP_FONT_EXTRASPACE * 2);
	SDL_FillRect( letter->surface, NULL, SP_ALPHA_COLOR );

	SDL_Rect DestR;
	DestR.x = SP_FONT_EXTRASPACE;
	DestR.y = SP_FONT_EXTRASPACE;
	DestR.w = surface->w;
	DestR.h = surface->h;
	SDL_BlitSurface( surface, NULL, letter->surface, &DestR );
	SDL_FreeSurface( surface );

	//Setting every spFontBackgroundColor to the alpha color
	SDL_LockSurface( letter->surface );
	Uint16* pixel = ( Uint16* )( letter->surface->pixels );
	int scanline = letter->surface->pitch/letter->surface->format->BytesPerPixel;
	int x, y;
	for ( x = 0; x < letter->surface->w; x++ )
		for ( y = 0; y < letter->surface->h; y++ )
			if ( pixel[x + y * scanline] == spFontBackgroundColor )
				pixel[x + y * scanline] = SP_ALPHA_COLOR;
	SDL_UnlockSurface( letter->surface );

	TTF_SizeUNICODE( font->font, buffer, &( letter->width ), &( letter->height ) );
	if ( font->maxheight < letter->height )
		font->maxheight = letter->height;
}

static void spFontInternalAddOneCharacter( spFontPointer font, Uint32 character, Uint16 color )
{
	if (spFontGetLetter(font,character))
		return;
	spLetterPointer letter = ( spLetterPointer )malloc( sizeof( spLetter ) );

	spFontChangeLetter( font, letter, character, color );
	letter->character = character;

	//tree insert
	font->root = spFontInsert( letter, font->root );
}

PREFIX void spFontAdd( spFontPointer font, char* characters, Uint16 color )
{
	//parsing the characters string.
	int pos = 0;
	while (1)
	{
		Uint32 character = spFontGetUnicodeFromUTF8(&(characters[pos]));
		if (character == 0)
			break;
		pos+=spFontLastUTF8Length;
		spFontInternalAddOneCharacter(font,character,color);
	}
}

PREFIX void spFontAddRange( spFontPointer font, char* from, char* to, Uint16 color )
{
	//getting the characters strings
	Uint32 c_from = spFontGetUnicodeFromUTF8(from);
	if (c_from == 0)
		return;
	Uint32 c_to = spFontGetUnicodeFromUTF8(to);
	if (c_to == 0)
		return;
	Uint32 character;
	if (c_from > c_to)
	{
		character = c_from;
		c_from = c_to;
		c_to = character;
	}
	for (character = c_from; character <= c_to; character++)
		spFontInternalAddOneCharacter(font,character,color);
}
Пример #12
0
PREFIX void spFontChangeButton( spFontPointer font, spLetterPointer letter, Uint32 character, char* caption, Uint16 fgColor, Uint16 bgColor )
{
	letter->color = fgColor;
	SDL_Color sdlcolor = {( fgColor >> 11 ) << 3, ( ( fgColor << 5 ) >> 10 ) << 2, ( ( fgColor & 31 ) << 3 )};
  int width;
  if (spFontCorrectStrategy(caption) == SP_FONT_BUTTON)
  {
    char buffer[5];
    buffer[0] = character;
    buffer[1] = 0; //TODO: utf8
    SDL_Surface* surface = TTF_RenderUTF8_Solid( font->font, caption, sdlcolor );
    width = font->maxheight + SP_FONT_EXTRASPACE * 2;
    if ( width & 1 )
      width++;
    letter->surface = spCreateSurface(width, width);
    SDL_LockSurface(letter->surface);
    int x,y;
    Uint16* pixel = (Uint16*)letter->surface->pixels;
    int w = letter->surface->pitch/letter->surface->format->BytesPerPixel;
    for (x = 0; x < letter->surface->w; x++)
      for (y = 0; y < letter->surface->h; y++)
      {
        if ((x-width/2)*(x-width/2)+(y-width/2)*(y-width/2) <= width*width/4)
        {
          if ((x-width/2)*(x-width/2)+(y-width/2)*(y-width/2) <= width*width/5)
            pixel[x+y*w] = bgColor;
          else
            pixel[x+y*w] = fgColor;
        }
        else
          pixel[x+y*w] = SP_ALPHA_COLOR;
      }
    SDL_UnlockSurface(letter->surface);

    SDL_Rect DestR;
    DestR.x = width/2-surface->w/2;
    DestR.y = font->maxheight/2+SP_FONT_EXTRASPACE-surface->h/2;
    DestR.w = surface->w;
    DestR.h = surface->h;
    SDL_BlitSurface( surface, NULL, letter->surface, &DestR );

    SDL_FreeSurface( surface );
  }
  else
  {
    int buttonWidth = font->maxheight + SP_FONT_EXTRASPACE * 2;
    int border = buttonWidth/14;
    SDL_Surface* surface = TTF_RenderUTF8_Solid( font->font, caption, sdlcolor );
    width = surface->w+2*SP_FONT_EXTRASPACE+2*border;
    if ( width & 1 )
      width++;
    letter->surface = spCreateSurface(width, font->maxheight+SP_FONT_EXTRASPACE*2);
    SDL_LockSurface(letter->surface);
    int x,y;
    Uint16* pixel = (Uint16*)letter->surface->pixels;
    int w = letter->surface->pitch/letter->surface->format->BytesPerPixel;
    for (x = 0; x < letter->surface->w; x++)
      for (y = 0; y < letter->surface->h; y++)
      {
        if (x < border        || y < border ||
            x >= width-border || y >= letter->surface->h-border)
          pixel[x+y*w] = fgColor;
        else
          pixel[x+y*w] = bgColor;
      }
    SDL_UnlockSurface(letter->surface);

    SDL_Rect DestR;
    DestR.x = SP_FONT_EXTRASPACE+border;
    DestR.y = font->maxheight/2+SP_FONT_EXTRASPACE-surface->h/2;
    DestR.w = surface->w;
    DestR.h = surface->h;
    SDL_BlitSurface( surface, NULL, letter->surface, &DestR );

    SDL_FreeSurface( surface );
  }

  letter->height = font->maxheight;
  letter->width = width;
}


PREFIX void spFontAddButton( spFontPointer font, Uint32 character, char* caption, Uint16 fgColor, Uint16 bgColor )
{
  spLetterPointer letter = ( spLetterPointer )malloc( sizeof( spLetterStruct ) );

	spFontChangeButton( font, letter, character, caption, fgColor, bgColor );
	letter->character = character;

	//tree insert
	font->buttonRoot = spFontInsert( letter, font->buttonRoot );
}