-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameEntity.cpp
142 lines (124 loc) · 2.57 KB
/
GameEntity.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// Entity.cpp
// HelloCpp
//
// Created by shaoleibo on 15-1-31.
// Copyright (c) 2015Äê Bullets in a Burning Box, Inc. All rights reserved.
//
#include "GameEntity.h"
USING_NS_CC;
GameEntity::GameEntity():m_speed(0),m_position( CCPoint(0,0) ),m_size( CCSize() )
{
m_pSprite = NULL;
m_nType = ENTITY_NONE;
m_fColliderRate = 1;
m_position = CCPoint();
}
GameEntity::~GameEntity()
{
m_pSprite = NULL;
}
void GameEntity::SetPosition( const CCPoint point )
{
m_position = point;
if( m_pSprite != NULL )
{
m_pSprite->setPosition( point );
}
}
CCPoint GameEntity::GetPosition() const
{
if( m_pSprite != NULL )
{
return m_pSprite->getPosition();
}
return CCPoint();
}
void GameEntity::Update( float dt )
{
}
void GameEntity::SetAvata( CCSprite* pSprite )
{
if( pSprite == NULL )
{
m_pSprite = NULL;
return;
}
if( m_pSprite != NULL )
{
if( pSprite != NULL )
pSprite->retain();
m_pSprite->release();
}
m_pSprite = pSprite;
}
CCSize GameEntity::GetSize() const
{
if( m_pSprite != NULL )
{
return m_pSprite->getTextureRect().size;
}
return CCSize();
}
void GameEntity::SetVisible( bool bVisible )
{
if( m_pSprite != NULL )
{
m_pSprite->setVisible( bVisible );
}
}
void GameEntity::SetScale(const float scale)
{
if( m_pSprite != NULL )
{
m_pSprite->setScale( scale );
}
}
float GameEntity::GetScale() const
{
if( m_pSprite != NULL )
{
return m_pSprite->getScale();
}
return 1;
}
bool GameEntity::GetVisible() const
{
if( m_pSprite != NULL )
{
return m_pSprite->isVisible();
}
return false;
}
int GameEntity::GetZOrder() const
{
if( m_pSprite != NULL )
{
return m_pSprite->getZOrder();
}
return 0;
}
void GameEntity::ColliderFrom(GameEntity *collider)
{
}
CCRect GameEntity::GetBoundingBox() const
{
if( m_pSprite != NULL )
{
CCRect bound = m_pSprite->boundingBox();
CCPoint anchor = m_pSprite->getAnchorPoint();
CCPoint anchorPoint = CCPoint( bound.size.width / m_fColliderRate * anchor.x, bound.size.height / m_fColliderRate * anchor.y );
int x = GetPosition().x - anchorPoint.x;
int y = GetPosition().y - anchorPoint.y;
return CCRect( x,y,bound.size.width / m_fColliderRate, bound.size.height / m_fColliderRate );
}
return CCRect();
}
void GameEntity::IntoCollider(GameEntity *entity)
{
m_bInCollider = true;
}
void GameEntity::ExitCollider(GameEntity *entity)
{
m_bInCollider = false;
}