Пример #1
0
//*************************************************************************************************
void Game::repaint()
{
    SDL_BlitSurface(m_background, nullptr, m_backbuffer, nullptr);

    SDL_Rect sourceRect;
    sourceRect.y = 0;
    sourceRect.x = 10;
    sourceRect.w = CELL_SIZE;
    sourceRect.h = CELL_SIZE;

    SDL_Rect destRect;
    destRect.x = toDisplayPosition(m_board.m_x[0]);
    destRect.y = toDisplayPosition(m_board.m_y[0]);
    SDL_BlitSurface(m_bricks, &sourceRect, m_backbuffer, &destRect);

    sourceRect.x = 0;
    for (int i = 1; i < m_board.m_length; ++i)
    {
        destRect.x = toDisplayPosition(m_board.m_x[i]);
        destRect.y = toDisplayPosition(m_board.m_y[i]);
        SDL_BlitSurface(m_bricks, &sourceRect, m_backbuffer, &destRect);
    }

    sourceRect.x = 20;
    destRect.x = toDisplayPosition(m_board.m_GoalX);
    destRect.y = toDisplayPosition(m_board.m_GoalY);
    SDL_BlitSurface(m_bricks, &sourceRect, m_backbuffer, &destRect);

    renderScore();

    SDL_Flip(m_backbuffer);
}
Пример #2
0
void TableProtoScene::ScoreBoard::Render() {
#ifndef _WIN32
	if (!initialized) {
		objInit();
		initialized = true;
	}
#endif /*_WIN32*/
	RECT rect = {0, 0, PanelWidth, PanelHeight};
	SpriteRenderer::instantiate(myDevice)->ShowSprite(texture, (int)xpos, (int)ypos,
		PanelWidth, PanelHeight, 0xffffffff, &rect, 0, 0, &myMatrix);
	if ((playerID() >= 0) && (playerID() < (GameStatus::gameStat()->chkGameType(SanmaT) ? 3 : 4))) {
		renderWind();
		renderRank();
		renderScore();
		renderName();
	}
}
Пример #3
0
void renderAll(Game& game) {
    SDL_RenderClear(game.renderer);

    if (game.bonusItem.alive)
        renderItem(game.renderer, game.bonusItem);

    for (unsigned int i = 0; i < game.daMissiles.size(); i++)
        renderMissile(game.renderer, game.daMissiles[i]);
    for (unsigned int i = 0; i < game.daEnemies.size(); i++)
        renderEnemy(game.renderer, game.daEnemies[i]);
    for (unsigned int i = 0; i < game.daBlasts.size(); i++)
        renderBlast(game.renderer, game.daBlasts[i]);

    if (game.daBox.alive)
        renderBox(game.renderer, game.daBox);

    for (unsigned int i = 0; i < game.lives.size(); i++)
        renderBlast(game.renderer, game.lives[i]);

    renderScore(game);

    SDL_UpdateWindowSurface(game.window);
}
Пример #4
0
int main(int argc, char *argv[])
{
	srand(time(NULL));
	SDL_Window *screen;
	SDL_Renderer *renderPrim;
	SDL_Event eventHandle;
	SDL_Texture *scoreDisplay;
	TTF_Font *defaultText;
	SDL_Color cPlayer = {0,255,255,255};
	SDL_Color cPoint = {255,255,0,255};
	SDL_Color cBackground = {0,0,0,255};
	SDL_Color cScore = {0,255,0,255};
	int runningGame,gotPoint, pointCount, oldScore;
	runningGame = 0;
	gotPoint = 0;
	pointCount = -1;//first point spawns on player
	SDL_Rect rPlayer = {0,0,PLAYER_WIDTH, PLAYER_HEIGHT};
	SDL_Rect rPoint = {0,0,POINT_WIDTH,POINT_HEIGHT};
	SDL_Rect rScore = {0,0,0,0};
	screen = init("Piss easy snake", SCREEN_WIDTH, SCREEN_HEIGHT);
	renderPrim = createRenderer(screen);
	defaultText = loadFont("default.ttf", 15, renderPrim);
	while(runningGame == 0)
	{
		oldScore = pointCount;
		if(gotPoint == 1)
		{
			pointCount++;
			rPoint.x = rand() % SCREEN_WIDTH;//new random position
			rPoint.y = rand() % SCREEN_HEIGHT;
			gotPoint = 0;
		}
		while(SDL_PollEvent(&eventHandle) != 0)
		{
			if(eventHandle.type == SDL_KEYDOWN)
			{
				handleInput(&rPlayer, eventHandle, &runningGame);
			
			}
			else if(eventHandle.type == SDL_QUIT)
			{
				runningGame = 1;
			
			}
		
		
		}
		
		SDL_SetRenderDrawColor(renderPrim, cBackground.r,cBackground.g,cBackground.b,cBackground.a);
		SDL_RenderClear(renderPrim);
		SDL_SetRenderDrawColor(renderPrim,cPlayer.r,cPlayer.g,cPlayer.b,cPlayer.a);
		SDL_RenderFillRect(renderPrim,&rPlayer);
		SDL_SetRenderDrawColor(renderPrim,cPoint.r,cPoint.g,cPoint.b,cPoint.a);
		SDL_RenderFillRect(renderPrim,&rPoint);
		if(oldScore < pointCount)
		{
			scoreDisplay = renderScore(defaultText,cScore,&rScore, renderPrim, pointCount, scoreDisplay);
		}
		SDL_RenderCopy(renderPrim, scoreDisplay, NULL, &rScore); 
		SDL_RenderPresent(renderPrim);
		
		gotPoint = SDL_HasIntersection(&rPlayer,&rPoint);
	}
	SDL_DestroyRenderer(renderPrim);
	SDL_DestroyWindow(screen);
	TTF_CloseFont(defaultText);
	TTF_Quit();
	SDL_Quit();
	return 0;
}
int main(int argc, char * argv[])
{
    bool firsttime = true;
    ostringstream convert;
    convert << playerScore;
    playerScoreTX = convert.str();
    srand(time(NULL));


    GameTextures a, b, c, d, e;

    int indicator = 0;
    int adder = 150;
    int goSpeed = 30;



    if(!init())
        cout << "\nSDL Failed to Initialize. ERROR: " << SDL_GetError();

    else
    {

        if(!loadMedia(a) || !loadMedia(b) || !loadMedia(c) || !loadMedia(d) || !loadMedia(e))
            cout << "\nLoading media failed. ERROR: " << SDL_GetError();
        else if(!renderScore(36))
            cout << "\nSDL Has Failed to handle text. ERROR: " << SDL_GetError();
        else
        {

            bool quit = false;
            SDL_Event event;
            mainShip ship;
            monsterGroup MOBS;



            shipProtector protectora(150, 515);
            shipProtector protectorb(375, 515);
            shipProtector protectorc(600, 515);
            shipProtector protectord(825, 515);
            shipProtector protectore(1025, 515);


            protectora.setColliders();
            protectorb.setColliders();
            protectorc.setColliders();
            protectord.setColliders();
            protectore.setColliders();

            MOBS.spawn(head);

            while (!quit)
            {



                    while(SDL_PollEvent(&event) != 0)
                    {
                        if(event.type == SDL_QUIT)
                            quit = true;

                        ship.handleEvent(event);
                    }

                   if(!dead && monstersKilled != 55)
                {

                    if(!skip)
                    {

                    ship.moveShip();



                    if(MOBS.getHeading(head))
                    {
                        goSpeed -= 1;
                        if(goSpeed <= 3)
                            goSpeed = 3;
                    }


                    if(indicator % goSpeed == 0)
                    {
                        track = false;
                        MOBS.setDirection(head);
                    }


                    bgTexture.render(0,0);
                    textTexture.render(140, 7);


                    switch(shipLives)
                    {
                    case 3:
                    {
                        shipLivesTexture.render(1045, 0);
                        shipLivesTexture.render(1125, 0);
                        shipLivesTexture.render(1205, 0);
                        break;
                    }

                    case 2:
                    {
                        shipLivesTexture.render(1045, 0);
                        shipLivesTexture.render(1125, 0);
                        break;
                    }
                    case 1:
                    {
                        shipLivesTexture.render(1045, 0);
                        break;
                    }
                    case 0:
                    {
                        gameOver.render(0 , 0);
                        dead = true;
                        break;
                    }



                    }

                    psetColliders(pbulletContainer);
                    setColliders(bulletContainer);
                    ship.setShipColliders();



                    MOBS.setGColliders(head);

                    pfindCollision(pbulletContainer, ship);

                    findCollision(bulletContainer, protectora, MOBS, a);
                    findCollision(bulletContainer, protectorb, MOBS, b);
                    findCollision(bulletContainer, protectorc, MOBS, c);
                    findCollision(bulletContainer, protectord, MOBS, d);
                    findCollision(bulletContainer, protectore, MOBS, e);

                    pfindCColision(pbulletContainer, protectora, a);
                    pfindCColision(pbulletContainer, protectorb, b);
                    pfindCColision(pbulletContainer, protectorc, c);
                    pfindCColision(pbulletContainer, protectord, d);
                    pfindCColision(pbulletContainer, protectore, e);




                    ostringstream convert;
                    convert << playerScore;
                    playerScoreTX = convert.str();
                    renderScore(36);

                    if(shootlevel >= 15)
                    {
                    if(indicator % shootlevel == 0)
                    {
                        int index = rand() % 55 + 1;
                        MOBS.shoot(head, index);
                    }
                    }

                    else if(shootlevel < 15)

                    {
                        if(indicator % 15 == 0)
                    {
                        int index = rand() % 55 + 1;
                        MOBS.shoot(head, index);
                    }
                    }


                    ship.render();
                    protectora.renderProtector(1, killTarget, a);
                    protectorb.renderProtector(2 , -1, b);
                    protectorc.renderProtector(3, -1, c);
                    protectord.renderProtector(4, -1, d);
                    protectore.renderProtector(5, -1, e);






                    MOBS.renderMGroup(head);


                    renderBullet(bulletContainer, 0);
                    prenderBullet(pbulletContainer, 0);



                    if(indicator % 120 == 0)
                        cout << "\nYour Score : " << playerScore;

                    SDL_RenderPresent(mainRenderer); // RENDER ALL TO FRONT BUFFER
                    indicator++;

                }

                }
                else if(dead)
                {
                    const Uint32 timeEntered = SDL_GetTicks();
                    SDL_RenderClear(mainRenderer);
                    gameOver.render(0,0);
                    SDL_RenderPresent(mainRenderer);


                    if(SDL_GetTicks() - 6000 == timeEntered)
                        quit = true;
                    else
                        skip = true;


                }

                else if(monstersKilled >= 55)
                {
                    if(firsttime)
                    {
                        int tempscore = 1000;
                        tempscore = tempscore / (SDL_GetTicks() / 1000);

                        playerScore = playerScore + (tempscore * 25);
                        ostringstream convert;
                        convert << playerScore;
                        playerScoreTX = convert.str();
                        firsttime = false;
                    }

                    else
                {

                    const Uint32 timeEntered = SDL_GetTicks();
                    SDL_RenderClear(mainRenderer);
                    youWin.render(0, 0);

                    renderScore(100);
                    textTexture.render(570, 590);
                    SDL_RenderPresent(mainRenderer);

                    skip = true;
                }

                }

            }

        }
    }
    close(a);
    close(b);
    close(c);
    close(d);
    close(e);
    return 0;
}