//初期化
bool GameLayer::init()
{
    if (!Layer::init())
        return false;
    
    initBackground(); //背景の初期化
    initBalls(); //ボールの初期表示
    
    return true;
}
Exemplo n.º 2
0
int main(void) {
    const int ballsCount = 20;
    const int SLEEP_TIME = 1;

    /* initialize system objects */
    Ball ballsArr[ballsCount];
    srand(time(NULL));
    initBalls(ballsCount, ballsArr);

    /* infinite loop engine */
    while(1) {
        clearScreen();
        updateBalls(ballsCount, ballsArr);
        drawBalls(ballsCount, ballsArr);
        tSleep(SLEEP_TIME);
    }
    return EXIT_SUCCESS;
}
Exemplo n.º 3
0
//初期化
bool GameLayer::init()
{
    if (!Layer::init())
        return false;

    // シングルタップイベントの取得
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->setSwallowTouches(_swallowsTouches);
    touchListener->onTouchBegan = CC_CALLBACK_2(GameLayer::onTouchBegan, this);
    touchListener->onTouchMoved = CC_CALLBACK_2(GameLayer::onTouchMoved, this);
    touchListener->onTouchEnded = CC_CALLBACK_2(GameLayer::onTouchEnded, this);
    touchListener->onTouchCancelled = CC_CALLBACK_2(GameLayer::onTouchCancelled, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

    initBackground(); //背景の初期化
    initBalls(); //ボールの初期表示

    return true;
}
Exemplo n.º 4
0
void MainGame::run() {
    init();
    initBalls();

    // Start our previousTicks variable
    Uint32 previousTicks = SDL_GetTicks();

    // Game loop
    while (m_gameState == GameState::RUNNING) {
        m_fpsLimiter.begin();
        processInput();

        // Calculate the frameTime in milliseconds
        Uint32 newTicks = SDL_GetTicks();
        Uint32 frameTime = newTicks - previousTicks;
        previousTicks = newTicks; // Store newTicks in previousTicks so we can use it next frame
        // Get the total delta time
        float totalDeltaTime = (float)frameTime / DESIRED_FRAMETIME;

        int i = 0; // This counter makes sure we don't spiral to death!
        // Loop while we still have steps to process.
        while (totalDeltaTime > 0.0f && i < MAX_PHYSICS_STEPS) {
            // The deltaTime should be the the smaller of the totalDeltaTime and MAX_DELTA_TIME
            float deltaTime = std::min(totalDeltaTime, MAX_DELTA_TIME);
            // Update all physics here and pass in deltaTime

            update(deltaTime);
          
            // Since we just took a step that is length deltaTime, subtract from totalDeltaTime
            totalDeltaTime -= deltaTime;
            // Increment our frame counter so we can limit steps to MAX_PHYSICS_STEPS
            i++;
        }

        m_camera.update();
        draw();
        m_fps = m_fpsLimiter.end();
    }
}
//初期化
bool GameLayer::init(int level)
{
    if (!Layer::init())
        return false;
    
    // シングルタップイベントの取得
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->setSwallowTouches(_swallowsTouches);
    touchListener->onTouchBegan = CC_CALLBACK_2(GameLayer::onTouchBegan, this);
    touchListener->onTouchMoved = CC_CALLBACK_2(GameLayer::onTouchMoved, this);
    touchListener->onTouchEnded = CC_CALLBACK_2(GameLayer::onTouchEnded, this);
    touchListener->onTouchCancelled = CC_CALLBACK_2(GameLayer::onTouchCancelled, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

    _level = level; //レベルの保持
    
    initBackground(); //背景の初期化
    initBalls(); //ボールの初期表示
    initEnemy(); //敵の表示
    initMembers(); //メンバーの表示
    initLevelLayer(); //レベル表示レイヤーの表示
    
    return true;
}