📄 gameobject.cpp
字号:
// ***************************************************************
// GameObject version: 1.0
// -------------------------------------------------------------
// File Name: GameObject.cpp
// Created: 2007/07/18
// Modified: 2007/07/18 15:28
// Author: William.Liang
// Msn: lwq49@msn.com
// Email: lwq49@21cn.com, lwq49@msn.com
// Description:
//
// Purpose:
// -------------------------------------------------------------
// license:
//
// The contents of this file are subject to the Mozilla Public
// License Version 1.1 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy
// of the License at http://www.mozilla.org/MPL/ Software dis-
// tributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or im-
// plied. See the License for the specific language governing
// rights and limitations under the License.
//
// The Initial Developer of the Original Code is William.Liang .
// Copyright (C) 2007 - All Rights Reserved.
// ***************************************************************
#include "StdAfx.h"
#include ".\Gameobject.h"
//#include "..\FrameCom\FrameCom.h"
//************************************
// <p>Description: 构造函数</p>
//************************************
CGameObject::CGameObject(void)
{
m_pParent = NULL;
m_lpGDI = NULL;
m_enGameType = Type_Unknow;
ZeroMemory(m_szName, MAX_NAME);
ZeroMemory(&m_BasalInfo, sizeof(m_BasalInfo));
ZeroMemory(&m_GameBasalInfo, sizeof(m_GameBasalInfo));
m_GameBasalInfo.Scaling.cx = 1;
m_GameBasalInfo.Scaling.cy = 1;
m_GameBasalInfo.Alpha = 0xFF;
m_BasalInfo.Visabled = true;
m_BasalInfo.Disabled = true;
m_BasalInfo.Clickabled = true;
m_bClipping = false;
}
//************************************
// <p>Description: 析构函数</p>
//************************************
CGameObject::~CGameObject(void)
{
//Release();
}
//************************************
// <p>Description: 求区域</p>
//************************************
void CGameObject::CalcRotateRegion(){
//float fAngle = m_GameBasalInfo.Angle*180/M_PI;
//float fCosAngle = cos(fAngle);
//float fSinAngle = sin(fAngle);
float fCosAngle = cos(m_GameBasalInfo.Angle);
float fSinAngle = sin(m_GameBasalInfo.Angle);
//求旋转后的4个坐标点
_POINT piPos[4];
//设置旧的4个坐标点
piPos[0] = piPos[1] = piPos[2] = piPos[3] = m_BasalInfo.LocalPos;
piPos[1].x += m_BasalInfo.Size.cx;
piPos[2].x += m_BasalInfo.Size.cx; piPos[2].y += m_BasalInfo.Size.cy;
piPos[3].y += m_BasalInfo.Size.cy;
//中心点
_POINT piCenter;
piCenter = piPos[0];
piCenter = piCenter+m_BasalInfo.AnchorPos;
//旋转点的距离
_SIZE siDistance[4];
for(int i=0;i<4;i++){
siDistance[i].cx = piPos[i].x - piCenter.x;
siDistance[i].cy = piPos[i].y - piCenter.y;
//求旋转后新位置
piPos[i].x = piCenter.x + siDistance[i].cx*fCosAngle - siDistance[i].cy*fSinAngle;
piPos[i].y = piCenter.y + siDistance[i].cx*fSinAngle + siDistance[i].cy*fCosAngle;
}
//求最小X,Y 和 最大X,Y
_POINT piMin = piPos[0];
_POINT piMax = piPos[0];
for(int i=1;i<4;i++){
if(piMin.x > piPos[i].x) piMin.x = piPos[i].x;
if(piMin.y > piPos[i].y) piMin.y = piPos[i].y;
if(piMax.x < piPos[i].x) piMax.x = piPos[i].x;
if(piMax.y < piPos[i].y) piMax.y = piPos[i].y;
}
m_GameBasalInfo.Region.left = piMin.x;
m_GameBasalInfo.Region.top = piMin.y;
m_GameBasalInfo.Region.right = piMax.x;
m_GameBasalInfo.Region.bottom = piMax.y;
NotifiyChange();
}
//************************************
// <p>Description: 设置父对象</p>
// <p>Parameters: </p>
// <p> IUnknownEx * pIUnknownEx</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetParent(IUnknownEx* pIUnknownEx){
m_pParent = pIUnknownEx;
}
//************************************
// <p>Description: 返回父对象</p>
// <p>Parameters: </p>
//
// <p>Returns: IUnknownEx*</p>
//************************************
IUnknownEx* CGameObject::GetParent(){
return m_pParent;
}
//************************************
// <p>Description: 移动对象</p>
// <p>Parameters: </p>
// <p> _POINT piPoint</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::MoveTo(_POINT piPoint){
//重置区域位置
m_GameBasalInfo.Region = m_GameBasalInfo.Region + (piPoint-m_BasalInfo.LocalPos);
m_BasalInfo.LocalPos = piPoint;
m_BasalInfo.ScreenPos.x = m_BasalInfo.LocalPos.x + m_BasalInfo.ContainerPos.x;// - m_BasalInfo.AnchorPos.x;
m_BasalInfo.ScreenPos.y = m_BasalInfo.LocalPos.y + m_BasalInfo.ContainerPos.y;// - m_BasalInfo.AnchorPos.y;
NotifiyChange();
}
//************************************
// <p>Description: 移动对象</p>
// <p>Parameters: </p>
// <p> _POINT piPoint</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::MoveToOffset(_POINT piPoint){
//重置区域位置
m_GameBasalInfo.Region = m_GameBasalInfo.Region + piPoint;
m_BasalInfo.LocalPos.x += piPoint.x;
m_BasalInfo.LocalPos.y += piPoint.y;
m_BasalInfo.ScreenPos.x = m_BasalInfo.LocalPos.x + m_BasalInfo.ContainerPos.x;// - m_BasalInfo.AnchorPos.x;
m_BasalInfo.ScreenPos.y = m_BasalInfo.LocalPos.y + m_BasalInfo.ContainerPos.y;// - m_BasalInfo.AnchorPos.y;
NotifiyChange();
}
//************************************
// <p>Description: 返回对象坐标相对于屏幕</p>
// <p>Parameters: </p>
//
// <p>Returns: _POINT</p>
//************************************
_POINT CGameObject::GetScreenPosition(){
return m_BasalInfo.ScreenPos;
}
//************************************
// <p>Description: 返回对象相对于容器的坐标</p>
// <p>Parameters: </p>
//
// <p>Returns: _POINT</p>
//************************************
_POINT CGameObject::GetLocalPosition(){
return m_BasalInfo.LocalPos;
}
//************************************
// <p>Description: 返回对象容器坐标</p>
// <p>Parameters: </p>
//
// <p>Returns: _POINT</p>
//************************************
_POINT CGameObject::GetContainerPosition(){
return m_BasalInfo.ContainerPos;
}
//************************************
// <p>Description: 返回中心点</p>
// <p>Parameters: </p>
//
// <p>Returns: _POINT</p>
//************************************
_POINT CGameObject::GetAnchorPosition(){
return m_BasalInfo.AnchorPos;
}
//************************************
// <p>Description: 计算容器坐标</p>
// <p>Parameters: </p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::CalcContainerPosition(){
//设置上一级的容器坐标
if(m_pParent!=NULL){
IBaseObject* pIBaseObject = GET_OBJECTPTR_INTERFACE(m_pParent, IBaseObject);
if(pIBaseObject){
m_BasalInfo.ContainerPos = pIBaseObject->GetScreenPosition();
//if(pIBaseObject->GetObjectType()==Type_Group){
// //重置相对容器的位置
// m_BasalInfo.LocalPos.x += m_BasalInfo.ContainerPos.x;
// m_BasalInfo.LocalPos.y += m_BasalInfo.ContainerPos.y;
//}
m_BasalInfo.ScreenPos.x = m_BasalInfo.LocalPos.x + m_BasalInfo.ContainerPos.x;
m_BasalInfo.ScreenPos.y = m_BasalInfo.LocalPos.y + m_BasalInfo.ContainerPos.y;
}
}
}
//************************************
// <p>Description: 屏幕坐标转本地坐标</p>
// <p>Parameters: </p>
//
// <p>Returns: void</p>
//************************************
_POINT CGameObject::ScreenToLocal(_POINT piScreen){
return piScreen - GetContainerPosition() - m_BasalInfo.LocalPos;
}
//************************************
// <p>Description: 本地坐标转屏幕坐标</p>
// <p>Parameters: </p>
//
// <p>Returns: void</p>
//************************************
_POINT CGameObject::LocalToScreen(_POINT piLocal){
return m_BasalInfo.ContainerPos + m_BasalInfo.LocalPos + piLocal;
}
//************************************
// <p>Description: 设置名字</p>
// <p>Parameters: </p>
// <p> LPCTSTR lpName</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetObjectName(LPCTSTR lpName){
strcpy(m_szName, lpName);
}
//************************************
// <p>Description: 获取名字</p>
// <p>Parameters: </p>
//
// <p>Returns: LPCTSTR</p>
//************************************
LPCTSTR CGameObject::GetObjectName(){
return m_szName;
}
//设置类型
void CGameObject::SetObjectType(enGameObjectType enGameObjectType){
m_enGameType = enGameObjectType;
}
//************************************
// <p>Description: 返回类型</p>
// <p>Parameters: </p>
//
// <p>Returns: enGameObjectType</p>
//************************************
enGameObjectType CGameObject::GetObjectType(){
return m_enGameType;
}
//************************************
// <p>Description: 设置缓冲类型</p>
// <p>Parameters: </p>
// <p> WORD wType</p>
//************************************
void CGameObject::SetCacheType(WORD wType){
}
//************************************
// <p>Description: 返回缓冲类型</p>
//
// <p>Returns: WORD</p>
//************************************
WORD CGameObject::GetCacheType(){
return 0;
}
//************************************
// <p>Description: 对象创建</p>
// <p>Parameters: </p>
// <p> LPCTSTR lpName</p>
// <p> _SIZE siSize</p>
// <p> enGameObjectType enType</p>
// <p> ...</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameObject::Create(LPCTSTR lpName, _SIZE siSize, enGameObjectType enType, ...){
SetObjectName(lpName);
SetSize(siSize);
m_enGameType = enType;
return true;
}
//************************************
// <p>Description: 设置可视</p>
// <p>Parameters: </p>
// <p> bool bFlag</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetVisabled(bool bFlag){
m_BasalInfo.Visabled = bFlag;
NotifiyChange();
}
//************************************
// <p>Description: 设置禁用</p>
// <p>Parameters: </p>
// <p> bool bFlag</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetDisabled(bool bFlag){
m_BasalInfo.Disabled = bFlag;
NotifiyChange();
}
//************************************
// <p>Description: 设置点击</p>
// <p>Parameters: </p>
// <p> bool bFlag</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetClickabled(bool bFlag){
m_BasalInfo.Clickabled = bFlag;
}
//************************************
// <p>Description: 是否可视</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameObject::IsVisabled(){
return m_BasalInfo.Visabled;
}
//************************************
// <p>Description: 是否禁用</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameObject::IsDisabled(){
return m_BasalInfo.Disabled;
}
//************************************
// <p>Description: 是否可点击</p>
//
// <p>Returns: bool</p>
//************************************
bool CGameObject::IsClickabled(){
return m_BasalInfo.Clickabled;
}
//************************************
// <p>Description: 设置角度</p>
// <p>Parameters: </p>
// <p> float fAngle</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetAngle(float fAngle){
m_GameBasalInfo.Angle = fAngle*M_PI/180.0f;
CalcRotateRegion();
}
//************************************
// <p>Description: 设置角度</p>
// <p>Parameters: </p>
// <p> float fAngle</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetAngleOffset(float fAngle){
m_GameBasalInfo.Angle += fAngle*M_PI/180.0f;
CalcRotateRegion();
}
//************************************
// <p>Description: 设置透明</p>
// <p>Parameters: </p>
// <p> WORD wAlpha</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetAlpha(WORD wAlpha){
m_GameBasalInfo.Alpha = wAlpha;
NotifiyChange();
}
//************************************
// <p>Description: 设置透明</p>
// <p>Parameters: </p>
// <p> WORD wAlpha</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetAlphaOffset(WORD wAlpha){
m_GameBasalInfo.Alpha += wAlpha;
NotifiyChange();
}
//************************************
// <p>Description: 设置Z空间</p>
// <p>Parameters: </p>
// <p> WORD wZ</p>
//
// <p>Returns: void</p>
//************************************
void CGameObject::SetZ(WORD wZ){
m_GameBasalInfo.Z = wZ;
NotifiyChange();
}
//************************************
// <p>Description: 设置Z空间</p>
// <p>Parameters: </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -