📄 plane.cpp
字号:
// Plane.cpp: implementation of the CPlane class.
//
/**///////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Plane.h"
//------------------------------------------------------------------
//Macro define
//The radius of the plane
#define PLANE_RADIUS 4
/**///////////////////////////////////////////////////////////////////////
// Construction/Destruction
/**///////////////////////////////////////////////////////////////////////
CPlane::CPlane()
{
memset(&m_ptPos,0,sizeof(m_ptPos));
memset(&m_rcWndPlay,0,sizeof(m_rcWndPlay));
}
CPlane::~CPlane()
{
}
//--------------------------------------------------------------------
//Description:
// Draw the plane normal status to the DC
//---------------------------------------------------------------------
void CPlane::DrawNormal(HDC hdc)
{
HBRUSH hBrush = CreateSolidBrush(RGB(0,255,0));
HGDIOBJ hOldSel = SelectObject(hdc,hBrush);
Ellipse(hdc,
m_ptPos.x - PLANE_RADIUS,
m_ptPos.y - PLANE_RADIUS,
m_ptPos.x + PLANE_RADIUS,
m_ptPos.y + PLANE_RADIUS);
SelectObject(hdc,hOldSel);
DeleteObject(hBrush);
}
//--------------------------------------------------------------------
//Description:
// Draw the plane destroy status to the DC
//---------------------------------------------------------------------
void CPlane::DrawDestroy(HDC hdc)
{
HBRUSH hBrush = CreateSolidBrush(RGB(255,0,0));
HGDIOBJ hOldSel = SelectObject(hdc,hBrush);
Ellipse(hdc,
m_ptPos.x - PLANE_RADIUS,
m_ptPos.y - PLANE_RADIUS,
m_ptPos.x + PLANE_RADIUS,
m_ptPos.y + PLANE_RADIUS);
SelectObject(hdc,hOldSel);
DeleteObject(hBrush);
}
//--------------------------------------------------------------------
//Description:
// Set current position
//---------------------------------------------------------------------
void CPlane::SetCurrentPos(const LPPOINT lppt)
{
m_ptPos = *lppt;
}
//--------------------------------------------------------------------
//Description:
// Get the current rect of plane
//---------------------------------------------------------------------
void CPlane::GetCurrentRect(RECT *lprcOut)
{
lprcOut->left = m_ptPos.x - PLANE_RADIUS;
lprcOut->top = m_ptPos.y - PLANE_RADIUS;
lprcOut->right = m_ptPos.x + PLANE_RADIUS;
lprcOut->bottom = m_ptPos.y + PLANE_RADIUS;
}
//--------------------------------------------------------------------
//Description:
// Move the distance base on the current position
//---------------------------------------------------------------------
void CPlane::Move(int iX, int iY)
{
m_ptPos.x += iX;
m_ptPos.y += iY;
if(m_ptPos.x < m_rcWndPlay.left)
{
m_ptPos.x = 0;
}
if(m_ptPos.x > m_rcWndPlay.right)
{
m_ptPos.y = m_rcWndPlay.right;
}
if(m_ptPos.y < m_rcWndPlay.top)
{
m_ptPos.y = m_rcWndPlay.top;
}
if(m_ptPos.y > m_rcWndPlay.bottom)
{
m_ptPos.y = m_rcWndPlay.bottom;
}
}
//--------------------------------------------------------------------
//Description:
// Get the current position of plane
//---------------------------------------------------------------------
void CPlane::GetCurrentPos(LPPOINT lpptOut)
{
*lpptOut = m_ptPos;
}
//--------------------------------------------------------------------
//Description:
// Initialize the playing window
//---------------------------------------------------------------------
void CPlane::Initialize(const RECT *lprcWndPlay)
{
m_rcWndPlay = *lprcWndPlay;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -