Example #1
0
/**
 *  This is a semi-private blit function and it performs low-level surface
 *  scaled blitting only.
 */
int
SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
                    SDL_Surface * dst, SDL_Rect * dstrect)
{
    static const Uint32 complex_copy_flags = (
                SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA |
                SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD |
                SDL_COPY_COLORKEY
            );

    /* Save off the original dst width, height */
    int dstW = dstrect->w;
    int dstH = dstrect->h;
    SDL_Rect full_rect;
    SDL_Rect final_dst = *dstrect;
    SDL_Rect final_src = *srcrect;

    /* Clip the dst surface to the dstrect */
    full_rect.x = 0;
    full_rect.y = 0;
    full_rect.w = dst->w;
    full_rect.h = dst->h;
    if (!SDL_IntersectRect(&final_dst, &full_rect, &final_dst)) {
        return 0;
    }

    /* Did the dst width change? */
    if ( dstW != final_dst.w ) {
        /* scale the src width appropriately */
        final_src.w = final_src.w * dst->clip_rect.w / dstW;
    }

    /* Did the dst height change? */
    if ( dstH != final_dst.h ) {
        /* scale the src width appropriately */
        final_src.h = final_src.h * dst->clip_rect.h / dstH;
    }

    /* Clip the src surface to the srcrect */
    full_rect.x = 0;
    full_rect.y = 0;
    full_rect.w = src->w;
    full_rect.h = src->h;
    if (!SDL_IntersectRect(&final_src, &full_rect, &final_src)) {
        return 0;
    }

    if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
        src->map->info.flags |= SDL_COPY_NEAREST;
        SDL_InvalidateMap(src->map);
    }

    if ( !(src->map->info.flags & complex_copy_flags) &&
            src->format->format == dst->format->format &&
            !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
        return SDL_SoftStretch( src, &final_src, dst, &final_dst );
    } else {
        return SDL_LowerBlit( src, &final_src, dst, &final_dst );
    }
}
Example #2
0
File: main.c Project: pikhq/cmako
static void render_screen()
{
	static int screen_inited;

	static SDL_Surface *real_screen;
	static SDL_Surface *mako_screen;

	if(!inited_sdl)
		init_sdl();

	if(!screen_inited) {
		const SDL_VideoInfo *info = SDL_GetVideoInfo();

		if(info->wm_available) {
			if(!SDL_SetVideoMode(320, 240, 0,
						SDL_HWSURFACE | SDL_ANYFORMAT | SDL_DOUBLEBUF | SDL_RESIZABLE)) {
				fprintf(stderr, "%s.\n", SDL_GetError());
				exit(1);
			}
		} else {
			if(!SDL_SetVideoMode(info->current_w, info->current_h, 0,
						SDL_HWSURFACE | SDL_ANYFORMAT | SDL_DOUBLEBUF | SDL_RESIZABLE)) {
				fprintf(stderr, "%s.\n", SDL_GetError());
				exit(1);
			}
			SDL_ShowCursor(SDL_DISABLE);
		}

		real_screen = SDL_GetVideoSurface();
		mako_screen = SDL_CreateRGBSurfaceFrom(framebuf, 320, 240, 32,
				320*sizeof(uint32_t), 0xFF0000, 0xFF00, 0xFF, 0);

		screen_inited = 1;
	}

	if(real_screen->h == 240 && real_screen->w == 320)
		SDL_BlitSurface(mako_screen, NULL, real_screen, NULL);
	else {
		int desired_h = real_screen->w * 3 / 4;
		if(desired_h > real_screen->h)
			desired_h = real_screen->h;
		int desired_w = desired_h * 4 / 3;

		SDL_Rect rect = {
			.x = (real_screen->w - desired_w)/2,
			.y = (real_screen->h - desired_h)/2,
			.w = desired_w,
			.h = desired_h
		};

		SDL_SoftStretch(mako_screen, NULL, real_screen, &rect);
	}

	SDL_Flip(real_screen);
}

