예제 #1
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;
	}
}
예제 #2
0
void SideMenu::draw()
{
	SDL_SetRenderDrawColor(renderer, 150, 150, 150, 255);
	SDL_RenderFillRect(renderer, &menuRect);
}
예제 #3
0
int main( int argc, char* args[] )
{
    if (argc != 2) {
        printf("Usage: Chip8Emul filename\n");
        return 1;
    }

    Chip8Struct cpu;
    cpu.clear();
    Chip8Logic logic;
    logic.loadFontset(cpu.mem);
    logic.loadProgram(cpu.mem, cpu.waitKey, cpu.PC, args[1]);
    // map keyboard to keys in chip8;
    std::map<int,int> keymap = {
        {SDLK_1, 0x1}, {SDLK_2, 0x2}, {SDLK_3, 0x3}, {SDLK_4, 0xC},
        {SDLK_q, 0x4}, {SDLK_w, 0x5}, {SDLK_e, 0x6}, {SDLK_r, 0xD},
        {SDLK_a, 0x7}, {SDLK_s, 0x8}, {SDLK_d, 0x9}, {SDLK_f, 0xE},
        {SDLK_z, 0xA}, {SDLK_x, 0x0}, {SDLK_c, 0xB}, {SDLK_v, 0xF},
        //{SDLK_5, 0x5}, {SDLK_6, 0x6}, {SDLK_7, 0x7},
        {SDLK_8, 0x8}, {SDLK_9, 0x9}, {SDLK_0, 0x0}, {SDLK_ESCAPE,-1}
    };

    //Start up SDL and create window
    if( !init() )
    {
        printf( "Failed to initialize!\n" );
    }
    else
    {
        //Main loop flag
        bool quit = false;

        //Event handler
        SDL_Event e;

        unsigned insns_per_frame       = 7;
        unsigned max_consecutive_insns = 0;
        int frames_done = 0;

        auto start = std::chrono::system_clock::now();

        //While application is running
        while( !quit )
        {
            for(unsigned a=0; a<max_consecutive_insns && !logic.isWaitingForKey(cpu.waitKey); ++a) {
                logic.executeCommand(cpu, logic.getNextOpcode(cpu.mem, cpu.PC, cpu.waitKey));
            }

            // Handle events on queue
            while( SDL_PollEvent( &e ) != 0 )
            {
                std::map<int,int>::iterator it;
                switch(e.type) {
                case SDL_QUIT:
                    quit = true;
                    break;
                case SDL_KEYDOWN:
                case SDL_KEYUP:
                    it = keymap.find(e.key.keysym.sym);
                    if (it == keymap.end()) break;
                    if (it->second == -1) {quit = true; break;}
                    logic.setKeypad(cpu.V, cpu.keys, cpu.waitKey, it->second, SDL_KEYDOWN == e.type);
                    break;
                }
            }
            auto cur = std::chrono::system_clock::now();
            std::chrono::duration<double> elapsed_seconds = cur-start;
            int frames = int(elapsed_seconds.count() * 60) - frames_done;

            if(frames > 0)
            {
                frames_done += frames;
                int st = std::min(frames, cpu.SoundTimer+0); cpu.SoundTimer -= st;
                int dt = std::min(frames, cpu.DelayTimer+0); cpu.DelayTimer -= dt;

                // Render audio
                SDL_LockAudio();
                 AudioQueue.emplace_back( obtained.freq*(         st)/60,  true );
                 AudioQueue.emplace_back( obtained.freq*(frames - st)/60, false );
                SDL_UnlockAudio();

                Uint32 pixels[CHIP8_W*CHIP8_H]; logic.renderTo(cpu.disp, pixels);

                SDL_SetRenderDrawColor(gRenderer, 0,0,0,0);
                SDL_RenderClear(gRenderer);
                int PIXEL_W = SCREEN_WIDTH/CHIP8_W;
                int PIXEL_H = SCREEN_HEIGHT/CHIP8_H;
                SDL_SetRenderDrawColor(gRenderer, 0xFF,0xFF,0xFF,0xFF);
                for (int i=0; i<CHIP8_H; ++i) {
                    for (int j=0; j<CHIP8_W; ++j) {
                        if (pixels[i*CHIP8_W + j]) {
                            SDL_Rect rect = { j*PIXEL_W, i*PIXEL_H, PIXEL_W, PIXEL_H };
                            SDL_RenderFillRect(gRenderer, &rect);
                        }
                    }
                }

//                    SDL_UpdateTexture(texture, nullptr, pixels, 4*CHIP8_W);
//                    SDL_RenderCopy(gRenderer, texture, nullptr, nullptr);
                SDL_RenderPresent(gRenderer);
            }

            max_consecutive_insns = std::max(frames, 1) * insns_per_frame;
            if(logic.isWaitingForKey(cpu.waitKey) || !frames) SDL_Delay(1000/60);
        }
    }

    //Free resources and close SDL
    close();

    return 0;
}
예제 #4
0
int main(int argc, char* args[])
{
	bool running = true;

	SDL_Event e;

	if (init())
	{
		if (loadMedia())
		{
			while (running)
			{
				// First, handle events:
				while (SDL_PollEvent(&e) != 0)
				{
					if (e.type == SDL_QUIT)
					{
						running = false;
					}
					else if (e.type == SDL_KEYDOWN)
					{
						switch (e.key.keysym.sym)
						{
							case SDLK_ESCAPE:
							running = false;
							break;
						}
					}
				}

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

				// Render a red rectangle/quad in the middle of the screen
				SDL_Rect fillRect { screen_width / 4, screen_height / 4, screen_width / 2, screen_height / 2 };
				SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
				SDL_RenderFillRect(renderer, &fillRect);

				// Render a green outline rectangle/quad around red rectangle
				SDL_Rect outlineRect = { screen_width / 6, screen_height / 6, screen_width * 2 / 3, screen_height * 2 / 3 };
				SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
				SDL_RenderDrawRect(renderer, &outlineRect);

				// Draw a blue horizontal line across middle of screen
				SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xFF, 0xFF);
				SDL_RenderDrawLine(renderer, 0, screen_height / 2, screen_width, screen_height / 2);

				// Draw a dotted yellow line vertically across the screen
				SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0x00, 0xFF);
				for (int i = 0; i < screen_height; i += 4)
					SDL_RenderDrawPoint(renderer, screen_width / 2, i);

				// Finally, update screen
				SDL_RenderPresent(renderer);
			}
		}
	}

	close();
}
예제 #5
0
void cGraphicsSDL2::DrawFillRect(sRect &rect, sColor *color /*= nullptr*/) {
    SetDrawColor(color);
    SDL_RenderFillRect(m_Renderer, (SDL_Rect*)&rect);
}
예제 #6
0
/*
================================================================================

Game::Draw

    Gets called once per frame to draw the current snapshot of the game.

================================================================================
*/
void Game::Draw()
{
    // clear the screen
    SDL_SetRenderDrawColor(mRenderer, 0, 0, 0, 255);
    SDL_RenderClear(mRenderer);
	
	if (mBackground)
	{
		Render(mBackground->GetRenderable(), &mBackground->GetRect(), SDL_FLIP_NONE);
	}
	if (mForeground)
	{
		//Render(mForeground->GetRenderable(), &mForeground->GetRect(), SDL_FLIP_NONE);
	}
	if (mFlagPole)
	{
		Render(mFlagPole->GetRenderable(), &mFlagPole->GetRect(), SDL_FLIP_NONE);
	}

    //
    // draw the grid
    //
    if (mGrid)
	{
        int tileWidth = mGrid->TileWidth();
        int tileHeight = mGrid->TileHeight();
        GG::Rect tileRect(0, 0, tileWidth, tileHeight);
        for (int y = 0; y < mGrid->NumRows(); y++)
		{
            for (int x = 0; x < mGrid->NumCols(); x++)
			{
                const GG::Renderable* renderable = mGrid->GetTile(y, x)->GetRenderable();
                if (renderable)
				{
                    Render(renderable, &tileRect, SDL_FLIP_NONE);
                }
                tileRect.x += tileWidth;
            }
            tileRect.y += tileHeight;
            tileRect.x = 0;
        }
    }

	// Draw the collision rectangles
	if (rectVisible)
	{
		SDL_SetRenderDrawColor(mRenderer, 255, 0, 0, 255);
		SDL_RenderFillRect(mRenderer, &mRobot->GetBottomTileRect());
		SDL_SetRenderDrawColor(mRenderer, 150, 0, 0, 255);
		SDL_RenderFillRect(mRenderer, &mRobot->GetTopTileRect());
		SDL_SetRenderDrawColor(mRenderer, 255, 255, 0, 255);
		SDL_RenderFillRect(mRenderer, &mRobot->GetCollisonRect());
		for (auto coinIt = mCoins.begin(); coinIt != mCoins.end(); ++coinIt)
		{
			Coin* coin = *coinIt;
			SDL_RenderFillRect(mRenderer, &coin->GetRect());
		}
		for (auto crawlerIt = mCrawlers.begin(); crawlerIt != mCrawlers.end(); ++crawlerIt)
		{
			Crawler* crawler = *crawlerIt;
			SDL_RenderFillRect(mRenderer, &crawler->GetCollisionRect());
		}
		for (auto meteorIt = mMeteors.begin(); meteorIt != mMeteors.end(); ++meteorIt)
		{
			Meteor* meteor = *meteorIt;
			SDL_RenderFillRect(mRenderer, &meteor->GetRect());
		}
		SDL_SetRenderDrawColor(mRenderer, 0, 0, 255, 255);
		for (auto crawlerIt = mCrawlers.begin(); crawlerIt != mCrawlers.end(); ++crawlerIt)
		{
			Crawler* crawler = *crawlerIt;
			SDL_RenderFillRect(mRenderer, &crawler->GetTileRect());
		}
	}

	//
    // draw the robot
    //
	if (mRobot)
	{
		Render(mRobot->GetRenderable(), &mRobot->GetRect(), mRobot->GetDirection()?SDL_FLIP_HORIZONTAL:SDL_FLIP_NONE);
	}

	//
    // draw the coins
    //
	std::list<Coin*>::iterator coinIt = mCoins.begin();
    for ( ; coinIt != mCoins.end(); ++coinIt)
	{
        Coin* coin = *coinIt;
        Render(coin->GetRenderable(), &coin->GetRect(), SDL_FLIP_NONE);
    }

	//
    // draw the mushrooms
    //
	std::list<Layer*>::iterator mushIter = mMushrooms.begin();
    for ( ; mushIter != mMushrooms.end(); ++mushIter)
	{
        Layer* mushroom = *mushIter;
        Render(mushroom->GetRenderable(), &mushroom->GetRect(), SDL_FLIP_NONE);
    }

	//
    // draw the crawlers
    //
    for (auto crawlerIt = mCrawlers.begin(); crawlerIt != mCrawlers.end(); ++crawlerIt)
	{
        Crawler* crawler = *crawlerIt;
		if (crawler->GetDirection() == 1)
		{
			Render(crawler->GetRenderable(), &crawler->GetRect(), SDL_FLIP_HORIZONTAL);
		}
		else
		{
			Render(crawler->GetRenderable(), &crawler->GetRect(), SDL_FLIP_NONE);
		}
    }

    //
    // draw the explosions
    //
    std::list<Explosion*>::iterator it = mExplosions.begin();
    for ( ; it != mExplosions.end(); ++it)
	{
        Explosion* boom = *it;
        Render(boom->GetRenderable(), &boom->GetRect(), SDL_FLIP_NONE);
    }

	//
    // draw the meteors
    //
    std::list<Meteor*>::iterator metIt = mMeteors.begin();
    for ( ; metIt != mMeteors.end(); ++metIt)
	{
        Meteor* meteor = *metIt;
        Render(meteor->GetRenderable(), &meteor->GetRect(), SDL_FLIP_NONE);
    }

	// Draw the points label
	if (mPointsLabel)
	{
		Render(mPointsLabel->GetRenderable(), &mPointsLabel->GetRect(), SDL_FLIP_NONE);
	}

	// Draw the lives label
	if (mLivesLabel)
	{
		Render(mLivesLabel->GetRenderable(), &mLivesLabel->GetRect(), SDL_FLIP_NONE);
	}

    // display everything we just drew
    SDL_RenderPresent(mRenderer);
}
예제 #7
0
파일: snake.c 프로젝트: Finelizzyx/snake
int main (int argc, char *argv[])
{
	/* déclaration des variables*/
	win = NULL;
	renderer = NULL;
	continuer = SDL_TRUE;
	snake = NULL;
	points = NULL;
	tempsActuel = 0;
	tempsPrecedent = 0;
	niveauActuel = 1;
	pause = SDL_FALSE;
	gagner = SDL_FALSE;

    srand(time(NULL));

	/* Initialisation de la SDL. */
	init();

	/* Création de la fenêtre et du renderer */
	win = SDL_CreateWindow("Snake", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, 0);
	renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);

	/* Création de la police */
	if((police = TTF_OpenFont("data/arial.ttf", 14)) == NULL)
        snakeERROR("Impossible d'ouvrir le fichier data/arial.ttf : %s\n", TTF_GetError());


    snake = initSerpent(renderer);
    ajouterSerpent(snake, renderer);
    points = initPoints();
    chargerPoints(points, niveauActuel);

    afficherPoints(renderer, points);
    afficherSerpent(renderer, snake);

	while(continuer)
    {
		SDL_Event e;
		if(SDL_PollEvent(&e)) {
            switch(e.type)
            {
                case SDL_QUIT:
                    continuer = SDL_FALSE;
                    break;
                case SDL_KEYUP:
                    if(e.key.keysym.sym == SDLK_ESCAPE)
                        continuer = SDL_FALSE;
                    break;
                case SDL_KEYDOWN:
                    switch(e.key.keysym.sym)
                    {
                        case SDLK_UP:
                            snake->direction = HAUT;
                            break;
                        case SDLK_DOWN:
                            snake->direction = BAS;
                            break;
                        case SDLK_RIGHT:
                            snake->direction = DROITE;
                            break;
                        case SDLK_LEFT:
                            snake->direction = GAUCHE;
                            break;
                        case SDLK_p:
                            if(pause)
                            {
                                pause = SDL_FALSE;
                                SDL_RenderFillRect(renderer, &rectPause);
                            }
                            else
                            {
                                pause = SDL_TRUE;
                                rectPause = afficherTexte(renderer, "PAUSE", police, 400, 300, 255, 255, 255);
                            }
                            break;
                    }
            }
		}

        tempsActuel = SDL_GetTicks();
        if(tempsActuel - tempsPrecedent > INTERVALLE && !pause) /* Si 0.2 sec se sont écoulées */
        {
            deplacerSerpent(snake, renderer);
            afficherSerpent(renderer, snake);
            afficherPoints(renderer, points);
            if(pointsVide(points))
            {
                /* Il reste des niveaux à faire */
                if(niveauActuel < MAX_NIVEAUX)
                    chargerPoints(points, ++niveauActuel);
                /* On a fini tous les niveaux */
                else
                {
                    continuer = SDL_FALSE;
                    gagner = SDL_TRUE;
                    afficherTexte(renderer, "Gagné !", police, 400, 300, 255, 255, 255);
                }
            }
            tempsPrecedent = tempsActuel;
        }
	}

	quit();

	return EXIT_SUCCESS;
}
예제 #8
0
파일: rockpush.c 프로젝트: amfo/rockpush
void set_score(Rock_Scroll_Map *map, Rock_Screen *screen_data)
{
  SDL_Rect screen_target;
  SDL_Rect target;
  SDL_Surface *text;
  SDL_Texture *text_texture;
  SDL_Color text_color = {200, 200, 200};
  SDL_Color bg_color   = {0, 0, 0};
  char score_text[25];
  uint8_t i;
  int w, h;

    screen_target.x = SCORE_X;
    screen_target.y = SCORE_Y;
    screen_target.w = SCORE_WIDTH;
    screen_target.h = SCORE_HEIGHT;

    SDL_RenderFillRect(screen_data->screen, &screen_target);

    for (i = 0; i < map->lives; i ++) {
        target.x = (i * TILE_SIZE) + TILE_HALF;
        target.y = SCORE_Y + ((SCORE_HEIGHT - TILE_SIZE) / 2);
        target.h = target.w = TILE_SIZE;
        SDL_RenderCopy(screen_data->screen, screen_data->sprites_texture, &rocco[WAIT_RIGHT].size, &target);
    }

    target.x = 5 * TILE_SIZE + TILE_HALF;
    target.y = SCORE_Y + ((SCORE_HEIGHT - TILE_SIZE) / 2);
    target.h = target.w = TILE_SIZE;
    SDL_RenderCopy(screen_data->screen, screen_data->sprites_texture, &tiles[DIAMOND].size, &target);

    sprintf(score_text, "%d ", map->diamonds);

    TTF_SizeText(font, score_text, &w, &h);
    target.x = 6 * TILE_SIZE + TILE_HALF;
    target.y = SCORE_Y + ((SCORE_HEIGHT - h) / 2);
    target.w = w;
    target.h = h;

    text = TTF_RenderText_Shaded(font, score_text, text_color, bg_color);
    text_texture = SDL_CreateTextureFromSurface(screen_data->screen, text);
    SDL_RenderCopy(screen_data->screen, text_texture, NULL, &target);
    SDL_FreeSurface(text);
    SDL_DestroyTexture(text_texture);

    sprintf(score_text, "PUNTOS %d ", map->points);

    TTF_SizeText(font, score_text, &w, &h);
    target.x = 10 * TILE_SIZE;
    target.y = SCORE_Y + 14;
    target.w = w >> 1;
    target.h = h >> 1;

    text = TTF_RenderText_Shaded(font, score_text, text_color, bg_color);
    text_texture = SDL_CreateTextureFromSurface(screen_data->screen, text);
    SDL_RenderCopy(screen_data->screen, text_texture, NULL, &target);
    SDL_FreeSurface(text);
    SDL_DestroyTexture(text_texture);

    sprintf(score_text, "NIVEL %d ", map->level + 1);

    TTF_SizeText(font, score_text, &w, &h);
    target.x = 10 * TILE_SIZE;
    target.y = SCORE_Y + 50;
    target.w = w >> 1;
    target.h = h >> 1;

    text = TTF_RenderText_Shaded(font, score_text, text_color, bg_color);
    text_texture = SDL_CreateTextureFromSurface(screen_data->screen, text);
    SDL_RenderCopy(screen_data->screen, text_texture, NULL, &target);
    SDL_FreeSurface(text);
    SDL_DestroyTexture(text_texture);
}
void drawGameOver(  SDL_Window* window,
					SDL_Renderer* renderer,
					List* texture,
					TTF_Font* font[],
					List* users,
					List* meteors,
					List* lasers,
					clock_t* runtime,
					int* screen,
					int* game_type ) {

	SDL_Color color = {255,255,255,255};
	SDL_Texture* txt[4] = {NULL};
	txt[0] = LoadTxtTexture(renderer, font[FONT_INDEX_BIG], "GAME OVER", &color, texture);
	txt[1] = LoadTxtTexture(renderer, font[FONT_INDEX_MED], "Menu", &color, texture);
	txt[2] = LoadTxtTexture(renderer, font[FONT_INDEX_MED], "Close", &color, texture);

	SDL_Rect txt_rect[3], txt_background[2];

	int i;
	for( i = 0; i < 3; i++ ) {
		if(SDL_QueryTexture(txt[i], NULL, NULL, &(txt_rect[i].w), &(txt_rect[i].h)) < 0) {
			fprintf(stderr, "%s\n", SDL_GetError());
		}
	}

	for( i = 1; i < 3; i++ ) {
		txt_background[i-1].h = txt_rect[i].h; // rect do background
		txt_background[i-1].w = txt_rect[i].w + 30; // rect do background
	}
	txt_rect[0].x = (WINDOW_SIZE_X - txt_rect[0].w)/2;
	txt_rect[0].y = (WINDOW_SIZE_Y - txt_rect[0].h)/2 - 50;

	txt_rect[1].x = 30;
	txt_rect[1].y = WINDOW_SIZE_Y - txt_background[0].h - 30;

	txt_rect[2].x = WINDOW_SIZE_X - txt_background[1].w - 30;
	txt_rect[2].y = WINDOW_SIZE_Y - txt_background[1].h - 30;

	txt_background[0].x = txt_rect[1].x-15; // rect do background
	txt_background[0].y = txt_rect[1].y; // rect do background

	txt_background[1].x = txt_rect[2].x - 15; // rect do background 
	txt_background[1].y = txt_rect[2].y; // rect do background

	int selectButton = -1;

	SDL_Event e;

	Point mouse;

	runtime[1] = SDL_GetTicks();
	ctrlFramerate( runtime[1] - runtime[0] ); // delay para considerar a mudança de página
	while( *screen == SCREEN_GAMEOVER ) {
		runtime[0] = SDL_GetTicks();

	    SDL_SetRenderDrawColor( renderer, 26, 26, 26, 255 ); // Fundo
	    SDL_RenderClear( renderer ); // Limpa a tela

		while(SDL_PollEvent(&e)) {
			switch(e.type) {
				case SDL_QUIT:
					closeALL(window, renderer, texture, font, users, meteors, lasers);
					exit(0);
				break;
			    case SDL_MOUSEMOTION:
			    	SDL_GetMouseState(&(mouse.x), &(mouse.y));
			    break;
				case SDL_MOUSEBUTTONUP:
					if( selectButton == 0 ) {
						*screen = SCREEN_MENU;
					} else if( selectButton == 1 ) {
						closeALL(window, renderer, texture, font, users, meteors, lasers);
						exit(0);
					}
				break;
			}
		}

		selectButton = -1;
		SDL_RenderCopy(renderer, txt[0], NULL, &(txt_rect[0]));
		for( i = 1; i < 3; i++ ) {
			if(insidePoint( mouse, &(txt_background[i - 1]) )) {
				selectButton = i - 1;
				SDL_SetRenderDrawColor(renderer, 200,0,0,255);
			} else {
				SDL_SetRenderDrawColor(renderer, 50,50,50,255);
			}

			SDL_RenderFillRect(renderer, &(txt_background[i-1]));
			SDL_RenderCopy(renderer, txt[i], NULL, &(txt_rect[i]));
		}

		SDL_RenderPresent(renderer);

		runtime[1] = SDL_GetTicks();
		ctrlFramerate( runtime[1] - runtime[0] );
	}
	destroyNonMainTexture(texture);
}
예제 #10
0
void StageState::Render() {
	bg.Render(0, 0);
	bg.Render(bg.GetWidth(), 0);
	bg.Render(bg.GetWidth(), bg.GetHeight());
	bg.Render(0, bg.GetHeight());
	tileMap.Render(Camera::pos.GetXpoint(), Camera::pos.GetYpoint());

	moneyText.SetText(to_string(data->money));
	moneyText.SetPos(20, 20, false, false);
	moneyText.Render();

	SDL_Rect fillRect = { 20, 70, 100, 10 };
	if (data->fame <= 255){
		SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 255 - data->fame, 0, data->fame, 255);
	}
	if (data->fame >= 255){
		SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 255, 255, 255, 255);
	}
	SDL_RenderFillRect(Game::GetInstance().GetRenderer(), &fillRect);
	
	for(int i = 0; i < roomArray.size(); i++){
        roomArray[i]->Render(&tileMap);
    }
	switch (action)	{
	case NONE:
		RenderArray();
		occupancyMap.Render(&tileMap);
		break;
	case TILE_SELECT:
		selectionBox.Render(&tileMap);
		RenderArray();
		break;
	case GUI_ROOM:
		RenderArray();
		roomSheet.RenderRoomSheet();
		break;
	case CONSTRUCT_ROOM:
		selectionBox.Render(&tileMap);
		RenderArray();
		break;
	case DESTROY_ROOM:
		RenderArray();
		break;
	case AREA_SELECT:
		RenderArray();
		break;
	case GUI_A:
		RenderArray();
		gui.Render();
		break;
	case SUB_GUI_EDIT :
		RenderArray();
		subGuiEdit.Render();
		break;
	case EDIT_DOOR:
		RenderArray();
		break;
	case BUY:
		RenderArray();
		buySheet.RenderObjectSheet();
		break;
	case EDIT_OBJECT:{
			vector<Point> tiles = objectArray[selectedObject]->GetAccessPoints();
			for (int i = 0; i < tiles.size(); i++){
				Point center = tileMap.GetTileCenter(tiles[i]);
				center.x = center.x - tileMap.GetTileWidth()/2;
				center.y = center.y - tileMap.GetTileHeight()/2;

				if (obstacleMap[(tiles[i].y)*tileMap.GetWidth() + tiles[i].x] != -1){
					okTile.Render(center.x + Camera::pos.x, center.y+Camera::pos.y);
				}
				else{
					noTile.Render(center.x + Camera::pos.x, center.y + Camera::pos.y);
				}
			}

		}

		RenderArray();
		break;
	default:
		RenderArray();
		break;
	}
	if (sheet.GetRender()){
		sheet.SetHunger(to_string(objectArray[selectedCharacter]->GetHunger()));
		sheet.SetSatisfaction(to_string(int(objectArray[selectedCharacter]->satisfaction)));
		sheet.SetMoney(to_string(objectArray[selectedCharacter]->money));
		sheet.Render();
	}
	if (objSheet.GetRender()){
		objSheet.Open(objectArray[selectedCharacter]->GetTextAttributes());
		objSheet.Render();
	}

	//Dinheiro e fama
	
		
	moneyText.SetText(to_string(data->money));
	moneyText.SetPos(20, 20, false, false);
	moneyText.Render();

	costText.Render();

	if (data->fame <= 255){
		SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 255 - data->fame, 0, data->fame, 255);
	}
	if (data->fame >= 255){
		SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 255, 255, 255, 255);
	}
	SDL_RenderFillRect(Game::GetInstance().GetRenderer(), &fillRect);
	int anchorx = data->fame * 100 / 255;
	SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 153, 153, 0, 255);
	fillRect = { 20 + anchorx, 68, 3, 14 };
	SDL_RenderFillRect(Game::GetInstance().GetRenderer(), &fillRect);
}
예제 #11
0
void fill_rect(SDL_Rect rect)
{
    SDL_RenderFillRect(gRender, &rect);
}
예제 #12
0
static void
DrawRects(SDL_Renderer * renderer, SDL_Rect * rect)
{
    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
    SDL_RenderFillRect(renderer, rect);
}
예제 #13
0
int main(void)
{
	SDL_Window *window;
	SDL_Renderer *renderer;
    SDL_Joystick *stick;
    SDL_Event event;
    SDL_Rect rect = { 0, 0, 256, 192 };
    int i;

    consoleDemoInit();
    puts("Hello world!  Initializing FAT...");

    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
        puts("# error initializing SDL");
        puts(SDL_GetError());
        return 1;
    }
    puts("* initialized SDL");

    if (SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_ACCELERATED, &window, &renderer) < 0 &&
		SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_SOFTWARE, &window, &renderer) < 0) {
        exit(1);
    }

    stick = SDL_JoystickOpen(0);
    if (stick == NULL) {
        puts("# error opening joystick");
        puts(SDL_GetError());
    }
    puts("* opened joystick");

    SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderFillRect(renderer, &rect);
    SDL_RenderPresent(renderer);

    while (1)
        while (SDL_PollEvent(&event))
            switch (event.type) {
            case SDL_JOYBUTTONDOWN:
				
				SDL_SetRenderDrawColor(renderer, rand(), rand(), rand(), SDL_ALPHA_OPAQUE);
				SDL_RenderFillRect(renderer, &rect);
				SDL_RenderPresent(renderer);
                if (rect.w > 8) {
                    rect.x += 4;
                    rect.y += 3;
                    rect.w -= 8;
                    rect.h -= 6;
                }
				/*
				  printf("button %d pressed at %d ticks\n",
				  event.jbutton.button, SDL_GetTicks()); 
				*/
                break;
            case SDL_QUIT:
                SDL_Quit();
                return 0;
            default:
                break;
            }
    return 0;
}
예제 #14
0
파일: gfx_sdl2.c 프로젝트: eaburns/mid
void gfxfillrect(Gfx *g, Rect r, Color c){
	SDL_Rect sr = { r.a.x*2, r.a.y*2, (r.b.x - r.a.x)*2, (r.b.y - r.a.y)*2 };
	rendcolor(g, c);
	SDL_RenderFillRect(g->rend, &sr);
}
예제 #15
0
void SquareRenderer::render(){
	SDL_SetRenderDrawColor(app_renderer, color->r, color->g, color->b, color->a);
	SDL_RenderFillRect(app_renderer, rect);
}
예제 #16
0
void draw_ghost(SDL_Renderer *r, Ghost *s) {
    SDL_SetRenderDrawColor(r, 255, 255, 0, 255);
    SDL_RenderFillRect(r, &s->rect);
}
예제 #17
0
파일: Rectangle.cpp 프로젝트: bleowy/ESLY
void Rectangle::render(){
	Shape::render();
	SDL_RenderFillRect(renderer, &rect);
}
예제 #18
0
void Renderer::Draw(SDL_Rect rectangle){
	SDL_SetRenderDrawColor(gRenderer, 0xFF, 0x00, 0x00, 0xFF);
	SDL_RenderFillRect(gRenderer, &rectangle);
}
예제 #19
0
void RenderableRectangleFilled::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_RenderFillRect(renderer->getSDLRenderer(), &rect);
}
예제 #20
0
void MapViewer::DrawSquares(SDL_Renderer* renderer, uint8_t r, uint8_t g, uint8_t b , SDL_Rect rect) const
{
	SDL_SetRenderDrawColor(renderer, r, g, b, 0);
	SDL_RenderFillRect(renderer, &rect);
}
예제 #21
0
inline void FillRectDIB(SDL_Rect &rect, unsigned char color) {
    SDL_SetRenderDrawColor(renderer, windowsPalette[color].r, windowsPalette[color].g, windowsPalette[color].b, 255);
    SDL_RenderFillRect(renderer, &rect);
}
예제 #22
0
void LangtonApp::OnRender() {
	SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
	SDL_RenderClear(renderer);
	SDL_GetWindowSize(window, &winX, &winY);
	int fitsquaresx = winX / squareSize + 2;
	int fitsquaresy = winY / squareSize + 2;
	int originx = winX / 2 - squareSize / 2;
	int originy = winY / 2 + squareSize / 2;
	LangtonAnt ant = automata.getAnt();
	if (tracking) {
		if (ABS(ant.x - centreX) > fitsquaresx / 4)
			centreX = ant.x;
		if (ABS(ant.y - centreY) > fitsquaresy / 4)
			centreY = ant.y;
	}
	int firstx = centreX - fitsquaresx / 2;
	int firsty = centreY - fitsquaresy / 2;
	for (int x = firstx; x < fitsquaresx + firstx; x++)
		for (int y = firsty; y < fitsquaresy + firsty; y++) {
			SDL_Rect drect = {
				originx + (x - centreX) * squareSize, 
				originy - (y - centreY) * squareSize, 
				squareSize, squareSize
			};
			Square_Colour sqc = automata.getSquare(x, y);
			if (x == ant.x && y == ant.y) {
				SDL_SetRenderDrawColor(renderer,
						0xFF,
						0x00,
						0x00,
						0xFF);
				SDL_RenderFillRect(renderer, &drect);
			}
			else if (sqc == Square_Colour::White) {
				SDL_SetRenderDrawColor(renderer, 
						0xFF, 
						0xFF, 
						0xFF, 
						0xFF);
				SDL_RenderFillRect(renderer, &drect);
			}
//			switch (sqc) {
//				case Square_Colour::White:
//					SDL_SetRenderDrawColor(renderer, 
//							0xFF, 
//							0xFF, 
//							0xFF, 
//							0xFF);
//					break;
//				default:
//					SDL_SetRenderDrawColor(renderer, 
//							0x00, 
//							0x00, 
//							0x00, 
//							0xFF);
//					break;
//			}
		}

	SDL_RenderPresent(renderer);
}
예제 #23
0
static void
DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
{
    const SDL_Rect area = { x, y, w, h };
    SDL_RenderFillRect(r, &area);
}
예제 #24
0
파일: draw13.c 프로젝트: j4y4r/j4ymame
static int draw13_window_draw(sdl_window_info *window, UINT32 dc, int update)
{
	sdl_info *sdl = (sdl_info *) window->dxdata;
	render_primitive *prim;
	texture_info *texture=NULL;
	float vofs, hofs;
	int blit_pixels = 0;

	if (video_config.novideo)
	{
		return 0;
	}

    if (sdl->resize_pending)
	{
		SDL_SetWindowSize(window->sdl_window, sdl->resize_width, sdl->resize_height);
		SDL_GetWindowSize(window->sdl_window, &window->width, &window->height);
		sdl->resize_pending = 0;
		SDL_RenderSetViewport(sdl->sdl_renderer, NULL);
	}

    //SDL_SelectRenderer(window->sdl_window);

	if (sdl->blittimer > 0)
	{
		/* SDL Underlays need alpha = 0 ! */
		SDL_SetRenderDrawBlendMode(sdl->sdl_renderer, SDL_BLENDMODE_NONE);
		//SDL_SetRenderDrawColor(0,0,0,255);
		SDL_SetRenderDrawColor(sdl->sdl_renderer, 0,0,0,0);
		SDL_RenderFillRect(sdl->sdl_renderer, NULL);
		sdl->blittimer--;
	}

	// compute centering parameters
	vofs = hofs = 0.0f;

	if (video_config.centerv || video_config.centerh)
	{
		int ch, cw;

		if ((window->fullscreen) && (!video_config.switchres))
		{
			ch = window->monitor->center_height;
			cw = window->monitor->center_width;
		}
		else
		{
			ch = window->height;
			cw = window->width;
		}

		if (video_config.centerv)
		{
			vofs = (ch - window->blitheight) / 2.0f;
		}
		if (video_config.centerh)
		{
			hofs = (cw - window->blitwidth) / 2.0f;
		}
	}

	sdl->last_hofs = hofs;
	sdl->last_vofs = vofs;

	window->primlist->acquire_lock();

	// now draw
	for (prim = window->primlist->first(); prim != NULL; prim = prim->next())
	{
		Uint8 sr, sg, sb, sa;

		switch (prim->type)
		{
			case render_primitive::LINE:
				sr = (int)(255.0f * prim->color.r);
				sg = (int)(255.0f * prim->color.g);
				sb = (int)(255.0f * prim->color.b);
				sa = (int)(255.0f * prim->color.a);

				SDL_SetRenderDrawBlendMode(sdl->sdl_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
				SDL_SetRenderDrawColor(sdl->sdl_renderer, sr, sg, sb, sa);
				SDL_RenderDrawLine(sdl->sdl_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs,
						prim->bounds.x1 + hofs, prim->bounds.y1 + vofs);
				break;
			case render_primitive::QUAD:
				texture = texture_update(window, prim);
				if (texture)
					blit_pixels += (texture->rawheight * texture->rawwidth);
				render_quad(sdl, texture, prim,
						round_nearest(hofs + prim->bounds.x0),
						round_nearest(vofs + prim->bounds.y0));
				break;
			default:
				throw emu_fatalerror("Unexpected render_primitive type");
		}
	}

	window->primlist->release_lock();

	sdl->last_blit_pixels = blit_pixels;
	sdl->last_blit_time = -osd_ticks();
	SDL_RenderPresent(sdl->sdl_renderer);
	sdl->last_blit_time += osd_ticks();

	return 0;
}
예제 #25
0
int main(int argc, char *argv[])
{
    int pos_x = 100;
    int pos_y = 100;
    const int res_x = 640;
    const int res_y = 480;

    int scale = 1;

    setup *app = sdl_setup("Movement", pos_x, pos_y, res_x, res_y);

    if (TTF_Init() != 0)
    {
        logSDLError("TTF_Init");
        cleanup("rw", app->renderer, app->window);
        free(app);
        SDL_Quit();
        return -1;
    }

    SDL_Rect container;
    container.x = 20;
    container.y = 20;
    container.w = res_x - 2 * container.x;
    container.h = res_y - 2 * container.y;

    SDL_Rect box;
    box.w =	scale * container.x;
    box.h = scale * container.y;
    box.x = container.x;//res_x / 2 - box.w / 2;
    box.y = res_y / 2 - box.h / 2;

    SDL_Rect goal;
    goal.w = box.w;
    goal.h = box.h;
    goal.x = res_x - container.x;
    goal.y = res_y / 2 - goal.h / 2;

    SDL_Rect winner;
    winner.h = container.h - 20;
    winner.w = container.w - 20;
    winner.x = container.x + 10;
    winner.y = container.y + 10;

    int size = 26;
    SDL_Rect *army	= addEnemy(size);
//    SDL_Rect *army2	= addEnemy(size);

    bool quit = false;
    bool won = false;
    SDL_Event e;

    while (!quit)
    {
        while (SDL_PollEvent(&e))
        {
            if (e.type == SDL_QUIT)
            {
                quit = true;
                break;
            }
            if (e.type == SDL_KEYDOWN)
            {
                switch(e.key.keysym.sym)
                {
                case SDLK_ESCAPE:
                    quit = true;
                    break;
                case SDLK_UP:
                    box.y -= box.h;
                    break;
                case SDLK_DOWN:
                    box.y += box.h;
                    break;
                case SDLK_LEFT:
                    box.x -= box.w;
                    break;
                case SDLK_RIGHT:
                    box.x += box.w;
                    break;
                default:
                    break;
                }
            }
        }
        if (!won)
        {
            randomMove(army, size, 1);
//        randomMove(army2, size, 3);
            if (contains(&container, &box) || enemyCollision(&box, army, size))// || enemyCollision(&box, army2, size))
            {
                printf("Collision\n");
                if (collision(&goal, &box))
                {
                    won = true;
                    printf("WINNER!\n");
                }
                box.x = container.x;//res_x / 2 - box.w / 2;
                box.y = res_y / 2 - box.h / 2;
            }
            renderHard(app->renderer, &container, &box, &goal, army, NULL, size);
            SDL_Delay(2);
        }
        if (won)
        {
//            SDL_Delay(100);
            SDL_SetRenderDrawColor(app->renderer, 0xff, 0xff, 0xff, 0xff);
            SDL_RenderFillRect(app->renderer, &winner);

            const string f_name = "fonts/Gidole-Regular.ttf";
            SDL_Color f_color = {25, 25, 25, 25};
            SDL_Texture *slogan = renderText(app->renderer, "You have WON the game! BANZAI!!!", f_name, 30, f_color);
            if (slogan == NULL)
            {
                cleanup("rw", app->renderer, app->window);
                free(army);
                free(app);
                TTF_Quit();
                SDL_Quit();
                logSDLError("renderText");
                return -2;
            }
            int slgn_h, slgn_w;
            SDL_QueryTexture(slogan, NULL, NULL, &slgn_w, &slgn_h);

            int x = res_x / 2 - slgn_w / 2;
            int y = res_y / 2 - slgn_h / 2;

            renderTexture(app->renderer, slogan, x, y, NULL);

            SDL_RenderPresent(app->renderer);
        }
    }

    cleanup("rw", app->renderer, app->window);
    free(army);
    free(app);
    SDL_Quit();

    return 0;
}