• 射击小游戏一01(子弹添加添加)


    void HelloWorld::ccTouchesEnded(CCSet *touches,cocos2d::CCEvent *event)
    
    {
    
        CCTouch *touch = (CCTouch*)(touches->anyObject());
    
        CCPoint location = touch->getLocationInView();
    
        location = CCDirector::sharedDirector()->convertToGL(location);
    
        
    
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
        CCSprite *projectile = CCSprite::create("Projectile.png",CCRectMake(0, 0, 20, 20));
    
        projectile->setPosition(ccp(20, winSize.height/2));
    
        
    
         // Determinie offset of location to projectile
    
        int offX = location.x - projectile->getPosition().x;
    
        int offY = location.y - projectile->getPosition().y;
    
        
    
        if (offX <= 0) return;
    
        
    
        this->addChild(projectile);
    
        
    
         // Determine where we wish to shoot the projectile to
    
        int realX = winSize.width + (projectile->getContentSize().width/2);
    
        float ratio = (float)offY/(float)offX;
    
        int realY = (realX*ratio) + projectile->getPosition().y;
    
        CCPoint realDest = ccp(realX,realY);
    
        
    
         // Determine the length of how far we're shooting
    
        int offRealX = realX - projectile->getPosition().x;
    
        int offRealY = realY - projectile->getPosition().y;
    
        float length = sqrtf(( offRealX * offRealX )+(offRealY * offRealY));
    
        
    
        float velocity = 480/1;// 480pixels/1sec
    
        float realMoveDuration = length / velocity;
    
        
    
        // Move projectile to actual endpoint
    
        projectile->runAction(CCSequence::create(CCMoveTo::create(realMoveDuration, realDest),CCCallFuncN::create(this, callfuncN_selector(HelloWorld::spriteMoveFinished)),NULL));
    
        
    
        
    
    }
  • 相关阅读:
    宁波工程学院2020新生校赛C
    宁波工程学院2020新生校赛B
    宁波工程学院2020新生校赛A -恭喜小梁成为了宝可梦训练家~(水题)
    POJ 1611
    牛客算法周周练11E
    牛客算法周周练11C
    牛客算法周周练11A
    CodeForces 1176C
    CodeForces 445B
    UVALive 3027
  • 原文地址:https://www.cnblogs.com/jiackyan/p/3017899.html
Copyright © 2020-2023  润新知