本文整理汇总了C++中Hero::getCollisionRect方法的典型用法代码示例。如果您正苦于以下问题:C++ Hero::getCollisionRect方法的具体用法?C++ Hero::getCollisionRect怎么用?C++ Hero::getCollisionRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hero
的用法示例。
在下文中一共展示了Hero::getCollisionRect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Savepoint::update()
{
mFrame++;
if (mTextCounter > 0)
{
mTextCounter--;
}
Hero *hero = getRoom()->getHero();
Entity::CollisionRect cr= hero->getCollisionRect();
bool heroOn = Collides(getCollisionRect(), cr);
if (heroOn && !mHeroOn)
{
// SAVE
GameState::put(GameState::LOCATION_X, getRoom()->getWorldOffsetX() * getRoom()->getTileWidth() + this->getPosition().x);
GameState::put(GameState::LOCATION_Y, getRoom()->getWorldOffsetY() * getRoom()->getTileHeight() + this->getPosition().y + 10);
GameState::saveToFile();
Sound::playSample("data/sounds/coin.wav");
mTextCounter = 50;
}
mHeroOn = heroOn;
}
示例2: update
void Powerup::update()
{
if (GameState::getInt(mKind) != 0)
{
return;
}
Hero *hero = getRoom()->getHero();
Entity::CollisionRect cr = hero->getCollisionRect();
if (Collides(getCollisionRect(), cr))
{
GameState::put(mKind, 1);
std::string explanation;
PowerUpScreen* screen;
if (mKind == GameState::POWERUP_HIJUMP) {
screen = new PowerUpScreen("HI JUMP SOCKS", "JUMP HIGHER");
} else if (mKind == GameState::POWERUP_GUN) {
screen = new PowerUpScreen("POWER GUN", "USE Z");
} else if (mKind == GameState::POWERUP_GRENADE) {
screen = new PowerUpScreen("GRAVITY GRANADE", "USE X");
}
ScreenManager::add(screen);
}
mFrame++;
}
示例3: update
void Spike::update()
{
Hero* hero = mRoom->getHero();
if (Collides(hero->getCollisionRect(), getCollisionRect()))
{
hero->kill();
}
}
示例4: update
void SimpleWalkingMonster::update()
{
switch(mState)
{
case State_Walking:
{
mVelocity.y += 6.0f;
mVelocity.x = 20.0f * ((mFacing==Facing_Left)?-1:1);
setVelocity(mVelocity);
int bumps = moveWithCollision();
if ((bumps & (Direction_Up | Direction_Down)) != 0)
{
mVelocity.y = 0;
}
if ((bumps & (Direction_Left)) != 0)
{
mFacing = Facing_Right;
}
if ((bumps & (Direction_Right)) != 0)
{
mFacing = Facing_Left;
}
int offsetX = (mState==Facing_Right)?-getHalfSize().x-2:getHalfSize().x+2;
int offsetY = getHalfSize().y+2;
float2 position = getPosition();
int x = (position.x+offsetX) / (float)mRoom->getTileWidth();
int y = (position.y+offsetY) / (float)mRoom->getTileHeight();
if (!mRoom->isCollidable(x, y))
{
if (mFacing == Facing_Left)
{
mFacing = Facing_Right;
}
else
{
mFacing = Facing_Left;
}
}
if (mRand.getFloat(1.0f) < WALK_TO_IDLE_CHANCE)
{
mState = State_Idling;
}
}
break;
case State_Idling:
if (mRand.getFloat(1.0f) < IDLE_TO_WALK_CHANCE)
{
if (mRand.getFloat(1.0f) > 0.5)
{
mFacing = Facing_Left;
}
else
{
mFacing = Facing_Right;
}
mState = State_Walking;
}
break;
}
Hero* hero = mRoom->getHero();
if (Collides(hero->getCollisionRect(), getCollisionRect()))
{
hero->kill();
}
mFrame++;
}
示例5: update
void Shot::update(){
if (++mLife > 180){
setCollided(true);
}
if (touchesDangerousTile()){
setCollided(true);
}
if(hasCollided()){
if (--mCollidedTimer < 0){
remove();
//remove
}
return;
}
// move
int cur_x = getPosition().x;
int cur_y = getPosition().y;
int floor_y, edge_x;
int bumps;
/*
floor_y= cur_y+getHalfSize().y+5;
if (mFacingDirection == Direction_Left){
edge_x=cur_x-getHalfSize().x;
} else {
edge_x=cur_x+getHalfSize().x;
}
*/
if(mGravity[mShotType] == ShotType_Bullet){
setVelocity(float2(mInitialVelocity[mShotType].x*getDirection(),mInitialVelocity[mShotType].y));
} else {
setVelocity(float2(mInitialVelocity[mShotType].x*getDirection(),mInitialVelocity[mShotType].y+GRAVITY*mLife));
}
//setVelocity(float2(12.0f,.0f));
bumps=moveWithCollision();
if((bumps & Direction_Left) != 0 || (bumps & Direction_Right) != 0 || (bumps & Direction_Up) != 0|| (bumps & Direction_Down) != 0 ){
setCollided(true);
if (mShotType == ShotType_GravityGrenade || mShotType == ShotType_Fireball) { Sound::playSample("data/sounds/grenadeexplode.wav"); }
}
if(!mHurtPlayer){
std::vector<Entity*> collidedEntity = mRoom->checkEntitiesForCollision(this);
if(collidedEntity.size() > 0){
setCollided(true);
if (mShotType == ShotType_GravityGrenade || mShotType == ShotType_Fireball) { Sound::playSample("data/sounds/grenadeexplode.wav"); }
for(int i=0;i<collidedEntity.size();i++){
attack(collidedEntity[i]);
}
}
} else {
Hero* h = mRoom->getHero();
Entity::CollisionRect cr= h->getCollisionRect();
if(Collides(getCollisionRect(),cr)){
setCollided(true);
if (mShotType == ShotType_GravityGrenade || mShotType == ShotType_Fireball) { Sound::playSample("data/sounds/grenadeexplode.wav"); }
if(mShotType == ShotType_Fireball || mShotType == ShotType_Bullet){
h->die();
return;
}
if(mShotType == ShotType_GravityGrenade){
attack(h);
return;
}
}
}
mFrame++;
}