void drawWorld(int player) {
	int i;

	nebu_Video_CheckErrors("before world");

	setupLights(eWorld);

	if (gSettingsCache.show_recognizer &&
		game->player[player].data->speed != SPEED_GONE) {
		drawRecognizer();
	}

	if (gSettingsCache.show_wall == 1) {
		glColor3f(1,1,1);
		drawWalls();
	}

	setupLights(eCycles);

	drawPlayers(player);

	setupLights(eWorld);

	{
		TrailMesh mesh;
		mesh.pVertices = (vec3*) malloc(1000 * sizeof(vec3));
		mesh.pNormals = (vec3*) malloc(1000 * sizeof(vec3));
		mesh.pColors = (unsigned char*) malloc(1000 * 4 * sizeof(float));
		mesh.pTexCoords = (vec2*) malloc(1000 * sizeof(vec2));
		mesh.pIndices = (unsigned short*) malloc(1000 * 2);

		for(i = 0; i < game->players; i++) {
			if (game->player[i].data->trail_height > 0 ) {
				int vOffset = 0;
				int iOffset = 0;
				mesh.iUsed = 0;
				trailGeometry(game->player + i, gPlayerVisuals + i,
					&mesh, &vOffset, &iOffset);
				bowGeometry(game->player + i, gPlayerVisuals + i,
					&mesh, &vOffset, &iOffset);
				trailStatesNormal(game->player + i, gScreen->textures[TEX_DECAL]);
				trailRender(&mesh);
				trailStatesRestore();
			}
		}
		free(mesh.pVertices);
		free(mesh.pNormals);
		free(mesh.pColors);
		free(mesh.pTexCoords);
		free(mesh.pIndices);
	}

	for(i = 0; i < game->players; i++)
		if (game->player[i].data->trail_height > 0 )
			drawTrailLines(game->player + i, gPlayerVisuals + i);

	nebu_Video_CheckErrors("after world");
}
Example #2
0
/**
 Author: 	Joel Denke, Marcus Isaksson
 Description: 	Draw all graphics
 */
void drawGraphics()
{
	int i;
	startDraw();
	drawBackground(SCREEN_WIDTH,SCREEN_HEIGHT);
	drawObjects(&gameWorld, NO_OBJECTS, oColor);
	drawPlayers(gameWorld.players, no_players, pColor);
	endDraw();
}
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  drawPanel
 *  Description:  
 * =====================================================================================
 */
