Exemplo n.º 1
0
void RenderableRectangle::Render(Renderer  * renderer)
{
	SDL_SetRenderDrawColor(renderer->getSDLRenderer(), baseColor.r, baseColor.g, baseColor.b, baseColor.a);
	SDL_Rect rect = { position.x,position.y,size.x*scale.x,size.y*scale.y };
	SDL_RenderDrawRect(renderer->getSDLRenderer(), &rect);
}
Exemplo n.º 2
0
void SDL::rect( int x, int y, int w, int h, SDL_Color color )
{
	SDL_Rect rect = { (int)(x - origin.x), (int)(y - origin.y), (int)w, (int)h };
	setColor( color );
	SDL_RenderDrawRect( renderer, &rect );
}
Exemplo n.º 3
0
void OptionsMenu::Draw(SDL_Renderer* rR) {
	SDL_SetRenderDrawBlendMode(rR, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(rR, 4, 4, 4, 235);
	SDL_RenderFillRect(rR, &rRect);
	SDL_SetRenderDrawColor(rR, 255, 255, 255, 255);
	rRect.x += 1;
	rRect.y += 1;
	rRect.h -= 2;
	rRect.w -= 2;
	SDL_RenderDrawRect(rR, &rRect);
	rRect.x -= 1;
	rRect.y -= 1;
	rRect.h += 2;
	rRect.w += 2;

	for(unsigned int i = 0; i < lMO.size(); i++) {
		if(i == activeMenuOption) {
			CCFG::getText()->Draw(rR, lMO[i]->getText(), lMO[i]->getXPos(), lMO[i]->getYPos(), 16, 255, 255, 255);
		} else {
			CCFG::getText()->Draw(rR, lMO[i]->getText(), lMO[i]->getXPos(), lMO[i]->getYPos(), 16, 90, 90, 90);
		}
	}

	SDL_SetRenderDrawColor(rR, 4, 4, 4, 245);
	SDL_RenderFillRect(rR, &rVolumeBG);

	SDL_SetRenderDrawColor(rR, activeMenuOption == 0 ? 150 : 90, activeMenuOption == 0 ? 150 : 90, activeMenuOption == 0 ? 150 : 90, 255);
	SDL_RenderFillRect(rR, &rVolume);

	if(activeMenuOption == 0) {
		SDL_SetRenderDrawColor(rR, 255, 255, 255, 255);
		SDL_RenderDrawRect(rR, &rVolumeBG);
	} else {
		SDL_SetRenderDrawColor(rR, 160, 160, 160, 55);
		SDL_RenderDrawRect(rR, &rVolumeBG);
	}

	CCFG::getText()->Draw(rR, CCFG::getKeyString(CCFG::keyIDA), 185, 89, 16, activeMenuOption == 1 ? 255 : 90, activeMenuOption == 1 ? 255 : 90, activeMenuOption == 1 ? 255 : 90);
	CCFG::getText()->Draw(rR, CCFG::getKeyString(CCFG::keyIDS), 185, 113, 16, activeMenuOption == 2 ? 255 : 90, activeMenuOption == 2 ? 255 : 90, activeMenuOption == 2 ? 255 : 90);
	CCFG::getText()->Draw(rR, CCFG::getKeyString(CCFG::keyIDD), 185, 137, 16, activeMenuOption == 3 ? 255 : 90, activeMenuOption == 3 ? 255 : 90, activeMenuOption == 3 ? 255 : 90);
	CCFG::getText()->Draw(rR, CCFG::getKeyString(CCFG::keyIDSpace), 185, 161, 16, activeMenuOption == 4 ? 255 : 90, activeMenuOption == 4 ? 255 : 90, activeMenuOption == 4 ? 255 : 90);
	CCFG::getText()->Draw(rR, CCFG::getKeyString(CCFG::keyIDShift), 185, 185, 16, activeMenuOption == 5 ? 255 : 90, activeMenuOption == 5 ? 255 : 90, activeMenuOption == 5 ? 255 : 90);

	CCFG::getText()->Draw(rR, CCFG::canMoveBackward ? "TRUE" : "FALSE", 357, 209, 16, activeMenuOption == 6 ? 255 : 90, activeMenuOption == 6 ? 255 : 90, activeMenuOption == 6 ? 255 : 90);

	if(inSetKey) {
		SDL_SetRenderDrawColor(rR, 20, 20, 20, 245);
		SDL_RenderFillRect(rR, &rSetKeyRect);
		SDL_SetRenderDrawColor(rR, 255, 255, 255, 255);
		rSetKeyRect.x += 1;
		rSetKeyRect.y += 1;
		rSetKeyRect.h -= 2;
		rSetKeyRect.w -= 2;
		SDL_RenderDrawRect(rR, &rSetKeyRect);
		rSetKeyRect.x -= 1;
		rSetKeyRect.y -= 1;
		rSetKeyRect.h += 2;
		rSetKeyRect.w += 2;

		CCFG::getText()->Draw(rR, "PRESS KEY FOR " + lMO[activeMenuOption]->getText(), 92, rSetKeyRect.y + 16, 16, 255, 255, 255);
		CCFG::getText()->Draw(rR, "PRESS ESC TO CANCEL", 92, rSetKeyRect.y + 40, 16, 255, 255, 255);
	}

	SDL_SetRenderDrawBlendMode(rR, SDL_BLENDMODE_NONE);
	CCore::getMap()->setBackgroundColor(rR);
}
Exemplo n.º 4
0
void draw_rect(SDL_Renderer *rnd, const SDL_Rect *rect, Uint8 r, Uint8 g,
			   Uint8 b, Uint8 a)
{
	SDL_SetRenderDrawColor(rnd, r, g, b, a);
	SDL_RenderDrawRect(rnd, rect);
}
Exemplo n.º 5
0
void renderRect( int x, int y, int w, int h, const SDL_Color& col, SDL_Renderer* destination, bool filled) {
    SDL_SetRenderDrawColor(destination, col.r, col.g, col.b, col.a);
    SDL_Rect rect; rect.x = x; rect.y = y; rect.w = w; rect.h = h;
    if(filled) {    SDL_RenderFillRect(destination, &rect); }
    else {          SDL_RenderDrawRect(destination, &rect); }
}
Exemplo n.º 6
0
bool Renderer::renderCollider(SDL_Rect collider, int color) {
	SDL_SetRenderDrawColor(Renderer::g_renderer, color, color, color, color);
	SDL_RenderDrawRect(Renderer::g_renderer, &collider);
	SDL_SetRenderDrawColor(Renderer::g_renderer, 0, 0, 0, 0);
	return true;
}
Exemplo n.º 7
0
//title screen loop
void Game::title_screen( SDL_Rect window_outline )
{
    //light pink color for larger text
    SDL_Color color = { 219, 112, 147 };
    
    //create and load title text texture
    Texture title;
    title.load_text(big_font, color, "PONG");
    
    //create and load first button text texture
    Texture button1;
    button1.load_text(medium_font, color, "1 PLAYER");
    
    //create and load second button text texture
    Texture button2;
    button2.load_text(medium_font, color, "2 PLAYER");
    
    //create and load third button text texture
    Texture button3;
    button3.load_text(medium_font, color, "INSTRUCTIONS");
    
    //create and load credits text texture
    Texture credit;
    credit.load_text(smallest_font, color, "PONG IS ORIGINALLY CREATED BY ATARI INC.");
    
    //create button1 outline
    SDL_Rect button_outline = { WINDOW_WIDTH/2 - button1.get_width()/2 - 7, (WINDOW_HEIGHT*4)/10 - button1.get_height()/2 - 10, button1.get_width() + 14, button1.get_height() + 14 };
    //create button select (determines which button is outlined)
    int button_select = 0;
    
    //title screen loop terminator
    bool terminated = false;
    
    //create object that reads in events
    SDL_Event event;
    
    //title screen loop
    while (terminated == false)
    {
        //take in events
        while ( SDL_PollEvent(&event) )
        {
            //if there's a quit event
            if ( event.type == SDL_QUIT )
            {
                //stop title screen loop
                terminated = true;
                //tell level control to end game
                level = END;
            }
            
            //if there's a non-repeat keypress event
            if ( event.type == SDL_KEYDOWN && event.key.repeat == 0 )
            {
                //if down key was pressed
                if ( event.key.keysym.sym == SDLK_DOWN )
                {
                    //if first button is selected
                    if (button_select == 0)
                    {
                        //move outline to second button
                        ++button_select;
                        button_outline.y += (WINDOW_HEIGHT*1)/10;
                    }
                    
                    //if second button is selected
                    else if (button_select == 1)
                    {
                        //move outline to third button
                        ++button_select;
                        button_outline.y += (WINDOW_HEIGHT*1)/10;
                        button_outline.x -= 55;
                        button_outline.w += 110;
                    }
                    
                    //if third button is selected
                    else if (button_select == 2)
                    {
                        //move outline to first button
                        button_select = 0;
                        button_outline.y -= (WINDOW_HEIGHT*2)/10;
                        button_outline.x += 55;
                        button_outline.w -= 110;
                    }
                }
                
                //if up key is pressed
                if ( event.key.keysym.sym == SDLK_UP )
                {
                    //if first button is selected
                    if (button_select == 0)
                    {
                        //move outline to third button
                        button_select = 2;
                        button_outline.y += (WINDOW_HEIGHT*2)/10;
                        button_outline.x -= 55;
                        button_outline.w += 110;
                    }
                    
                    //if second button is selected
                    else if (button_select == 1)
                    {
                        //move outline to first button
                        --button_select;
                        button_outline.y -= (WINDOW_HEIGHT*1)/10;
                    }
                    
                    //if third button is selected
                    else if (button_select == 2)
                    {
                        //move outline to second button
                        --button_select;
                        button_outline.y -= (WINDOW_HEIGHT*1)/10;
                        button_outline.x += 55;
                        button_outline.w -= 110;
                    }
                    
                }
                
                //if enter key is pressed
                else if ( event.key.keysym.sym == SDLK_RETURN )
                {
                    //if first button is selected
                    if (button_select == 0)
                    {
                        //end title screen loop
                        terminated = true;
                        //change level to computer battle
                        level = COMPUTER_BATTLE;
                    }
                    
                    //if second button is selected
                    else if (button_select == 1)
                    {
                        //end title screen loop
                        terminated = true;
                        //change level to player battle
                        level = PLAYER_BATTLE;
                    }
                    
                    //if third button is selected
                    else if (button_select == 2)
                    {
                        //end title screen loop
                        terminated = true;
                        //change level to instructions
                        level = INSTRUCTIONS;
                    }
                }
            }
        }
        
        //clear window black
        SDL_SetRenderDrawColor( renderer, 0, 0, 0, 255 );
        SDL_RenderClear(renderer);
        
        //set renderer color to white
        SDL_SetRenderDrawColor( renderer, 255, 255, 255, 255 );
        
        //render window outline
        SDL_RenderDrawRect( renderer, &window_outline );
        //render button outline
        SDL_RenderDrawRect( renderer, &button_outline );
        
        //render title text
        title.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*2)/10);
        //render button texts
        button1.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*4)/10);
        button2.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*5)/10);
        button3.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*6)/10);
        //render credit text
        credit.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*9)/10);
        
        //update window with new renders
        SDL_RenderPresent( renderer );
    }
}
Exemplo n.º 8
0
static void draw_cmd (void)
{
    SDL_Color colour = { 255, 255, 255 };
   // SDL_Color rectcolour = {100, 100, 100};

    SDL_Surface *cmdsrf = NULL;
    SDL_Texture *cmdtex = NULL;
    SDL_Rect dstrect;
    char value[4] = "000";

    sprintf (value, "%03i", cmd_value);

    dstrect.x = 10;
    dstrect.y = 10;
    //Draw cmd name

    cmdsrf = TTF_RenderText_Solid (font, udp_cmds[cmd_index].name, colour);
    cmdtex = SDL_CreateTextureFromSurface(ren, cmdsrf);
    SDL_QueryTexture(cmdtex, NULL, NULL, &dstrect.w, &dstrect.h);

    //Draw red box around cmd
    if (cmd_mode == MODE_CMD)
    {
        dstrect.y -= 1;
        SDL_SetRenderDrawColor (ren, 255, 0, 0, 0);
        SDL_RenderDrawRect(ren, &dstrect);
        dstrect.y += 1;
    }


    SDL_RenderCopy(ren, cmdtex, NULL, &dstrect);

    if (udp_cmds[cmd_index].data_size == 0)
        return;

    if (score_entry)
    {
        cmdsrf = TTF_RenderText_Solid (font, score_str, colour);
        cmdtex = SDL_CreateTextureFromSurface(ren, cmdsrf);
        dstrect.x = 300;
        SDL_QueryTexture(cmdtex, NULL, NULL, &dstrect.w, &dstrect.h);

        SDL_RenderCopy(ren, cmdtex, NULL, &dstrect);
        return;
    }

    //Draw data value
    cmdsrf = TTF_RenderText_Solid (font, value, colour);
    cmdtex = SDL_CreateTextureFromSurface(ren, cmdsrf);
    dstrect.x = 400;
    SDL_QueryTexture(cmdtex, NULL, NULL, &dstrect.w, &dstrect.h);

    //Draw red box around value
    if (cmd_mode == MODE_VALUE)
    {
        dstrect.y -= 1;
        SDL_SetRenderDrawColor (ren, 255, 0, 0, 0);
        SDL_RenderDrawRect(ren, &dstrect);
        dstrect.y += 1;
    }

    SDL_RenderCopy(ren, cmdtex, NULL, &dstrect);
}
Exemplo n.º 9
0
void GeomRendApp::run()
{
	// start up SDL and create window
	auto blit_success = 0;
	auto update_success = 0;
	auto quit = false;
		
	// Event handler
	// INFO: http://wiki.libsdl.org/SDL_Event
	SDL_Event e;
	
	if (!initApp())
	{
		std::cout << "Failed to initialize!\n" << std::endl;
	}
	else
	{
		
		while (!quit)
		{
			while (SDL_PollEvent(&e) != 0)
			{
				if (e.type == SDL_QUIT)
				{
					quit = true;
					std::cout << " Program quit after %i ticks!" << e.quit.timestamp << std::endl;
				}
			}
			
			// clear screen
			SDL_SetRenderDrawColor(gCurrentRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
			SDL_RenderClear (gCurrentRenderer);		

			// render the red filled quad
			SDL_Rect fillRect = {SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2};
			SDL_SetRenderDrawColor(gCurrentRenderer, 0xFF, 0x00, 0x00, 0xFF);
			SDL_RenderFillRect(gCurrentRenderer, &fillRect);
			
			// render the green quad
			SDL_Rect outlineRect = {SCREEN_WIDTH / 6, SCREEN_HEIGHT / 6, SCREEN_WIDTH * 2 / 3, SCREEN_HEIGHT * 2 / 3};
			SDL_SetRenderDrawColor(gCurrentRenderer, 0x00, 0xFF, 0x00, 0xFF);
			SDL_RenderDrawRect(gCurrentRenderer, &outlineRect);
		
			// draw the blue line
			SDL_SetRenderDrawColor(gCurrentRenderer, 0x00, 0x00, 0x00, 0x00);
			SDL_RenderDrawLine(gCurrentRenderer, 0, SCREEN_HEIGHT / 2, SCREEN_WIDTH, SCREEN_HEIGHT / 2);
			
			// draw yellow dot line
			SDL_SetRenderDrawColor(gCurrentRenderer, 0xFF, 0xFF, 0x00, 0xFF);
			for (auto i = 0; i < SCREEN_HEIGHT; i += 4)
			{
				SDL_RenderDrawPoint(gCurrentRenderer, SCREEN_WIDTH / 2, i);
			}
			
			// update the screen
			SDL_RenderPresent(gCurrentRenderer);
		}
		
	}
	
	close();
}
Exemplo n.º 10
0
void drawFighterDatabase(void)
{
	SDL_Rect r;
	Entity *fighter;
	int i, y, numCannons;
	
	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
	SDL_RenderFillRect(app.renderer, NULL);
	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
	
	r.w = 700;
	r.h = 650;
	r.x = (SCREEN_WIDTH / 2) - r.w / 2;
	r.y = (SCREEN_HEIGHT / 2) - r.h / 2;
	
	SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
	SDL_RenderFillRect(app.renderer, &r);
	SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
	SDL_RenderDrawRect(app.renderer, &r);
	
	drawText(SCREEN_WIDTH / 2, 50, 28, TA_CENTER, colors.white, DB_TEXT);
	
	drawText(SCREEN_WIDTH / 2, 90, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages);
	
	fighter = dbFighters[page];
	
	drawText(SCREEN_WIDTH / 2, 130, 28, TA_CENTER, colors.white, fighter->name);
	
	blitRotated(fighter->texture, r.x + (r.w / 2), 250, rotation);
	
	if (fighter->flags & EF_COMMON_FIGHTER)
	{
		drawText(SCREEN_WIDTH / 2, 170, 18, TA_CENTER, colors.darkGrey, COMMON_TEXT);
		
		drawText(r.x + (r.w / 2), 290, 18, TA_CENTER, colors.lightGrey, "%s: %d", DESTROYED_TEXT, numDestroyed);
	}
	
	drawText(r.x + 25, 200, 22, TA_LEFT, colors.white, "%s: %s", AFFILIATION_TEXT, fighter->affiliation);
	drawText(r.x + 25, 240, 22, TA_LEFT, colors.white, "%s: %d", ARMOUR_TEXT, fighter->health);
	drawText(r.x + 25, 280, 22, TA_LEFT, colors.white, "%s: %d", SHIELD_TEXT, fighter->shield);
	drawText(r.x + 25, 320, 22, TA_LEFT, colors.white, "%s: %.0f", SPEED_TEXT, ((fighter->speed * fighter->speed) * FPS));
	
	y = 200;
	
	for (i = 1 ; i < BT_MAX ; i++)
	{
		numCannons = countFighterGuns(fighter, i);
		if (numCannons > 0)
		{
			drawText(r.x + r.w - 25, y, 22, TA_RIGHT, colors.white, "%s x %d", gunName[i], numCannons);
			
			y += 40;
		}
	}
	
	if (fighter->missiles > 0)
	{
		drawText(r.x + r.w - 25, y, 22, TA_RIGHT, colors.white, "Missiles x %d", fighter->missiles);
	}
	
	y = MAX(y, 320) + 75;
	
	limitTextWidth(r.w - 100);
	drawText(r.x + 25, y, 18, TA_LEFT, colors.white, fighter->description);
	limitTextWidth(0);
	
	drawWidgets("fighterDB");
}
Exemplo n.º 11
0
Arquivo: map.c Projeto: odrevet/GE2
void map_draw(map* p_map, SDL_Renderer* renderer){
  //offset the map drawing to the left in order to display the chipset
  const int x_offset = p_map->x_offset;
  
  const int x_from = -(p_map->o_camera.x % p_map->tile_width) + x_offset;
  const int x_to   =   x_from + SCREEN_WIDTH + (x_from == 0 ? 0 : p_map->tile_width) + x_offset;
  const int y_from = -(p_map->o_camera.y % p_map->tile_height);
  const int y_to   =   y_from + SCREEN_HEIGHT + (y_from == 0 ? 0 : p_map->tile_height);
  
  int tile_y_index = p_map->o_camera.y / p_map->tile_height;
  for (int y=y_from;y<y_to;y+=p_map->tile_height){
    int tile_x_index = p_map->o_camera.x / p_map->tile_width;
    for (int x=x_from;x<x_to;x+=p_map->tile_width){
      //get the tile in the map tiles
      tile* p_tile = map_get_tile(p_map,
				  tile_x_index,
				  tile_y_index);
      
      //draw the tile
      map_draw_tile(p_map, p_tile, x, y, renderer);
      
      //draw a horizontal grid line
      SDL_RenderDrawLine(renderer,
			 0,
			 y,
			 SCREEN_WIDTH,
			 y);

      //draw a vertical grid line
      SDL_RenderDrawLine(renderer,
			 x,
			 0,
			 x,
			 SCREEN_HEIGHT);
 
      //increment the tile index and check if it's in the map size rang
      if(++tile_x_index >= p_map->width)break;
    }
    //increment the tile index and check if it's in the map size rang
    if(++tile_y_index >= p_map->height)break;
  }

  //draw a rectangle on the selected map tile
  SDL_Rect rect = {.x= p_map->map_tile_x_index * p_map->tile_width,
		   .y= p_map->map_tile_y_index * p_map->tile_height + y_from,
		   .w= p_map->tile_width,
		   .h= p_map->tile_height};  
  SDL_SetRenderDrawColor(renderer, 0xFF, 0x0, 0x0, 0xFF);
  SDL_RenderDrawRect(renderer, &rect);
    
#ifdef DEBUG
  //Draw the debug menu
  debug_map(p_map, renderer,
	    x_from, x_to,
	    y_from, y_to,
	    p_map->o_camera.x / p_map->tile_width,
	    p_map->o_camera.y / p_map->tile_height);
#endif
}

void map_mouse_move(map* p_map, SDL_Renderer* renderer, int x, int y){
  const int x_from = p_map->o_camera.x % p_map->tile_width;
  const int y_from = p_map->o_camera.y % p_map->tile_height;
  
  int map_tile_x_index = (x + x_from) / p_map->tile_width;
  int map_tile_y_index = (y + y_from) / p_map->tile_height;
    
  p_map->map_tile_x_index = map_tile_x_index;
  p_map->map_tile_y_index = map_tile_y_index;
}

void map_tile_click(map* p_map,
		    int x,
		    int y,
		    Uint8 button){
  int x_offset = p_map->x_offset;
  
  if(x < x_offset){
    //the click was on the chipset part
    //set the selected tile in the chipset
    p_map->chipset_tile_x_index = x / p_map->tile_width;
    p_map->chipset_tile_y_index = y / p_map->tile_height;
  }
  else{
    //the clic was on the map part
    //change the clicked tile with the selected tile
    int clicked_tile_x_index = (x + p_map->o_camera.x - x_offset) / p_map->tile_width;
    int clicked_tile_y_index = (y + p_map->o_camera.y) / p_map->tile_height;
#ifdef DEBUG
    printf("click at index %d %d\n",
	   clicked_tile_x_index,
	   clicked_tile_y_index);
#endif
    //check if the index is in the map boundaries
    if(clicked_tile_x_index >= 0 && clicked_tile_x_index < p_map->width &&
       clicked_tile_y_index >= 0 && clicked_tile_y_index < p_map->height){    
      tile* p_tile = map_get_tile(p_map,
				  clicked_tile_x_index,
				  clicked_tile_y_index);
      p_tile->x = p_map->chipset_tile_x_index;
      p_tile->y = p_map->chipset_tile_y_index;
    }
  }
}
Exemplo n.º 12
0
void cGraphicsSDL2::DrawRect(sRect &rect, sColor *color /*= nullptr*/) {
    SetDrawColor(color);
    SDL_RenderDrawRect(m_Renderer, (SDL_Rect*)&rect);
}
Exemplo n.º 13
0
void sprite_render_frame(float bg_width, float bg_height, Sprite *sprite, DArray *meta_info, SDL_Renderer *rend, int draw_bounding_box) {
    
    //find position location of frame in spritesheet using parsed meta info
    int x_offset = 0;
    int y_offset = 0; 
    int width = 0;
    int height = 0;
    
    //printf("render: sprite->animation:%i current frame:%i\n", sprite->animation, sprite->current_frame[sprite->animation]);
    sprite_get_offset_wh_by_frame(sprite->animation, sprite->current_frame[sprite->animation], meta_info, &x_offset, &y_offset, &width, &height);
    
    //printf("loading animation %i at frame %i using x:%i y:%i width:%i height:%i\n", animation, current_frame, x_offset, y_offset, width, height);	
     
    //First we must create an SDL_Rect for the position of the image, as SDL
	//won't accept raw coordinates as the image's position
    
    //boundry check
    if(sprite->x < 0) {
        sprite->x = 0;
    }
    //TODO width of background image
    //if(sprite->x > SCREEN_WIDTH - width) {
    //    sprite->x = SCREEN_WIDTH - width;
    //}
    //if(sprite->x > bg_width - width) {
    //    sprite->x = bg_height - width;
    //}
    if(sprite->y < 200) {
        sprite->y = 200;
    }
    //if(sprite->y > SCREEN_HEIGHT - height) {
    //    sprite->y = SCREEN_HEIGHT - height; 
    //}
    if(sprite->y > bg_height - height) {
        sprite->y = bg_height - height; 
    }
    //printf("plot (%i,%i)\n", sprite->x, sprite->y);
    
    if(draw_bounding_box) {
        Uint8 r = 0;
        Uint8 g = 255;
        Uint8 b = 0;
        Uint8 a = 0;
        int result = SDL_SetRenderDrawColor(rend, r, g, b, a);
        if(result != 0) {
            printf("render color failed: %s\n", SDL_GetError());
            exit(1);
        }
        result = SDL_RenderDrawRect(rend, &sprite->bounding_box);
        if(result != 0) {
            printf("render rect failed: %s\n", SDL_GetError());
            exit(1);
        }
        r = 255;
        g = 255;
        b = 255;
        a = 255;
        SDL_SetRenderDrawColor(rend, r, g, b, a);
    }


    SDL_Rect pos;
	pos.x = sprite->x;
	pos.y = sprite->y;
    pos.w = width;
    pos.h = height;
    
    SDL_Rect clip;
    clip.x = x_offset;
    clip.y = y_offset;
    clip.w = width;
    clip.h = height;

    /**
    Uint8 r = 0;
    Uint8 g = 0;
    Uint8 b = 0;
    int result = SDL_GetTextureColorMod(sprite->texture, &r, &g, &b);
    printf("get color mod: r: %i, g: %i, b: %i\n", r, g, b);
    result =  SDL_SetTextureColorMod(sprite->texture,
                                        0,
                                        0,
                                        255);
    **/
    //SDL_RenderCopy(rend, sprite->texture, &clip, &pos);
    //SDL_RenderCopyEx(rend, sprite->texture, &clip, &pos, 0, NULL, SDL_FLIP_HORIZONTAL);
    SDL_RenderCopyEx(rend, sprite->texture, &clip, &pos, 0, NULL, sprite->direction);
}
Exemplo n.º 14
0
void ScrollableContainer::draw(SDL_Renderer * renderer)
{
	if(isVisible())
	{
		if(renderTarget == NULL)
		{
			renderTarget = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_UNKNOWN,SDL_TEXTUREACCESS_TARGET,getWidth(),getHeight());
		}

		if(childAreaTexture == nullptr)
		{
			childAreaTexture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_UNKNOWN,SDL_TEXTUREACCESS_TARGET,childArea.w,childArea.h);
		}

		SDL_Texture * callerTexture = SDL_GetRenderTarget(renderer);

		SDL_SetRenderTarget(renderer,renderTarget);

		SDL_SetRenderDrawColor(renderer,bgColor.r,bgColor.g,bgColor.b,bgColor.a);

		SDL_RenderClear(renderer);


		SDL_SetRenderTarget(renderer,childAreaTexture);
		SDL_RenderClear(renderer);


		for(it = widgets.begin();it != widgets.end();++it)
		{
			(*it)->draw(renderer);
		}

		SDL_Color prevColor;

		SDL_SetRenderTarget(renderer,renderTarget);
		SDL_RenderCopy(renderer,childAreaTexture,nullptr,&childArea);

		if(vScroll || hScroll)
		{
			SDL_GetRenderDrawColor(renderer,&prevColor.r,&prevColor.g,&prevColor.b,&prevColor.a);

			SDL_SetRenderDrawColor(renderer,scrollColor.r,scrollColor.g,scrollColor.b,scrollColor.a);
			if(vScroll)
			{
				SDL_RenderFillRect(renderer,&vScrollRect);
			}

			if(hScroll)
			{
				SDL_RenderFillRect(renderer,&hScrollRect);
			}

			SDL_SetRenderDrawColor(renderer,prevColor.r,prevColor.g,prevColor.b,prevColor.a);
		}

		if(borderVisible)
		{
			SDL_GetRenderDrawColor(renderer,&prevColor.r,&prevColor.g,&prevColor.b,&prevColor.a);

			SDL_SetRenderDrawColor(renderer,0,0,255,255);

			SDL_RenderDrawRect(renderer,&childArea);

			SDL_SetRenderDrawColor(renderer,prevColor.r,prevColor.g,prevColor.b,prevColor.a);
		}
		

		SDL_SetRenderTarget(renderer,callerTexture);

		SDL_RenderCopy(renderer,renderTarget,NULL,&getArea());
		callerTexture = NULL;
	}
}
Exemplo n.º 15
0
void gfxdrawrect(Gfx *g, Rect r, Color c){
	SDL_Rect sr = { r.a.x, r.a.y, r.b.x - r.a.x, r.b.y - r.a.y };
	rendcolor(g, c);
	SDL_RenderDrawRect(g->rend, &sr);
}
Exemplo n.º 16
0
int main ( int argc, char** argv )
{
	/* initialize random seed: */
	  srand (time(NULL));

    // initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }
    /*//Initialize SDL_ttf
	if( TTF_Init() == -1 )
	{
		printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
		return 1;
	}

	 Sans = TTF_OpenFont("lazy.ttf", 28);
	if( Sans == NULL )
	{
		printf( "Unable to open Font! SDL Error: %s\n", SDL_GetError() );
	}*/

    // make sure SDL cleans up before exit
    atexit(SDL_Quit);

    //Set texture filtering to linear
    if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
    {
        printf( "Warning: Linear texture filtering not enabled!" );
    }

    // create a new window
    SDL_Window *win = SDL_CreateWindow("Tetris", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
    if (win == nullptr){
        std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    gRenderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (gRenderer == nullptr){
        SDL_DestroyWindow(win);
        std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
        SDL_Quit();
        return 1;
    }

    bool quit = false;	//Main loop flag
    SDL_Event e;	//Event handler

    CurPiece= new Piece(static_cast<TetrisPieces>(rand()%7),80,Block::Blocksize,gRenderer); //currently existing piece
    //blocks.push_back(Block(Block::Blocksize*5,Block::Blocksize*10,gRenderer,{100,80,70,0xFF}));

    //Set callback
    SDL_TimerID timerID = SDL_AddTimer( 1000, callback,NULL);

    while( !quit )	//While application is running
    {
        //Handle events on queue
        while( SDL_PollEvent( &e ))
        {
            //User requests quit
            if( e.type == SDL_QUIT )
            {
                quit = true;
            }//User presses a key
            else if( e.type == SDL_KEYDOWN )
            {
				if(e.key.keysym.sym == SDLK_LEFT)
				{
					CurPiece->Move(-Block::Blocksize,0);
					if(checkEdgeCollision()||CheckCollision())
						CurPiece->Move(Block::Blocksize,0);
				}
				if(e.key.keysym.sym == SDLK_RIGHT)
				{
					CurPiece->Move(Block::Blocksize,0);
					if(checkEdgeCollision()||CheckCollision())
						CurPiece->Move(-Block::Blocksize,0);
				}
				if(e.key.keysym.sym == SDLK_DOWN)
				{
					CurPiece->Move(0,Block::Blocksize);
					if(checkEdgeCollision()||CheckCollision())
						CurPiece->Move(0,-Block::Blocksize);
				}
				if(e.key.keysym.sym == SDLK_SPACE)
				{
					CurPiece->Rotate();
				}
            }
        }

        //Clear screen
        SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
        SDL_RenderClear( gRenderer );

        //DisplayText("score:",outlineRect.w+outlineRect.x+20,50,{0x00,0x00,0x00,0xFF});
		SDL_SetRenderDrawColor( gRenderer, 0x00, 0x00, 0x00, 0xFF );
		SDL_RenderDrawRect( gRenderer, &outlineRect );

		for_each (blocks.begin(), blocks.end(), std::mem_fun_ref(&Block::Draw));
		CurPiece->Draw();
        //Update screen
        SDL_RenderPresent( gRenderer );
        //SDL_Delay(100);
    }

    delete CurPiece;

    //Free global font
	TTF_CloseFont( Sans );

    //Destroy window
	SDL_DestroyRenderer( gRenderer );
	SDL_DestroyWindow( win );

	SDL_RemoveTimer( timerID );
	//Quit SDL subsystems
	SDL_Quit();
    // all is well ;)
    printf("Exited cleanly\n");
    return 0;
}
Exemplo n.º 17
0
void SDLRenderer::drawRect(const Rect& rect) {
    SDL_Rect sdlRect = { rect.x, rect.y, rect.w, rect.h };
    SDL_RenderDrawRect(renderer, &sdlRect);
}
Exemplo n.º 18
0
static void drawChallenges(void)
{
	Mission *m;
	Challenge *c;
	SDL_Rect r;
	int i, start, end;

	r.x = 135;
	r.y = 165;
	r.w = r.h = 96;

	start = page * CHALLENGES_PER_PAGE;
	end = start + CHALLENGES_PER_PAGE;
	
	i = 0;

	for (m = game.challengeMissionHead.next ; m != NULL ; m = m->next)
	{
		m->rect = r;

		if (i >= start && i < end)
		{
			if (game.currentMission == m)
			{
				blit(challengeIconHighlight, r.x, r.y, 0);
			}
			else
			{
				blit(challengeIcon, r.x, r.y, 0);
			}

			drawText(r.x + (r.w / 2), r.y + 28, 30, TA_CENTER, colors.white, "%d", i + 1);

			if (m->available)
			{
				drawText(r.x + (r.w / 2), r.y + r.w + 5, 18, TA_CENTER, (m->completedChallenges < m->totalChallenges) ? colors.white : colors.green, "%d / %d", m->completedChallenges, m->totalChallenges);
			}
			else
			{
				drawText(r.x + (r.w / 2), r.y + r.w + 5, 18, TA_CENTER, colors.lightGrey, LOCKED_TEXT);
			}

			r.x += 150;

			if (r.x > SCREEN_WIDTH - 200)
			{
				r.y += 165;
				r.x = 135;
			}
		}

		i++;
	}

	r.y = SCREEN_HEIGHT - 245;
	r.x = 100;
	r.w = SCREEN_WIDTH - 200;
	r.h = 150;

	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
	SDL_RenderFillRect(app.renderer, &r);
	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
	SDL_SetRenderDrawColor(app.renderer, 64, 64, 64, SDL_ALPHA_OPAQUE);
	SDL_RenderDrawRect(app.renderer, &r);

	r.y = 240;

	if (game.currentMission)
	{
		drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - r.y, 24, TA_CENTER, colors.white, game.currentMission->description);

		r.y -= 50;
		c = game.currentMission->challengeData.challenges[0];
		drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, CRAFT_TEXT, game.currentMission->craft);
		drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (c->passed) ? colors.green : colors.white, "1. %s", getChallengeDescription(c));

		r.y -= 30;
		drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, colors.white, TIME_TEXT, timeLimit);

		c = game.currentMission->challengeData.challenges[1];
		if (c)
		{
			drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (c->passed) ? colors.green : colors.white, "2. %s", getChallengeDescription(c));
		}

		r.y -= 30;
		drawText((SCREEN_WIDTH / 2) - 25, SCREEN_HEIGHT - r.y, 18, TA_RIGHT, hasRestrictions ? colors.red : colors.white, RESTRICTIONS_TEXT, restrictions);

		c = game.currentMission->challengeData.challenges[2];
		if (c)
		{
			drawText((SCREEN_WIDTH / 2) + 25, SCREEN_HEIGHT - r.y, 18, TA_LEFT, (c->passed) ? colors.green : colors.white, "3. %s", getChallengeDescription(c));
		}
	}
}
Exemplo n.º 19
0
//player versus player battle loop
void Game::player_battle( SDL_Rect window_outline )
{
    //create score counts
    int player1_score = 0;
    int player2_score = 0;
    
    //load score textures
    std::vector<Texture> scores(4);
    std::stringstream score_count;
    //light pink color
    SDL_Color color = { 219, 112, 147 };
    for (int i = 0; i < scores.size(); ++i)
    {
        score_count.str("");
        score_count << i;
        scores[i].load_text(big_font, color, score_count.str().c_str());
    }
    
    //white color
    color = { 255, 255, 255 };
    //load player1 wins text texture
    Texture player1_wins;
    player1_wins.load_text(medium_font, color, "PLAYER 1 WINS!");
    
    //load player2 wins text texture
    Texture player2_wins;
    player2_wins.load_text(medium_font, color, "PLAYER 2 WINS!");
    
    //load try again text texture
    Texture try_again;
    try_again.load_text(medium_font, color, "TRY AGAIN?");
    
    //yes or no text texture
    Texture yes_or_no;
    yes_or_no.load_text(medium_font, color, "YES   NO");
    
    //create yes or no button outline
    SDL_Rect button_outline = { WINDOW_WIDTH/2 - yes_or_no.get_width()/2 - 14, (WINDOW_HEIGHT*7)/10 - yes_or_no.get_height()/2 - 10, yes_or_no.get_width()/2, yes_or_no.get_height() + 14 };
    //yes or no button select
    bool button_select = true;
    
    //create ball
    Ball* ball = new Ball;
    //create right paddle (player)
    PlayerPaddle* paddle1 = new PlayerPaddle;
    //create left paddle (computer)
    PlayerPaddle* paddle2 = new PlayerPaddle(PLAYER_BATTLE);
    
    //create a polymorphic vector of colliders for ball collisions
    std::vector<Collider*> paddles;
    paddles.push_back(paddle1);
    paddles.push_back(paddle2);
    
    //create player battle loop terminator
    bool terminated = false;
    //create object that reads in events
    SDL_Event event;
    
    //game loop
    while (terminated == false)
    {
        //event loop
        while ( SDL_PollEvent(&event) )
        {
            //if there's a quit event
            if ( event.type == SDL_QUIT )
            {
                terminated = true;
                level = END;
            }
            
            //check events for velocity change
            paddle1->handle(event);
            paddle2->handle(event);
            
            //if no one has won yet
            if ( player1_score != 3 && player2_score != 3)
                //check events for ball (to start movement if spawned)
                ball->handle(event);
            
            //if a player won
            if (player1_score == 3 || player2_score == 3)
            {
                //if there's a non-repeat keypress event
                if ( event.type == SDL_KEYDOWN && event.key.repeat == 0)
                {
                    //if left or right key was pressed
                    if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_RIGHT)
                    {
                        //if button outline is over YES
                        if (button_select == true)
                            //move button outline right
                            button_outline.x += 150;
                        //if button outline is over NO
                        else if (button_select == false)
                            //move button outline left
                            button_outline.x -= 150;
                        
                        //switch to other button
                        button_select = !button_select;
                    }
                    
                    //if enter key was pressed
                    if ( event.key.keysym.sym == SDLK_RETURN)
                    {
                        //if YES button is selected
                        if (button_select == true)
                            //allow player battle to end so it can restart
                            terminated = true;
                        //if NO button is selected
                        else if (button_select == false)
                        {
                            //change level to title
                            level = TITLE;
                            //allow player battle to end
                            terminated = true;
                        }
                    }
                }
            }
        }
        
        //move objects and modify score counts
        ball->move(paddles, player1_score, player2_score);
        paddle1->move();
        paddle2->move();
        
        //clear window black
        SDL_SetRenderDrawColor( renderer, 0, 0, 0, 255 );
        SDL_RenderClear(renderer);
        
        //set renderer color to light pink
        SDL_SetRenderDrawColor( renderer, 219, 112, 147, 255 );
        
        //render (2-pixel width) dotted line in center
        for (int i = 0; i <= 1; ++i)
            for (int j = 0; j <= WINDOW_HEIGHT; ++j)
            {
                SDL_RenderDrawPoint(renderer, WINDOW_WIDTH/2 + i, j);
                if (j % 20 == 0)
                    j += 10;
            }
        
        //render player1 score
        if (player1_score == 0) scores[0].render( (WINDOW_WIDTH*4)/10, (WINDOW_HEIGHT*3)/20 );
        else if (player1_score == 1) scores[1].render( (WINDOW_WIDTH*4)/10, (WINDOW_HEIGHT*3)/20 );
        else if (player1_score == 2) scores[2].render( (WINDOW_WIDTH*4)/10, (WINDOW_HEIGHT*3)/20 );
        else if (player1_score == 3) scores[3].render( (WINDOW_WIDTH*4)/10, (WINDOW_HEIGHT*3)/20 );
        
        //render player2 score
        if (player2_score == 0) scores[0].render( (WINDOW_WIDTH*6)/10, (WINDOW_HEIGHT*3)/20 );
        else if (player2_score == 1) scores[1].render( (WINDOW_WIDTH*6)/10, (WINDOW_HEIGHT*3)/20 );
        else if (player2_score == 2) scores[2].render( (WINDOW_WIDTH*6)/10, (WINDOW_HEIGHT*3)/20 );
        else if (player2_score == 3) scores[3].render( (WINDOW_WIDTH*6)/10, (WINDOW_HEIGHT*3)/20 );
        
        //render paddles
        paddle1->render();
        paddle2->render();
        
        //set renderer color to white
        SDL_SetRenderDrawColor( renderer, 255, 255, 255, 255 );
        
        //if a player won
        if (player1_score == 3 || player2_score == 3 )
        {
            //if player1 wins, render player1 wins text
            if (player1_score == 3)
                player1_wins.render(WINDOW_WIDTH/2, (WINDOW_HEIGHT*3)/10);
            
            //if player2 wins, render player2 wins text
            else if (player2_score == 3)
                player2_wins.render(WINDOW_WIDTH/2, (WINDOW_HEIGHT*3)/10);
            
            //render try again text
            try_again.render(WINDOW_WIDTH/2, (WINDOW_HEIGHT*6)/10);
            
            //render yes or no text
            yes_or_no.render(WINDOW_WIDTH/2, (WINDOW_HEIGHT*7)/10);
            
            //render yes or no button outline
            SDL_RenderDrawRect( renderer, &button_outline );
        }
        
        //render ball
        ball->render();
        
        //render window outline
        SDL_RenderDrawRect( renderer, &window_outline );
        
        //update window with new renders
        SDL_RenderPresent( renderer );
    }
    
    //cleanup
    delete paddle1;
    delete paddle2;
    delete ball;
}
Exemplo n.º 20
0
int main( int argc, char* args[] ) {
  //Start up SDL and create window
  if( !init() ) {
    printf( "Failed to initialize!\n" );
  } else {
    //Load media
    if( !loadMedia() ) {
      printf( "Failed to load media!\n" );
    } else {
      //Main loop flag
      bool quit = false;

      //Event handler
      SDL_Event e;

      //The dot that will be moving around on the screen
      Dot dot( Dot::DOT_WIDTH / 2, Dot::DOT_HEIGHT / 2 );
      Dot otherDot( SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4 );

      //Set the wall
      SDL_Rect wall;
      wall.x = 300;
      wall.y = 40;
      wall.w = 40;
      wall.h = 400;

      //While application is running
      while( !quit ) {
        //Handle events on queue
        while( SDL_PollEvent( &e ) != 0 ) {
          //User requests quit
          if( e.type == SDL_QUIT ) {
            quit = true;
          }

          //Handle input for the dot
          dot.handleEvent( e );
        }

        //Move the dot and check collision
        dot.move( wall, otherDot.getCollider() );

        //Clear screen
        SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
        SDL_RenderClear( gRenderer );

        //Render wall
        SDL_SetRenderDrawColor( gRenderer, 0x00, 0x00, 0x00, 0xFF );
        SDL_RenderDrawRect( gRenderer, &wall );

        //Render dots
        dot.render();
        otherDot.render();

        //Update screen
        SDL_RenderPresent( gRenderer );
      }
    }
  }

  //Free resources and close SDL
  close();

  return 0;
}
Exemplo n.º 21
0
//instructions loop
void Game::instructions( SDL_Rect window_outline )
{
    //light pink color for instructions text
    SDL_Color color = { 219, 112, 147 };
    
    //load first instruction texture
    Texture instruction1;
    instruction1.load_text(small_font, color, "GET THE BALL BEHIND YOUR OPPONENT");
    
    //load second instruction texture
    Texture instruction2;
    instruction2.load_text(small_font, color, "USE THE UP/DOWN OR W/D KEYS TO MOVE");
    
    //load third instruction texture
    Texture instruction3;
    instruction3.load_text(small_font, color, "PRESS SPACE TO LAUNCH BALL FROM CENTER");
    
    //load fourth instruction texture
    Texture instruction4;
    instruction4.load_text(small_font, color, "SCORE 3 POINTS TO WIN");
    
    //load back button texture
    Texture back;
    back.load_text(small_font, color, "BACK TO MENU");
    
    //create button outline
    SDL_Rect button_outline = { WINDOW_WIDTH/2 - back.get_width()/2 - 7, (WINDOW_HEIGHT*7)/10 - back.get_height()/2 - 10, back.get_width() + 14, back.get_height() + 14 };
    
    //instructions loop terminator
    bool terminated = false;
    
    //create event reader
    SDL_Event event;
    
    //instructions loop
    while (terminated == false)
    {
        //event loop (while there are events in queue)
        while ( SDL_PollEvent(&event) != 0 )
        {
            //if quit event
            if (event.type == SDL_QUIT)
            {
                //end instructions loop
                terminated = true;
                //end main loop
                level = END;
            }
            
            //if non-repeat key press event
            else if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
                //if enter key
                if ( event.key.keysym.sym == SDLK_RETURN)
                {
                    //end instructions loop
                    terminated = true;
                    //change level to title screen
                    level = TITLE;
                }
        }
        
        //clear window black
        SDL_SetRenderDrawColor( renderer, 0, 0, 0, 255 );
        SDL_RenderClear(renderer);
        
        //set renderer color to light pink
        SDL_SetRenderDrawColor( renderer, 219, 112, 147, 255 );
        
        //render instructions
        instruction1.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*2)/10);
        instruction2.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*3)/10);
        instruction3.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*4)/10);
        instruction4.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*5)/10);
        //render back button
        back.render( WINDOW_WIDTH/2, (WINDOW_HEIGHT*7)/10);
        
        //set renderer color to white
        SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
        
        //render back button outline
        SDL_RenderDrawRect(renderer, &button_outline);
        //render window outline
        SDL_RenderDrawRect(renderer, &window_outline);
        
        //update window with new renders
        SDL_RenderPresent( renderer );
    }
}
Exemplo n.º 22
0
// SDL REQUIRES this signature for main
int main(int argc, char* args[]) {

    // Main Loop flag
    bool quit = false;

    int render = 0;

    // Event handler
    SDL_Event e;

    //Start up SDL and create window
    if( !init() )
    {
        printf("Failed to initialize!\n");
        return 1;
    }
    else
    {
        //Load media
        if( !loadMedia() )
        {
            printf("Failed to load media!\n");
            return 1;
        }
    }

    gTexture = gKeyPressTextures[KEY_PRESS_SURFACE_DEFAULT];

    SDL_Rect lowerViewport;
    lowerViewport.x = 0;
    lowerViewport.y = SCREEN_HEIGHT / 2;
    lowerViewport.w = SCREEN_WIDTH ;
    lowerViewport.h = SCREEN_HEIGHT / 2;

    SDL_Rect topViewport;
    topViewport.x = 0;
    topViewport.y = 0;
    topViewport.w = SCREEN_WIDTH;
    topViewport.h = SCREEN_HEIGHT / 2;

    SDL_Rect fullViewport;
    fullViewport.x = 0;
    fullViewport.y = 0;
    fullViewport.w = SCREEN_WIDTH;
    fullViewport.h = SCREEN_HEIGHT;

    // While application is running
    while (!quit) {

        // Handle events on queue
        while (SDL_PollEvent(&e) != 0) {

            // User requests quit
            if (e.type == SDL_QUIT || e.key.keysym.sym == SDLK_ESCAPE) {
                quit = true;
            }

            // User presses a key
            else if (e.type == SDL_KEYDOWN)
            {
                switch(e.key.keysym.sym)
                {
                    default:
                    render = RENDER_NULL;
                    break;

                    case SDLK_h:
                    gTexture = gKeyPressTextures[KEY_PRESS_SURFACE_LEFT];
                    render = RENDER_SHAPE;
                    break;

                    case SDLK_j:
                    gTexture = gKeyPressTextures[KEY_PRESS_SURFACE_DOWN];
                    render = RENDER_SHAPE;
                    break;

                    case SDLK_k:
                    gTexture = gKeyPressTextures[KEY_PRESS_SURFACE_UP];
                    render = RENDER_SHAPE;
                    break;

                    case SDLK_l:
                    gTexture = gKeyPressTextures[KEY_PRESS_SURFACE_RIGHT];
                    render = RENDER_SHAPE;
                    break;

                    case SDLK_SPACE:
                    gTexture = gKeyPressTextures[KEY_PRESS_SURFACE_SPACE];
                    render = RENDER_SHAPE;
                    break;

                    case SDLK_c:
                    render = RENDER_CIRCLE;

                }
            }
        } //  while (SDL_PolLEvent(&e) != 0

        if (render != RENDER_NULL) {

            // Clear screen
            SDL_RenderClear(gRenderer);

            switch(render)
            {
                case RENDER_CIRCLE:
                // Render image of circle via LTexture
                SDL_RenderSetViewport(gRenderer, &fullViewport);
                gBackgroundTexture.render(0, 0);
                gCircleTexture.render(240, 190);
                break;


                case RENDER_SHAPE:
                // Render image to screen via texture set previously
                SDL_RenderSetViewport(gRenderer, &topViewport);
                SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);

                SDL_RenderSetViewport(gRenderer, &lowerViewport);
                //Render red filled quad
                SDL_Rect fillRect = {SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2};
                SetRenderDrawColor(gRenderer, BASE01);
                SDL_RenderFillRect( gRenderer, &fillRect );

                // Draw a rectanglular outline with empty center
                SDL_Rect outlineRect = {SCREEN_WIDTH / 6, SCREEN_HEIGHT / 6, SCREEN_WIDTH * 2 / 3, SCREEN_HEIGHT * 2 / 3 };
                SetRenderDrawColor(gRenderer, BASE03);
                SDL_RenderDrawRect(gRenderer, &outlineRect);

                // Draw a thin pixel line
                SetRenderDrawColor(gRenderer, BLUE);
                SDL_RenderDrawLine(gRenderer, 0, SCREEN_HEIGHT / 2, SCREEN_WIDTH, SCREEN_HEIGHT / 2);

                // Draw vertical line of cyan dots
                SetRenderDrawColor(gRenderer, CYAN);
                for (int i = 0; i < SCREEN_HEIGHT; i += 4) {
                    SDL_RenderDrawPoint(gRenderer, SCREEN_WIDTH / 2, i);
                }

                SetRenderDrawColor(gRenderer, BASE03);

                break;

            } // render switch

            // Update screen
            SDL_RenderPresent(gRenderer);

        } // if render != null
    } // while (!quit)

    // Free up resources and close SDL
    close();

    return 0;
}
Exemplo n.º 23
0
void affichage_classement(SDL_Renderer *s,map_t *m) {
int x,y, h, w;

x=m->largeur_affichage*SIZE*0.1;
y=m->hauteur_affichage*SIZE/9;
w=m->largeur_affichage*SIZE*0.8;
h=m->hauteur_affichage*SIZE/3;

    SDL_Rect rect1 = {x, y, w, h};


y=(m->hauteur_affichage*SIZE*5)/9;

    SDL_Rect rect2 = {x, y, w, h};

//SDL_FillRect(screen, &pos, SDL_MapRGB(screen->format, (r), (g),(b));


/*
int nb_e1 ;
int nb_e2;

    if(m->nombre_tank_actif%2 == 0) {
        nb_e1=m->nombre_tank_actif/2;
        nb_e2=m->nombre_tank_actif/2;
    }
    else {
        nb_e1=m->nombre_tank_actif/2;
        nb_e2=(m->nombre_tank_actif-1)/2;
    }

tank_t tab_tmp[m->nombre_tank_actif];
memcpy(tab_tmp, m->tanks, m->nombre_tank_actif * sizeof(tank_t));

tank_t equipe1[nb_e1];
tank_t equipe2[nb_e2];
*/

/*
// Tri équipe 0
int k = 0;

for(i=0; i<m->nombre_tank_actif; i+=2) {
    i_max = i;
    max = m->tanks[i].score;

    for(j=i+2; j<m->nombre_tank_actif; j+=2) {
        if( m->tanks[i].score > max) {
            max = m->tanks[i].score;
             i_max = j;
        }
    }
    tmp=tab_tmp[i];
    tab_tmp[i] = tab_tmp[i_max];
    tab_tmp[i_max] =tmp;
    equipe1[k]=tab_tmp[i];
    k++;
}*/
/*
// Tri équipe 0
k = 0;
for(i=1; i<m->nombre_tank_actif; i+=2) {
    i_max = i;
    max = m->tanks[i].score;

    for(j=i+2; j<m->nombre_tank_actif; j+=2) {
        if( m->tanks[i].score > max) {
            max = m->tanks[i].score;
             i_max = j;
        }
    }
    tmp=tab_tmp[i];
    tab_tmp[i] = tab_tmp[i_max];
    tab_tmp[i_max] =tmp;
    equipe2[k]=tab_tmp[i];
    k++;
}
*/


    // CLASSEMENT
    int equipe_joueur = m->num_tank_joueur %2;
    char txt[100];
    int score_equipe_1;
    int score_equipe_2;
    int i,j;

    if(equipe_joueur == 0) {
        score_equipe_1 = m->score_equipe_joueur;
        score_equipe_2 = m->score_equipe_adverse;
    }
    else {
         score_equipe_2 = m->score_equipe_joueur;
         score_equipe_1 = m->score_equipe_adverse;
    }


    if(score_equipe_1 < score_equipe_2) {
        SDL_SetRenderDrawColor(s, 21, 67,  172, 255);
        SDL_RenderDrawRect(s, &rect1);
        SDL_RenderFillRect(s, &rect1);

        SDL_SetRenderDrawColor(s, 71, 158, 73, 255);
        SDL_RenderDrawRect(s, &rect2);
        SDL_RenderFillRect(s, &rect2);
    }
    else {
        SDL_SetRenderDrawColor(s, 71, 158, 73, 255);
        SDL_RenderDrawRect(s, &rect1);
        SDL_RenderFillRect(s, &rect1);

        SDL_SetRenderDrawColor(s, 21, 67,  172, 255);
        SDL_RenderDrawRect(s, &rect2);
        SDL_RenderFillRect(s, &rect2);
    }




    if(score_equipe_1 < score_equipe_2) {
        sprintf(txt, "Equipe 2 : %d", score_equipe_2);
        affichage_ligne_classement(s, m, 1, 0, txt,  WHITE);


        sprintf(txt, "Joueurs  Score");
        affichage_ligne_classement(s, m, 2, 0, txt,  WHITE);

        j=1;
        for(i=1; i<m->nombre_tank_actif; i+=2) {
            sprintf(txt, "  %d         %d", i, m->tanks[i].score);
            if(i == m->num_tank_joueur) {
                affichage_ligne_classement(s, m, 3+j, 0, txt,  RED);
            }
            else {
                affichage_ligne_classement(s, m, 3+j, 0, txt,  WHITE);
            }
            j++;
        }/*
        for(i=1; i<nb_e1; i++) {
            sprintf(txt, "?            %d         %d", i, equipe2[i].score);
            if( equipe2[i].id_joueur == m->num_tank_joueur) {
                affichage_ligne_classement(s, m, 3+j, 0, txt,  RED);
            }
            else {
                affichage_ligne_classement(s, m, 3+j, 0, txt,  WHITE);
            }
        }*/




        sprintf(txt, "Equipe 1 : %d", score_equipe_1);
        affichage_ligne_classement(s, m, 1, 1, txt,  WHITE);


        sprintf(txt, "Joueurs  Score");
        affichage_ligne_classement(s, m, 2, 1, txt,  WHITE);

        j=1;
        for(i=0; i<m->nombre_tank_actif; i+=2) {
            sprintf(txt, " %d         %d", i, m->tanks[i].score);

            if(i == m->num_tank_joueur) {
                affichage_ligne_classement(s, m, 3+j, 1, txt,  RED);
            }
            else {
                affichage_ligne_classement(s, m, 3+j, 1, txt,  WHITE);
            }
            j++;
        }/*
        for(i=0; i<nb_e1; i++) {
            sprintf(txt, "?            %d         %d", i, equipe1[i].score);
            if( equipe2[i].id_joueur == m->num_tank_joueur) {
             affichage_ligne_classement(s, m, 3+j, 1, txt,  RED);
            }
            else {
                affichage_ligne_classement(s, m, 3+j, 1, txt,  WHITE);
            }
        }*/

    }
    else {
        sprintf(txt, "Equipe 1 : %d", score_equipe_1);
        affichage_ligne_classement(s, m, 1, 0, txt,  WHITE);


        sprintf(txt, "Joueurs  Score");
        affichage_ligne_classement(s, m, 2, 0, txt,  WHITE);

        j=1;
        for(i=0; i<m->nombre_tank_actif; i+=2) {
            sprintf(txt, " %d         %d", i, m->tanks[i].score);

            if(i == m->num_tank_joueur) {
                affichage_ligne_classement(s, m, 3+j, 0, txt,  RED);
            }
            else {
                affichage_ligne_classement(s, m, 3+j, 0, txt,  WHITE);
            }

            j++;
        }


        sprintf(txt, "Equipe 2 : %d", score_equipe_2);
        affichage_ligne_classement(s, m, 1, 1, txt,  WHITE);


        sprintf(txt, "Joueurs  Score");
        affichage_ligne_classement(s, m, 2, 1, txt,  WHITE);

        j=1;
        for(i=1; i<m->nombre_tank_actif; i+=2) {
            sprintf(txt, " %d         %d", i, m->tanks[i].score);
            if(i == m->num_tank_joueur) {
                affichage_ligne_classement(s, m, 3+j, 1, txt,  RED);
            }
            else {
                affichage_ligne_classement(s, m, 3+j, 1, txt,  WHITE);
            }
            j++;
        }


    }

    // Affiche le tout à l'écran
    SDL_RenderPresent(s);


}
Exemplo n.º 24
0
void stinkingRich::HUDRenderSystem::update(float deltaTime) {
	const int x = stinkingRich::StinkingRich::leftGap + stinkingRich::constants::boardWidth + 1;
	const int y = stinkingRich::StinkingRich::topGap;

	const int w = stinkingRich::StinkingRich::windowWidth - stinkingRich::StinkingRich::leftGap
			- 15;
	const int h = stinkingRich::constants::boardHeight;

	const SDL_Rect rect = { x, y, w, h };

	const auto &textRenderer = stinkingRich::StinkingRich::getTextRenderer();

	auto players = engine->getEntitiesFor(ashley::Family::getFor( { typeid(stinkingRich::Player),
			typeid(stinkingRich::Renderable) }));

	const auto &playerMapper = ashley::ComponentMapper<stinkingRich::Player>::getMapper();
	const auto &renderableMapper = ashley::ComponentMapper<stinkingRich::Renderable>::getMapper();

	const auto playerWidth = renderableMapper.get(players->at(0))->w;
	const auto playerHeight = renderableMapper.get(players->at(0))->h;

	SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
	SDL_RenderFillRect(renderer, &rect);

	int fontPaddingTop = 0;
	auto fontHeight = TTF_FontHeight(textRenderer->getFont());

	if (fontHeight < playerHeight) {
		fontPaddingTop = (playerHeight - fontHeight) / 2;
	}

	SDL_Surface *tempSurface = SDL_CreateRGBSurface(0, w, h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000,
			0xFF000000);
	SDL_FillRect(tempSurface, nullptr, SDL_MapRGBA(tempSurface->format, 0xFF, 0xFF, 0xFF, 0xFF));

	const int leftPadding = 5;
	const int textRenderX = playerWidth + leftPadding*2;
	int textRenderY = (h/10) + fontPaddingTop;

	for (unsigned int i = 0; i < players->size(); i++) {
		auto playerComponent = playerMapper.get(players->at(i));
		auto currentPlayerID = playerMapper.get(stinkingRich::StinkingRich::currentPlayer.lock())->id;

		std::stringstream ss;
		if(playerComponent->id == currentPlayerID) {
			ss << "*";
		}

		ss << playerComponent->getBalance();

		textRenderer->setColor( { 0x00, 0x00, 0x00, 0xFF });
		textRenderer->renderToSurface(tempSurface, textRenderX, textRenderY,
				ss.str(), w);

		textRenderY += (h / 5);
	}

	SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, tempSurface);

	SDL_RenderCopy(renderer, texture, nullptr, &rect);

	for (unsigned int i = 0; i < players->size(); i++) {
		auto renderableComponent = renderableMapper.get(players->at(i));

		const int playerY = y + (h / 10) + i * (h / 5);

		const SDL_Rect dstRect = { x + leftPadding, playerY, renderableComponent->w,
				renderableComponent->h };
		SDL_RenderCopy(renderer, renderableComponent->texture, nullptr, &dstRect);
	}

	SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
	SDL_RenderDrawRect(renderer, &rect);

	SDL_FreeSurface(tempSurface);
	SDL_DestroyTexture(texture);
}
Exemplo n.º 25
0
void renderRect( SDL_Rect& rect, const SDL_Color& col, SDL_Renderer* destination, bool filled) {
    SDL_SetRenderDrawColor(destination, col.r, col.g, col.b, col.a);
    if(filled) {    SDL_RenderFillRect(destination, &rect); }
    else {          SDL_RenderDrawRect(destination, &rect); }
}
Exemplo n.º 26
0
void GraphicsEngine::draw(SDL_Rect rectangle, SDL_Color c){
    SDL_SetRenderDrawColor(renderer(), c.r, c.g, c.b, c.a);
    SDL_RenderDrawRect(renderer(), &rectangle);
}
Exemplo n.º 27
0
void SDL::rect( RectF rect, SDL_Color color )
{
	SDL_Rect r = { (int)(rect.x - origin.x), (int)(rect.y - origin.y), (int)rect.w, (int)rect.h };
	setColor( color );
	SDL_RenderDrawRect( renderer, &r );
}
Exemplo n.º 28
0
void Player::draw(SDL_Renderer *ren){
  SDL_SetRenderDrawColor(ren, 255,255,255,255);
  SDL_RenderDrawRect(ren, &player);
  //xVel = 0;
}
Exemplo n.º 29
0
int
main(int argc, char *argv[])
{
	int quit = 0;
	/* event handler */
	SDL_Event event;

	/* the dot that will be moving around the screen */
	Dot dot;

	/* set the wall */
	SDL_Rect wall;
	wall.x = 300;
	wall.y = 40;
	wall.w = 40;
	wall.h = 400;

	/* starts up SDL and create window */
	if (init_sdl() == -1) {
		fprintf(stderr, "Failed to initialize SDL!\n");
		return -1;
	}

	/* load media */
	if (load_media() == -1) {
		fprintf(stderr, "Failed to load media!\n");
		return -2;
	}


	/* main loop */
	while (quit == 0) {
		/* handle events on queue */
		while (SDL_PollEvent(&event) != 0) {
			/* users request quit */
			if (event.type == SDL_QUIT)
				quit = 1;

			/* handle user key press */
			dot.handleEvent(event);
		}

		/* move the dot and check collision */
		dot.move(wall);


		/* clear screen */
		SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(gRenderer);

		/* render wall */
		SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
		SDL_RenderDrawRect(gRenderer, &wall);

		/* render dot */
		dot.render();

		/* update screen */
		SDL_RenderPresent(gRenderer);
	}

	/* free resources and close */
	close_sdl();

	return 0;
}
Exemplo n.º 30
0
void Renderer::DrawRect(const SDL_Rect &rect, Camera &cam)
{
	SDL_Rect r = cam.WorldToScreen(rect);

	SDL_RenderDrawRect(Get(), &r);
}