⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 donuts.c

📁 Windows Mobile 6 DirectX 2D源码
💻 C
📖 第 1 页 / 共 4 页
字号:
                            playPanned(hsoPyramidExplode, target);
                        }
                        addObject( OBJ_SPHERE, target->dst.left,
                            target->dst.top, -1.0, -1.0 );
                        addObject( OBJ_CUBE, target->dst.left,
                            target->dst.top, -1.0, -1.0 );
                        addObject( OBJ_CUBE, target->dst.left,
                            target->dst.top, -1.0, -1.0 );
                        score += 20;
                        break;
                    case OBJ_CUBE:
                        if(bWantSound)
                        {
                            playPanned(hsoCubeExplode, target);
                        }
                        addObject( OBJ_SPHERE, target->dst.left,
                            target->dst.top, -1.0, -1.0 );
                        addObject( OBJ_SPHERE, target->dst.left,
                            target->dst.top, -1.0, -1.0 );
                        break;
                        score += 40;
                    case OBJ_SPHERE:
                        if(bWantSound)
                        {
                            playPanned(hsoSphereExplode, target);
                        }
                        score += 20;
                    }

                    l = target->dst.left;
                    t = target->dst.top;
                    DeleteFromList( target );
                }

                hit = TRUE;
            }

            if( hit )
            {
                if( bullet == &DL )
                {
                    hit = FALSE;
                    if (!lastShield && !showDelay && !bTest)
                    {
                        if(bWantSound)
                        {
                            playPanned(hsoShipExplode, bullet);
                            SndObjStop(hsoEngineIdle);
                        }
                        score -= 150;
                        if (score < 0)
                            score = 0;

                        addObject( OBJ_SPHERE, l, t, -1.0, -1.0 );
                        addObject( OBJ_SPHERE, l, t, -1.0, -1.0 );
                        addObject( OBJ_SPHERE, l, t, -1.0, -1.0 );
                        addObject( OBJ_SPHERE, l, t, -1.0, -1.0 );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        addObject( OBJ_BULLET, l, t,
                            randDouble( -0.5, 0.5 ), randDouble( -0.5, 0.5 ) );
                        initShip(TRUE);
                    }
                }

                break;
            }
        }

        if( hit )
        {
            save = bullet;
            bullet = bullet->next;
            
            if (save != &DL)
                DeleteFromList( save );
        }
        else
        {
            bullet = bullet->next;
        }

    } while (bullet != &DL);
}

void EraseScreen( void )
{
    DDBLTFX     ddbltfx;
    HRESULT     ddrval;

    // iForceErase forces us to erase so we can get of stray GDI pixels
    if (iForceErase)
    {
        iForceErase--;
    }
    else if( bSpecialEffects )   // cool looking screen with no colorfill
    {
        return;
    }

    // Erase the background
    memset (&ddbltfx, 0, sizeof (ddbltfx));
    ddbltfx.dwSize = sizeof( ddbltfx );
#ifdef NONAMELESSUNION
    ddbltfx.u5.dwFillColor = dwFillColor;
#else
    ddbltfx.dwFillColor = dwFillColor;
#endif
    while( 1 )  
    {

        ddrval = lpBackBuffer->lpVtbl->Blt( lpBackBuffer, NULL, NULL,
                 NULL, DDBLT_COLORFILL, &ddbltfx );

        if( ddrval == DD_OK )
        {
            break;
        }
        if( ddrval == DDERR_SURFACELOST )
        {
            if( !RestoreSurfaces() )
                return;
        }
        if( ddrval != DDERR_WASSTILLDRAWING )
        {
            return;
        }
    }
}

void FlipScreen( void )
{
    HRESULT     ddrval;
    RECT src, dest;

    src.left = 0;
    src.top = 0;
    src.right = ScreenX;
    src.bottom = ScreenY;

    dest.left = 0;
    dest.top  = 0;
    dest.right = ScreenX;
    dest.bottom = ScreenY;

    // Flip the surfaces
    while( 1 )
    {
        if (bSingleBuffer)
        {
            //copy back buffer to front.
            ddrval = lpFrontBuffer->lpVtbl->Blt( lpFrontBuffer, &dest, lpBackBuffer, &src, dwTransType, NULL );
        }
        else 
        {
            ddrval = lpFrontBuffer->lpVtbl->Flip( lpFrontBuffer, NULL, 0);
        }

        if( ddrval == DD_OK )
        {
            break;
        }
        if( ddrval == DDERR_SURFACELOST )
        {
            if( !RestoreSurfaces() )
            {
                return;
            }
        }
        if( ddrval != DDERR_WASSTILLDRAWING )
        {
            break;
        }
    }
}

void DrawDisplayList( void )
{
    LPDBLNODE   this;
    LPDBLNODE   last;
    HRESULT     ddrval;
    TCHAR        scorebuf[11];
    int         rem;

    // blt everything in reverse order if we are doing destination transparency
    // calculate score string
    scorebuf[0] = score/10000000 + TEXT('0');
    rem = score % 10000000;
    scorebuf[1] = rem/1000000 + TEXT('0');
    rem = score % 1000000;
    scorebuf[2] = rem/100000 + TEXT('0');
    rem = score % 100000;
    scorebuf[3] = rem/10000 + TEXT('0');
    rem = score % 10000;
    scorebuf[4] = rem/1000 + TEXT('0');
    rem = score % 1000;
    scorebuf[5] = rem/100 + TEXT('0');
    rem = score % 100;
    scorebuf[6] = rem/10 + TEXT('0');
    rem = score % 10;
    scorebuf[7] = rem + TEXT('0');
    if( bSoundEnabled )
    {
        scorebuf[8] = 14 + TEXT('0');
        scorebuf[9] = 13 + TEXT('0');
        scorebuf[10] = TEXT('\0');
    }
    else
    {
        scorebuf[8] = TEXT('\0');
    }

    EraseScreen();
    if( dwTransType == DDBLT_KEYDEST )
    {
        bltScore(scorebuf, 10, ScreenY-26);

        if( bShowFrameCount )
            DisplayFrameRate();

        this = DL.next; // start with the topmost bitmap
        last = DL.next; // don't blt it twice

        if (showDelay)
            last = &DL;
    }
    else
    {
        this = &DL;     // start with the bottommost bitmap (the ship)
        last = &DL;     // don't blt it twice

        if (showDelay)
            this = this->prev;
    }

    do
    {
        while (!IsRectEmpty(&this->src))
        {
            ddrval = lpBackBuffer->lpVtbl->Blt( lpBackBuffer, &(this->dst), this->surf, &(this->src), dwTransType, NULL );

            if( ddrval == DD_OK )
            {
                break;
            }
            if( ddrval == DDERR_SURFACELOST )
            {
                if( !RestoreSurfaces() )
                    return;
            }
            if( ddrval != DDERR_WASSTILLDRAWING )
            {
                return;
            }
        }
        if( dwTransType != DDBLT_KEYDEST )
        {
            this = this->prev;
        }
        else
        {
            this = this->next;
        }
    }
    while( this != last );

    if( dwTransType != DDBLT_KEYDEST )
    {
        bltScore(scorebuf, 10, ScreenY-26);

        if( bShowFrameCount )
            DisplayFrameRate();
    }

    FlipScreen();
}

void DisplayFrameRate( void )
{
    DWORD               time2;
    TCHAR               buff[256];

    dwFrameCount++;
    time2 = timeGetTime() - dwFrameTime;
    if( time2 > 1000 )
    {
        dwFrames = (dwFrameCount*1000)/time2;
        dwFrameTime = timeGetTime();
        dwFrameCount = 0;
    }
    if( dwFrames == 0 )
    {
        return;
    }

    if (dwFrames != dwFramesLast)
    {
        dwFramesLast = dwFrames;
    }

    if( dwFrames > 99 )
    {
        dwFrames = 99;
    }
    buff[0] = (TCHAR)((dwFrames / 10) + TEXT('0'));
    buff[1] = (TCHAR)((dwFrames % 10) + TEXT('0'));
    buff[2] = TEXT('\0');
    bltScore(buff, ScreenX/2-25, 10);
}