static void delay()
{
	SDL_framerateDelay(&fps);
}
int
SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, bool update)
{
  SDL_Rect dest;

  dest.x = (int)x;
  dest.y = (int)y;
  dest.w = (int)sw;
  dest.h = (int)sh;

  if(alpha != 255)
    SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha);


  SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
                                  sw, sh, sdl_surface->format->BitsPerPixel,
                                  sdl_surface->format->Rmask, sdl_surface->format->Gmask,
                                  sdl_surface->format->Bmask,
                                  0);

  SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
  SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest);

  int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest);
  SDL_FreeSurface(sdl_surface_copy);

  if (update == UPDATE)
    update_rect(screen, dest.x, dest.y, dest.w, dest.h);

  return ret;
}
Example #4
0
// Blit the output bitmap to the screen and flip the buffer if double buffered
void drawFrame(void)
{
	SDL_Rect dstRect;
	
	dstRect.x = 0;
	dstRect.y = 0;
	dstRect.w = GB_DISPLAY_WIDTH * scaleFactor;
	dstRect.h = GB_DISPLAY_HEIGHT * scaleFactor;

	if (showTilemap)
	{
		drawTilemap(gbSurface);
	}

	if (SDL_SoftStretch(gbSurface, NULL, screen, &dstRect) != 0)
	{
		printf("ERROR: Cannot blit surface\n");
		exit(0);
	}
	
    if (SDL_Flip(screen) != 0)
	{
		printf("ERROR: Could not flip framebuffer\n");
	}
    
    frames++;
}
Example #5
0
File: main.c Project: odrevet/GE
game_status state_game_over(SDL_Surface *screen, game* p_game)
{
  bool done=false;
  image* game_over;
  game_over = image_load("./res/images/game_over.png");

  SDL_Rect srcrect = {0,0,160,144};
  SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);

  while (!done)
    {
      //events
      SDL_Event event;
      while (SDL_PollEvent(&event))
        {
	  switch ( event.type )
            {
            case SDL_QUIT:
	      done = true;
	      break;
            case SDL_KEYUP:
	      switch ( event.key.keysym.sym )
                {
                default:break;
                }
            default:break;
            }
        }
      image_draw(game_over, get_backbuffer_surface(), 0, 0);
      SDL_SoftStretch(get_backbuffer_surface(), &srcrect, screen, &dstrect);
      SDL_Flip(screen);
    }

  return MAIN_MENU;
}
Example #6
0
File: event.c Project: odrevet/GE
bool event_exec_text(event *p_event, struct t_game* p_game)
{
  event_text *data = (event_text*)p_event->data;

  bool done=false;
  SDL_Event event;
  SDL_Rect srcrect = {0,0,160,144};                               //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
  SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);    //equals screen resolution

  message_box* p_message_box = NULL;
  p_message_box = gui_new_message_box(p_message_box, data->text, 0, 144-32, 32, 160, 0, 146, 30);
  p_message_box->p_font = font_load("res/fonts/saxmono.ttf", 10);
  p_message_box->border = 0;
  p_message_box->border_color = 999;
  p_message_box->radius = 0;

  while (!done){
    while (SDL_PollEvent (&event)){
      switch (event.type){
      case SDL_KEYDOWN:
	if(event.key.keysym.sym==SDLK_SPACE){
	  done = true;
	}
	break;
      case SDL_QUIT:
	exit(0);
	break;
      case SDL_JOYBUTTONDOWN:
	switch(event.jbutton.button)
	  {
	  case 0:
	    break;
	  case 1:
	    break;
	  case 2:
	    break;
	  case 3:
	    done = true;
	    break;
	  case 4:
	    break;
	  case 5:
	    break;
	  case 6:
	    break;
	  }
      }
    }

    gui_message_box_draw(p_message_box, get_backbuffer_surface());
    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
    SDL_Flip(SDL_GetVideoSurface());
  }

  gui_message_box_free(p_message_box);

  return true;
}
Example #7
0
void BltRectR(int pno, int dx, int dy, int sx, int sy, int hx, int hy, int scx, int scy)
{
#if		SDL_USE_OPENGL
	SDL_GL_PutTexture(&s_pYGSTexture[pno], dx, dy, (float)hx * ((float)scx / 65536.0f), (float)hy * ((float)scy / 65536.0f), sx, sy, hx, hy);
#else
	if ( s_pYGSTexture[pno] == NULL ) return;

#if		!USE_SOFTSTRETCH
	// 拡大しないで適当に誤魔化す描画
	SDL_Rect	src;
	SDL_Rect	dst;
	int			wx = hx * ((float)scx / 65536.0f), wy = hy * ((float)scy / 65536.0f);

	if ( scx < 65536 )
	{
		src.x = sx + (hx - wx) / 2;
		src.w = hx - (hx - wx);
		dst.x = dx + s_iOffsetX;
	}
	else
	{
		src.x = sx;
		src.w = hx;
		dst.x = dx + (wx - hx) / 2 + s_iOffsetX;
	}

	if ( scy < 65536 )
	{
		src.y = sy + (hy - wy) / 2;
		src.h = hy - (hy - wy);
		dst.y = dy + s_iOffsetY;
	}
	else
	{
		src.y = sy;
		src.h = hy;
		dst.y = dy + (wy - hy) / 2 + s_iOffsetY;
	}

	SDL_BlitSurface( s_pYGSTexture[pno], &src, s_pScreenSurface, &dst );
#else
	// ちゃんと拡大して描画する
	SDL_Rect	src;
	SDL_Rect	dst;

	src.x = sx;					src.y = sy;
	src.w = hx;					src.h = hy;
	dst.x = dx + s_iOffsetX;	dst.y = dy + s_iOffsetY;
	dst.w = hx * ((float)scx / 65536.0f);
	dst.h = hy * ((float)scy / 65536.0f);

	if ( src.w == 0 || src.h == 0 || dst.w == 0 || dst.h == 0 ) { return; }

	SDL_SoftStretch( s_pYGSTexture[pno], &src, s_pScreenSurface, &dst );
#endif
#endif
}
Example #8
0
void DisplayWindow::SurfaceBlit()
{
    // scale between them
    SDL_Rect srcrect = { 0, 0, m_Surface->Width(), m_Surface->Height() };
    SDL_Rect dstrect = { 0, 0, m_Width, m_Height };
    SDL_LockSurface(m_SrcSurface);
    SDL_SoftStretch(m_SrcSurface, &srcrect, m_Screen, &dstrect);
    SDL_UnlockSurface(m_SrcSurface);

//  printf("src %d %d dest %d %d\n", m_Surface->Width(), m_Surface->Height(), m_Width, m_Height);
}
int SurfaceImpl::resize(int w_, int h_)
{
  w = w_;
  h = h_;
  SDL_Rect dest;
  dest.x = 0;
  dest.y = 0;
  dest.w = w;
  dest.h = h;
  int ret = SDL_SoftStretch(sdl_surface, NULL,
                            sdl_surface, &dest);
  return ret;
}
Example #10
0
File: main.c Project: odrevet/GE
game_status state_main_menu(SDL_Surface *screen, game* p_game)
{
  bool done=false;
  image* main_title;
  main_title = image_load("./res/images/main_title.png");
  SDL_Rect srcrect = {0,0,160,144};
  SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);
  int next_state=STAY;
  while (!done)
    {
      //events
      SDL_Event event;
      while (SDL_PollEvent(&event))
        {
	  switch ( event.type )
            {
            case SDL_QUIT:
	      done = true;
	      break;
            default:
	      break;
            }
        }

      image_draw(main_title, get_backbuffer_surface(), 0, 0);
      SDL_SoftStretch(get_backbuffer_surface(), &srcrect, screen, &dstrect);
      SDL_Flip(screen);

      if(next_state == STAY)next_state = menu_main(screen, p_game);
      else if(next_state!=QUIT){
	switch(next_state){
	case LOAD:
	  menu_load(screen, &p_game);
	  next_state = state_in_game(screen, p_game);
	  break;
	case 1:
	  p_game = game_load("./res/scripts/state.xml");
	  next_state = state_in_game(screen, p_game);
	  break;
	default:
	  break;
	}
      }
      else if(next_state==QUIT)done=true;
    }

  image_free(main_title);

  return QUIT;
}
Example #11
0
bool AutoMenu::rendre() {
	if (_fond)
		_fond->dessiner(_rendu);

	int sourisX, sourisY;
	SDL_GetMouseState(&sourisX, &sourisY);
	menu->souris(sourisX/2, sourisY/2, false);

	menu->afficher();

	SDL_SoftStretch(_rendu, NULL, _ecran, NULL);
	SDL_Flip(_ecran);

	return gererEvenementsSDL() && (!_quitter) && (!_quitterMenu);
}
Example #12
0
void finish_game(gamedata &g){

// Stop enginenoise
  g.sound.stop(0);
  g.sound.stop(1);
// Display winnerbox
  if (g.winner > 0 && !demo){
    winnerbox(g, g.winner, 1, 0, g.planeinfo[g.winner].control);
    if (g.players == 2){
      winnerbox(g, g.winner, 2, 240, g.planeinfo[g.winner].control);
    }
// Update display
    SDL_Rect rect;
      rect.x = 0;
      rect.y = 0;
      rect.w = 320;
      rect.h = 240;
    SDL_BlitSurface(g.virtualscreen, &rect, g.physicalscreen, NULL);
    //SDL_Flip(g.physicalscreen);
	if(SDL_MUSTLOCK(ScreenSurface)) SDL_LockSurface(ScreenSurface);
		SDL_Surface *p = SDL_ConvertSurface(g.physicalscreen, ScreenSurface->format, 0);
		SDL_SoftStretch(p, NULL, ScreenSurface, NULL);
	if(SDL_MUSTLOCK(ScreenSurface)) SDL_UnlockSurface(ScreenSurface);
		SDL_Flip(ScreenSurface);
		SDL_FreeSurface(p);


    //SDL_UpdateRect(g.physicalscreen, 0, 0, 0, 0);
    g.sound.play(SOUND_FINISH);
// Wait 4 Seconds
   int then = time(0);
   while (time(0) - then < 4){ if(demo) break;}
  }
// Clean up linkedlists
  g.radar.clearlist();
  g.gun.clearlist();
  g.p.clearlist();
  g.dp.clearlist();
  g.explosion.clearlist();
  g.flame.clearlist();
  g.smoke.clearlist();
  g.fall.clearlist();
  g.shot.clearlist();
  g.drakgun.clearlist();
  g.laser.clearlist();

}
int
SurfaceSDL::draw_bg(Uint8 alpha, bool update)
{
  SDL_Rect dest;

  dest.x = 0;
  dest.y = 0;
  dest.w = screen->w;
  dest.h = screen->h;

  if(alpha != 255)
    {
    /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
      to temp sur, blit the temp into the screen */
    /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
      already have an alpha mask yet... */

    SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
                                    sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
                                    sdl_surface->format->Rmask, sdl_surface->format->Gmask,
                                    sdl_surface->format->Bmask,
                                    0);
    int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
    SDL_FillRect(sdl_surface_copy, NULL, colorkey);
    SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);


    SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
    SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);

    int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);

    if (update == UPDATE)
      SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);

    SDL_FreeSurface (sdl_surface_copy);
    return ret;
    }

  int ret = SDL_SoftStretch(sdl_surface, NULL, screen, &dest);

  if (update == UPDATE)
    SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);

  return ret;
}
Example #14
0
void
PutImage_fit()
{
  SDL_Rect srcRect;
  SDL_Rect dstRect;

  srcRect.x = 0;
  srcRect.y = 0;
  srcRect.w = CV_WIDTH;
  srcRect.h = CV_HEIGHT;
  dstRect.x = 0;
  dstRect.y = 0;
  dstRect.w = 320;
  dstRect.h = 240;

  PutImage_blit();
  SDL_SoftStretch( blit_surface, &srcRect, back_surface, &dstRect );
}
Example #15
0
void Utilities::upload_2d_mipmap(const PixelFormatDescriptor& pfd, GLsizei w, GLsizei h, const void *data)
{
    GLenum internalFormat_gl, format_gl, type_gl;
    toOpenGL(pfd, internalFormat_gl, format_gl, type_gl);
    PushClientAttrib pca(GL_CLIENT_PIXEL_STORE_BIT);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    GL_DEBUG(glTexImage2D)(GL_TEXTURE_2D, 0, internalFormat_gl, w, h, 0, format_gl, type_gl, data);
    
    if (w == 1 && h == 1) return;
    
    uint32_t alphaMask = pfd.getAlphaMask(),
        redMask = pfd.getRedMask(),
        greenMask = pfd.getGreenMask(),
        blueMask = pfd.getBlueMask();
    int bpp = pfd.getColourDepth().getDepth();
    
    SDL_Surface *surf = SDL_CreateRGBSurfaceFrom((void *)data, w, h, bpp, w * bpp / 8, redMask, greenMask, blueMask, alphaMask);
    SDL_assert(surf != nullptr);
    
    GLsizei newW = w;
    GLsizei newH = h;
    GLint level = 0;
    
    do {
        if (newW > 1) newW /= 2;
        if (newH > 1) newH /= 2;
        level++;
        
        SDL_Surface *newSurf = SDL_CreateRGBSurface(0, newW, newH, bpp, redMask, greenMask, blueMask, alphaMask);
        SDL_assert(newSurf != nullptr);
        
        /// @todo this is 'low-quality' and not thread-safe
        SDL_SoftStretch(surf, nullptr, newSurf, nullptr);
        
        GL_DEBUG(glTexImage2D)(GL_TEXTURE_2D, level, internalFormat_gl, newW, newH, 0, format_gl, type_gl, newSurf->pixels);
        SDL_FreeSurface(newSurf);
    } while (!(newW == 1 && newH == 1));
    
    SDL_FreeSurface(surf);
}
Example #16
0
	int Surface::softStretch(State & state, SDL_Surface * surface){
		Stack * stack = state.stack;
		Surface * interfaceSurface = state.getInterface<Surface>("LuaSDL_Surface");
		Rect * interfaceRect = state.getInterface<Rect>("LuaSDL_Rect");

		SDL_Rect * r1 = interfaceRect->get(1);
		SDL_Rect * r2 = interfaceRect->get(3);
		SDL_Surface * destSurface = interfaceSurface->get(2);

		if (destSurface){
			stack->push<bool>(
				SDL_SoftStretch(
				surface,
				(r1) ? r1 : NULL,
				destSurface,
				(r2) ? r2 : NULL) == 0);
			return 1;
		}
		else{
			return 0;
		}
	}
