forked from HigherFire/Final-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
32 lines (30 loc) · 766 Bytes
/
Player.cpp
File metadata and controls
32 lines (30 loc) · 766 Bytes
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
#include"Player.h"
bool Player::initWithFile(const char *pszFilename)
{
CCAssert(pszFilename != NULL, "Invalid filename for Player");
//作些自己的初始化
bool bRet = CCSprite::initWithFile(pszFilename);
velocity = ccp(0.f, 0.f); //速度初始化
return bRet;
}
Player* Player::create(const char *pszFileName)
{
Player *pobPlayer = new Player();
if (pobPlayer && pobPlayer->initWithFile(pszFileName))
{
pobPlayer->autorelease();
return pobPlayer;
}
CC_SAFE_DELETE(pobPlayer);
return NULL;
}
void Player::update(float dt)
{//2
CCPoint gravity = ccp(0.f, -450.f);
//3
CCPoint gravityStep = ccpMult(gravity, dt);
//4
this->velocity = ccpAdd(this->velocity, gravityStep);
//5
this->setPosition(ccpAdd(this->getPosition(), velocity*dt));
}