void DeleteFromList( LPDBLNODE this )
{
    this->next->prev = this->prev;
    this->prev->next = this->next;
    LocalFree( this );
}

void UpdateEnginePan(void)
{
    double pan = (2 * DL.posx / (double) ScreenX) - 1.0;
    double hack = 0.2;
    SndObjSetPan(hsoEngineIdle, hack * pan);
}
void UpdateEngineIdle(void)
{
    double absvel = sqrt(DL.vely*DL.vely + DL.velx * DL.velx);
    double rate = 1.0 + absvel; //log10(10.0 + absvel);
    SndObjSetRate(hsoEngineIdle, rate);
}


void UpdateDisplayList( void )
{
    LPDBLNODE   this;
    LPDBLNODE   save;
    DWORD       thisTickCount = GetTickCount();
    DWORD       tickDiff = thisTickCount - lastTickCount;
    double      maxx, maxy;
    double      maxframe;
    DWORD       input;
    BOOL        event = FALSE;

    lastTickCount = thisTickCount;

    if( bTest )
    {
        input = (KEY_RIGHT | KEY_FIRE);
    }
    else 
    {
        input = GlobalInput;
    }

    if (showDelay)
    {
        showDelay -= (int)tickDiff;
        if (showDelay < 0)
        {
            showDelay = 0;
            lastShield = FALSE;
            initShip( FALSE );
        }
    }

    // update the ship
    if( !showDelay )
    {
        DL.posx += DL.velx * (double)tickDiff;
        DL.posy += DL.vely * (double)tickDiff;
    }
    if( DL.posx > MAX_SHIP_X )
    {
        DL.posx = MAX_SHIP_X;
        DL.velx = -DL.velx;
        event = TRUE;
    }
    else if ( DL.posx < 0 )
    {
        DL.posx =0;
        DL.velx = -DL.velx;
        event = TRUE;
    }
    if( DL.posy > MAX_SHIP_Y )
    {
        DL.posy = MAX_SHIP_Y;
        DL.vely = -DL.vely;
        event = TRUE;
    }
    else if ( DL.posy < 0 )
    {
        DL.posy =0;
        DL.vely = -DL.vely;
        event = TRUE;
    }
    if (event)
    {
        if(bWantSound)
        {
            playPanned(hsoShipBounce, &DL);
            UpdateEngineIdle();
        }
        event = FALSE;
    }
    UpdateEnginePan();

    if ((event = (showDelay || ((input & KEY_SHIELD) == KEY_SHIELD))) !=
        lastShield)
    {
        if (event && !showDelay)
                {
                    if(bWantSound)
                    {
                        SndObjPlay(hsoShieldBuzz);
                    }
                    bPlayBuzz = TRUE;
                }
        else
                {
                if(bWantSound)
                {
                    SndObjStop(hsoShieldBuzz);
                }
                bPlayBuzz = FALSE;
            }
        lastShield = event;
    }
    if (event)
    {
        input &= ~(KEY_FIRE);
    }

    if (input & KEY_FIRE)
    {
        if( !showDelay )
        {
            // add a bullet to the scene
            score--;
            if(score < 0)
                score = 0;

            if(bWantSound)
            {
                SndObjPlay(hsoFireBullet);
            }
            addObject( OBJ_BULLET, Dirx[(int)DL.frame]*6.0 + 16.0 + DL.posx,
                                   Diry[(int)DL.frame]*6.0 + 16.0 + DL.posy,
                                   Dirx[(int)DL.frame]*500.0/1000.0,
                                   Diry[(int)DL.frame]*500.0/1000.0 );
        }
    }

    event = FALSE;
    if( input & KEY_LEFT )
    {
            DL.frame -= 1.0;
            if( DL.frame < 0.0 )
                DL.frame += MAX_SHIP_FRAME;
    }
    if( input & KEY_RIGHT )
    {
            DL.frame += 1.0;
            if( DL.frame >= MAX_SHIP_FRAME)
                DL.frame -= MAX_SHIP_FRAME;
    }
    if( input & KEY_UP )
    {
            DL.velx += Dirx[(int)DL.frame] * 10.0/1000.0;
            DL.vely += Diry[(int)DL.frame] * 10.0/1000.0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -