Beispiel #1
0
void CDlgGame::OnPaint()
{
	CPaintDC dc(this);

	CClientCmdHandler *pClientCmdHandler = CClientCmdHandler::GetInstancePtr();
	if(pClientCmdHandler == NULL)
	{
		return ;
	}

	CRect rc;
	GetClientRect(&rc);

	dc.FillSolidRect(&rc, RGB(255,255,255));
	
	DrawPlayer(dc.GetSafeHdc(), pClientCmdHandler->m_HostPlayer.m_ObjectPos.x, pClientCmdHandler->m_HostPlayer.m_ObjectPos.z, pClientCmdHandler->m_HostPlayer.m_ObjectStatus.nDir, pClientCmdHandler->m_HostPlayer.m_szObjectName);

	for(CPlayerObjectMgr::iterator itor = pClientCmdHandler->m_PlayerObjMgr.begin(); itor != pClientCmdHandler->m_PlayerObjMgr.end(); ++itor)
	{
		CPlayerObject *pObject = itor->second;

		DrawPlayer(dc.GetSafeHdc(),  pObject->m_ObjectPos.x, pObject->m_ObjectPos.z,pObject->m_ObjectStatus.nDir, pObject->m_szObjectName);

		//DrawItem(dc.GetSafeHdc(), rand()%300,rand()%300);

		//DrawNpc(dc.GetSafeHdc(), rand()%300,rand()%300);
	}

	return ;
}
Beispiel #2
0
void CGame::PlayTurn() {

	int x,y;

	scare_mouse();
	DrawBoard();
	DrawPlayer();
	DrawScores();
	DrawCursor();

	blit(background, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	unscare_mouse();

	while (!players[currplayer].Done()) {

		if (mouse_b & 1) {

			x = mouse_x;
			y = mouse_y;
			players[currplayer].HandleMouse(x,y);
			rest (200); //rest for a bit so it doesnt keep catching mouse clicks
			
			scare_mouse();
			DrawBoard();
			DrawScores(); //shouldnt have to redraw this, but i dont have time to do a decent redraw management system
			if (!players[currplayer].Done())
				DrawPlayer(); //only redraw if not at end of turn
			DrawCursor();
	
			blit(background, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
			unscare_mouse();
		}

		
	}//end while

	players[currplayer].ResetTurnComplete();
		

	//update currplayer

	int oldcurrplayer;
	oldcurrplayer = currplayer;

	do {
		if (currplayer == (numplayers-1)) {  //if currplayer is last in line
			currplayer = 0;
		}
		else {
			currplayer++;
		}

	//stop increment currplayer if the curr isnt playing AND we have gone through the whole list already
	} while (!players[currplayer].stillplaying && currplayer != oldcurrplayer);


}
Beispiel #3
0
void CGame::GameDraw(CDC * pDC)
	{
	m_dcBuffer.CreateCompatibleDC( pDC);
	m_dcImage.CreateCompatibleDC(pDC);
	m_dcMask.CreateCompatibleDC(pDC);

	m_dcBuffer.SelectObject(m_bit[0]);

	//»æÖƱ³¾°
	m_dcImage.SelectObject(m_bit[1]);
	m_dcBuffer.BitBlt(0,0,780,600,&m_dcImage,0,0,SRCCOPY);


	if (m_gameState==FAIPAI)
	{
	 if (m_isShuffle)
	 {
	 m_dcImage.SelectObject(m_bit[3]);
	// m_dcBuffer.BitBlt(250,50,255,164,&m_dcImage,m_imageIndex*255,0,SRCCOPY);
	 m_dcBuffer.TransparentBlt(250,50,255,164,&m_dcImage,m_imageIndex*255,0,255,164,RGB(16,101,148));
	}
	 if (m_isSendCard)
	 {
	 m_dcImage.SelectObject(m_bit[2]);
	 for (int i=0;i<m_cardNums;i++)
		 {
		 m_dcBuffer.BitBlt(150+8*i,20,80-4,105-3,&m_dcImage,80*2+2,105*4+2,SRCCOPY);
		 }
	 }
	 calculateTwoPoint(150+8*m_cardNums,20,m_card[54-m_cardNums].coord_x,m_card[54-m_cardNums].coord_y);
	// m_dcBuffer.BitBlt((m_coor_y-m_b)/m_k,m_coor_y,80,105,&m_dcImage,80*2,4*105,SRCCOPY);
	 m_dcBuffer.TransparentBlt((m_coor_y-m_b)/m_k,m_coor_y,80,105,&m_dcImage,80*2,4*105,80,105,RGB(255,0,255));
	}
//»æÖÆÍæ¼Ò
	DrawPlayer(m_playA);
	DrawPlayer(m_playB);
	DrawPlayer(m_playC);

	

//»æÖƵØÖ÷
	DrawHost();
	
//»æÖÆ°´Å¥Í¼Æ¬
	DrawImageButton();

    DrawSendCard();

	DrawPass();//»æÖÆpass
	pDC->BitBlt(0,0,780,600,&m_dcBuffer,0,0,SRCCOPY);



	m_dcBuffer.DeleteDC();
	m_dcImage.DeleteDC();
	m_dcMask.DeleteDC();
	}
Beispiel #4
0
// Gameplay Screen Draw logic
void DrawGameplayScreen(void)
{
    // TODO: Draw GAMEPLAY screen here!
    
    HideCursor();
    
    // Background
    DrawTextureEx(bg, Vector2Zero(), 0, 10, WHITE);
    
    // Ground
    DrawRectangle(0, groundPositionY, GetScreenWidth(), 1, RED);
   
    DrawPlayer(player);
    
    // Draw triangles 
    for (int i=0; i<maxTriangles; i++)
    {
        if (triangles[i].isActive) DrawObjectOnCameraPosition(triangleTexture, triangles[i].position);
    }
    
    for (int i=0; i<maxPlatforms; i++)
    {
        if (platforms[i].isActive) DrawObjectOnCameraPosition(platformTexture, platforms[i].position);
        //if (platforms[i].isActive) DrawRectangleRec(platforms[i].collider, RED);
    }
    
    if (!startGame) DrawText ("PRESS SPACE", 20, GetScreenHeight()-30, 15, WHITE);
}
Beispiel #5
0
/*******************************************************************************
関数名:	void DrawGame(void)
引数:	なし
戻り値:	なし
説明:	ゲームの描画関数
*******************************************************************************/
void DrawGame(void)
{
	//カメラの設置
	SetCamera();

	//ステージの描画処理
	DrawStageManager();
	DrawMeshDome();
	
	//DrawModel();
	DrawParticle();
	DrawEnemy();
	DrawEnemyBullet();
	DrawItemBullet();

	if( IsDebugMode()) DrawPlayer();
	
	DrawPlayerBullet();
	DrawGun();
	DrawShadow();
	//DrawBillBoard();	

	DrawTime();
	DrawGunSight();
	DrawNumBullet();
	DrawNumLife();
	DrawClock();
	DrawEnemyNum();
}
void RenderingManagerC::update()
{

	

	// Clear the backbuffer to a blue color
	    g_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 
	                         D3DCOLOR_XRGB(0,0,255), 1.0f, 0L );
	
	    // Begin the scene
	    g_pd3dDevice->BeginScene();
	
		DrawBackground();
		DrawPlayer();
		
		DrawRaycast();

		DrawPortal(true);
		DrawPortal(false);

		DrawCrossHair();
		//DrawBox(71.0f, 673.0f, 1218.0f, 673.0f, 0x00000000, 0xFFFFFFFF);
		DrawStaticObjects();

	

		DrawTurrents();
	    // End the scene
	    g_pd3dDevice->EndScene();

		// Present the backbuffer contents to the display
		g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Beispiel #7
0
// Gameplay Screen Draw logic
void DrawAisle01Screen(void)
{
    DrawTexture(background, -scroll, 0, WHITE);
    
    // Draw monsters
	DrawMonster(lamp, scroll);
    DrawMonster(picture, scroll);
    
    // Draw door
    Vector2 doorScrollPos = { doorCenter.position.x - scroll, doorCenter.position.y };
    if (doorCenter.selected) DrawTextureRec(doors, doorCenter.frameRec, doorScrollPos, GREEN);
    else DrawTextureRec(doors, doorCenter.frameRec, doorScrollPos, WHITE);
    
    doorScrollPos = (Vector2){ doorLeft.position.x - scroll, doorLeft.position.y };
    if (doorLeft.selected) DrawTextureRec(doors, doorLeft.frameRec, doorScrollPos, GREEN);
    else DrawTextureRec(doors, doorLeft.frameRec, doorScrollPos, WHITE);
    
    doorScrollPos = (Vector2){ doorRight.position.x - scroll, doorRight.position.y };
    if (doorRight.selected) DrawTextureRec(doors, doorRight.frameRec, doorScrollPos, GREEN);
    else DrawTextureRec(doors, doorRight.frameRec, doorScrollPos, WHITE);
    
    // Draw messsages
    if (msgState < 2) DrawRectangle(0, 40, GetScreenWidth(), 200, Fade(LIGHTGRAY, 0.5f));
    else if (msgState == 2) DrawRectangle(0, 80, GetScreenWidth(), 100, Fade(LIGHTGRAY, 0.5f));

    if (msgState == 0) 
    {
        DrawTextEx(font, msgBuffer, (Vector2){ msgPosX, 80 }, font.baseSize, 2, WHITE);
    }
    else if (msgState == 1)
    {
        DrawTextEx(font, message, (Vector2){ msgPosX, 80 }, font.baseSize, 2, WHITE);
        
        if ((msgCounter/30)%2) DrawText("PRESS ENTER or CLICK", GetScreenWidth() - 280, 200, 20, BLACK);
    }
    else if (msgState == 2)
    {
        if ((msgCounter/30)%2)
        {
            DrawTextEx(font, "CHOOSE WISELY!", (Vector2){ 300, 95 }, font.baseSize*2, 2, WHITE);
            
            DrawRectangleRec(lamp.bounds, Fade(RED, 0.6f));
            DrawRectangleRec(picture.bounds, Fade(RED, 0.6f));
        }
    }
    else
    {
        if ((monsterHover) && ((msgCounter/30)%2))
        {
            DrawRectangle(0, 0, GetScreenWidth(), 50, Fade(LIGHTGRAY, 0.5f));
            DrawText("PRESS SPACE or CLICK to INTERACT", 420, 15, 20, BLACK);
        }
    }

    DrawPlayer();       // NOTE: Also draws mouse pointer!
}
Beispiel #8
0
INT CGpApp::Render()
{
	if(8>m_nSkip)
		return 0;

	m_pDev->SetRenderState(LC_RS_CLEAR_COLOR, 0xFF006699);
	
	m_pDev->BeginScene();	// Prepare Rendering...
	m_pDev->Clear(LC_CLEAR_COLOR_BUFFER | LC_CLEAR_DEPTH_BUFFER);	// Clear Backbuffer

	
	m_pSpt->Begin();				// Sprite Begin

	// Draw Game Play

	DrawBackground();
	DrawMissile();
	DrawShield();
	DrawPlayer();
	DrawEnergyBar();
	DrawPlayerLife();

	m_pFontScore->DrawTxt();

	if(m_bShowSt)
		m_pFont->DrawTxt();




//	LCXRECT	rc;
//	LCXVECTOR2 vcPos;
//
//	vcPos = m_pFont->GetPosition();
//	m_pFont->GetAttrib(LC_FONT_RECT_SCALEUP, &rc);
//	vcPos.x += rc.w;
//
//	m_pFont->GetRect(&rc, 10);
//	vcPos.x = rc.x;
//	vcPos.y = rc.y;
//	m_pFont->DrawTxt(NULL, 0, -1, &vcPos);


	m_pSpt->End();				// Sprite End

	m_pDev->EndScene();			// Post Rendering...


	return LC_OK;
}
Beispiel #9
0
void StageDraw()
{
    DrawMap(map, 0);
    DrawEnemy(map);
    DrawItem(map);
    DrawBomb(map);
    DrawEffect(map);
    DrawPlayer(map);
    
#if !MAP_EDIT_MODE
    DrawTextureObject(res.player_right, 0, 0);
    FontPrintf(32, 16, "x %d", life);
    
    DrawTextureObject(res.font_stage, 128, 16);
    FontPrintf(128 + 16 * 5, 16, "%d", stageNum + 1);

    DrawTextureObject(res.font_score, 128 + 16 * 5 + 32, 16);
    FontPrintf(128 + 16 * 5 + 32 + 16 * 5 + 16 , 16, "%d", score);
    PrintWindow("fps: %d", engineFps);
#endif    
}
Beispiel #10
0
void TesseractWidget::paintGL() {
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(75,aspect,.1,1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(TheWorld->Myself->Position.x,TheWorld->Myself->Position.y,TheWorld->Myself->Position.z,TheWorld->Myself->LookAt.x,TheWorld->Myself->LookAt.y,TheWorld->Myself->LookAt.z,TheWorld->Myself->HeadVector.x,TheWorld->Myself->HeadVector.y,TheWorld->Myself->HeadVector.z);
    emit TheWorld->drawBeginSignal();
    for (QMap<int,Bnode>::iterator it=TheWorld->Blocks.begin(); it!=TheWorld->Blocks.end(); ++it) {
        bool Cancel=0;
        emit TheWorld->drawBlockSignal(it,Cancel);
        if (Cancel==0) {
            if (it.value().PointedAt==0)
                DrawBlock(it.value(),2);
            else
                DrawBlock(it.value(),3);
        }
    }
    if (creatingblock)
        DrawBlock(Bnode(currentblocktype,(TheWorld->Myself->LookAt+tempc)/2,((TheWorld->Myself->LookAt-tempc)/2).Abs()),1);
    for (QMap<int,Player>::iterator it=TheWorld->Players.begin(); it!=TheWorld->Players.end(); ++it)
        if (it!=TheWorld->Myself)
            DrawPlayer(it.value());
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    emit TheWorld->drawDoneSignal();
    SetColor(TheWorld->BlockTypes[currentblocktype].Color);
    renderText(20,20,currentblocktype);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
    glFlush();
}
Beispiel #11
0
void DrawStream(int t)
{
	int i;
	int scr_x = 32;
	int scr_y = 0;
	int strm_scrl;
	SDL_Rect draw_from, draw_to;
	
	for (i = 0; i < 256; i++) {
		ending_pal[i].r = i;
		ending_pal[i].g = (i * 7 / 8) + 16 + sin( (float)t / 8 )*16;
		ending_pal[i].b = (i * 3 / 4) + 32 + sin( (float)t / 8 )*32;
	}
	

	if (t >= 300) {
		scr_x = 32 + rand()%32 - rand()%32;
		scr_y = rand()%8;
	}
	
	if (t < 10) {
		scr_y = (20 - t * 2);
	}
	
	DrawLevel(scr_x, scr_y, 0, 0);
	DrawPlayer(344 - scr_x, 228 - scr_y, 0, 0);
	
	for (i = 0; i < 7; i++) {
		strm_scrl = (t * 20) % 128;
		draw_to.x = 0 - strm_scrl - scr_x + (128*i);
		draw_to.y = 19 - scr_y;
		
		if (i >= 300) {
			draw_to.y += rand()%4;
			draw_to.y -= rand()%4;
		}
		SDL_BlitSurface(streamspr, NULL, screen, &draw_to);
	}
	
	// glitter
	for (i = 0; i < 20; i++) {
		draw_from.x = (rand()%3)*32;
		draw_from.y = 0;
		draw_from.w = 32;
		draw_from.h = 32;
	
		draw_to.x = rand()%(640+32)-32;
		draw_to.y = (rand()%(124)) + 3;
		
		SDL_BlitSurface(glitter, &draw_from, screen, &draw_to);
	}
	
	if (t > 250) {
		if (t < 300) {
			if (t == 251) {
				SND_CircuitRelease(1000);
			}
			DrawCircle(320+32 - scr_x, 240 - scr_y, (t - 254) * 10, 255);
			DrawCircle(320+32 - scr_x, 240 - scr_y, (t - 252) * 10, 225);
			DrawCircle(320+32 - scr_x, 240 - scr_y, (t - 250) * 10, 195);
		}
	}
	
	UpdatePalette();
	VideoUpdate();
}
Beispiel #12
0
static void PlayGame()
{
    Uint8 *keystate;
    int quit = 0;
    int turn;
    int prev_ticks = 0, cur_ticks = 0; /* for keeping track of timing */
    int awaiting_respawn = 0;

    /* framerate counter variables */
    int start_time, end_time;
    int frames_drawn = 0;

    /* respawn timer */
    int respawn_timer = -1;
	
    prev_ticks = SDL_GetTicks();
	
    start_time = time(NULL);

    /* Reset the score counters. */
    player.score = 0;
    opponent.score = 0;

    /* Start sound playback. */
    StartAudio();
    StartMusic();

    /* Start the music update thread. */
    music_update_thread = SDL_CreateThread(UpdateMusicThread, NULL);
    if (music_update_thread == NULL) {
	printf("Unable to start music update thread.\n");
    }

    /* Start the game! */
    while ((quit == 0) && network_ok) {

	/* Determine how many milliseconds have passed since
	   the last frame, and update our motion scaling. */
	prev_ticks = cur_ticks;
	cur_ticks = SDL_GetTicks();
	time_scale = (double)(cur_ticks-prev_ticks)/30.0;
				
	/* Update SDL's internal input state information. */
	SDL_PumpEvents();
		
	/* Grab a snapshot of the keyboard. */
	keystate = SDL_GetKeyState(NULL);

	/* Lock the mutex so we can access the player's data. */
	SDL_LockMutex(player_mutex);
		
	/* If this is a network game, take note of variables
	   set by the network thread. These are handled differently
	   for a scripted opponent. */
	if (opponent_type == OPP_NETWORK) {

	    /* Has the opponent respawned? */
	    if (network_opponent_respawn) {
		printf("Remote player has respawned.\n");
		opponent.shields = 100;
		network_opponent_respawn = 0;
		awaiting_respawn = 0;
	    }
		
	    /* Has the local player been hit? */
	    if (local_player_hit) {
		local_player_hit--;
		player.shields -= PHASER_DAMAGE;
		ShowPhaserHit(&player);
				/* No need to check for death, the
				   other computer will tell us. */
	    }
		}

	/* Update phasers. */
	player.firing -= time_scale;
	if (player.firing < 0) player.firing = 0;
	opponent.firing -= time_scale;
	if (opponent.firing < 0) opponent.firing = 0;
	ChargePhasers(&player);

	/* If the local player is destroyed, the respawn timer will
	   start counting. During this time the controls are disabled
	   and explosion sequence occurs. */
	if (respawn_timer >= 0) {
	    respawn_timer++;

	    if (respawn_timer >= ((double)RESPAWN_TIME / time_scale)) {
		respawn_timer = -1;
		InitPlayer(&player);

				/* Set the local_player_respawn flag so the
				   network thread will notify the opponent
				   of the respawn. */
		local_player_respawn = 1;

		SetStatusMessage("GOOD LUCK, WARRIOR!");
	    }
	}

	/* Respond to input and network events, but not if we're in a respawn. */
	if (respawn_timer == -1) {
	    if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1;
			
	    /* Left and right arrow keys control turning. */
	    turn = 0;
	    if (keystate[SDLK_LEFT]) turn += 10;
	    if (keystate[SDLK_RIGHT]) turn -= 10;
			
	    /* Forward and back arrow keys activate thrusters. */
	    player.accel = 0;
	    if (keystate[SDLK_UP]) player.accel = PLAYER_FORWARD_THRUST;
	    if (keystate[SDLK_DOWN]) player.accel = PLAYER_REVERSE_THRUST;
			
	    /* Spacebar fires phasers. */
	    if (keystate[SDLK_SPACE]) {

		if (CanPlayerFire(&player)) {

		    FirePhasers(&player);

		    /* If it's a hit, either notify the opponent
		       or exact the damage. Create a satisfying particle
		       burst. */
		    if (!awaiting_respawn &&
			CheckPhaserHit(&player,&opponent)) {

			ShowPhaserHit(&opponent);
			DamageOpponent();

			/* If that killed the opponent, set the
			   "awaiting respawn" state, to prevent multiple
			   kills. */
			if (opponent.shields <= 0 &&
			    opponent_type == OPP_NETWORK)
			    awaiting_respawn = 1;
       		    }
		}
	    }
			
	    /* Turn. */
	    player.angle += turn * time_scale;
	    if (player.angle < 0) player.angle += 360;
	    if (player.angle >= 360) player.angle -= 360;

	    /* If this is a network game, the remote player will
	       tell us if we've died. Otherwise we have to check
	       for failed shields. */
	    if (((opponent_type == OPP_NETWORK) && local_player_dead) ||
		(player.shields <= 0))
	    {
		printf("Local player has been destroyed.\n");
		local_player_dead = 0;
				
		/* Kaboom! */
		KillPlayer();
				
		/* Respawn. */
		respawn_timer = 0;
	    }
	}

	/* If this is a player vs. computer game, give the computer a chance. */
	if (opponent_type == OPP_COMPUTER) {
	    if (RunGameScript() != 0) {
		fprintf(stderr, "Ending game due to script error.\n");
		quit = 1;
	    }
			
	    /* Check for phaser hits against the player. */
	    if (opponent.firing) {
		if (CheckPhaserHit(&opponent,&player)) {
					
		    ShowPhaserHit(&player);
		    player.shields -= PHASER_DAMAGE;

		    /* Did that destroy the player? */
		    if (respawn_timer < 0 && player.shields <= 0) {
			KillPlayer();
			respawn_timer = 0;
		    }
		}
	    }

	    ChargePhasers(&opponent);
	    UpdatePlayer(&opponent);
	}

	/* Update the player's position. */
	UpdatePlayer(&player);

	/* Update the status information. */
	SetPlayerStatusInfo(player.score, player.shields, player.charge);
	SetOpponentStatusInfo(opponent.score, opponent.shields);

	/* Make the camera follow the player (but impose limits). */
	camera_x = player.world_x - SCREEN_WIDTH/2;
	camera_y = player.world_y - SCREEN_HEIGHT/2;
		
	if (camera_x < 0) camera_x = 0;
	if (camera_x >= WORLD_WIDTH-SCREEN_WIDTH)
	    camera_x = WORLD_WIDTH-SCREEN_WIDTH-1;
	if (camera_y < 0) camera_y = 0;
	if (camera_y >= WORLD_HEIGHT-SCREEN_HEIGHT)
	    camera_y = WORLD_HEIGHT-SCREEN_HEIGHT-1;

	/* Update the particle system. */
	UpdateParticles();

	/* Keep OpenAL happy. */
	UpdateAudio(&player, &opponent);
				
	/* Redraw everything. */
	DrawBackground(screen, camera_x, camera_y);
	DrawParallax(screen, camera_x, camera_y);
	DrawParticles(screen, camera_x, camera_y);
	if (opponent.firing)
	    DrawPhaserBeam(&opponent, screen, camera_x, camera_y);
	if (player.firing)
	    DrawPhaserBeam(&player, screen, camera_x, camera_y);

	if (respawn_timer < 0)
	    DrawPlayer(&player);
	if (!awaiting_respawn)
	    DrawPlayer(&opponent);
	UpdateStatusDisplay(screen);
		
	/* Release the mutex so the networking system can get it.
	   It doesn't stay unlocked for very long, but the networking
	   system should still have plenty of time. */
	SDL_UnlockMutex(player_mutex);
	
	/* Flip the page. */
	SDL_Flip(screen);

	frames_drawn++;
    }

    end_time = time(NULL);
    if (start_time == end_time) end_time++;

    /* Display the average framerate. */
    printf("Drew %i frames in %i seconds, for a framerate of %.2f fps.\n",
	   frames_drawn,
	   end_time-start_time,
	   (float)frames_drawn/(float)(end_time-start_time));


    /* Terminate the music update thread. */
    if (music_update_thread != NULL) {
	SDL_KillThread(music_update_thread);
	music_update_thread = NULL;
    }
	
    /* Stop audio playback. */
    StopAudio();
    StopMusic();
}
Beispiel #13
0
//renders one frame
void Render(void)
{
   LIST * cur;

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   DrawStarfield(&g_starfield);

   for(cur = g_asteroid_list; cur; cur = cur->next)
      DrawAsteroid(cur->d);

   if(g_ships)
      DrawPlayer(&g_player);
   else
   {
      RenderText(15.2858f, 27.0f, 50.0f, 1.0f, 0.75f, 0.0f, 0.0f, "GAME OVER");

      if(!g_hisct_delay)
      {
         RenderText(13.1906f, 26.0f, 50.0f, 0.5f, 0.75f, 0.5f, 0.5f, "hit F2 to start a new game");
         DrawHiScoreTable(&g_hisct);
      }
   }

   for(cur = g_alien_list; cur; cur = cur->next)
      DrawAlien(cur->d);

   for(cur = g_shot_list; cur; cur = cur->next)
      DrawShot(cur->d);

   for(cur = g_explosion_list; cur; cur = cur->next)
      DrawExplosion(cur->d);

   for(cur = g_burst_list; cur; cur = cur->next)
      DrawBurst(cur->d);

   for(cur = g_powerup_list; cur; cur = cur->next)
      DrawPowerup(cur->d);

   if(g_paused)
   {
      RenderText(0.011792f, 6.0f, 50.0f, 6.36f, 1.0f, 0.5f, 0.5f, "paused");
      RenderText(11.0954f, 4.0f, 50.0f, 1.0f, 1.0f, 0.5f, 0.5f, "(hit p to resume)");
   }

   RenderText(29.3f, 28.7f, 50.0f, 1.0f, 0.75f, 0.75f, 0.75f, "%10d", g_score);
   RenderText(0.1f, 28.7f, 50.0f, 1.0f, 0.75f, 0.75f, 0.75f, "%d", (g_ships ? g_ships - 1 : 0));
   if(g_level < 1000)
   {
      if(g_time_to_reset)
         RenderText(7.9526f, 0.5f, 50.0f, 1.0f, 0.25f, 0.25f, 0.25f, "warping to level %03d...", g_level + 1);
      else if(g_level)
         RenderText(15.2858f, 0.5f, 50.0f, 1.0f, 0.25f, 0.25f, 0.25f, "level %03d", g_level);
   }
   else
      RenderText(13.1906f, 0.5f, 50.0f, 1.0f, 1.0f, 1.0f, 1.0f, "you are a god");

   if(g_ships && g_time_to_reset)
   {
      RenderText(15.2858f, 15.0f, 50.0f, 1.0f, 0.0f, 0.75f, 0.0f, "GOOD JOB!");
      RenderText(14.5001f, 14.0f, 50.0f, 0.5f, 0.5f, 0.75f, 0.5f, "completion bonus: %3d", (g_level > 99 ? 999 : g_level * 10));
   }

   RenderText(0.1f, 0.2f, 0.0f, 0.5f, 0.5f, 0.0f, 0.5f, "%.1ffps", g_fps);

   glFlush();
   glutSwapBuffers();
}
Beispiel #14
0
void View::DrawPlayers(const Model &model) const {
  DrawPlayer(model.player1_top, color_p1);
  DrawPlayer(model.player1_bottom, color_p1);
  DrawPlayer(model.player2_top, color_p2);
  DrawPlayer(model.player2_bottom, color_p2);
}
Beispiel #15
0
static void PlayGame()
{
    Uint8 *keystate;
    int quit = 0;
    int turn;
    int prev_ticks = 0, cur_ticks = 0; /* for keeping track of timing */

    /* framerate counter variables */
    int start_time, end_time;
    int frames_drawn = 0;
	
    /* Start audio playback. */
    StartAudio();
    StartMusic();

    /* Start the music update thread. */
    music_update_thread = SDL_CreateThread(UpdateMusicThread, NULL);
    if (music_update_thread == NULL) {
	printf("Unable to start music update thread.\n");
    }

    prev_ticks = SDL_GetTicks();
    start_time = time(NULL);
	
    while (quit == 0) {
		
	/* Determine how many milliseconds have passed since
	   the last frame, and update our motion scaling. */
		
	prev_ticks = cur_ticks;
	cur_ticks = SDL_GetTicks();
	time_scale = (double)(cur_ticks-prev_ticks)/30.0;
				
	/* Update SDL's internal input state information. */
	SDL_PumpEvents();
		
	/* Grab a snapshot of the keyboard. */
	keystate = SDL_GetKeyState(NULL);
		
	/* Respond to input. */
	if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1;
		
	/* Left and right arrow keys control turning. */
	turn = 0;
	if (keystate[SDLK_LEFT]) turn += 15;
	if (keystate[SDLK_RIGHT]) turn -= 15;
		
	/* Forward and back arrow keys activate thrusters. */
	player.accel = 0;
	if (keystate[SDLK_UP]) player.accel = PLAYER_FORWARD_THRUST;
	if (keystate[SDLK_DOWN]) player.accel = PLAYER_REVERSE_THRUST;
		
	/* Spacebar slows the ship down. */
	if (keystate[SDLK_SPACE]) {
	    player.velocity *= 0.8;
	}
		
	/* Just an amusing way to test the particle system. */
	if (keystate[SDLK_e]) {
	    CreateParticleExplosion(
		player.world_x, player.world_y, 255, 255, 255, 10, 300);
	    CreateParticleExplosion(
		player.world_x, player.world_y, 255, 0, 0, 5, 100);
	    CreateParticleExplosion(
		player.world_x, player.world_y, 255, 255, 0, 2, 50);
	}
		
	/* Allow a turn of four degrees per frame. */
	player.angle += turn * time_scale;
	if (player.angle < 0) player.angle += 360;
	if (player.angle >= 360) player.angle -= 360;

	/* Update the player's position. */
	UpdatePlayer(&player);
	UpdatePlayer(&opponent);

	/* Make the camera follow the player (but impose limits). */
	camera_x = player.world_x - SCREEN_WIDTH/2;
	camera_y = player.world_y - SCREEN_HEIGHT/2;
		
	if (camera_x < 0) camera_x = 0;
	if (camera_x >= WORLD_WIDTH-SCREEN_WIDTH)
	    camera_x = WORLD_WIDTH-SCREEN_WIDTH-1;
	if (camera_y < 0) camera_y = 0;
	if (camera_y >= WORLD_HEIGHT-SCREEN_HEIGHT)
	    camera_y = WORLD_HEIGHT-SCREEN_HEIGHT-1;

	/* Update the particle system. */
	UpdateParticles();
				
	/* Keep OpenAL happy. */
	UpdateAudio(&player, &opponent);
	       
	/* Redraw everything. */
	DrawBackground(screen, camera_x, camera_y);
	DrawParallax(screen, camera_x, camera_y);
	DrawParticles(screen, camera_x, camera_y);
	DrawPlayer(&player);
	DrawPlayer(&opponent);
	
	/* Flip the page. */
	SDL_Flip(screen);

	frames_drawn++;

    }

    end_time = time(NULL);
    if (start_time == end_time) end_time++;

    /* Display the average framerate. */
    printf("Drew %i frames in %i seconds, for a framerate of %.2f fps.\n",
	   frames_drawn,
	   end_time-start_time,
	   (float)frames_drawn/(float)(end_time-start_time));

    /* Terminate the music update thread. */
    if (music_update_thread != NULL) {
	SDL_KillThread(music_update_thread);
	music_update_thread = NULL;
    }
	
    /* Stop audio playback. */
    StopAudio();
    StopMusic();

}
Beispiel #16
0
void display() {
  float x, z;
  float deltaTime;
  float p2Speed = 0.20f;
  float stepX, stepZ;
  int i = 0;
  Vec chase;
  Vec move;
  float len = 0;

  now_t = glutGet(GLUT_ELAPSED_TIME);
  deltaTime = (now_t - prev_t) / 1000.0f;
  prev_t = now_t;  

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();

  glPushMatrix();
    gluLookAt (rotateX, rotateY, startZ + rotateZ,
               0.0, 0.0, 0.0,
               0.0, 1.0, 0.0);

    glRotatef(10, 0, 1, 0);
    glRotatef(20, 1, 0, 0);
    drawLines();

    stepX = 0.08f;
    stepZ = 0.08f;    

    //Draw surface 
    for (z = -1; z < 0.99; z += stepZ) {
      for (x = -1; x < 0.99f; x += stepX) {

        if ((i++) % 2) { 		
          dSquare( x, 	       0.0f, z, 
                   x + stepX,  0.0f, z, 	
                   x + stepX,  0.0f, z + stepZ,
                   x,  	       0.0f, z + stepZ,
                   1.0f, 1.0f, 1.0f,
                   1.0f, 1.0f, 1.0f,
                   1.0f, 1.0f, 1.0f,
                   1.0f, 1.0f, 1.0f);
        } else {
 	  dSquare( x, 	       0.0f, z, 
                   x + stepX,  0.0f, z, 	
                   x + stepX,  0.0f, z + stepZ,
                   x,  	       0.0f, z + stepZ,
                   1.0f, 0.0f, 0.0f,
                   1.0f, 0.0f, 0.0f,
                   1.0f, 0.0f, 0.0f,
                   1.0f, 0.0f, 0.0f);
        } 
     }
  }  
  glPopMatrix();

  glPushMatrix();
    gluLookAt (rotateX, rotateY, startZ + rotateZ,
               0.0, 0.0, 0.0,
               0.0, 1.0, 0.0);

    glRotatef(10, 0, 1, 0);
    glRotatef(20, 1, 0, 0);

    chase.x = pCurr[1].x - pCurr[2].x;
    chase.y = pCurr[1].y - pCurr[2].y;
    chase.z = pCurr[1].z - pCurr[2].z;

    len = sqrt((chase.x * chase.x) + (chase.y * chase.y) + 
	       (chase.z * chase.z)); 

    //Normalize vector
    move.x = chase.x / len;
    move.y = chase.y / len;
    move.z = chase.z / len;

    pCurr[2].x += (move.x * p2Speed) * deltaTime; 
    pCurr[2].y += (move.y * p2Speed) * deltaTime; 
    pCurr[2].z += (move.z * p2Speed) * deltaTime;

    glTranslatef(pCurr[2].x - p[2].x,  
		 pCurr[2].y - p[2].y,
		 pCurr[2].z - p[2].z);
    DrawPlayer(&player2);

  glPopMatrix();

  glPushMatrix();
    gluLookAt (rotateX, rotateY, startZ + rotateZ,
               0.0, 0.0, 0.0,
               0.0, 1.0, 0.0);

    glRotatef(10, 0, 1, 0);
    glRotatef(20, 1, 0, 0);
  
    glTranslatef(pCurr[1].x, pCurr[1].y, pCurr[1].z);
    DrawPlayer(&player1);
  glPopMatrix();

  glFlush();
  glutSwapBuffers();

  glutPostRedisplay();
}
Beispiel #17
0
void CAutomap::DrawObjects (void)
{
if (!((gameOpts->render.automap.bTextured & 2) || m_bRadar))
	return;
int color = IsTeamGame ? GetTeam (gameData.multiplayer.nLocalPlayer) : gameData.multiplayer.nLocalPlayer;	// Note link to above if!
CCanvas::Current ()->SetColorRGBi (RGBA_PAL2 (playerColors [color].red, playerColors [color].green, playerColors [color].blue));
int bTextured = (gameOpts->render.automap.bTextured & 1) && !m_bRadar;
if (bTextured) {
	glDisable (GL_CULL_FACE);
	glEnable (GL_BLEND);
	gameStates.render.grAlpha = 0.5f;
	}
glDisable (GL_TEXTURE_2D);
glLineWidth (2 * GLfloat (screen.Width ()) / 640.0f);
DrawPlayer (OBJECTS + LOCALPLAYER.nObject);
if (!m_bRadar) {
	DrawMarkers ();
	if ((gameData.marker.nHighlight > -1) && (gameData.marker.szMessage [gameData.marker.nHighlight][0] != 0)) {
		char msg [10 + MARKER_MESSAGE_LEN + 1];
		sprintf (msg, TXT_MARKER_MSG, gameData.marker.nHighlight + 1,
					gameData.marker.szMessage [(gameData.multiplayer.nLocalPlayer * 2) + gameData.marker.nHighlight]);
		CCanvas::Current ()->SetColorRGB (196, 0, 0, 255);
		fontManager.SetCurrent (SMALL_FONT);
		GrString (5, 20, msg, NULL);
		}
	}
// Draw player(s)...
if (AM_SHOW_PLAYERS) {
	for (int i = 0; i < gameData.multiplayer.nPlayers; i++) {
		if ((i != gameData.multiplayer.nLocalPlayer) && AM_SHOW_PLAYER (i)) {
			if (OBJECTS [gameData.multiplayer.players [i].nObject].info.nType == OBJ_PLAYER) {
				color = (gameData.app.nGameMode & GM_TEAM) ? GetTeam (i) : i;
				CCanvas::Current ()->SetColorRGBi (RGBA_PAL2 (playerColors [color].red, playerColors [color].green, playerColors [color].blue));
				if (bTextured)
					glEnable (GL_BLEND);
				DrawPlayer (OBJECTS + gameData.multiplayer.players [i].nObject);
				}
			}
		}
	}

if (bTextured)
	glEnable (GL_BLEND);

CObject* objP = OBJECTS.Buffer ();
g3sPoint	spherePoint;

FORALL_OBJS (objP, i) {
	int size = objP->info.xSize;
	switch (objP->info.nType) {
		case OBJ_HOSTAGE:
			CCanvas::Current ()->SetColorRGBi (m_colors.nHostage);
			G3TransformAndEncodePoint (&spherePoint, objP->info.position.vPos);
			G3DrawSphere (&spherePoint,size, !m_bRadar);
			break;

		case OBJ_MONSTERBALL:
			CCanvas::Current ()->SetColorRGBi (m_colors.nMonsterball);
			G3TransformAndEncodePoint (&spherePoint, objP->info.position.vPos);
			G3DrawSphere (&spherePoint,size, !m_bRadar);
			break;

		case OBJ_ROBOT:
			if (AM_SHOW_ROBOTS && ((gameStates.render.bAllVisited && bTextured) || m_visited [0][objP->info.nSegment])) {
				static int t = 0;
				static int d = 1;
				int h = SDL_GetTicks ();
				if (h - t > 333) {
					t = h;
					d = -d;
					}
				float fScale = float (h - t) / 333.0f;
				if (ROBOTINFO (objP->info.nId).companion) {
					if (d < 0)
						CCanvas::Current ()->SetColorRGB (0, 123 - int ((123 - 78) * fScale + 0.5f), 151 - int ((151 - 112) * fScale + 0.5f), 255);
					else
						CCanvas::Current ()->SetColorRGB (0, 78 + int ((123 - 78) * fScale + 0.5f), 122 + int ((151 - 112) * fScale + 0.5f), 255);
					}
				else {
					if (d < 0)
						CCanvas::Current ()->SetColorRGB (123 - int ((123 - 78) * fScale + 0.5f), 0, 135 - int ((135 - 96) * fScale + 0.5f), 255);
					else
						CCanvas::Current ()->SetColorRGB (78 + int ((123 - 78) * fScale + 0.5f), 0, 96 + int ((135 - 96) * fScale + 0.5f), 255);
					}
				G3TransformAndEncodePoint (&spherePoint, objP->info.position.vPos);
				//transformation.Begin (&objP->info.position.vPos, &objP->info.position.mOrient);
				G3DrawSphere (&spherePoint, bTextured ? size : (size * 3) / 2, !m_bRadar);
				//transformation.End ();
				}
			break;

		case OBJ_POWERUP:
			switch (objP->info.nId) {
				case POW_KEY_RED:
					CCanvas::Current ()->SetColorRGBi (RGBA_PAL2 (63, 5, 5));
					size *= 4;
					break;
				case POW_KEY_BLUE:
					CCanvas::Current ()->SetColorRGBi (RGBA_PAL2 (5, 5, 63));
					size *= 4;
					break;
				case POW_KEY_GOLD:
					CCanvas::Current ()->SetColorRGBi (RGBA_PAL2 (63, 63, 10));
					size *= 4;
					break;
				default:
					if (!(AM_SHOW_POWERUPS (1) && (gameStates.render.bAllVisited || m_visited [0][objP->info.nSegment])))
						continue;
					CCanvas::Current ()->SetColorRGBi (ORANGE_RGBA); //orange
					break;
				}
			G3TransformAndEncodePoint (&spherePoint, objP->info.position.vPos);
			G3DrawSphere (&spherePoint, size, !m_bRadar);
			break;
		}
	}
void __fastcall DrawPlayer2(TCanvas3D *ACanvas, int x, int y, int z)
{
  DrawPlayer(ACanvas,x,y,z, clWhite,clLime,clRed,clYellow);
}
void __fastcall DrawPlayer1(TCanvas3D *ACanvas, int x, int y, int z)
{
  DrawPlayer(ACanvas,x,y,z, clNavy,clBlue,clMaroon,TColor(RGB(231,116,118)));
}