Example #17
0
/**
 *  This is a semi-private blit function and it performs low-level surface
 *  scaled blitting only.
 */
int
SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
                SDL_Surface * dst, SDL_Rect * dstrect)
{
    static const Uint32 complex_copy_flags = (
        SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA |
        SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD |
        SDL_COPY_COLORKEY
    );

    if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
        src->map->info.flags |= SDL_COPY_NEAREST;
        SDL_InvalidateMap(src->map);
    }

    if ( !(src->map->info.flags & complex_copy_flags) &&
         src->format->format == dst->format->format &&
         !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
        return SDL_SoftStretch( src, srcrect, dst, dstrect );
    } else {
        return SDL_LowerBlit( src, srcrect, dst, dstrect );
    }
}
Example #18
0
/*
 * Separate out the actual rendering, so that render to texture can be done.
 */
static void actual_rendering() {
	SDL_Rect srcRect, dstRect;
#if SDL_VERSION_ATLEAST(2,0,0)
	SDL_Texture *texture;
#endif

	if (scale_data.min_scale_factor - 1e-3f > scale_factor) {
		/* Prepare for the unscaled and centered copy of the entire console. */
		srcRect.x=0; srcRect.y=0; srcRect.w=scale_screen->w; srcRect.h=scale_screen->h;
		if (TCOD_ctx.fullscreen) {
			dstRect.x=TCOD_ctx.fullscreen_offsetx; dstRect.y=TCOD_ctx.fullscreen_offsety;
		} else {
			dstRect.x=0; dstRect.y=0;
		}
		dstRect.w=scale_screen->w; dstRect.h=scale_screen->h;
	} else {
		/* Prepare for the scaled copy of the displayed console area. */
		srcRect.x=scale_data.src_x0; srcRect.y=scale_data.src_y0; srcRect.w=scale_data.src_copy_width; srcRect.h=scale_data.src_copy_height;
		dstRect.x=scale_data.dst_offset_x; dstRect.y=scale_data.dst_offset_y;
		dstRect.w=scale_data.dst_display_width; dstRect.h=scale_data.dst_display_height;
	}
#if SDL_VERSION_ATLEAST(2,0,0)
	texture = SDL_CreateTextureFromSurface(renderer, scale_screen);
	SDL_RenderCopy(renderer, texture, &srcRect, &dstRect);
	SDL_DestroyTexture(texture);
#else
	SDL_SoftStretch(scale_screen, &srcRect, screen, &dstRect);
#endif

	if ( TCOD_ctx.sdl_cbk ) {
#if SDL_VERSION_ATLEAST(2,0,0)
		TCOD_ctx.sdl_cbk((void *)renderer);
#else
		TCOD_ctx.sdl_cbk((void *)screen);
#endif
	}
}
Example #19
0
/**
 *  This is a semi-private blit function and it performs low-level surface
 *  scaled blitting only.
 */
int
SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
                SDL_Surface * dst, SDL_Rect * dstrect)
{
    /* Save off the original dst width, height */
    int dstW = dstrect->w;
    int dstH = dstrect->h;
    SDL_Rect final_dst = *dstrect;
    SDL_Rect final_src = *srcrect;

    /* Clip the dst surface to the dstrect */
    SDL_SetClipRect( dst, &final_dst );

    /* Did the dst width change? */
    if ( dstW != dst->clip_rect.w ) {
        /* scale the src width appropriately */
        final_src.w = final_src.w * dst->clip_rect.w / dstW;
    }

    /* Did the dst height change? */
    if ( dstH != dst->clip_rect.h ) {
        /* scale the src width appropriately */
        final_src.h = final_src.h * dst->clip_rect.h / dstH;
    }

    /* Clip the src surface to the srcrect */
    SDL_SetClipRect( src, &final_src );

    src->map->info.flags |= SDL_COPY_NEAREST;

    if ( src->format->format == dst->format->format && !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
        return SDL_SoftStretch( src, &final_src, dst, &final_dst );
    } else {
        return SDL_LowerBlit( src, &final_src, dst, &final_dst );
    }
}
Example #20
0
int main(int argc, char* argv[]) {
    // commandline argument parser options
    struct arg_lit *help = arg_lit0("h", "help", "print this help and exit");
    struct arg_lit *vers = arg_lit0("v", "version", "print version information and exit");
    struct arg_file *file = arg_file1("f", "file", "<file>", "font file");
    struct arg_int *fh = arg_int1("g", "height", "<value>", "font height in pixels (6 or 8)");
    struct arg_str *text = arg_str1("t", "text", "<value>", "text to show");
    struct arg_int *scale = arg_int0("s", "scale", "<value>", "scaling for the window");
    struct arg_end *end = arg_end(20);
    void* argtable[] = {help,vers,file,fh,text,scale,end};
    const char* progname = "fonttool";
    
    // Make sure everything got allocated
    if(arg_nullcheck(argtable) != 0) {
        printf("%s: insufficient memory\n", progname);
        goto exit_0;
    }
    
    // Parse arguments
    int nerrors = arg_parse(argc, argv, argtable);

    // Handle help
    if(help->count > 0) {
        printf("Usage: %s", progname);
        arg_print_syntax(stdout, argtable, "\n");
        printf("\nArguments:\n");
        arg_print_glossary(stdout, argtable, "%-25s %s\n");
        goto exit_0;
    }
    
    // Handle version
    if(vers->count > 0) {
        printf("%s v0.1\n", progname);
        printf("Command line One Must Fall 2097 Font file editor.\n");
        printf("Source code is available at https://github.com/omf2097 under MIT license.\n");
        printf("(C) 2013 Tuomas Virtanen\n");
        goto exit_0;
    }
    
    // Handle errors
    if(nerrors > 0) {
        arg_print_errors(stdout, end, progname);
        printf("Try '%s --help' for more information.\n", progname);
        goto exit_0;
    }
    
    // Init SDL
    SDL_Init(SDL_INIT_VIDEO);
    
    // Scale
    int _sc = 1;
    if(scale->count > 0) {
        _sc = scale->ival[0];
    }
    if(_sc > 4) _sc = 4;
    if(_sc < 1) _sc = 1;
    
    // Font size
    int _fs = fh->ival[0];
    if(_fs < 6 || _fs > 8 || _fs == 7) {
        printf("Only valid values for fontsize are 6 and 8.\n");
        goto exit_1;
    }
    
    // Load fonts
    sd_font *font = sd_font_create();
    if(sd_font_load(font, file->filename[0], _fs)) {
        printf("Couldn't load small font file!\n");
        goto exit_2;
    }
    
    // Create surface for font rendering
    SDL_Surface *surface = 0;
    if((surface = render_text(font, text->sval[0], 320)) == 0) {
        printf("Failed to render text!\n");
        goto exit_3;
    }
   
    // Init window
    SDL_Window *window = SDL_CreateWindow(
        "Fonttool v0.1",
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        320 * _sc,
        200 * _sc,
        SDL_WINDOW_SHOWN
    );
    if (!window) {
        printf("Could not create window: %s\n", SDL_GetError());
        goto exit_3;
    }
   
    // Rects
    SDL_Rect srcrect, dstrect;
    srcrect.x = 0;
    srcrect.y = 0;
    srcrect.w = surface->w;
    srcrect.h = surface->h;
    dstrect.x = 0;
    dstrect.y = 0;
    dstrect.w = surface->w * _sc;
    dstrect.h = surface->h * _sc;

    // Run until windows closed.
    SDL_Surface *window_surface = SDL_GetWindowSurface(window);
    Uint32 tcolor = SDL_MapRGBA(window_surface->format, 0, 0, 0, 0);
    SDL_Event e;
    int run = 1;
    while(run) {
        if(SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT) {
                run = 0;
            }
        }
        
        SDL_FillRect(window_surface, NULL, tcolor);
        if(_sc == 1) {
            SDL_BlitSurface(surface, &srcrect, window_surface, &dstrect);
        } else {
            SDL_SoftStretch(surface, &srcrect, window_surface, &dstrect);
        }
        SDL_UpdateWindowSurface(window);
        SDL_Delay(10);
    }

    // Quit
    SDL_DestroyWindow(window); 
exit_3:
    if(surface) SDL_FreeSurface(surface);
exit_2:
    sd_font_delete(font);
exit_1:
    SDL_Quit();
exit_0:
    arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0]));
    return 0;
}
Example #21
0
void drawmap(bool fScreenshot, short iBlockSize)
{
	if(iBlockSize != TILESIZE)
	{
		SDL_Rect srcrect;
		srcrect.x = 0;
		srcrect.y = 0;
		srcrect.w = 640;
		srcrect.h = 480;

		SDL_Rect dstrect;
		dstrect.x = 0;
		dstrect.y = 0;
		dstrect.w = iBlockSize * 20;
		dstrect.h = iBlockSize * 15;

		if(SDL_SoftStretch(spr_background.getSurface(), &srcrect, blitdest, &dstrect) < 0)
		{
			fprintf(stderr, "SDL_SoftStretch error: %s\n", SDL_GetError());
			return;
		}
	}
	else
	{
		spr_background.draw(0,0);
	}

	drawlayer(0, false, iBlockSize);
	drawlayer(1, false, iBlockSize);


	SDL_Rect rSrc = {0, 0, iBlockSize, iBlockSize};
	SDL_Rect rDst = {0, 0, iBlockSize, iBlockSize};

	for(int j = 0; j < MAPHEIGHT; j++)
	{
		for(int i = 0; i < MAPWIDTH; i++)
		{
			int displayblock = displayblock = g_map.objectdata[i][j];

			if(displayblock != BLOCKSETSIZE)
			{
				rSrc.x = displayblock * iBlockSize;
				rSrc.y = iBlockSize * 30;

				rDst.x = i * iBlockSize;
				rDst.y = j * iBlockSize;

				if(displayblock >= 7 && displayblock <= 14)
					rSrc.y = iBlockSize * (g_map.iSwitches[(displayblock - 7) % 4] + 30);
				
				SDL_BlitSurface(g_map.tilesetsurface[iBlockSize == TILESIZE ? 0 : iBlockSize == PREVIEWTILESIZE ? 1 : 2], &rSrc, screen, &rDst);
			}
		}
	}

	drawlayer(2, false, iBlockSize);
	drawlayer(3, false, iBlockSize);

	for(int j = 0; j < MAPHEIGHT; j++)
	{
		for(int i = 0; i < MAPWIDTH; i++)
		{
			Warp * warp = &g_map.warpdata[i][j];
			
			if(warp->connection != -1)
			{
				SDL_Rect rSrc = {warp->connection * iBlockSize, warp->direction * iBlockSize, iBlockSize, iBlockSize};
				SDL_Rect rDst = {i * iBlockSize, j * iBlockSize, iBlockSize, iBlockSize};

				SDL_BlitSurface(spr_warps[iBlockSize == TILESIZE ? 0 : iBlockSize == PREVIEWTILESIZE ? 1 : 2].getSurface(), &rSrc, screen, &rDst);
			}
		}
	}
}
Example #22
0
File: menu.c Project: odrevet/GE
int menu_start(SDL_Surface* destination, game *p_game)
{
  bool menu_done=false;
  bool timerset = false;

  SDL_Event event;
  int choice_current=0;
  int choice_nb = 3;
  message_box* p_menu = NULL;
  p_menu = gui_new_message_box(p_menu, "  Status\n  Save\n  Load", 12, 16, 70, 100, 0, 0, 30);
  //p_menu = gui_new_message_box(p_menu, "  Item\n  Status\n  Options\n  Save\n  Load", 12, 16, 70, 100, 0, 0, 30);
  p_menu->p_font = font_load("res/fonts/saxmono.ttf", 12);
  p_menu->border = 5;
  p_menu->border_color = 342;
  p_menu->radius = 10;

  image* p_cursor=image_load("./res/chipsets/cursor.png");
  image_set_transp_color(p_cursor, 255, 0, 255);

  //cursor coords
  int src_x = 0;
  int src_y = 0;
  int dest_x = p_menu->x + 2;
  int dest_y = p_menu->y + 5;

  while(!menu_done){
    SDL_Rect srcrect = {0,0,160,144};                               //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);    //equals screen resolution
    gui_message_box_draw(p_menu, get_backbuffer_surface());
    image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
    SDL_Flip(SDL_GetVideoSurface());
    SDL_EnableKeyRepeat(10, 10);
    while (SDL_PollEvent(&event))
      {
	switch ( event.type )
	  {
	  case SDL_KEYUP:
	    switch ( event.key.keysym.sym ){
	    case SDLK_RETURN:
	      src_x = 16;
	      menu_done = true;
	      image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
	      SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
	      SDL_Flip(SDL_GetVideoSurface());
	      SDL_Delay(200);
	      break;
	    case SDLK_UP:
	      if (choice_current > 0){
		choice_current--;
		dest_y -= TTF_FontLineSkip(p_menu->p_font);
	      }
	      else{
		//play sound error
	      }
	      break;
	    case SDLK_DOWN:
	      if (choice_current < choice_nb-1){
		choice_current++;
		dest_y += TTF_FontLineSkip(p_menu->p_font);
	      }
	      else{
		//play sound error
	      }
	      break;
	    default:
	      break;
	    }
	  case SDL_JOYBUTTONDOWN:
	    switch(event.jbutton.button)
	      {
	      case 0:
		break;
	      case 1:
		break;
	      case 2:
		src_x = 16;
		menu_done = true;
		image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
		SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
		SDL_Flip(SDL_GetVideoSurface());
		SDL_Delay(200);
		break;
	      case 3:
		break;
	      case 4:
		break;
	      case 5:
		break;
	      case 6:
		break;
	      }

	    break;
	  default:
	    break;
	  }
      }


    unsigned int start;
    if (!timerset) {
      timerset=true;
      start=SDL_GetTicks();
    }

    unsigned int now=SDL_GetTicks();
    if ((now-start)>100) {
      timerset=false;
      SDL_JoystickUpdate();
      int joystate = SDL_JoystickGetHat(p_game->p_unit->joystick, 0);
      switch (joystate){
      case SDL_HAT_DOWN:
	if (choice_current < choice_nb-1){
	  choice_current++;
	  dest_y += TTF_FontLineSkip(p_menu->p_font);
	}
	else{
	  //play sound error
	}
	break;
      case SDL_HAT_UP:
	if (choice_current > 0){
	  choice_current--;
	  dest_y -= TTF_FontLineSkip(p_menu->p_font);
	}
	else{
	  //play sound error
	}
	break;
      }
    }

  }

  image_free(p_cursor);

  return choice_current;
}
Example #23
0
File: menu.c Project: odrevet/GE
int menu_main(SDL_Surface* destination, game *p_game){
  bool menu_done=false;
  SDL_Event event;
  int choice_current=0;
  int choice_nb = 2;
  message_box* p_menu = NULL;
  p_menu = gui_new_message_box(p_menu, "  Load\n  New Game\n", 30, 70, 40, 100, 0, 0, 30);
  p_menu->p_font = font_load("res/fonts/saxmono.ttf", 12);
  p_menu->border = 5;
  p_menu->border_color = 342;
  p_menu->radius = 10;

  image* p_cursor=image_load("./res/chipsets/cursor.png");
  image_set_transp_color(p_cursor, 255, 0, 255);

  SDL_Joystick* joystick;
  joystick = SDL_JoystickOpen(0);
  //cursor coords
  int src_x = 0;
  int src_y = 0;
  int dest_x = p_menu->x + 2;
  int dest_y = p_menu->y + 5;

  while(!menu_done){
    SDL_Rect srcrect = {0,0,160,144};                               //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);    //equals screen resolution
    gui_message_box_draw(p_menu, get_backbuffer_surface());
    image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
    SDL_Flip(destination);

    while (SDL_PollEvent(&event)){
      switch ( event.type ){

      case SDL_JOYBUTTONDOWN:
	switch(event.jbutton.button)
	  {
	  case 0:
	    break;
	  case 1:
	    break;
	  case 2:
	    src_x = 16;
	    menu_done = true;
	    image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
	    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
	    SDL_Flip(SDL_GetVideoSurface());
	    SDL_Delay(200);
	    break;
	  case 3:
	    break;
	  case 4:
	    break;
	  case 5:
	    break;
	  case 6:
	    break;
	  }

      case SDL_KEYUP:
	switch ( event.key.keysym.sym ){
	case SDLK_RETURN:
	  src_x = 16;
	  menu_done = true;
	  image_draw_part(p_cursor, get_backbuffer_surface(), dest_x, dest_y, src_x, src_y, 16, 16);
	  SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
	  SDL_Flip(SDL_GetVideoSurface());
	  SDL_Delay(200);
	  break;
	case SDLK_UP:
	  if (choice_current > 0){
	    choice_current--;
	    dest_y -= TTF_FontLineSkip(p_menu->p_font);
	  }
	  else{
	    //play sound error
	  }
	  break;
	case SDLK_DOWN:
	  if (choice_current < choice_nb-1){
	    choice_current++;
	    dest_y += TTF_FontLineSkip(p_menu->p_font);
	  }
	  else{
	    //play sound error
	  }
	  break;
	default:
	  break;


	}
	break;
      default:
	break;
      }
    }

    int joystate = SDL_JoystickGetHat(joystick, 0);
    switch (joystate){
    case SDL_HAT_DOWN:
      if (choice_current < choice_nb-1){
	choice_current++;
	dest_y += TTF_FontLineSkip(p_menu->p_font);
      }
      else{
	//play sound error
      }

      break;
    case SDL_HAT_UP:
      if (choice_current > 0){
	choice_current--;
	dest_y -= TTF_FontLineSkip(p_menu->p_font);
      }
      else{
	//play sound error
      }
      break;
    }

  }

  if(choice_current==0)choice_current=LOAD;       //index to next state

  SDL_JoystickClose(joystick);
  image_free(p_cursor);
  gui_message_box_free(p_menu);

  return choice_current;
}
Example #24
0
File: menu.c Project: odrevet/GE
int menu_status(SDL_Surface* destination, game *p_game){
  bool menu_done=false;
  SDL_Event event;

  char text[255];

  sprintf(text, "Name %s\nXP %d\n",  p_game->p_unit->name, p_game->p_unit->XP);
  message_box* p_menu = NULL;
  p_menu = gui_new_message_box(p_menu, text, 12, 16, 70, 100, 0, 0, 30);
  p_menu->p_font = font_load("res/fonts/saxmono.ttf", 12);
  p_menu->border = 5;
  p_menu->border_color = 342;
  p_menu->radius = 10;

  while(!menu_done){
    SDL_Rect srcrect = {0,0,160,144};                               //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);    //equals screen resolution
    gui_message_box_draw(p_menu, get_backbuffer_surface());
    SDL_SoftStretch(backbuffer,&srcrect,SDL_GetVideoSurface(),&dstrect);
    SDL_Flip(SDL_GetVideoSurface());

    while (SDL_PollEvent(&event))
      {
	switch ( event.type )
	  {
	  case SDL_KEYUP:
	    switch ( event.key.keysym.sym ){
	    case SDLK_RETURN:
	      menu_done = true;
	      break;
	    default:
	      break;

	    }
	    break;
	  case SDL_JOYBUTTONDOWN:
	    switch(event.jbutton.button)
	      {
	      case 0:
		break;
	      case 1:
		menu_done = true;
		break;
	      case 2:
		break;
	      case 3:
		break;
	      case 4:
		break;
	      case 5:
		break;
	      case 6:
		break;
	      }
	  default:
	    break;
	  }
      }
  }
  return 1;
}
Example #25
0
File: main.c Project: odrevet/GE
game_status state_in_game(SDL_Surface *screen, game* p_game)
{
  int i=0;
  bool done=false;

  game_status ret_code = GAME_OVER;
  SDL_Rect srcrect = {0,0,160,144};
  dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH);

#ifdef USE_LUA
  lua_State *L;
  L = lua_open();
  luaopen_base(L);
  luaL_openlibs(L);
  luaopen_globals(L);
  luaopen_game(L);
  luaopen_unit(L);
  luaopen_sprite(L);
  luaopen_var(L);
  luaopen_map(L);

  //register lua functions
  lua_register(L ,"say", script_lua_unit_say);
  lua_register(L ,"unit_get_x", script_lua_unit_get_x);
  lua_register(L ,"unit_get_y", script_lua_unit_get_y);
  lua_register(L ,"unit_set_index_x", script_lua_unit_set_index_x);
  lua_register(L ,"unit_set_index_y", script_lua_unit_set_index_y);
  lua_register(L ,"event_text", script_lua_event_exec_text);
  lua_register(L ,"event_teleport", script_lua_event_exec_teleport);
  lua_register(L ,"unit_set_life", script_lua_unit_set_life);
  lua_register(L ,"unit_set_speed", script_lua_unit_set_speed);

  p_game->L = L;
  g_game = p_game;
#endif


  long timelastcall=SDL_GetTicks();

  if(map_get_current(p_game->p_map, p_game->cur_map)->music != NULL){
    char* music = strdup(map_get_current(p_game->p_map, p_game->cur_map)->music);
    Mix_Music* ingame_music = music_load(music);
    music_play(ingame_music);
  }

  message_box* p_menu = NULL;
  p_menu = menu_ingame_create(p_game);
  bool action;

  while (!done)
    {
      action = false;
      SDL_Event event;
      SDL_JoystickUpdate();
      while (SDL_PollEvent(&event)){
	switch ( event.type ){
	case SDL_QUIT:
	  ret_code = QUIT;
	  done = true;
	  break;
	case SDL_KEYUP:
	  switch ( event.key.keysym.sym ){
	  case SDLK_RETURN:
	    switch(menu_start(get_backbuffer_surface(), p_game)){
	    case 0:
	      menu_status(get_backbuffer_surface(), p_game);
	      break;
	    case 1:
	      menu_save(get_backbuffer_surface(), p_game);
	      break;
	    case 2:
	      ret_code = LOAD;
	      done=true;
	      break;
	    }
	    break;
	  default:break;
	  }
	  break;
	case SDL_JOYBUTTONDOWN:
	  switch(event.jbutton.button){
	  case 0:
	    switch(menu_start(get_backbuffer_surface(), p_game)){
	    case 0:
	      menu_status(get_backbuffer_surface(), p_game);
	      break;
	    case 1:
	      menu_save(get_backbuffer_surface(), p_game);
	      break;
	    case 2:
	      ret_code = LOAD;
	      done=true;
	      break;
	    }
	    break;
	  case 2:
	    action = true;
	    break;
	  }
	  break;
	default:break;
	}

	unit_handle_key(p_game->p_unit, &event, p_game);
      }

      int joystate = SDL_JoystickGetHat(p_game->p_unit->joystick, 0);
      switch (joystate){
      case SDL_HAT_DOWN:
	unit_set_vel_y(p_game->p_unit, p_game->p_unit->speed);
	unit_set_vel_x(p_game->p_unit, 0);
	p_game->p_unit->p_sprite->animation_current = DOWN;
	p_game->p_unit->dir = DOWN;
	p_game->p_unit->current_action = NOTHING;

	break;
      case SDL_HAT_UP:
	unit_set_vel_y(p_game->p_unit, -p_game->p_unit->speed);
	unit_set_vel_x(p_game->p_unit, 0);
	p_game->p_unit->p_sprite->animation_current = UP;
	p_game->p_unit->dir = UP;
	p_game->p_unit->current_action = NOTHING;
	break;
      case SDL_HAT_RIGHT:
	unit_set_vel_x(p_game->p_unit, p_game->p_unit->speed);
	unit_set_vel_y(p_game->p_unit, 0);
	p_game->p_unit->p_sprite->animation_current = RIGHT;
	p_game->p_unit->dir = RIGHT;
	p_game->p_unit->current_action = NOTHING;
	break;
      case SDL_HAT_LEFT:
	unit_set_vel_x(p_game->p_unit, -p_game->p_unit->speed);
	unit_set_vel_y(p_game->p_unit, 0);
	p_game->p_unit->p_sprite->animation_current = LEFT;
	p_game->p_unit->dir = LEFT;
	p_game->p_unit->current_action = NOTHING;
	break;
      default:
	break;
      }

      //drawing
      SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
      map_draw(map_get_current(p_game->p_map, p_game->cur_map), backbuffer);

      if(p_game->p_unit->current_action == FIGHT){
	anim_sprite_draw(p_game->p_unit->weapon, get_backbuffer_surface());
      }

      anim_sprite_draw(p_game->p_unit->p_sprite, backbuffer);

      for(i=0;i<p_game->NPC_nb;i++){
	NPC_update(p_game->p_NPC+i, map_get_current(p_game->p_map, p_game->cur_map), p_game->p_unit);
	anim_sprite_draw(p_game->p_NPC[i].p_sprite, backbuffer);
      }

      for(i=0;i<p_game->ennemie_nb;i++){
	ennemie_update(p_game->p_ennemie+i, map_get_current(p_game->p_map, p_game->cur_map), p_game->p_unit);
	anim_sprite_draw(p_game->p_ennemie[i].p_sprite, backbuffer);
      }

      Uint8* key = SDL_GetKeyState(NULL);
      if(key[p_game->p_unit->key_b] || action){
	for(i=0;i<p_game->NPC_nb;i++){

	  if(sprite_intersect((sprite*)p_game->p_unit->p_sprite, (sprite*)p_game->p_NPC[i].p_sprite)){
	    struct t_event* p_event = malloc(sizeof(struct t_event));
	    p_event->is_auto = true;
	    p_event->p_next = NULL;
	    p_event->type = EVENT_SCRIPT;

	    event_script* p_event_script = malloc(sizeof(event_script));
	    p_event_script->language = strdup("lua");
	    p_event_script->script = strdup(p_game->p_NPC[i].script);
	    p_event_script->version = strdup("1.0");

	    p_event->data = p_event_script;
	    event_exec_script(p_event, p_game);

	    event_free(p_event);
	  }
	}
      }


      //logic
      sprite_calc_bounding_box((sprite*)p_game->p_unit->p_sprite, true);



      //events when entering a tile
      point* p_point_enter = unit_check_on_tile_enter(p_game->p_unit, map_get_current(p_game->p_map, p_game->cur_map));
      if( p_point_enter != NULL &&
	  map_get_current(p_game->p_map, p_game->cur_map)->pp_tile[p_point_enter->y][p_point_enter->x].p_event != NULL &&
	  map_get_current(p_game->p_map, p_game->cur_map)->pp_tile[p_point_enter->y][p_point_enter->x].p_event->is_auto){

	p_game->p_unit->p_sprite->v_anim[p_game->p_unit->p_sprite->animation_current].frame_current = 1;
	event_dispatch(map_get_current(p_game->p_map, p_game->cur_map)->pp_tile[p_point_enter->y][p_point_enter->x].p_event, p_game);
	free(p_point_enter);

      }

      map* p_cur_map = map_get_current(p_game->p_map, p_game->cur_map);

      if(SDL_GetTicks() - timelastcall>1000/40) {

	unit_update(p_game->p_unit, p_cur_map);

	for(i=0;i<p_game->ennemie_nb;i++){

	  //Check weapon / ennemie collides
	  if(p_game->p_unit->current_action == FIGHT){
	    if(sprite_intersect((sprite*)p_game->p_unit->weapon, (sprite*)p_game->p_ennemie[i].p_sprite)){
	      p_game->p_ennemie[i].HP--;
	      if(p_game->p_ennemie[i].HP <= 0){                       //ennemie dead
		//sound dead
		//animation dead
		p_game->p_unit->XP += p_game->p_ennemie[i].XP;      //increase unit status
		p_game->p_unit->gold += p_game->p_ennemie[i].gold;

		ennemie_remove(p_game->p_ennemie, i, &p_game->ennemie_nb);      //remove ennemie
		break;
	      }
	    }
	  }

	  //Check unit / ennemie collides
	  if(p_game->p_unit->invincible_time <= 0 && sprite_intersect((sprite*)p_game->p_unit->p_sprite, (sprite*)p_game->p_ennemie[i].p_sprite)){
	    //sample_play(unit_hitted);
	    p_game->p_unit->invincible_time = 40;
	    unit_hitted(p_game->p_unit, p_game->p_ennemie+i, p_cur_map);
	    if(p_game->p_unit->HP <= 0){
	      //sound dead
	      //animation dead
	      //message game over
	      ret_code = GAME_OVER;
	      done = true;
	      break;
	    }
	  }
	}

	//Game events
	menu_ingame_update(get_backbuffer_surface(), p_menu, p_game);

	//update timer
	timelastcall=SDL_GetTicks();
      }

#if RENDER == 3 && !GEKKO
      SDL_GL_SwapBuffers();
#else
      SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
      SDL_Flip(screen);
#endif

    }

  game_free(p_game);
  return ret_code;
}
Example #26
0
void drawall(gamedata &g){

  int ypos;
  int ypos2;

  // Set screenheight
  int screenheight = 0;
  if (g.players == 1){
    screenheight = limit(GAME_HEIGHT,GAME_HEIGHT,240); //464);
  }else{
    screenheight = limit(GAME_HEIGHT,GAME_HEIGHT,120);
  }

  if(!g.scoreBarPos) // top
  {
	ypos = 0;
	ypos2 = 8;
  }
  else // bottom
  {
	ypos = screenheight - 16;
	ypos2 = screenheight - 8;
  }

  // Player 1
//  int x1 = limit(int(g.player1->x)-308, 0, GAME_WIDTH-320);
  int x1 = limit(int(g.player1->x)-160, 0, GAME_WIDTH-320);
  int y1 = limit(int(g.player1->y)-54, 0, GAME_HEIGHT-screenheight);
  SDL_Rect srcrect;
    srcrect.x = x1;
    srcrect.y = y1;
    srcrect.w = 320;
    srcrect.h = screenheight;
  SDL_BlitSurface(g.gamescreen, &srcrect, g.virtualscreen, NULL);
  SDL_Rect cliprect;
    cliprect.x = 0;
    cliprect.y = 0;
    cliprect.w = 320;
    cliprect.h = screenheight;
  SDL_SetClipRect(g.virtualscreen, &cliprect);
  drawblits(g,x1,y1);
  SDL_SetClipRect(g.virtualscreen, NULL);

  if (g.players == 1){
  if(GameState == STATE_GAME)
//	  display_playinfo(g.virtualscreen, 1, *g.player1, screenheight - 16, g.images, g.mission,
//                   g.targetscore, g.whitefont, g.greenfont, g);
	  display_playinfo(g.virtualscreen, 1, *g.player1, ypos, g.images, g.mission,
                   g.targetscore, g.whitefont, g.greenfont, g);
  }else{
  if(GameState == STATE_GAME)
	  display_playinfo(g.virtualscreen, 1, *g.player1, screenheight - 8, g.images, g.mission,
                   g.targetscore, g.whitefont, g.greenfont, g);
  }

/*
  display_playinfo(g.virtualscreen, 1, *g.player1, screenheight, g.images, g.mission,
                   g.targetscore, g.whitefont, g.greenfont, g);
*/

  // Player 2
  if (g.players == 2){
    int x2 = limit(int(g.player2->x)-160, 0, GAME_WIDTH-320);
    int y2 = limit(int(g.player2->y)-54, 0, GAME_HEIGHT-screenheight);//-208); //224);
    SDL_Rect srcrect;
      srcrect.x = x2;
      srcrect.y = y2;
      srcrect.w = 320;
      srcrect.h = screenheight;
    SDL_Rect desrect;
      desrect.x = 0;
      desrect.y = 120;
      desrect.w = 320;
      desrect.h = screenheight;
    SDL_BlitSurface(g.gamescreen, &srcrect, g.virtualscreen, &desrect);
    SDL_Rect cliprect;
      cliprect.x = 0;
      cliprect.y = 120;
      cliprect.w = 320;
      cliprect.h = screenheight;
    SDL_SetClipRect(g.virtualscreen, &cliprect);
    drawblits(g,x2,y2-120);
    SDL_SetClipRect(g.virtualscreen, NULL);

    if(GameState == STATE_GAME)
  	  display_playinfo(g.virtualscreen, 2, *g.player2, 240 - 8, g.images, g.mission,
                     g.targetscore, g.whitefont, g.greenfont, g);
/*
    display_playinfo(g.virtualscreen, 2, *g.player2, 464, g.images, g.mission,
                     g.targetscore, g.whitefont, g.greenfont, g);
*/
  }

  if(GameState == STATE_INTRO || GameState == STATE_MENU)
  {
	if(CurrentMenu == MenuMainIntro)
		menuDraw(CurrentMenu, 140, 100, g);
	else if(CurrentMenu == MenuMain)
		menuDraw(CurrentMenu, 120, 100, g);
	else if(CurrentMenu == MenuOptions)
		menuDraw(CurrentMenu, 110, 100,g);
	else if(CurrentMenu == MenuGameOptions)
		menuDraw(CurrentMenu, 20, 80, g);
	else
		menuDraw(CurrentMenu, 140, 100, g);
  }
  else if(GameState == STATE_MENU_PLANE_SELECT)
  {
	menuPlanesDraw(20, 10, g);
  }
  else if(GameState == STATE_MENU_PLAYER_CONTROL_SELECT)
  {
	menuSelectPlayerDraw(g);
  }

  // Best AI Score
  if (g.planes > g.players){
    plane bestp;
    bool found = false;
    g.p.reset();
    while (g.p.next()){
      if ((g.p().control == 0) && (g.p().side > 0)){
        if (!found){
          bestp = g.p();
          found = true;
        }else{
          if ((g.mission == 0) || (g.mission == 1)){
            if (g.p().score > bestp.score){
              bestp = g.p();
            }
          }else{
            if (g.p().targetscore < bestp.targetscore){
              bestp = g.p();
            }          
          }
        }
      }
    }
    // Display AI
    if(GameState == STATE_GAME){
	    SDL_Rect rect;
	    char compstring[] = "Plane x";
	    compstring[6] = '0' + bestp.side;

	    if (g.players == 1){
	        rect.x = 304;
	        rect.y = ypos;
	        rect.w = 16;
	        rect.h = 16;
	        SDL_FillRect(g.virtualscreen,&rect,16);
	        g.images[bestp.image+13].blit(g.virtualscreen,304,ypos);
		g.whitefont.write(g.virtualscreen, 24, ypos2, compstring);
	    }
	    else{
		// TODO: display the best player score
	    }
	    // Display score
	    if (g.players == 1){
	    display_score(g.virtualscreen, bestp, 112, ypos2, g.mission, g.targetscore,
		          g.whitefont, g.greenfont);
	    }else{
	    display_score(g.virtualscreen, bestp, 112, screenheight-8, g.mission, g.targetscore,
		          g.whitefont, g.greenfont);
	    }
    }

  }

  // Update screen display
  SDL_Rect rect;
    rect.x = 0;
    rect.y = 0;
    rect.w = 320;
    rect.h = 240;
  SDL_BlitSurface(g.virtualscreen, &rect, g.physicalscreen, NULL);

  //SDL_Flip(g.physicalscreen);
	if(SDL_MUSTLOCK(ScreenSurface)) SDL_LockSurface(ScreenSurface);
		SDL_Surface *p = SDL_ConvertSurface(g.physicalscreen, ScreenSurface->format, 0);
		SDL_SoftStretch(p, NULL, ScreenSurface, NULL);
	if(SDL_MUSTLOCK(ScreenSurface)) SDL_UnlockSurface(ScreenSurface);
		SDL_Flip(ScreenSurface);
		SDL_FreeSurface(p);
  //SDL_UpdateRect(g.physicalscreen, 0, 0, 0, 0);

  g.sound.update();

}
Example #27
0
File: main.c Project: odrevet/GE
int state_in_game(SDL_Surface *screen)
{
    SDL_Rect srcrect = {0, 0, 480, 480};                      //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width
    SDL_Rect dstrect = set_rect(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH);    //equals screen resolution

    int bomb_nb=0;
    int flame_nb=0;
    bool done = false;
    int i=0;                     //generic accumulator 1
    int j=0;                     //generic accumulator 2
    int k=0;                     //unit accumulator
    int tick_count=0;
    int tick_trigger=0;
    int time_elapsed=0;         //time elapsed in this round (in secondes)
    int last_time=0;
    int current_game_status=-1;

    timer *timer_battle = timer_init();
    timer_start(timer_battle);

    // load sample.wav in to sample
    Mix_Chunk *sample = sample_load("res/boom.wav");
    Mix_Music* music = music_load("res/music.xm");
    music_play(music);

    //initialize map
    map *p_map = malloc(sizeof(map));
    p_map->tile_height = 32;
    p_map->tile_width = 32;
    map_load_level(p_map, "res/level_01.map");
    p_map->p_chipset = image_load("res/classic.png");
    SDL_Surface* surface_menu = IMG_Load("./res/menu.png");
    SDL_SetColorKey(surface_menu, SDL_SRCCOLORKEY, SDL_MapRGB(surface_menu->format, 255, 0, 255));

    for (k=0;k<g_game.unit_nb;k++)
    {
        unit_tile_protect(g_game.v_unit+k, p_map);
    }

    int block_nb = map_block_add(p_map, g_game.block_fill, .5);         ///@todo the disp % is not implemented yet
    int panel_nb = panel_add(g_game.v_panel, p_map, block_nb);

    int random_comment = rand() % 9;
    char sz_comment[32];
    SDL_Rect pos_comment = set_rect(10, 465, 0, 0);
    int comment_time_elapsed;
    timer *timer_comment = timer_init();

    //Menu
    TTF_Font *font_menu = font_load("res/asia.ttf", 20);
    TTF_Font *font_result = font_load("res/asia.ttf", 75);

    SDL_Rect cur_pos;
    cur_pos.x = 42;
    cur_pos.y = 425;

    char sz_time[10];

    while (!done)
    {
        SDL_Event event;
        SDL_JoystickUpdate();
        while(SDL_PollEvent(&event)){
            for (k=0;k<g_game.unit_nb;k++)
            {
                if (!g_game.v_unit[k].is_dead)
                {
                    unit_handle_key(g_game.v_unit+k, &event, k, g_game.v_bomb, p_map, &bomb_nb);
                }
            }
           if(event.type == SDL_QUIT || ((event.type == SDL_KEYDOWN) && (event.key.keysym.sym == SDLK_ESCAPE)) || (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 6)){
                    done = true;
                    current_game_status = MAIN_MENU;
            }
            else if((event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN)|| (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 5)){
                    Mix_PauseMusic();
                    state_paused(screen);
                    Mix_ResumeMusic();
            }
        }

        for (k=0;k<g_game.unit_nb;k++){
            if(!g_game.v_unit[k].use_keyboard){
                int joystate = SDL_JoystickGetHat(g_game.v_unit[k].joystick, 0);
                switch (joystate){
                    case SDL_HAT_DOWN:
                        unit_set_vel_y(g_game.v_unit+k, g_game.v_unit[k].speed);
                        unit_set_vel_x(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = DOWN;
                    break;
                    case SDL_HAT_UP:
                        unit_set_vel_y(g_game.v_unit+k, -g_game.v_unit[k].speed);
                        unit_set_vel_x(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = UP;
                    break;
                    case SDL_HAT_RIGHT:
                        unit_set_vel_x(g_game.v_unit+k, g_game.v_unit[k].speed);
                        unit_set_vel_y(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = RIGHT;
                    break;
                    case SDL_HAT_LEFT:
                        unit_set_vel_x(g_game.v_unit+k, -g_game.v_unit[k].speed);
                        unit_set_vel_y(g_game.v_unit+k, 0);
                        g_game.v_unit[k].p_sprite->animation_current = LEFT;
                    break;
                    default:
                        if ( g_game.v_unit[k].vel_x != 0 ){
                            unit_set_vel_x(g_game.v_unit+k, 0);
                            g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1;
                        }
                        if ( g_game.v_unit[k].vel_y != 0 ){
                            unit_set_vel_y(g_game.v_unit+k, 0);
                            g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1;
                        }

                    break;
                }
            }
        }

        tick_count = SDL_GetTicks();
        if (tick_count > tick_trigger / 60){
            tick_trigger = tick_count;
            SDL_FillRect(backbuffer, 0, SDL_MapRGB(backbuffer->format, 10, 20, 80));


            //draw the map
            map_draw(p_map, backbuffer);
            for (i=0;i<panel_nb;i++)
            {
                if(p_map->pp_tile[g_game.v_panel[i]->p_sprite->y / TILE_SIZE][g_game.v_panel[i]->p_sprite->x / TILE_SIZE].type != BLOCK)panel_draw(g_game.v_panel[i], backbuffer);
            }


            //check panels
            for (i=0;i<panel_nb;i++)
            {
                // for all units
                for (k=0;k<g_game.unit_nb;k++)
                {
                    //Check for bonus
                    if (g_game.v_panel[i]->p_sprite->y / TILE_SIZE == unit_get_bounding_index_center_y(g_game.v_unit+k)
                            && (g_game.v_panel[i]->p_sprite->x / TILE_SIZE == unit_get_bounding_index_center_x(g_game.v_unit+k)))
                    {
                        panel_apply(g_game.v_panel[i], g_game.v_unit+k);

                        panel_free(g_game.v_panel[i]);
                        panel_nb--;

                        //Left shift the vector
                        for (j=i;j<panel_nb;j++)
                        {
                            g_game.v_panel[j] = g_game.v_panel[j+1];
                        }
                    }
                }
            }

            //Draw and update bombs
            for (i=0;i<bomb_nb;i++)
            {
                bomb_draw(g_game.v_bomb[i], backbuffer);
                anim_sprite_update_frame(g_game.v_bomb[i]->p_sprite);
                bomb_update_timer(g_game.v_bomb[i]);

                if ((g_game.v_bomb[i]->time_left <= 0) || (p_map->pp_tile[g_game.v_bomb[i]->p_sprite->y / TILE_SIZE][g_game.v_bomb[i]->p_sprite->x / TILE_SIZE].type == FLAME))
                {
                    sample_play(sample);
                    bomb_explode(g_game.v_bomb[i], p_map, g_game.v_flame, &flame_nb);
                    bomb_nb--;

                    bomb_free(g_game.v_bomb[i]);

                    //Left shift the vector
                    for (j=i;j<bomb_nb;j++)
                    {
                        g_game.v_bomb[j] = g_game.v_bomb[j+1];
                    }
                }
            }

            //Check flame
            for (i=0;i<p_map->height;i++)
            {
                for (j=0;j<p_map->width[i];j++)
                {
                    // for all units, check if hitten (if unit center is on a tile with a flame flag)
                    for (k=0;k<g_game.unit_nb;k++)
                    {
                        if ((p_map->pp_tile[i][j].type == FLAME) &&
                                ((unit_get_index_x(g_game.v_unit+k) == j) &&
                                (unit_get_index_y(g_game.v_unit+k) == i)) &&
                                g_game.v_unit[k].is_dead == false)
                        {
                            g_game.v_unit[k].is_dead = true;
                            timer_start(timer_comment);

                            switch(random_comment)
                            {
                                case(0):sprintf(sz_comment, "Say goodbye, %s ", g_game.v_unit[k].name);
                                break;
                                case(1):sprintf(sz_comment, "burn %s, burn ! ", g_game.v_unit[k].name);
                                break;
                                case(2):sprintf(sz_comment, "%s vanished !!!!!! ", g_game.v_unit[k].name);
                                break;
                                case(3):sprintf(sz_comment, "unit_free(%s); //^^ ", g_game.v_unit[k].name);
                                break;
                                case(4):sprintf(sz_comment, "%s ? Where are you ? ", g_game.v_unit[k].name);
                                break;
                                case(5):sprintf(sz_comment, "%s was a good guy ", g_game.v_unit[k].name);
                                break;
                                case(6):sprintf(sz_comment, "HE says : \"HELLO, %s\" ", g_game.v_unit[k].name);
                                break;
                                case(7):sprintf(sz_comment, "%s has meet his programmer ", g_game.v_unit[k].name);
                                break;
                                case(8):sprintf(sz_comment, "$ %s>/dev/null ", g_game.v_unit[k].name);
                                break;
                                case(9):sprintf(sz_comment, "%s was not ignifugated ", g_game.v_unit[k].name);
                                break;
                            }
                        }
                    }
                }
            }

            //Draw and update flames
            for (i=0;i<flame_nb;i++)
            {
                flame_draw(g_game.v_flame[i], p_map, backbuffer);
                g_game.v_flame[i]->time_left--;
                if (g_game.v_flame[i]->time_left <= 0)
                {
                    flame_free(g_game.v_flame[i], p_map);
                    flame_nb--;

                    //Left shift the vector
                    for (j=i;j<flame_nb;j++)
                    {
                        g_game.v_flame[j] = g_game.v_flame[j+1];
                    }
                }
            }



            for (k=0;k<g_game.unit_nb;k++)
            {
                if (!g_game.v_unit[k].is_dead)
                {
                    unit_calc_bounding_box(g_game.v_unit+k);
                    unit_update(g_game.v_unit+k, p_map);
                }
            }
            // draw and update units
            unit_draw_from_z_index(g_game.v_unit, g_game.unit_nb, backbuffer);

            //Change every 1 second
            time_elapsed = timer_get_ticks (timer_battle) / 1000;
            if (time_elapsed != last_time){
                last_time = time_elapsed;       //Update current time

        /* Check if any unit won
                    This function is performed every second in order to dont call it to often, and
                    have a little delay if two or more units died almost in the same time (even ms, in the case
                    a unit is at the left of a bomb and an other at the right, the right unit win because the
                    flame is first put to the left...)
                */

                int unit_win;
                unit_win = unit_check_victory(g_game.v_unit, g_game.unit_nb);

                if (unit_win >= 0)
                {
                    //print win, sound, etc
                    g_game.v_unit[unit_win].victory++;
                    time_elapsed = 0;
                    ///@todo set a victories limit (from 1 to 5) and display a special image if win... for the moment, another battle
                    font_printf(font_result, TILE_SIZE * 2, TILE_SIZE * 5, 50, 150, 100, backbuffer, "%s wins", g_game.v_unit[unit_win].name);
                    done = true;
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                    break;
                }
                else if (unit_win == -1)
                {
                    font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "DRAW !");
                    done = true;
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                }

                if (g_game.time - time_elapsed <= 0)
                {
                    cur_pos.x = 240;
                    cur_pos.y = 140;
                    font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "TIMES UP !");
                    done = true;
                    ///@todo select action in times up (blocks falling, etc) for the moment, just a draw...
                    current_game_status = IN_GAME;
                    SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
                    SDL_Flip(screen);
                    SDL_Delay(2000);
                }

            }

            ////////////////////  MENU  ////////////////////
            //TIME
            sprintf(sz_time, "%.3d", g_game.time - time_elapsed);
            SDL_Surface *surface_time = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_time, SOLID);
            SDL_BlitSurface(surface_time, NULL, backbuffer, &cur_pos);
            SDL_FreeSurface(surface_time);
            SDL_Rect menu_src, menu_dest;
            menu_src.h = 32;
            menu_src.w = 32;
            menu_src.x = 0;
            menu_src.y = 0;

            menu_dest.x = 5;
            menu_dest.y = 420;

            SDL_BlitSurface(surface_menu, &menu_src, backbuffer, &menu_dest);

            //VICTORIES
            for (k=0;k<g_game.unit_nb;k++)
            {
                char sz_victory_nb[20];
                SDL_Rect vic_pos = set_rect(10, 450, 0, 0);
                sprintf(sz_victory_nb, "%s: %d", g_game.v_unit[k].name, g_game.v_unit[k].victory);

                vic_pos.x += k * 100;
                SDL_Surface *surface_victory = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_victory_nb, SOLID);
                SDL_BlitSurface(surface_victory, NULL, backbuffer, &vic_pos);
                SDL_FreeSurface(surface_victory);
            }

            //Comment
            if(timer_comment->started){
                comment_time_elapsed = timer_get_ticks(timer_comment) / 1000;
                if (comment_time_elapsed < 3)   //Display the comment 3 seconds
                {
                    font_printf(font_menu, pos_comment.x, pos_comment.y, 200, 200, 200, backbuffer, sz_comment);
                }
                else{   //done
                    timer_stop(timer_comment);
                    random_comment = rand() % 9;

                }
            }

            //DEBUG
#ifdef DEBUG
            font_printf(font_menu, 10, 10, 255, 255, 200, backbuffer, "flame nb : %d", flame_nb);
            font_printf(font_menu, 10, 30, 255, 255, 200, backbuffer, "bomb nb : %d", bomb_nb);
            font_printf(font_menu, 10, 50, 255, 255, 200, backbuffer, "unit nb : %d", g_game.unit_nb);
            font_printf(font_menu, 10, 70, 255, 255, 200, backbuffer, "fill nb : %.2f", g_game.block_fill);
            font_printf(font_menu, 10, 90, 255, 255, 200, backbuffer, "Blocks at startup : %d", block_nb);
            font_printf(font_menu, 10, 110, 255, 255, 200, backbuffer, "Time elapsed : %d", timer_get_ticks(timer_battle)/1000);
            font_printf(font_menu, 10, 130, 255, 255, 200, backbuffer, "unit 1 index: %d %d", unit_get_bounding_index_center_x(g_game.v_unit+0), unit_get_bounding_index_center_y(g_game.v_unit+0));


            SDL_Rect rect = unit_get_bounding_box(g_game.v_unit+0);
            SDL_FillRect(backbuffer, &rect, SDL_MapRGB(backbuffer->format, 255, 255, 0));
#endif

            SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect);
            SDL_Flip(screen);
        }//end thick
    }   //end while



    //Free the memory
    for (i=0;i<bomb_nb;i++)
    {
        bomb_free(g_game.v_bomb[i]);
    }
    for (i=0;i<panel_nb;i++)
    {
        panel_free(g_game.v_panel[i]);
    }
    for (i=0;i<flame_nb;i++)
    {
        flame_free(g_game.v_flame[i], p_map);
    }
    map_free(p_map);

    free(timer_battle);
    free(timer_comment);

    Mix_FreeChunk(sample);
    Mix_FreeMusic(music);

    TTF_CloseFont(font_menu);
    font_menu=NULL; // to be safe...

    TTF_CloseFont(font_result);
    font_result=NULL; // to be safe...

    return current_game_status;

}
Example #28
0
static int
X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
{
    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
    X11_TextureData *texturedata = (X11_TextureData *) texture->driverdata;

    if (data->makedirty) {
        SDL_AddDirtyRect(&data->dirty, dstrect);
    }
    if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
#ifndef NO_SHARED_MEMORY
        if (texturedata->shminfo.shmaddr) {
            XShmPutImage(data->display, data->drawable, data->gc,
                         texturedata->image, srcrect->x, srcrect->y,
                         dstrect->x, dstrect->y, srcrect->w, srcrect->h,
                         False);
        } else
#endif
        if (texturedata->pixels) {
            XPutImage(data->display, data->drawable, data->gc,
                      texturedata->image, srcrect->x, srcrect->y, dstrect->x,
                      dstrect->y, srcrect->w, srcrect->h);
        } else {
            XCopyArea(data->display, texturedata->pixmap, data->drawable,
                      data->gc, srcrect->x, srcrect->y, dstrect->w,
                      dstrect->h, dstrect->x, dstrect->y);
        }
    } else if (texturedata->yuv
               || texture->access == SDL_TEXTUREACCESS_STREAMING) {
        SDL_Surface src, dst;
        SDL_PixelFormat fmt;
        SDL_Rect rect;
        XImage *image = texturedata->scaling_image;

        if (!image) {
            int depth;
            void *pixels;
            int pitch;

            pitch = dstrect->w * SDL_BYTESPERPIXEL(texturedata->format);
            pixels = SDL_malloc(dstrect->h * pitch);
            if (!pixels) {
                SDL_OutOfMemory();
                return -1;
            }

            image =
                XCreateImage(data->display, data->visual, data->depth,
                             ZPixmap, 0, pixels, dstrect->w, dstrect->h,
                             SDL_BYTESPERPIXEL(texturedata->format) * 8,
                             pitch);
            if (!image) {
                SDL_SetError("XCreateImage() failed");
                return -1;
            }
            texturedata->scaling_image = image;

        } else if (image->width != dstrect->w || image->height != dstrect->h
                   || !image->data) {
            image->width = dstrect->w;
            image->height = dstrect->h;
            image->bytes_per_line =
                image->width * SDL_BYTESPERPIXEL(texturedata->format);
            image->data =
                (char *) SDL_realloc(image->data,
                                     image->height * image->bytes_per_line);
            if (!image->data) {
                SDL_OutOfMemory();
                return -1;
            }
        }

        /* Set up fake surfaces for SDL_SoftStretch() */
        SDL_zero(src);
        src.format = &fmt;
        src.w = texture->w;
        src.h = texture->h;
#ifndef NO_SHARED_MEMORY
        if (texturedata->shminfo.shmaddr) {
            src.pixels = texturedata->shminfo.shmaddr;
        } else
#endif
            src.pixels = texturedata->pixels;
        src.pitch = texturedata->pitch;

        SDL_zero(dst);
        dst.format = &fmt;
        dst.w = image->width;
        dst.h = image->height;
        dst.pixels = image->data;
        dst.pitch = image->bytes_per_line;

        fmt.BytesPerPixel = SDL_BYTESPERPIXEL(texturedata->format);

        rect.x = 0;
        rect.y = 0;
        rect.w = dstrect->w;
        rect.h = dstrect->h;
        if (SDL_SoftStretch(&src, srcrect, &dst, &rect) < 0) {
            return -1;
        }
        XPutImage(data->display, data->drawable, data->gc, image, 0, 0,
                  dstrect->x, dstrect->y, dstrect->w, dstrect->h);
    } else {
        XCopyArea(data->display, texturedata->pixmap, data->drawable,
                  data->gc, srcrect->x, srcrect->y, dstrect->w, dstrect->h,
                  srcrect->x, srcrect->y);
    }
    return 0;
}