日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

护盾的实现

發布時間:2024/3/13 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 护盾的实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在游戲中,由于大多的船的都是長方形的,所以把護盾做成了橢圓,而不是圓,另外也再護盾的外圍增加一個護盾的持續時間的一個計時器。效果:


所以,這里當敵人的子彈發射過來時,要在護盾邊上觸發(也就是橢圓的邊上)。

class ProtectBody : public CCSprite { public:static ProtectBody* create(float scaleX, float scaleY);//創造護盾bool init(float scaleX, float scaleY);//初始化bool checkCollision(const CCPoint &weaponPos);//橢圓碰撞void protectStart();//開始啟動護盾void protectFinished();//護盾啟動完成void protectEnd();//護盾結束void protectTimeEnd();//計時結束CC_SYNTHESIZE_READONLY(float, _sx, SX);//x軸縮放(不同的體型控制不同的縮放)CC_SYNTHESIZE_READONLY(float, _sy, SY);//y軸縮放(不同的體型控制不同的縮放)CC_SYNTHESIZE_READONLY(bool, _active, Active);//是否激活private:CCProgressTimer* _protectTime;//計時器 };實現的代碼十分簡單,可以一目了然。
ProtectBody* ProtectBody::create(float scaleX, float scaleY) {ProtectBody* protectBody = new ProtectBody();if(protectBody && protectBody->init(scaleX, scaleY)) {protectBody->autorelease();return protectBody;}else {delete protectBody;protectBody = NULL;return NULL;} } bool ProtectBody::init(float scaleX, float scaleY) {bool result = false;if(CCSprite::init()) {//初始化this->_active = false;this->_sx = scaleX;this->_sy = scaleY;this->initWithSpriteFrameName(protect_body_png);this->setScale(0);this->setOpacity(0);ccBlendFunc blend = {GL_SRC_ALPHA, GL_ONE};this->setBlendFunc(blend);this->_protectTime = CCProgressTimer::create(CCSprite::createWithSpriteFrameName(protect_time_png));this->_protectTime->setOpacity(50);this->_protectTime->setVisible(false);this->_protectTime->setType(kCCProgressTimerTypeRadial);this->_protectTime->setReverseProgress(true);CCSize size = this->getContentSize();this->_protectTime->setPosition(ccp(size.width / 2, size.height / 2));this->addChild(this->_protectTime);result = true;}return result; } bool ProtectBody::checkCollision(const CCPoint &weaponPos) {CCPoint shipPos = GameLayer::shareGameLayer()->getShip()->getPosition();CCSize s = this->getContentSize();//橢圓碰撞float x = weaponPos.x - shipPos.x;float y = weaponPos.y - shipPos.y;float w = s.width * this->_sx;float h = s.height * this->_sy;float r = (x * x) / (w * w) + (y * y) / (h * h);if(abs(r) <= 0.25) {return true;}return false; } void ProtectBody::protectStart() {this->_active = true;CCActionInterval* scaleAction = CCScaleTo::create(0.5f, this->_sx, this->_sy);CCActionInterval* fadeAction = CCFadeTo::create(0.5f, 255);CCCallFunc* callback = CCCallFunc::create(this, callfunc_selector(ProtectBody::protectFinished));this->runAction(CCSequence::create(CCSpawn::create(scaleAction, fadeAction, NULL), callback, NULL));} void ProtectBody::protectFinished() {GameLayer::shareGameLayer()->getShip()->setIsProtected(true);CCProgressFromTo* to = CCProgressFromTo::create(STATIC_DATA_FLOAT("protect_time"), 100, 0);CCCallFunc* callback = CCCallFunc::create(this, callfunc_selector(ProtectBody::protectEnd));this->_protectTime->setPercentage(100);this->_protectTime->setVisible(true);this->_protectTime->runAction(CCSequence::create(to, callback, NULL)); } void ProtectBody::protectEnd() {CCActionInterval* scaleAction = CCScaleTo::create(0.5f, 0, 0);CCActionInterval* fadeAction = CCFadeTo::create(0.5f, 0);CCCallFunc* callback = CCCallFunc::create(this, callfunc_selector(ProtectBody::protectTimeEnd));this->runAction(CCSequence::create(CCSpawn::create(scaleAction, fadeAction, NULL), callback, NULL));GameLayer::shareGameLayer()->getShip()->setIsProtected(false);GameLayer::shareGameLayer()->setIsAppearShield(false); } void ProtectBody::protectTimeEnd() {this->_active = false;//不激活this->_protectTime->setVisible(false);//計時器設置不可見 }

總結

以上是生活随笔為你收集整理的护盾的实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。