void GameLayer::updateHero(float dt) { setViewPointCenter(); if (m_pHero->getCurrActionState() == ACTION_STATE_MOVE && m_pHero->isInMoveAction(MOVE_STATE_UP) && m_pHero->getPosition().y < m_pHero->getPrePosition().y) { m_pHero->runJumpAction(false); } m_pHero->setPrePosition(m_pHero->getPosition()); if (m_pHero->getIsAttacking()) { m_shootTime += dt; if (m_shootTime >= m_pHero->getBulletInterval()) { //int curAmmoCapacity = m_pHero->getAmmoCapacity(); //if(curAmmoCapacity == 0) Bullet* bullet = getUnusedBullet(); bullet->launch(m_pHero); this->addChild(bullet); m_shootTime = 0.f; if (m_pHero->getShootDirection().x != 0) m_pHero->setFlippedX(m_pHero->getShootDirection().x < 0); } } /*if(m_pHero->getCurrActionState() == ACTION_STATE_MOVE) { CCLOG("ACTION_STATE_MOVE START"); if(m_pHero->isInMoveAction(MOVE_STATE_UP)) { CCLOG("MOVE_STATE_UP %f %f", m_pHero->getPhysicsBody()->getVelocity().x, m_pHero->getPhysicsBody()->getVelocity().y); } if(m_pHero->isInMoveAction(MOVE_STATE_DOWN)) { CCLOG("MOVE_STATE_DOWN %f %f", m_pHero->getPhysicsBody()->getVelocity().x, m_pHero->getPhysicsBody()->getVelocity().y); } if(m_pHero->isInMoveAction(MOVE_STATE_WALK)) { CCLOG("MOVE_STATE_WALK %f %f", m_pHero->getPhysicsBody()->getVelocity().x, m_pHero->getPhysicsBody()->getVelocity().y); } CCLOG("ACTION_STATE_MOVE END"); }*/ //CCLOG("(%f, %f) (%f, %f)", m_pHero->getPhysicsBody()->getPosition().x, m_pHero->getPhysicsBody()->getPosition().y, m_pHero->getPosition().x, m_pHero->getPosition().y); }
void WorldLayer::update(float dt) { //dt is the incremental timestep that occurs at approx. 1/60th of a second if(!p1->getDestination().equals(Vec2::ZERO)) { cocos2d::Point current = p1->getPosition(); cocos2d::Point next = p1->getDestination(); float dx = p1->getMoveSpeed(); //so we only want angle towards end destination float angle = atan2(next.x - current.x, next.y - current.y); //Are we there yet? if(!current.fuzzyEquals(next, 1.f)) { float travel = 0.f; if((travel = current.getDistance(next)) < dx) { dx = travel; } float xstep = dx * sin(angle); float ystep = dx * cos(angle); Size playerDim = p1->getContentSize(); //Account for continuous collision detection with collided body and clip movement Entity *obj = p1->getCollided(); if(obj != NULL) { obj->setMoveLock(0.f); } current.x += xstep; current.y += ystep; //Account for world boundary and clip movement if(current.x < playerDim.width / 2) { current.x = playerDim.width / 2; } else if(current.x > (dimensions.width - playerDim.width / 2)) { current.x = dimensions.width - playerDim.width / 2; } if(current.y < playerDim.height /2) { current.y = playerDim.height /2; } else if(current.y > (dimensions.height - playerDim.height / 2)) { current.y = dimensions.height - playerDim.height / 2; } } p1->setPosition(current); setViewPointCenter(current); } }
void HelloWorld::update(float delta) { Layer::update(delta); setViewPointCenter(m_player->getPosition()); }