void drawPanel (  ) {
    
    /* Draw Background */
    glColor3f( .15, .15, .15 );
    glBegin( GL_POLYGON );
        glVertex3f( BOARD_SIZE, 0.0f, -0.5f );
        glVertex3f( BOARD_SIZE, BOARD_SIZE, -0.5f );
        glColor3f( .2, .2, .2 );
        glVertex3f( BOARD_SIZE + PANEL_WIDTH, BOARD_SIZE, -0.5f );
        glVertex3f( BOARD_SIZE + PANEL_WIDTH, 0.0f, -0.5f );
    glEnd();

    /* Draw Players */
    drawPlayers();

    /* Draw Start Button */
    drawStartButton( );
}		
Example #4
0
void BlitzleApp::drawNextFrame(cv::Mat& resultOut) const
{
	cv::Mat frame;
	desktop->acquireNextFrame(frame);

	resultOut = frame;
	if (opts.withDebug)
	{
		detector->processFrameDebug(frame, resultOut);
	}
	else
	{
		std::vector<cv::Point> players;
		detector->processFrame(frame, players);
		drawPlayers(players, resultOut);
	}

	if (opts.outputScale != 1.0f)
	{
		resize(resultOut, resultOut, cv::Size(), opts.outputScale, opts.outputScale, cv::INTER_AREA);
	}
}
Example #5
0
int main(void) {
	/* Related object data */
	system_t* system;
	player_t* player1;
	player_t* player2;

	alt_timestamp_start();
	int start_time = alt_timestamp();
	int wind;
	int restart = 0;
	/* initialize all hardware dev */
	system = system_init(VIDEO_PIXEL_BUFFER_DMA_NAME,
			"/dev/video_character_buffer_with_dma_0",
			ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_NAME, PS2_0_NAME);
	if (!alt_up_sd_card_is_Present()) {
		printf("SD card not present\n");
		return -2;
	} else {
		printf("SD card detected.\n");
	}
	if (!alt_up_sd_card_is_FAT16()) {
		printf("SD card is not FAT16.\n");
		return -3;
	} else {
		printf("SD card is FAT 16.\n");
	}
	fireSound = initSoundbank("shotgun.wav");
	explosionSound = initSoundbank("big_bomb.wav");
	printf("Done Initializing\n");
	int end_time = alt_timestamp();
	srand(end_time - start_time);
	clearScreen(system);
	printf("Press enter to start game");
	restartGame(system);
	while (restart == 1) {
	/* initialize required objects */
	player1 = makePlayer(1, "Lomash");
	player2 = makePlayer(2, "TJ");

	/*
	 * Draw the screen for the first time.
	 */
	store_background_data();
	draw_background(system);
	drawPlayers(system);
	draw_ground(system);
	draw_windbox(system);
	draw_player1GUI(system);
	draw_player2GUI(system);
	update_wind(system, wind);
	draw_health(player1, system);
	draw_health(player2, system);
	update_power(player1, system);
	update_power(player2, system);
	usleep(2000000); // sleep to wait for video buffer to load
	while (TRUE) {

	printf(
	 "\n\n\n\n===========================================================\n");
	 printf("Player 1 Health = %d \t\t Player 2 Health = %d\n",
	 player1->health, player2->health);
	 wind = rand() % 11 - 5;
	 draw_windbox(system);
	 update_wind(system, wind);


//	 Player 1's turn

	 player_1_jump(system);
	 player_1_jump(system);
	 printf("Getting Player 1 Power.\n");
	 getKeyboardInput(1, player1, system); // Power
	 skipOneEnter(system);
	 printf("Getting Player 1 Angle.\n");
	 getKeyboardInput(2, player1, system); // Angle

//	 Player 1 Animation
	 printf("Starting animation\n");
	 clear_angle_drawer(system);
	 animate_cannon1(system);
	 playSound(fireSound, system->audio);
	 switch (animateShooting(system, player1, wind)) { // different value for result
	 case 1: {
	 update_health(player2, system, -DAMAGE);
	 printf(
	 "Player 1 hit player 2.\n Remaining Health for Player 2: %d\n",
	 player2->health);
	 break;
	 }
	 case 2: {
	 update_health(player1, system, -DAMAGE);
	 printf(
	 "Player 1 hit player 1.\n Remaining Health for Player 1: %d\n",
	 player1->health);
	 break;
	 }
	 default: {
	 break;
	 }
	 }
	 printf("Ended animation\n");

//	 Post-animation Calculation
	 if (player1->health <= 0 || player2->health <= 0) {
	 break;
	 }


//	 Player 2's turn


	 wind = rand() % 11 - 5;
	 draw_windbox(system);
	 update_wind(system, wind);
	 player_2_jump(system);
	 player_2_jump(system);
	 printf("Getting Player 2 Velocity.\n");
	 getKeyboardInput(1, player2, system);
//	 Player 2 Angle-Selection
	 skipOneEnter(system);
	 printf("Getting Player 2 Angle.\n");
	 getKeyboardInput(2, player2, system);

//	 Player 2 Animation
	 printf("Starting animation\n");
	 clear_angle_drawer(system);
	 animate_cannon2(system);
	 playSound(fireSound, system->audio);
//	 Post-animation Calculation
	 switch (animateShooting(system, player2, wind)) { // different value for result
	 case 1: {
	 update_health(player1, system, -DAMAGE);
	 printf(
	 "Player 2 hit player 1.\n Remaining Health for Player 1: %d\n",
	 player1->health);
	 break;
	 }
	 case 2: {
	 update_health(player2, system, -DAMAGE);
	 printf(
	 "Player 2 hit player 2.\n Remaining Health for Player 2: %d\n",
	 player2->health);
	 break;
	 }
	 default: {
	 break;
	 }
	 }

	 if (player1->health <= 0 || player2->health <= 0) {
	 break;
	 }
	};
	/*
	 * Find out who won.
	 */
		if (player1->health <= 0) {
			printf("Player 2 Wins!!! \n");
			draw_P2WIN(system);
		} else if (player2->health <= 0) {
			printf("Player 1 Wins!!!\n");
			draw_P1WIN(system);
		} else {
			printf("we shouldn't be here.\n");
		}
		restart = restartGame(system);
	}
	return 0; // FIN
}
Example #6
0
/**
  Function called to refresh the view on canvas
*/
void CGameBoard::OnUpdate()
{
    Clear(sf::Color(195, 195, 195)); /* Grey */
    sf::Shape rightBorder = sf::Shape::Rectangle(510, 0, 630, 510, sf::Color(127, 127, 127));
    Draw(rightBorder);

    if (m_fpsRefreshTime.GetElapsedTime() >= 1.0f)
    {
        m_frameRate = 1.f / GetFrameTime();
        m_fpsRefreshTime.Reset();
    }
    drawMap();
    drawFPS();
    drawStatus();
    drawExplosions();
    drawPlayers();
    drawBonusCanvas();

    if (!m_gameBegin || !m_connected)
    {
        return;
    }

    /* Handling Event */
    CPlayer *me = m_playersList[0]; /* I am the first player of the list */
    float x = me->GetPosition().x;
    float y = me->GetPosition().y;
    std::string pos = QString("%1 %2").arg(me->GetPosition().x).arg(me->GetPosition().y)
                                      .toStdString();
    if (me->isDead())
    {
        return;
    }

    sf::Event event;
    while (GetEvent(event))
    {
        switch (event.Type)
        {
        case sf::Event::KeyPressed:
            if (event.Key.Code == sf::Key::Space)
            {
                plantBomb();
            }
            else if (event.Key.Code == sf::Key::E)
            {
                useSpecialBonus();
            }
            break;
        default:
            break;
        }
    }


    if (GetInput().IsKeyDown(sf::Key::Right) ||
        GetInput().IsKeyDown(sf::Key::D))
    {
        switch (me->getCollision(Right, m_map))
        {
        case Floor:
        case Bonus:
            if (me->getDirection() != Right)
            {
                m_networkManager->sendMovePacket(me->getNick(), Right, x, y);
                me->setDirection(Right);
            }
            break;
        case Bomb:
            if (me->getBonus(CBonus::BombPass) != NULL)
            {
                me->setDirection(Right);
            }
            else if (me->getBonus(CBonus::BombKick) != NULL)
            {
                QList<CBomb *>::iterator it;
                for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                {
                    CBomb *bomb = *it;
                    if (bomb->getX() == me->getX() + 1 && bomb->getY() == me->getY())
                    {
                        bomb->setDirection(CBomb::Right);
                        m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                        break;
                    }
                }
            }
            break;
        default:
            break;
        }

        if (me->IsPaused())
        {
            me->Play();
        }
    }
     else if (GetInput().IsKeyDown(sf::Key::Left) ||
              GetInput().IsKeyDown(sf::Key::Q))
     {
         switch (me->getCollision(Left, m_map))
         {
         case Floor:
         case Bonus:
              if (me->getDirection() != Left)
              {
                  me->setDirection(Left);
                  m_networkManager->sendMovePacket(me->getNick(), Left, x, y);
              }
              break;
         case Bomb:
              if (me->getBonus(CBonus::BombPass) != NULL)
              {
                  me->setDirection(Left);
              }
              else if (me->getBonus(CBonus::BombKick) != NULL)
              {
                  QList<CBomb *>::iterator it;
                  for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                  {
                      CBomb *bomb = *it;
                      if (bomb->getX() == me->getX() - 1 && bomb->getY() == me->getY())
                      {
                          bomb->setDirection(CBomb::Left);
                          m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                          break;
                      }
                  }
              }
              break;
         default:
              break;
         }

         if (me->IsPaused())
         {
             me->Play();
         }
     }
     else if (GetInput().IsKeyDown(sf::Key::Down) ||
              GetInput().IsKeyDown(sf::Key::S))
     {
         switch (me->getCollision(Down, m_map))
         {
         case Floor:
         case Bonus:
             if (me->getDirection() != Down)
              {
                   me->setDirection(Down);
                   m_networkManager->sendMovePacket(me->getNick(), Down, x, y);
              }
             else if (me->getBonus(CBonus::BombKick) != NULL)
             {
                 QList<CBomb *>::iterator it;
                 for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                 {
                     CBomb *bomb = *it;
                     if (bomb->getX() == me->getX() && bomb->getY() == me->getY() + 1)
                     {
                         bomb->setDirection(CBomb::Down);
                         m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                         break;
                     }
                 }
             }
             break;
         case Bomb:
             if (me->getBonus(CBonus::BombPass) != NULL)
             {
                 me->setDirection(Down);
             }
             break;
         default:
             break;
         }

         if (me->IsPaused())
         {
             me->Play();
         }

     }
     else if (GetInput().IsKeyDown(sf::Key::Up) ||
              GetInput().IsKeyDown(sf::Key::Z))
     {
         switch (me->getCollision(Up, m_map))
         {
         case Floor:
         case Bonus:
               if (me->getDirection() != Up)
               {
                    m_networkManager->sendMovePacket(me->getNick(), Up, x, y);
                    me->setDirection(Up);
               }
               break;
         case Bomb:
               if (me->getBonus(CBonus::BombPass) != NULL)
               {
                   me->setDirection(Up);
               }
               else if (me->getBonus(CBonus::BombKick) != NULL)
               {
                   QList<CBomb *>::iterator it;
                   for (it = m_bombsList.begin(); it != m_bombsList.end(); ++it)
                   {
                       CBomb *bomb = *it;
                       if (bomb->getX() == me->getX() && bomb->getY() == me->getY() - 1)
                       {
                           bomb->setDirection(CBomb::Up);
                           m_map.setBlock(bomb->getX(), bomb->getY(), Floor);
                           break;
                       }
                   }
               }
               break;
         default:
             break;
         }

         if (me->IsPaused())
         {
             me->Play();
         }

     }
     else
     {
         if (me->getDirection() != Stopped && me->getElapsedTime() >= me->getStopTime())
         {
             me->setDirection(Stopped);
             m_networkManager->sendMovePacket(me->getNick(), Stopped, x, y);
             me->Pause();
         }
     }
}
Example #7
0
int main(int argc, char* args[])
{
	Player player1;
	Player player2;

	struct Ball ball;
	struct Vector vel;

	// Players vars
	int moveP1, moveP2;
	player1.score = player2.score = 0;

	// Keyboard
	const Uint8* keyState;

	char buffer[65];
	int r = 10;

	// Color

	SDL_Color textColor = { 255, 255, 255, 255 };
	
	// Init players positions
	moveP1 = moveP2 = SCREEN_HEIGHT / 2 - PLAYER_HEIGHT / 2;

	// Init ball
	ball.w = ball.h = 10;
	ball.x = SCREEN_WIDTH / 2 - ball.w / 2;
	ball.y = SCREEN_HEIGHT / 2 - ball.w / 2;	
	ball.speed = 4;

	// Init ball velocity
	vel.x = 1;
	vel.y = 1;

	if (initSDL());
	{
		loadFont();

		scorePlayer1 = loadTextTexture(_itoa(player1.score, buffer, r), textColor);
		scorePlayer2 = loadTextTexture(_itoa(player2.score, buffer, r), textColor);
		// Main loop
		while (!quit)
		{
			// Event loop
			while (SDL_PollEvent(&e) != 0)
			{
				// User presses the close button
				if (e.type == SDL_QUIT)
					quit = true;
			}

			keyState = SDL_GetKeyboardState(NULL);
			if (keyState[SDL_SCANCODE_A])
			{
				if ((moveP1 + PLAYER_HEIGHT) < SCREEN_HEIGHT)
				{
					moveP1 += PLAYER_SPEED;
					//printf("Player1: %d\n", moveP1 + PLAYER_HEIGHT);
				}
			}
			if (keyState[SDL_SCANCODE_S])
			{
				if (moveP1 > 10)
				{
					moveP1 -= PLAYER_SPEED;
					//printf("Player1: %d\n", moveP1);
				}
			}
			if (keyState[SDL_SCANCODE_J])
			{
				if ((moveP2 + PLAYER_HEIGHT) < SCREEN_HEIGHT)
				{
					moveP2 += PLAYER_SPEED;
					//printf("Player2: %d\n", moveP2 + PLAYER_HEIGHT);
				}
			}
			if (keyState[SDL_SCANCODE_K])
			{
				if (moveP2 > 10)
				{
					moveP2 -= PLAYER_SPEED;
					//printf("Player2: %d\n", moveP2);
				}
			}

			// Bounce of player1
			if ( (ball.x <= (20 + PLAYER_WIDTH)) && ((ball.y >= moveP1) && (ball.y <= moveP1 + PLAYER_HEIGHT)) )
			{
				vel.x *= -1;
			}

			// Bounce of player2
			else if ( (ball.x + 10 >= (SCREEN_WIDTH - PLAYER_WIDTH - 20)) && ((ball.y >= moveP2) && (ball.y <= moveP2 + PLAYER_HEIGHT)) )
			{
				vel.x *= -1;
			}

			// Bounce from top and bottom edges
			if ( (ball.y + 10 >= SCREEN_HEIGHT) || (ball.y <= 0) )
			{
				vel.y *= -1;
			}

			// Player 1 won
			if (ball.x + ball.w >= SCREEN_WIDTH)
			{
				player1.score += 1;
				scorePlayer1 = loadTextTexture(_itoa(player1.score, buffer, r), textColor);
				resetBall(&ball, "Player 1 won!\n");
			}

			// Player 2 won
			if (ball.x + ball.w <= 0)
			{
				player2.score += 1;
				scorePlayer2 = loadTextTexture(_itoa(player2.score, buffer, r), textColor);
				resetBall(&ball, "Player 2 won!\n");
			}

			ball.x += (int)vel.x * ball.speed;
			ball.y += (int)vel.y * ball.speed;

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

			// Draw objects
			drawPlayers(moveP1, moveP2);
			drawBall(ball);

			// Draw text
			renderTextTexture(scorePlayer1, SCREEN_WIDTH / 4 - scorePlayer1.w / 2, 20);
			renderTextTexture(scorePlayer2, SCREEN_WIDTH * 3 / 4 - scorePlayer2.w / 2, 20);

			// Update screen
			SDL_RenderPresent(renderer);
		}

		closeSDL();
	}

	return 0;
}