void CollisionManager::BarrierAndBullet(BulletBase * pBullet, Vector<BarrierBase *> &rBarrierVec) { for (int i = 0; i < rBarrierVec.size(); ++i) { BarrierBase * pBarrier = rBarrierVec.at(i); if (pBullet == nullptr || pBullet->getIsDead() || pBarrier == nullptr || pBarrier->getIsDead()) continue; if (pBullet->getBoundingBox().intersectsRect(pBarrier->getBoundingBox())) { if (pBullet->getIdMap().find(pBarrier->getmID()) == pBullet->getIdMap().end()) { pBullet->getIdMap().insert(pBarrier->getmID()); pBarrier->beHurt(pBullet->getAtkPro()); Sprite * HurtSprite = Sprite::create(); pBarrier->addChild(HurtSprite); CallFunc * ClearF = CallFunc::create([=](){HurtSprite->removeFromParentAndCleanup(true); }); HurtSprite->runAction(Sequence::create(Animate::create(AnimationMaker(pBullet->getSName(), pBullet->getAnimationFrameCount() + 1)), ClearF, NULL)); if (pBarrier->getAtkTarget()) { pBullet->getIdMap().erase(pBarrier->getmID()); pBullet->setPosition(pBarrier->getPosition()); pBullet->stopAllActions(); pBullet->doDead(); return; } } } } }
void SubPlayer :: onKeyReleased(cocos2d :: EventKeyboard :: KeyCode keyCode, Event* enent1) { switch(keyCode) { case EventKeyboard :: KeyCode :: KEY_UP_ARROW: { //keep in throw if (in_throw) break; pSubplayer -> stopActionByTag(_s_a_move_up); Director :: getInstance() -> getActionManager() ->removeActionByTag(_s_run, pSubplayer); auto animation = AnimationMaker(_s_stoprun); auto action_animate = Animate :: create(animation); pSubplayer -> runAction(action_animate); if (in_run) in_run--; } break; case EventKeyboard :: KeyCode :: KEY_DOWN_ARROW: { if (in_throw) break; pSubplayer -> stopActionByTag(_s_a_move_down); Director :: getInstance() -> getActionManager() ->removeActionByTag(_s_run, pSubplayer); auto animation = AnimationMaker(_s_stoprun); auto action_animate = Animate :: create(animation); pSubplayer -> runAction(action_animate); if (in_run) in_run--; } break; case EventKeyboard :: KeyCode :: KEY_RIGHT_ARROW: { if (in_throw) break; pSubplayer -> stopActionByTag(_s_a_move_right); Director :: getInstance() -> getActionManager() ->removeActionByTag(_s_runback, pSubplayer); auto animation = AnimationMaker(_s_stoprun); auto action_animate = Animate :: create(animation); pSubplayer -> runAction(action_animate); if (in_run) in_run--; } break; case EventKeyboard :: KeyCode :: KEY_LEFT_ARROW: { if (in_throw) break; pSubplayer -> stopActionByTag(_s_a_move_left); Director :: getInstance() -> getActionManager() ->removeActionByTag(_s_run, pSubplayer); auto animation = AnimationMaker(_s_stoprun); auto action_animate = Animate :: create(animation); pSubplayer -> runAction(action_animate); if (in_run) in_run--; } break; case EventKeyboard :: KeyCode :: KEY_P: { if (in_run) break; auto animation = AnimationMaker(_s_throw_2); auto action_animate = Animate :: create(animation); pSubplayer -> runAction(action_animate); in_throw = false; } break; } }
void SubPlayer :: onKeyPressed(cocos2d :: EventKeyboard :: KeyCode keyCode, Event* enent1) { if (in_throw) return; //Get the Position Size visibleSize = Director :: getInstance() -> getVisibleSize(); Vec2 origin = Director :: getInstance() -> getVisibleOrigin(); auto position = pSubplayer -> getPosition(); auto spritesize = pSubplayer -> getContentSize(); switch(keyCode) { case EventKeyboard :: KeyCode :: KEY_UP_ARROW: { //set the state in_run++; auto animation = AnimationMaker(_s_run); auto action_animate = RepeatForever :: create(Animate :: create(animation)); action_animate -> setTag(_s_run); pSubplayer -> runAction(action_animate); auto action_moveby = MoveBy :: create(0.1f, ccp(0.0f, 20.0f)); auto action_squence = Sequence :: create(action_moveby, CallFunc :: create(this, callfunc_selector(SubPlayer :: judge)), NULL); auto action_movebyforever = RepeatForever :: create(action_squence); action_movebyforever -> setTag(_s_a_move_up); if ((position.y < origin.y + visibleSize.height / 3 + 30.0f)) { pSubplayer -> runAction(action_movebyforever); } } break; case EventKeyboard :: KeyCode :: KEY_DOWN_ARROW: { in_run++; auto animation = AnimationMaker(_s_run); auto action_animate = RepeatForever :: create(Animate :: create(animation)); action_animate -> setTag(_s_run); pSubplayer -> runAction(action_animate); auto action_moveby = MoveBy :: create(0.1f, ccp(0.0f, -20.0f)); auto action_squence = Sequence :: create(action_moveby, CallFunc :: create(this, callfunc_selector(SubPlayer :: judge)), NULL); auto action_movebyforever = RepeatForever :: create(action_squence); action_movebyforever -> setTag(_s_a_move_down); if ((position.y > origin.y + spritesize.height / 2 + 30.0f)) { pSubplayer -> runAction(action_movebyforever); } } break; case EventKeyboard :: KeyCode :: KEY_RIGHT_ARROW: { in_run++; auto animation = AnimationMaker(_s_run); auto action_animate = RepeatForever :: create(Animate :: create(animation) -> reverse()); action_animate -> setTag(_s_runback); pSubplayer -> runAction(action_animate); auto action_moveby = MoveBy :: create(0.1f, ccp(20.0f, 0.0f)); auto action_squence = Sequence :: create(action_moveby, CallFunc :: create(this, callfunc_selector(SubPlayer :: judge)), NULL); auto action_movebyforever = RepeatForever :: create(action_squence); action_movebyforever -> setTag(_s_a_move_right); if ((position.x < origin.x + visibleSize.width - spritesize.width / 2 - 30.0f)) { pSubplayer -> runAction(action_movebyforever); } } break; case EventKeyboard :: KeyCode :: KEY_LEFT_ARROW: { in_run++; auto animation = AnimationMaker(_s_run); auto action_animate = RepeatForever :: create(Animate :: create(animation)); action_animate -> setTag(_s_run); pSubplayer -> runAction(action_animate); auto action_moveby = MoveBy :: create(0.1f, ccp(-20.0f, 0.0f)); auto action_squence = Sequence :: create(action_moveby, CallFunc :: create(this, callfunc_selector(SubPlayer :: judge)), NULL); auto action_movebyforever = RepeatForever :: create(action_squence); action_movebyforever -> setTag(_s_a_move_left); if ((position.x > origin.x + visibleSize.width / 2 + spritesize.width + 50.0f)) { pSubplayer -> runAction(action_movebyforever); } } break; case EventKeyboard :: KeyCode :: KEY_P: { //keep in run if (in_run) break; //set the state in_throw = true; pSubplayer -> stopAllActions(); auto animation = AnimationMaker(_s_throw_1); auto action_animate = Animate :: create(animation); pSubplayer -> runAction(action_animate); } break; } }