【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-BOMBER.CPP,希望本篇文章对您学习有所帮助。
/*****************************************************************************
*
* Bomber.cpp
*
* Electrical Engineering Faculty - Software Lab
* Spring semester 1998
*
* Tanks game
*
* Module description: Implements the bomber object. That's a unique game
* object - when in use it catches the keyboard input,
* enabling the player to position and direct it on board,
* and afterward when launched it acts like the other
* moving game objects.
*
*
* Authors: Eran Yariv - 28484475
* Moshe Zur - 24070856
*
*
* Date: 23/09/98
*
******************************************************************************/
#include <stdafx.h>
#include <bomber.h>
#include <Bomb.h>
/*------------------------------------------------------------------------------
Function: Constructor
Purpose: Contructs the bomber on a local machine (enabling player to control
the start position and direction).
Input: pParent - pointer to the tank that owns (launches) the bomber.
Output: None.
Remarks:
------------------------------------------------------------------------------*/
CBomber::CBomber (CTankObj *pParent) :
CMovingGameObject (MAP_WIDTH - BOMBER_WIDTH / 2, // XPos
MAP_HEIGHT / 2 - BOMBER_HEIGHT / 2, // YPos
BOMBER_WIDTH, // XSize
BOMBER_HEIGHT, // YSize
0, // Direction index
BOMBER_SPEED), // Velocity
m_pFather (pParent),
m_bLocal (TRUE),
m_MsgQueue(TANKS_APP->m_gIncomingMsgQueue),
m_Timer(TANKS_APP->m_gTimer),
m_dwLastMoveTick (0),
m_State (BOMBER_STATE_SETUP),
m_uEdgePos (UINT(1.5 * float (EDGE_TICKS)))
{
m_hImage = m_GlobalImageManager.GetImage (CImageManager::IMG_BOMBER);
if (!m_GlobalObjsList.IsObjectValid(m_pFather))
{
// Father tank is dead now
m_pFather = NULL;
m_State = BOMBER_STATE_DEAD;
m_pManouverSet = NULL;
}
else
{ // Wa have a legal father tank
m_pManouverSet = &m_pFather->GetManouverSet();
m_pFather->RelinquishInput();
}
}
/*------------------------------------------------------------------------------
Function: Constructor
Purpose: Contructs the bomber on a remote machine (a player on another
machine was launching the bomber, we are only displaying it).
Input: uDirInd - the bombers direction
uXPos,uYPos - the bombers position
dwInitFlightTime - the game time the bomber was launched
Output: None.
Remarks:
------------------------------------------------------------------------------*/
CBomber::CBomber ( UINT uDirInd,
UINT uXPos,
UINT uYPos,
DWORD dwInitFlightTime) :
CMovingGameObject (uXPos, // XPos
uYPos, // YPos
BOMBER_WIDTH, // XSize
BOMBER_HEIGHT, // YSize
uDirInd, // Direction index
BOMBER_SPEED), // Velocity
m_pFather (NULL),
m_bLocal (FALSE),
m_MsgQueue(TANKS_APP->m_gIncomingMsgQueue),
m_Timer(TANKS_APP->m_gTimer),
m_dwLastMoveTick (dwInitFlightTime),
m_State (BOMBER_STATE_FLYING),
m_pManouverSet (NULL),
m_dwInitialTime (dwInitFlightTime),
m_InitialPos (CPoint (uXPos, uYPos))
{
m_hImage = m_GlobalImageManager.GetImage (CImageManager::IMG_BOMBER);
m_GlobalImageManager.RotateImage (m_hImage, m_uDirectionIndex);
}
CPoint
CBomber::CalcEdgePos ()
{
CPoint res;
ASSERT (m_uEdgePos < (4 * EDGE_TICKS));
if (((m_uEdgePos >= (3 * EDGE_TICKS)) &&
(m_uEdgePos <= (4 * EDGE_TICKS - 1))) ||
(0 == m_uEdgePos))
// Left pane
res.x = - BOMBER_WIDTH / 2;
else if ((m_uEdgePos >= EDGE_TICKS) && (m_uEdgePos <= (2 * EDGE_TICKS)))
// Right pane
res.x = MAP_WIDTH - BOMBER_WIDTH / 2;
else if ((m_uEdgePos >= 1) && (m_uEdgePos <= (EDGE_TICKS - 1)))
// Top pane
res.x = ((MAP_WIDTH / EDGE_TICKS) * m_uEdgePos) - BOMBER_WIDTH / 2;
else if ((m_uEdgePos >= (2 * EDGE_TICKS + 1)) &&
(m_uEdgePos <= (3 * EDGE_TICKS - 1)))
// Bottom pane
res.x = ((MAP_WIDTH / EDGE_TICKS) * ((3 * EDGE_TICKS) - m_uEdgePos)) -
BOMBER_WIDTH / 2;
if ((m_uEdgePos >= (3 * EDGE_TICKS + 1)) &&
(m_uEdgePos <= (4 * EDGE_TICKS - 1)))
// Left pane
res.y = ((MAP_HEIGHT / EDGE_TICKS) *
(m_uEdgePos - (3 * EDGE_TICKS))) - BOMBER_HEIGHT / 2;
else if ((m_uEdgePos >= (EDGE_TICKS + 1)) &&
(m_uEdgePos <= (2 * EDGE_TICKS - 1)))
// Right pane
res.y = ((MAP_HEIGHT / EDGE_TICKS) * ((2 * EDGE_TICKS) - m_uEdgePos)) -
BOMBER_HEIGHT / 2;
else if ((m_uEdgePos >= 0) && (m_uEdgePos <= EDGE_TICKS))
// Top pane
res.y = MAP_HEIGHT - BOMBER_HEIGHT / 2;
else if ((m_uEdgePos >= (2 * EDGE_TICKS)) &&
(m_uEdgePos <= (3 * EDGE_TICKS)))
// Bottom pane
res.y = - BOMBER_HEIGHT / 2;
return res;
}
void
CBomber::FixEdgeDirection ()
{
BOOL bTop = (m_uEdgePos >= 0) && (m_uEdgePos <= EDGE_TICKS),
bLeft = ((m_uEdgePos >= (3 * EDGE_TICKS)) && (m_uEdgePos <= (4 * EDGE_TICKS - 1))) || (0 == m_uEdgePos),
bRight = (m_uEdgePos >= EDGE_TICKS) && (m_uEdgePos <= (2 * EDGE_TICKS)),
BBottom = (m_uEdgePos >= (2 * EDGE_TICKS)) && (m_uEdgePos <= (3 * EDGE_TICKS));
ASSERT (m_uEdgePos < (4 * EDGE_TICKS));
ASSERT (m_uDirectionIndex < MAX_DIRECTIONS);
UINT u90Deg = MAX_DIRECTIONS / 4;
if (bTop && (m_uDirectionIndex < (2 * u90Deg + 1)))
{ // fix dir
if (m_uDirectionIndex < u90Deg)
m_uDirectionIndex = (MAX_DIRECTIONS - 1);
else
m_uDirectionIndex = 2 * u90Deg + 1;
}
if (bLeft && ((m_uDirectionIndex < (u90Deg + 1)) || (m_uDirectionIndex > (3 * u90Deg - 1))))
{ // fix dir
if (m_uDirectionIndex < (u90Deg + 1))
m_uDirectionIndex = u90Deg + 1;
else
m_uDirectionIndex = (3 * u90Deg - 1);
}
if (bRight && (m_uDirectionIndex < (3 * u90Deg + 1)) && (m_uDirectionIndex > (u90Deg - 1)))
{ // fix dir
if (m_uDirectionIndex < (2 * u90Deg))
m_uDirectionIndex = u90Deg - 1;
else
m_uDirectionIndex = (3 * u90Deg + 1);
}
if (BBottom && ((m_uDirectionIndex > (2 * u90Deg - 1)) || (m_uDirectionIndex < 1)))
{ // fix dir
if (0 == m_uDirectionIndex)
m_uDirectionIndex = 1;
else if (m_uDirectionIndex < (3 * u90Deg))
m_uDirectionIndex = 2 * u90Deg - 1;
else
m_uDirectionIndex = 1;
}
}
StateType
CBomber::CalcState (DWORD dwCurTime)
{
m_bImageChanged = FALSE; // Assume no change since last CalcState
if (BOMBER_STATE_DEAD == m_State)
return STATE_DEAD;
if (BOMBER_STATE_FLYING == m_State)
{ // Flying now
int iD
上一篇:
BOMB.CPP
下一篇:
汝康皮肤护理液医治烧伤的可行性和效果分析