예제 #1
0
GameResult * GameRoad::update(void)
{
    int c = 0;	//該当ブロックカウント
    int i;

    RO_LEVEL *lv = &levels[now_level];
    GetHitKeyStateAll( Key ) ;

    switch(cond) {
    case RO_GAMEOVER:
        // キー待ち後遷移
        if(Key[KEY_INPUT_Y] == 1) {
            init(rd_g_res);
        }
        if(Key[KEY_INPUT_N] == 1) { // 終了
            ro_g_res.end_status(0);
            return &ro_g_res;
        }
        break;
    case RO_END:
        ro_g_res.end_status(1);
        return &ro_g_res; // 平常終了

    // 初期化
    case RO_INI: {

        DataLoad();
        cond = RO_GAME_S;

        for(i=0; i<RO_Y_CNT; i++) {
            for(int j=0; j<RO_X_CNT; j++) {
                roads[i][j] = 0;
                roads_se[i][j] = 0;
            }
        }
        PlaySoundMem(se_num[RO_SE_START] , DX_PLAYTYPE_BACK);
        break;
    }
    // ゲーム開始
    case RO_GAME_S:

        if(CheckSoundMem(se_num[RO_SE_START]) != 1) {
            cond = RO_GAME;
            PlaySoundMem(se_num[bgms[stage]] , DX_PLAYTYPE_LOOP);
        }
        break;
    // ゲーム中
    case RO_GAME:
        if(clearCheck() > -1) {
            cond = RO_CLEAR;
            BGMStop();
            break;
        }

        time++;
        // レベルチェック
        lv++;
        if(lv->road != -1 && lv->road <= all_road) {
            now_level++;
            lv++;
        } else {
            lv--;
        }

        move_time++;

        if(move_time >= 6) {
            move_time = 0;
            // 落下
            c = 0;
            if(block.ok == 1) {
                block.x -= lv->speed;
            }
        }

        // 新規ブロック生成
        newBlock();

        // 方向キー
        // 先へ
        if(Key[KEY_INPUT_LEFT] > 0) {
            move_time++;
        }
        // 停滞
        if(Key[KEY_INPUT_RIGHT] > 0) {
            move_time--;
        }
        // 位置移動(上)
        if(Key[KEY_INPUT_UP] == 1) {
            if(!(once_btn & 1)) {
                block.k--;
                if(block.k < 0) {
                    block.k = 0;
                }
                once_btn |= 1;
            }
        } else {
            once_btn &= ~1;
        }

        // 位置移動(下)
        if(Key[KEY_INPUT_DOWN] == 1) {
            if(!(once_btn & 2)) {
                block.k++;
                if(block.k > RO_Y_CNT-1) {
                    block.k = RO_Y_CNT-1;
                }
                once_btn |= 2;
            }

        } else {
            once_btn &= ~2;
        }
        // 向き変更キー
        if(Key[KEY_INPUT_RETURN] == 1 || Key[KEY_INPUT_Z] == 1) {
            if(!(once_btn & 4)) {
                block.col++;
                if(block.col > 2) {
                    block.col = 0;
                }
            }
            once_btn |= 4;
        } else {
            once_btn &= ~4;
        }

        roadSetCheck();

        break;

    // game clear
    case RO_CLEAR:
        if(ch_mode == 1) {
            chMoveSet();
            chMove();
        } else {
            PlaySoundMem(se_num[RO_SE_CLEAR] , DX_PLAYTYPE_BACK);
        }
        ch_mode = 1;
        break;

    }

    return 0;
}
예제 #2
0
void gpuPictoString::update(){

    float w = testApp::getInstance()->getW();
    float h = testApp::getInstance()->getH();
    
    if(bNeedUpdateCharPos){
        charPosList = calcCharPos();
        bNeedUpdateCharPos = false;
    }
    
    int total = gpuPicto::totalPicto;
    int totalPix = textureRes*textureRes;
    
    // manual mipmap
    //                              *** should check icon size
    
    resizeIcon(h);
    int iconSize = prm.iconSize * h;
    iconSize*=0.5;
    if(iconSize<1){ iconSize=1; }
    

    
    //
    //  nomad
    //
    bool bNomad = true;
    if(bNomad){
        if(total>0 && ofRandom(1.0)>0.95){
            
            if(gpchars.size()>2){
                int charIndexA = (int)ofRandom(2, gpchars.size()-2);
                int charIndexB = charIndexA + (int)ofRandom(-2, 2);
            
                if(charIndexA!=charIndexB){
                    int numPictoA = gpchars[charIndexA]->numPicto;
                    int numPictoB = gpchars[charIndexB]->numPicto;
                    int firstIdA = gpchars[charIndexA]->firstIndex;
                    int firstIdB = gpchars[charIndexB]->firstIndex;
                    
                    int indexA = ofRandom(firstIdA, numPictoA-1);
                    int indexB = ofRandom(firstIdB, numPictoB-1);
                    
                    float attractOnA = springPrmData[indexA*4+3];
                    float attractOnB = springPrmData[indexB*4+3];
                    
                    if(attractOnA<0 && attractOnB<0){
                        float Ax = finalTargetPosData[indexA*3 + 0];
                        float Ay = finalTargetPosData[indexA*3 + 1];
                        
                        finalTargetPosData[indexA*3 + 0] = finalTargetPosData[indexB*3 + 0];
                        finalTargetPosData[indexA*3 + 1] = finalTargetPosData[indexB*3 + 1];

                        finalTargetPosData[indexB*3 + 0] = Ax;
                        finalTargetPosData[indexB*3 + 1] = Ay;

                        finalTargetTex.loadData(finalTargetPosData, textureRes, textureRes, GL_RGB);
                    }
                }
            }
        }
    }
    
    
    {
//        offset = attractor::getPos();
        
        const ofVec2f& attr = attractor::getPos();
        float K = 20;
        float maxSpeed = 0.05;

        ofVec2f dir = attr - offset;
        ofVec2f acc =  K * 0.000167 * dir;
        offsetVel += acc;
        
        offsetVel.limit(maxSpeed);
        offset += offsetVel;
        
        ofVec2f dirf = attr - offset;
        if(dirf.length() > 0.1){
            offset += dirf - dirf.normalized() * 0.1;
        }
    }
    
    //
    //  check pictoChar
    //
    bool shouldUpdateSpringTexture = false;
    GPICTO_STR_ITR itr = gpchars.begin();
    int particleMax = textureRes*textureRes;
    for(; itr!=gpchars.end(); itr++){
        
        if((*itr)->update()){
            shouldUpdateSpringTexture = true;
            int index = (*itr)->firstIndex;
            int numPicto = (*itr)->numPicto;

            if(index<=particleMax){

                for(int i=0; i<numPicto; i++){
                    springPrmData[index*4 + 3] = -1;    // attractOn
                    
                    index++;
                    if(index>particleMax){
                        index = 0;
                    }
                }
            }
        }
    }
    
    if(clearCheck()){
        clearAll();
        bNeedUpdateCharPos = true;
    }

    if(testApp::gprm.bAutoPlay)
        shouldStartNextCheck();

    if(shouldUpdateSpringTexture){
        springPrmTex.loadData(springPrmData, textureRes, textureRes, GL_RGBA);
    }
    
    
    //
    // make random tex
    //
//    if(ofGetFrameNum()%3 == 0){
        for(int index=0; index<total; index++){
                randomData[index*3 + 0] = ofRandom(1.0);
                randomData[index*3 + 1] = ofRandom(1.0);
                randomData[index*3 + 2] = ofRandom(1.0);
//                randomData[index*4 + 3] = ofRandom(1.0);
        }
        randomTex.loadData(randomData, textureRes, textureRes, GL_RGB);
//    }


    //
    // 1. calc vel
    //
    velPingPong.dst->begin();{
        ofClear(0);
        updateVel.begin();{
            updateVel.setUniformTexture("backbuffer", velPingPong.src->getTextureReference(), 0);
            updateVel.setUniformTexture("posData", posPingPong.src->getTextureReference(), 1);
            updateVel.setUniformTexture("springData", springPrmTex, 2);
            updateVel.setUniformTexture("randomData", randomTex, 3);
            updateVel.setUniformTexture("targetData", finalTargetTex, 4);
            
            updateVel.setUniform1i("resolution", (int)textureRes);
            updateVel.setUniform2f("screen", (float)width, (float)height);
            updateVel.setUniform2f("offset", (float)offset.x, (float)offset.y);
            updateVel.setUniform2f("pastOffset", (float)pastOffset.x, (float)pastOffset.y);

            updateVel.setUniform1f("timestep", (float)timeStep);
            updateVel.setUniform1f("ACCEL",(float) prm.accel );
            updateVel.setUniform1f("SPEED",(float) prm.speed);
            updateVel.setUniform1f("VIBRATION",(float) prm.vibration );
            
            // draw the source velocity texture to be updated
            velPingPong.src->draw(0, 0);
        }updateVel.end();
    }velPingPong.dst->end();
    
    velPingPong.swap();
    
    
    //
    // 2. calc pos
    //
    posPingPong.dst->begin();{
        ofClear(0);
        updatePos.begin();{
            updatePos.setUniformTexture("prevPosData", posPingPong.src->getTextureReference(), 0); // Previus position
            updatePos.setUniformTexture("velData", velPingPong.src->getTextureReference(), 1);  // Velocity
            updatePos.setUniformTexture("springData", springPrmTex, 2);

            updatePos.setUniform1f("timestep",(float) timeStep );
//            updatePos.setUniform2f("offset", (float)offset.x, (float)offset.y);
//            updatePos.setUniform2f("pastOffset", (float)pastOffset.x, (float)pastOffset.y);
            posPingPong.src->draw(0, 0);
        }updatePos.end();
    }posPingPong.dst->end();
    
    posPingPong.swap();
    
    
    
    //
    // 3. render
    //
    renderFBO.begin();{

        ofClear(testApp::getBackgroundColor()); // ofClear(0);
        //ofClear(0, 0, 0, 0);

        updateRender.begin();{
            updateRender.setUniformTexture("posTex", posPingPong.dst->getTextureReference(), 0);
            updateRender.setUniformTexture("sparkTex", img->getTextureReference() , 1);
            updateRender.setUniformTexture("iconPrmTex", iconPrmTex, 2);
            updateRender.setUniformTexture("springData", springPrmTex, 3);

            updateRender.setUniform1i("resolution", (float)textureRes);
            updateRender.setUniform2f("screen", (float)testApp::getInstance()->getW(), (float)testApp::getInstance()->getH());
            updateRender.setUniform1i("size", (int)iconSize);
            updateRender.setUniform1f("imgWidth", imgSize);
            updateRender.setUniform1f("imgHeight", imgSize);
            // updateRender.setUniform2f("offset", (float)offset.x, (float)offset.y);

            ofPushStyle();
            //ofEnableBlendMode( OF_BLENDMODE_ADD );
            ofEnableBlendMode( OF_BLENDMODE_ALPHA);
            ofEnableAlphaBlending();
            ofEnableSmoothing();

            ofSetColor(255);
            ofFill();

            glBegin( GL_POINTS );{
                int count = 0;
                for(int y = 0; y < textureRes; y++){
                    for(int x = 0; x < textureRes; x++){
                      if(count >= total) break;
                        count++;
                        glVertex2d(x,y);
                        glTexCoord2i(x, y);
                    }
                    if(count >= total) break;
                }
            }glEnd();

            ofPopStyle();

        }updateRender.end();

        if(testApp::getDebugDraw()){
            {
                // Attractor
                const ofVec2f& attr = attractor::getPos();
                ofFill();
                ofSetColor(255, 55, 0);
                ofRect(attr.x*w, attr.y*h, 10, 10);

                ofFill();
                ofSetColor(5, 255, 0);
                ofRect(pastOffset.x*w, pastOffset.y*h, 10, 10);

                ofFill();
                ofSetColor(0, 5, 220);
                ofRect(offset.x*w, offset.y*h, 10, 10);
            }

            {
                // + line
                if(testApp::gprm.bWallMapMouseAdjust){
                    ofSetColor(0, 255, 0);
                }else{
                    ofSetColor(255, 0, 0);
                }
                glBegin(GL_LINES);
                glVertex3f(w/2, 0, 0); glVertex3f(w/2, h, 0);
                glVertex3f(0, h/2, 0); glVertex3f(w, h/2, 0);

                glVertex3f(1, 1, 0); glVertex3f(w-1, 1, 0);
                glVertex3f(1, h-1, 0); glVertex3f(w-1, h-1, 0);

                glVertex3f(1, 1, 0); glVertex3f(1, h-1, 0);
                glVertex3f(w-1, 1, 0); glVertex3f(w-1, h-1, 0);

                glVertex3f(1, 1, 0); glVertex3f(w-1, h-1, 0);
                glVertex3f(w-1, 1, 0); glVertex3f(1, h-1, 0);

                glEnd();
            }
        }

        if(testApp::gprm.bShowInfo){
            ofPushMatrix();{
                ofTranslate(0,0);
                ofSetColor(ofColor(255,255,255)-testApp::gprm.bg);
                ofFill();
                ofRect(0, 0, w, 30);
                ofSetColor(testApp::gprm.bg);
                int y = 23;
                ofDrawBitmapString("fps: " + ofToString(ofGetFrameRate()),20,y);
                ofDrawBitmapString("picto num: " + ofToString(gpuPicto::totalPicto), 200, y);

                ofDrawBitmapString("Frame num: " + ofToString(ofGetFrameNum()), 400, y);
            }ofPopMatrix();
        }
    }renderFBO.end();
    
    pastOffset = offset;

}