Esempio n. 1
0
//! Load image file
bool loadMedia( const std::string& foreground, 
		const std::string& background )
{
  bool success = true;
  
  // Load the foreground image
  if( !g_foreground.loadFromFile( foreground ) )
  {
    std::cerr << "Can't load foreground image "
	      << foreground
	      << "! SDL_Error: "
	      << SDL_GetError()
	      << std::endl;
    success = false;
  }   

  // Load the background image
  if( !g_background.loadFromFile( background ) )
  {
    std::cerr << "Can't load background image "
	      << background
	      << "! SDL_Error: "
	      << SDL_GetError()
	      << std::endl;
    success = false;
  }
    
  return success;
}
Esempio n. 2
0
void SDLInterface::render(SDLTexture &texture, glm::ivec2 position, glm::ivec2 dimensions)
{
    ASSERT(dimensions.x > 0, "Render dimensions must be positive");
    ASSERT(dimensions.y > 0, "Render dimensions must be positive");
    ASSERT(texture.get() != nullptr, "Cannot render null texture");

    LOG_DEBUG(mLogger, "Drawing texture at " << glm::to_string(position) << " with dimensions " << glm::to_string(dimensions));

    SDL_Rect destRect = {position.x, position.y, dimensions.x, dimensions.y};
    SDL_RenderCopy(mRenderer, texture.get(), NULL, &destRect);
}
Esempio n. 3
0
static void order(void)
{
   void  *f;
   char  *text;
   int   x, y;
	int size = 0;
	SDLTexture *restore = NULL;

	restore = render.createScreenTexture();

   f = loadfile("pic\\order.pcx", &size);

   text = (char *)loadfile("stuff\\order1.txt", NULL);

   fadeout(FADE_PALETTE);
   render.clear(0, 0, 0);
   showpcx(f, 20, size);
   blue->print_c(XMAX/2, 0, "ORDER RAVAGE NOW");
   x = 0; y = 30;
   beauty(tiny, x, y, text);
   unloadfile(text);

   fadein(NULL);

   input_wait(); input_fire(); input_wait();
   fadeout(FADE_PALETTE);

   text = (char *)loadfile("stuff\\order2.txt", NULL);

   render.clear(0, 0, 0);
   showpcx(f, 20, size);
   blue->print_c(XMAX/2, 0, "HOW TO ORDER");
   x = 0; y = 30;
   beauty(tiny, x, y, text);
   unloadfile(text);

   fadein(NULL);

   unloadfile(f);

   input_wait(); input_fire(); input_wait();
   fadeout(FADE_PALETTE);

	render.drawTexture(restore, 0, 0);
   fadein(level.palette);

	restore->destroy();
	delete restore;
}
Esempio n. 4
0
//! Close SDL_Window
void close()
{
  // Free the texture
  g_foreground.free();
  g_background.free();

  // Destroy the renderer
  SDL_DestroyRenderer( g_renderer );
  g_renderer = NULL;

  // Destroy window
  SDL_DestroyWindow( g_window );
  g_window = NULL;

  IMG_Quit();
  SDL_Quit();
}
Esempio n. 5
0
static void showpicture(char *file)
{
   void  *f;
	int size = 0;
	SDLTexture *restore;

	restore = render.createScreenTexture();

   f = loadfile(file, &size);
   fadeout(FADE_PALETTE);
   render.clear(0, 0, 0);
   showpcx(f, 0, size);
   unloadfile(f);
   fadein(NULL);
   input_wait(); input_fire(); input_wait();
   fadeout(FADE_PALETTE);

	render.drawTexture(restore, 0, 0);

   fadein(level.palette);

	restore->destroy();
	delete restore;
}
Esempio n. 6
0
//! Close SDL_Window
void close()
{
  // Free the sprite sheet
  g_modulated_texture.free();
  
  // Destroy the renderer
  SDL_DestroyRenderer( g_renderer );
  g_renderer = NULL;

  // Destroy window
  SDL_DestroyWindow( g_window );
  g_window = NULL;

  IMG_Quit();
  SDL_Quit();
}
Esempio n. 7
0
// Load image file
bool loadMedia( const std::string& sprite_sheet_name,
		const unsigned char color_key_red,
		const unsigned char color_key_green,
		const unsigned char color_key_blue )
{
  bool success = true;
  
  // Load the image file
  bool file_loaded = 
    g_sprite_sheet_texture.loadFromFile( sprite_sheet_name, 
					 color_key_red,
					 color_key_green,
					 color_key_blue );
  if( !file_loaded )
  {
    std::cerr << "Can't load sprite sheet " << sprite_sheet_name
	      << "! SDL_Error: " << SDL_GetError()
	      << std::endl;
    success = false;
  }   
  else
  {
    // Set sprite clips
    g_sprite_clips[0].x = 0;
    g_sprite_clips[0].y = 0;
    g_sprite_clips[0].w = 64;
    g_sprite_clips[0].h = 205;
    
    g_sprite_clips[1].x = 64;
    g_sprite_clips[1].y = 0;
    g_sprite_clips[1].w = 64;
    g_sprite_clips[1].h = 205;
    
    g_sprite_clips[2].x = 128;
    g_sprite_clips[2].y = 0;
    g_sprite_clips[2].w = 64;
    g_sprite_clips[2].h = 205;
    
    g_sprite_clips[3].x = 196;
    g_sprite_clips[3].y = 0;
    g_sprite_clips[3].w = 64;
    g_sprite_clips[3].h = 205;
  }
  
  return success;
}
Esempio n. 8
0
static void shutmenu(void)
{
   fadeout(FADE_ALL);
   s_unloadmod();

// Housekeeping.
   weapon_removeall(nowplayer);

   shutlevel();
   shutgame();
   playback_stop();
   cheatlevel = cheatsave;
// Restore Previous Saved Game State.
   gstate = gsave;
   player[nowplayer] = psave;
   player[1-nowplayer] = psave2;

// release resources.
   unloadfile(yesno);
	sYesNo.destroy();

   unloadfile(addsub);
	sAddSub.destroy();

   delete tiny;
   delete blue;

   delete back;

   unloadfile(pointer);
	sPointer.destroy();

   unloadfile(head);
	sHead.destroy();

	demoTexture.destroy();

   delete menuback;
}
Esempio n. 9
0
//! Load image file
bool loadMedia( const std::string& filename,
		const unsigned char color_key_red,
		const unsigned char color_key_green,
		const unsigned char color_key_blue )
{
  bool success = true;
  
  // Load the image file
  bool file_loaded = 
    g_modulated_texture.loadFromFile( filename, 
				      color_key_red,
				      color_key_green,
				      color_key_blue );
  if( !file_loaded )
  {
    std::cerr << "Can't load image " << filename
	      << "! SDL_Error: " << SDL_GetError()
	      << std::endl;
    success = false;
  }   
  
  return success;
}
Esempio n. 10
0
int main(int argc, char** argv){
	srand(time(NULL));
	rand();
	rand();
	rand();
	//Start our window
	int horizPix = 1920;
	int vertPix = 1080;
	try {
		Window::Init(horizPix, vertPix, "");
	}
	catch (const std::runtime_error &e){
		std::cout << e.what() << std::endl;
		Window::Quit();
		return -1;
	}
	SDLTexture wave = std::move(Window::LoadImage("wave.png"));
	SDLTexture blueSquareOcean = std::move(Window::LoadImage("blue_square_ocean.png"));


	//Our timer:
	Timer timer;
	//Rects for the text
	SDL_Rect waveBox;

	waveBox.x = 0;
	waveBox.y = Window::Box().h / 4;
	SDL_QueryTexture(wave.get(), NULL, NULL, &waveBox.w, &waveBox.h);

	int blueSquareOceanBoxW, blueSquareOceanBoxH;
	SDL_QueryTexture(blueSquareOcean.get(), NULL, NULL, &blueSquareOceanBoxW, &blueSquareOceanBoxH);
	

	std::cout << Window::Box().w/waveBox.w << std::endl;

	//Our event structure
	SDL_Event e;
	//For tracking if we want to quit
	bool quit = false;
	float waveCounter = 0;

	Player player;
	MonsterController mController;

	int score = 0;
	int timeElapsed = 0;
	std::stringstream ssScore;
	ssScore << score;
	std::stringstream ssTime;
	ssTime << timeElapsed;

	GameAttributeManager gameAttrMan;
	SDLTexture staticScoreText = Window::RenderText("Score: ", gameAttrMan.getTtfFontFileName(), gameAttrMan.getTextColor(), 30);
	SDLTexture staticTimeText = Window::RenderText("Time Elapsed: ", gameAttrMan.getTtfFontFileName(), gameAttrMan.getTextColor(), 30);
	SDLTexture staticLoseText = Window::RenderText("You lose!", gameAttrMan.getTtfFontFileName(), gameAttrMan.getTextColor(), 100);
	
	

	while (!quit){
		gameAttrMan.updateTimeElapsed();
		//Event Polling
		while (SDL_PollEvent(&e)){
			//If user closes he window
			if (e.type == SDL_QUIT)
				quit = true;
			if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP)
			{
				switch (e.key.keysym.sym)
				{
				case SDLK_w:
				case SDLK_a:
				case SDLK_s:
				case SDLK_d:
					player.move(e.key.keysym.sym, (e.type == SDL_KEYDOWN));
					break;
				default:
					break;
				}
			}
			//If user presses any key
		}

		//RENDERING
		Window::Clear();
		

		//Make the waves
		for (int x = (-waveBox.w); (x + waveCounter - 1) <= Window::Box().w; x += waveBox.w)
		{
			waveBox.x = x + (waveCounter - 1) * waveBox.w;
			Window::Draw(wave.get(), waveBox);
			
		}
		//Make the ocean
		for (int x = 0; x < Window::Box().w; x += blueSquareOceanBoxW)
		{
			for (int y = ((Window::Box().h / 4) + waveBox.h); y < Window::Box().h; y += blueSquareOceanBoxH)
			{
				Window::Draw(blueSquareOcean.get(), x, y);
			}
		}
		player.addRectX(cosf(player.getRotation()) * player.getVelocity().getY());
		player.addRectY(sinf(player.getRotation()) * player.getVelocity().getY());
		player.addRotation(player.getVelocity().getX() * 0.1f);
		player.draw();
		mController.checkDestroyMonsters(player.getRect(), gameAttrMan);
		mController.createMonsters();
		mController.moveAndDrawMonsters();
		if (mController.checkDestroyBarrels(player.getRect(), gameAttrMan) == -1)
		{
			Window::Draw(staticLoseText.get(), Window::Box().w / 2, Window::Box().h / 2);
			Window::Present();
			SDL_Delay(5000);
			quit = true;
		}
		mController.createBarrels();
		mController.moveAndDrawBarrels();
		Window::Draw(staticScoreText.get(), 0, 0);
		Window::Draw(gameAttrMan.getScoreTex(), 200, 0);
		Window::Draw(staticTimeText.get(), 0, 60);
		Window::Draw(gameAttrMan.getTimeTex(), 200, 60);
		waveCounter += 0.1f; 
		if (waveCounter > 1)
			waveCounter = 0;
		Window::Present();
	}
	Window::Quit();

	return 0;
}
Esempio n. 11
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("image",
     boost::program_options::value<std::string>(),
     "the image (with path) that will be used\n");
    
  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("image", 1 );
  
  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message")
    ("color_key_red,r",
     boost::program_options::value<unsigned>(),
     "the color key red value (0-255)\n")
    ("color_key_green,g",
     boost::program_options::value<unsigned>(),
     "the color key green value (0-255)\n")
    ("color_key_blue,b",
     boost::program_options::value<unsigned>(),
     "the color key blue value (0-255)\n");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  else
  {
    std::cerr << "The image (with path) must be specified."
	      << std::endl;

    return 1;
  }

  // Store the color key rgb values
  unsigned char color_key_r = 255, color_key_g = 255, color_key_b = 255;

  if( vm.count( "color_key_red" ) )
    color_key_r = vm["color_key_red"].as<unsigned>();

  if( vm.count( "color_key_green" ) )
    color_key_g = vm["color_key_green"].as<unsigned>();

  if( vm.count( "color_key_blue" ) )
    color_key_b = vm["color_key_blue"].as<unsigned>();
  
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name, color_key_r, color_key_g, color_key_b ) )
      return 1;
    else
    {
      bool quit = false;

      // The event
      SDL_Event event;

      // The modulation components
      unsigned char r = 255, g = 255, b = 255;
      
      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;

	  // On keypress, change rgb values
	  else if( event.type == SDL_KEYDOWN )
	  {
	    switch( event.key.keysym.sym )
	    {
	      // Increase red
	      case SDLK_q:
		r += 32;
		break;

	      // Increase green
	      case SDLK_w:
		g += 32;
		break;

	      // Increase blue
	      case SDLK_e:
		b += 32;
		break;
		
	      // Decrease red
	      case SDLK_a:
		r -= 32;
		break;

	      // Decrease green
	      case SDLK_s:
		g -= 32;
		break;

	      // Decrease blue
	      case SDLK_d:
		b -= 32;
		break;
	    }
	  }
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	
	SDL_RenderClear( g_renderer );

	// Modulate the render texture
	g_modulated_texture.setColor( r, g, b );
	g_modulated_texture.render( 0, 0 );
	
	// Update the screen
	SDL_RenderPresent( g_renderer );
      }
    }
  }
  
  // Close program
  close();

  return 0;
}
Esempio n. 12
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("image",
     boost::program_options::value<std::string>(),
     "the image (with path) that will be used\n");
    
  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("image", 1 );
  
  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message")
    ("color_key_red,r",
     boost::program_options::value<unsigned>(),
     "the color key red value (0-255)\n")
    ("color_key_green,g",
     boost::program_options::value<unsigned>(),
     "the color key green value (0-255)\n")
    ("color_key_blue,b",
     boost::program_options::value<unsigned>(),
     "the color key blue value (0-255)\n");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  else
  {
    std::cerr << "The image (with path) must be specified."
	      << std::endl;

    return 1;
  }

  // Store the color key rgb values
  unsigned char color_key_r = 255, color_key_g = 255, color_key_b = 255;

  if( vm.count( "color_key_red" ) )
    color_key_r = vm["color_key_red"].as<unsigned>();

  if( vm.count( "color_key_green" ) )
    color_key_g = vm["color_key_green"].as<unsigned>();

  if( vm.count( "color_key_blue" ) )
    color_key_b = vm["color_key_blue"].as<unsigned>();
  
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name, color_key_r, color_key_g, color_key_b ) )
      return 1;
    else
    {
      bool quit = false;

      // The event
      SDL_Event event;

      // The current animation frame
      int frame = 0;
      
      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	
	SDL_RenderClear( g_renderer );

	// Render the current frame
	SDL_Rect* current_clip = &g_sprite_clips[frame/4];
	
	g_sprite_sheet_texture.render( (screen_width_height[0] -
					current_clip->w)/2,
				       (screen_width_height[1] - 
					current_clip->h)/2,
				       current_clip );
	
	// Update the screen
	SDL_RenderPresent( g_renderer );

	// Increment the frame
	++frame;

	// Reset animation
	if( frame/4 >= g_frames )
	  frame = 0;
      }
    }
  }
  
  // Close program
  close();

  return 0;
}
Esempio n. 13
0
static void initmenu(void)
{
// Allocate Menu Background backup.
   menuback = new Back(MENUXS, MENUYS);
// Load menu screen.

   demoTexture.loadPointer(SDL_CreateTexture(render.getBase(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, HWXMAX, YMAX), true);
	clearmenu();

// Take a snapshot of the plain menu screen.
   menuback->save(MENUX, MENUY);
// .. freeze overlapping part of Title.
   head = (Sprite *)loadfile("pic\\ravage.spr", NULL);
	sHead.load(head, false);

// Load pointer.
   pointer = (Sprite *)loadfile("pic\\pointer.spr", NULL);
	sPointer.load(pointer, false);

// Set mouse area.
   //setmouselimits(MENUX, MENUY, MENUX+MENUXS-pointer->xs, MENUY+MENUYS-pointer->ys);
    setmouselimits(-BORDER, 0, 320, 240);
// Initialize POINTER animation buffer.
   back = new Back(pointer->xs, pointer->ys);
// Set events to initial values.
   pointer_enabled = 1;
   keys_enabled = 0;
   joy_enabled = 0;

// Several buttons & fonts.
   blue = new Font("fonts\\blue.fnt");
   tiny = new Font("fonts\\tiny.fnt");

   addsub = (Sprite *)loadfile("pic\\addsub.spr", NULL);
   sAddSub.load(addsub, false);

   yesno = (Sprite *)loadfile("pic\\yesno.spr", NULL);
   sYesNo.load(yesno, false);

// Write version information.
#ifdef SHAREWARE
   tiny->vanilla(215, 65, "shareware 1.1", 10);
#else
   tiny->vanilla(215, 65, "registered 1.1", 10);
#endif

// Save current game state in case the menu is in SHOP mode.
   gsave = gstate;
   psave = player[nowplayer];
   psave2 = player[1-nowplayer];
   player[1-nowplayer].active = 0;     // Deactivate unused player.

// Initialize DEMO GAME.
   cheatsave = cheatlevel;
   cheatlevel |= CHEAT_INVUL | CHEAT_NOMONEY;
   playback_start("demo1\\demo1.rec");
   player[nowplayer].control = playback_device;
   gstate.nplayers = 1; gstate.difficulty = 3;
   newgame(1);
   newlevel("demo1\\demo1");
   weapon_releaseall(nowplayer, STARTX1, STARTY);
// Start playing background music.
   s_loadmod("mods\\menu.uni");
   s_startmod();
// Fade In
   fadein(level.palette);
}
Esempio n. 14
0
int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("foreground",
     boost::program_options::value<std::string>(),
     "the foreground image (with path) that will be used\n")
    ("background",
     boost::program_options::value<std::string>(),
     "the background image (with path) that will be used\n");

  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("foreground", 1 );
  pd.add("background", 2 );

  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string foreground_image_name, background_image_name;

  if( vm.count( "foreground" ) )
    foreground_image_name = vm["foreground"].as<std::string>();
  else
  {
    std::cerr << "The foreground image (with path) must be specified."
	      << std::endl;

    return 1;
  }

  if( vm.count( "background" ) )
    background_image_name = vm["background"].as<std::string>();
  else
  {
    std::cerr << "The background image (with path) must be specified."
	      << std::endl;

    return 1;
  }
  
  std::cout << foreground_image_name << " " << background_image_name << std::endl;
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( foreground_image_name, background_image_name ) )
      return 1;
    else
    {
      bool quit = false;

      // Event
      SDL_Event event;

      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	SDL_RenderClear( g_renderer );

	// Render background texture to screen
	g_background.render( 0, 0 );

	// Render foreground texture to screen
	g_foreground.render( 240, 190 );

	// Update the screen
	SDL_RenderPresent( g_renderer );
      }
    }
  }
  
  // Close program
  close();

  return 0;
}