📄 baseobject.cpp
字号:
// BaseObject.cpp: implementation of the BaseObject class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Shoot.h"
#include "BaseObject.h"
#include "ShootView.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// 屏幕精灵类实现文件
//////////////////////////////////////////////////////////////////////
//构造函数
//参数:
//x_value:屏幕X坐标
//y_value:屏幕Y坐标
//输出:在屏幕特定位置放置一个对象(具体是什么要看派生类而定)
//注释:各个派生类必须有自己的构造函数。这样才能将实际的物体信息填充到成员变量中
BaseObject::BaseObject(int x_value,int y_value)
{
//初始化屏幕坐标
m_x = x_value;
m_y = y_value;
//初始化贴图坐标和尺寸,都是0。
m_isx = 0;
m_isy = 0;
m_w = 0;
m_h = 0;
//初始化生命力和攻击力
m_iLife = 1;
m_iAttackness = 1;
//是否被抛弃
m_bUsed = true;
//初速度
m_vx = 0;
m_vy = 0;
}
BaseObject::~BaseObject()
{
}
extern CShootApp theApp;
void BaseObject::Update()
{
//获得当前视类指针,以便得到设备文本句柄
CShootView * pView = (CShootView*)((CFrameWnd*)(theApp.m_pMainWnd))->GetActiveView();//->GetActiveView();
if(m_iLife>0)//每一次计时器触发的时候就更新当前坐标
{
m_x += m_vx * pView->GetFPS();
m_y += m_vy * pView->GetFPS();
}
//画出该对象到屏幕
pView->DrawObject(this);
}
bool BaseObject::OutOfSight()
//判断对象是否出界
{
CShootView * pView = (CShootView*)((CFrameWnd*)(theApp.m_pMainWnd))->GetActiveView();
return m_x+m_w<0 || m_y+m_h<0 || m_x>=pView->GetClientWidth() || m_y>=pView->GetClientHeight();
}
//调整对象的坐标,不让他出界
void BaseObject::AdjustPosition()
{
CShootView * pView = new CShootView;
m_x -= m_w / 2;
if( m_x < 0 )
m_x = 0;
else if( m_x + m_w - 1 >= pView->GetClientWidth() )
m_x = pView->GetClientWidth() - m_w;
if( m_y <0 )
m_y = m_y - m_h;
else
m_y -= m_h / 2;
delete pView;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -