コード例 #1
0
ファイル: CityScene.cpp プロジェクト: jypeitao/Cocosdx-tk
bool CityScene::init()
{
    Layer::init();

    char szRound[260];
    sprintf(szRound, "Round%d.tmx", mRound);
    TileMapInfo* tileMapInfo = TileMapInfo::createMapInfoWithFile(szRound);
    TMXTiledMap* tmxTileMap = tileMapInfo->getTileMap();
    this->addChild(tmxTileMap);

    mPlayerTank[0] = Tank::createTankWithTankType("player2U.png", tileMapInfo);

    mPlayerTank[0]->setObjType(PlayerTank);
    mPlayerTank[0]->getBullet();


    Size tileSize = tmxTileMap->getTileSize();
    Size mapSize = tmxTileMap->getContentSize();
    mPlayerTank[0]->setPosition(Point(mapSize.width / 2 - tileSize.width * 3, tileSize.height));

//
    mLayerPanel = Panel::create();
    addChild(mLayerPanel, 3);
//
    mEnemyAI = EnemyAI::createEnemyAIWithTank(mPlayerTank[0]);

    return true;
}
コード例 #2
0
ファイル: MapLayer.cpp プロジェクト: suli1/suli1-myGame
Point MapLayer::convertTo2d(Point position)
{
    TMXTiledMap* map = (TMXTiledMap*) getChildByTag(kTagTileMap);
    int mapWidth = map->getMapSize().width * map->getTileSize().width;
    int mapHeight = map->getMapSize().height * map->getTileSize().height;

    int x = position.x;
    int y = position.y;

    double distanse;
    double sin1;
    double sin11;
    double sin22;
    double cos11;
    double cos1;
    int d2x;
    int d2y;
    double mystatic5 = sqrt(5.0);
    double mystatic = 16 * mystatic5;
    //char mch[256];

    if(x > mapWidth/2){
        distanse = sqrt((x - mapWidth/2) * (x - mapWidth/2) + (mapHeight - y) * (mapHeight - y));
        sin1 = (mapHeight - y)/distanse;
        cos1 = (x - mapWidth/2)/distanse;
        sin11 = (sin1 * 2 - cos1) / mystatic5;
        cos11 = (sin1 + cos1 * 2) / mystatic5;
        d2y = distanse * 5 / 4 * sin11 / mystatic;
        sin22 = (2 * sin1 + cos1) / mystatic5;
        d2x = distanse * 5 / 4 * sin22 / mystatic;
        return Point(d2x,d2y);

    }else{
        distanse = sqrt((mapWidth/2 - x) * (mapWidth/2 - x) + (mapHeight - y) * (mapHeight - y));
        sin1 = (mapHeight - y)/distanse;
        cos1 = (mapWidth/2 - x)/distanse;
        sin11 = (sin1 * 2 - cos1) / mystatic5;
        cos11 = (sin1 + cos1 * 2) / mystatic5;
        d2x = distanse * 5 / 4 * sin11 / mystatic;
        //sin22 = 4.0 * cos11 / 5 + 3.0 * sin11 / 5;
        sin22 = (2 * sin1 + cos1) / mystatic5;
        d2y = distanse * 5 / 4 * sin22 / mystatic;
        return Point(d2x,d2y);
    }

}
コード例 #3
0
ファイル: MapLayer.cpp プロジェクト: suli1/suli1-myGame
bool MapLayer::init()
{
    bool bRet = false;

    do 
    {
        CC_BREAK_IF(!Layer::init());

        Size winSize = Director::getInstance()->getWinSize();

        // 初始化地图
        TMXTiledMap* map = TMXTiledMap::create("iso-test-zorder.tmx");
        map->setPosition((winSize.width - map->getContentSize().width)/2, 0);
        this->addChild(map, 0, kTagTileMap);

        // 初始化任务
        _tamara = Sprite::create("grossinis_sister1.png");
        map->addChild(_tamara, map->getChildren().size());
        _tamara->retain();
        int mapWidth = map->getMapSize().width * map->getTileSize().width;
        int mapHeight = map->getMapSize().height * map->getTileSize().height;
        _tamara->setPosition(mapWidth/2, 112);
        _tamara->setAnchorPoint(Point(0.5f, 0));
        

        _vmove = -1;
        _hmove = -1;
        _stepIndex = -1;
        _myAstar = new Astar();

        this->scheduleUpdate();

        auto listener = EventListenerTouchOneByOne::create();
        listener->onTouchBegan = CC_CALLBACK_2(MapLayer::onTouchBegan, this);
        this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

        bRet = true;
    } while (0);

    return bRet;
}
コード例 #4
0
ファイル: Tank.cpp プロジェクト: jypeitao/Cocosdx-tk
void Tank::initTankWithTankType(const char* tankTypeName, TileMapInfo* tileMapInfo)
{
    initWithSpriteFrameName(tankTypeName);
    mTileMapInfo = tileMapInfo;

    mTileMapInfo->getTileMap()->addChild(this);

    TMXTiledMap* tmxTileMap = mTileMapInfo->getTileMap();
    Size tileSize = tmxTileMap->getTileSize();
    Size tankSize = getContentSize();

    setScale((tileSize.height * 2 - 4) / (tankSize.height));

    mBullet = Bullet::createBulletWithTank(this);
}
コード例 #5
0
ファイル: CityScene.cpp プロジェクト: wsbjwjt/TanksWar
bool CityScene::init() {
    if (!Layer::init()) {
        return false;
    }
    
    char szRound[260];
    sprintf(szRound, "Round%d.tmx", mRound);
    TileMapInfo* tileMapInfo = TileMapInfo::createMapInfoWithFile(szRound);
    TMXTiledMap* tmxTileMap = tileMapInfo->getTileMap();
    this->addChild(tmxTileMap);
    
    mPlayerTank[0] = Tank::createTankWithTankType("player2U.png", tileMapInfo);
    
    
    Size tileSize = tmxTileMap->getTileSize();
    Size mapSize = tmxTileMap->getContentSize();
    mPlayerTank[0]->setPosition(Vec2(mapSize.width / 2 - tileSize.width * 3, tileSize.height));
    
    mLayerPanel = Panel::create();
    addChild(mLayerPanel, 3);
    
    return true;
}
コード例 #6
0
ファイル: LDZGameLayer.cpp プロジェクト: huji0624/LuckyLDZ
void LDZGameLayer::initLevel(int level){
    
    Size vs = Director::getInstance()->getVisibleSize();
    Vec2 vo = Director::getInstance()->getVisibleOrigin();
    
    _mode = MODE_BEGAIN;
    
    TMXTiledMap *map = TMXTiledMap::create("back.tmx");
    _map = map;
    _mapSize = Size(map->getMapSize().width * map->getTileSize().width , map->getMapSize().height * map->getTileSize().height);
    map->setPosition(Vec2(0, 0));
    this->addChild(map);
    
    //main char
    _mainC = Sprite::createWithSpriteFrameName("1.png");
    _mainC->setPosition(_mapSize.width/2, _mainC->getContentSize().height/2 + 10);
    this->addChild(_mainC,1);
    
    //progress
    auto progress = ProgressTimer::create(Sprite::createWithSpriteFrameName("tempb.png"));
    float progx = _mapSize.width/2 - _mainC->getContentSize().width/2 - progress->getContentSize().width/2 - 5;
    float progy = _mainC->getContentSize().height/2 + 10;
    progress->setPosition( progx, progy);
    progress->setType(cocos2d::ProgressTimer::Type::BAR);
    progress->setBarChangeRate(Vec2(0, 1));
    progress->setMidpoint(Vec2(0, 0));
    auto progback = Sprite::createWithSpriteFrameName("temp.png");
    progback->setPosition(progx, progy);
    this->addChild(progback);
    this->addChild(progress,1);
    progress->setVisible(false);
    progback->setVisible(false);
    _powerProg = progress;
    _powerProgBack = progback;
    
    //limit
    float height = 50 + arc4random()%100;
    float uy = _mapSize.height/3 + _mapSize.height/3*2*CCRANDOM_0_1() - 5;
    float dy = uy - height;
    _upLimit = Sprite::createWithSpriteFrameName("limit.png");
    _upLimit->setPosition(_mapSize.width/2, uy);
    this->addChild(_upLimit);
    _downLimit = Sprite::createWithSpriteFrameName("limit.png");
    _downLimit->setPosition(_mapSize.width/2, dy);
    this->addChild(_downLimit);
    
    //guide
    auto gt = ui::Text::create(LHLocalizedCString("guidetext"), Common_Font, 25);
    gt->setColor(Color3B::RED);
    gt->setPosition(Vec2(_mainC->getPosition().x , _mainC->getBoundingBox().getMaxY() + gt->getContentSize().height/2));
    this->addChild(gt);
    auto bl = Blink::create(1, 1);
    auto rp = RepeatForever::create(bl);
    gt->runAction(rp);
    
    auto da = Sprite::create("da.png");
    da->setScaleY(height/da->getContentSize().height);
    da->setPosition(Vec2(_mainC->getPosition().x,_downLimit->getPositionY()+height/2));
    this->addChild(da);
    
    auto lis = EventListenerTouchOneByOne::create();
    lis->onTouchBegan = [this,gt,progress,progback,da](Touch* tmpTouch, Event*){
        if (_mode == MODE_VIEW) {
            Vec2 loca = tmpTouch->getLocation();
            loca = this->convertToNodeSpace(loca);
            if (_mainC->getBoundingBox().containsPoint(loca)) {
                CallFunc *call = CallFunc::create([this](){
                    _mode = MODE_POWER;
                    this->scheduleUpdate();
                    CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("wiso.wav");
                });
                
                float focusMargin = 20;
                this->focusOn(_mainC->getPosition(), _mainC->getContentSize().height + focusMargin, true , call);
                _mode = MODE_BEGAIN;
                
                gt->removeFromParent();
                da->removeFromParent();
                
                progress->setVisible(true);
                progback->setVisible(true);
                progress->setPercentage(0);
            }
        }else if (_mode == MODE_POWER_END){
            _mode = MODE_POWER;
        }
        
        return true;
    };
    lis->onTouchMoved = [this](Touch* tmpTouch, Event*){
        Vec2 cu = tmpTouch->getLocation();
        Vec2 last = tmpTouch->getPreviousLocation();
        if (_mode == MODE_VIEW) {
            float toy = _focusCenter.y + (last.y - cu.y);
            if (toy+_focusLen/2 > _upLimit->getPositionY() + 20) {
                toy = _upLimit->getPositionY()+20 - _focusLen/2;
            }
            this->focusOn(Vec2(_focusCenter.x , toy),_focusLen, false);
        }else if (_mode == MODE_POWER){
            float dy = fabsf(cu.y - last.y);
            _powerProg->setPercentage(_powerProg->getPercentage()+dy/(_powerProg->getPercentage()+1)/MOVE_FACTOR);
        }
    };
    lis->onTouchEnded = [this](Touch*, Event*){
        if (_mode == MODE_POWER) {
            _mode = MODE_POWER_END;
            _powerCount = 0.1f;
        }
    };
    this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(lis, this);
    
    focusOn(Vec2(_mapSize.width/2,(uy - height/2)), vs.width, false);
    auto dl2 = DelayTime::create(1);
    CallFunc *call = CallFunc::create([this](){
        auto tmpcall = CallFunc::create([this](){
            _mode = MODE_VIEW;
        });
        this->focusOn(_mainC->getPosition(), _focusLen, true , tmpcall);
    });
    auto sq = Sequence::create(dl2,call, NULL);
    this->runAction(sq);
}