norains的专栏

只专注于WINCE开发

用户操作
[即时聊天] [发私信] [加为好友]
norainsID:norains
142879次访问,排名598,好友0人,关注者53人。
代码其实是一种乐趣
norains的文章
原创 189 篇
翻译 0 篇
转载 10 篇
评论 274 篇
norains的公告
联系方式请看置顶文章
最近评论
dfdf:讨厌MFC!我觉得MFC就是太乱了!看似无用的代码不要不行,MD微软啥都给我们做完了,原理性的东西我们却永远没法搞懂了!
ironox:有个地方 我觉得很别扭,不知道怎么办好

比如说 CReg reg(HKEY_CURRENT_USER,TEXT("ControlPanel\Volume"));
ControlPanel\Volume 有可能不存在呀,这个该怎么处理哦?对象虽然创建了,出错了也没提示
szterry:呵呵,果然工作狂技术狂,同感,一样的感觉……不过我才刚毕业一年……搞IT就是玩……
jinlking:这个botton的实现只是在主窗口画了一块区域,对于事件的处理还要放在主窗口的窗口处理函数之中,在对应的消息处理上调用CheckTap来判断是否是此“按钮”,问一下,这种方法与把按钮封装在子窗口中有什么区别,二者使用那个更好?
KUODY:博主真是好人
文章分类
收藏
    相册
    动漫
    文章图片
    程序交流
    xumercury的BLOG
    狗友们的博客
    清蒸石斑鱼
    美女如刀锋
    茁茁的BLOG
    魅力老姐的窝
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 "是男人就挺过二十秒"源代码收藏

    新一篇: 用PB模拟器调试WINCE系统之简单步骤 | 旧一篇: 串口伪驱动实例

    //========================================================================
    //TITLE:
    //    "是男人就挺过二十秒"源代码
    //AUTHOR:
    //    norains
    //DATE:
    //   wednesday  25-April-2007
    //Environment:
    //        EVC4.0 + Standard SDK 4.2
    //        EVC4.0 + Standard SDK 5.0
    //========================================================================

        "是男人就挺过二十秒"简单的源代码 ,但基本结构已经完备,编译完毕在wince下便可正常游戏.
      

    // Bullets.h: interface for the CBullets class.
    //
    //////////////////////////////////////////////////////////////////////

    #ifndef BULLETS_H
    #define BULLETS_H

    class CBullets  
    {
    public:
        BOOL CheckCollision(
    const RECT rcArea);
        
    void Destroy();
        
    void Move();
        
    void Draw(HDC hdc);
        BOOL Initialize(
    int iCount,int iMaxMoveDistance,const RECT *prcWnd);
        CBullets();
        
    virtual ~CBullets();

    protected:
        
    double AverageRandom(double min,double max);
        
    int m_iCount;
        RECT m_rcWnd;
        
    int m_iMaxMoveDistance;
        CRITICAL_SECTION m_csBulletData; 
    //The Move() and the CheckCollision() could not be call in the same time

        typedef 
    struct
        
    {
            LONG x;
            LONG y;
            
    int iMoveDistX;
            
    int iMoveDistY;
        }
    BULLETDATA,*LPBULLETDATA;
        LPBULLETDATA lpBullet; 
    //Pointer to the bullet
        void InitializeBullet(LPBULLETDATA lpBullet);
    }
    ;

    #endif // #ifndef BULLETS_H

    // Bullets.cpp: implementation of the CBullets class.
    //
    //////////////////////////////////////////////////////////////////////

    #include 
    "stdafx.h"
    #include 
    "Bullets.h"


    //-------------------------------------------------------------------
    //Macro define

    //The radius of the bullet
    #define BULLET_RADIUS            2
    //The color of the bullet
    #define BULLET_COLOR            RGB(0,0,0)


    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////

    CBullets::CBullets()
    {
        m_iCount 
    = 0;
        m_iMaxMoveDistance 
    = 0;
        lpBullet 
    = NULL;
        memset(
    &m_rcWnd,0,sizeof(m_rcWnd));

        
    //Initialize the critical section
        InitializeCriticalSection(&m_csBulletData);
    }


    CBullets::
    ~CBullets()
    {
        DeleteCriticalSection(
    &m_csBulletData);
    }

    //--------------------------------------------------------------------
    //Description:
    //    Initialize the bullets
    //
    //Parameters:
    //    iCount: [in] The count of the bullet to create
    //    iMaxMoveDistance: [in] The max distance to move by each moving action,
    //            and the value should not more than the half of the plane
    //    prcWnd: [in] The rect of the window to play the bullet
    //
    //Return Values:
    //    TRUE: Succeed
    //    FALSE: Failed
    //--------------------------------------------------------------------
    BOOL CBullets::Initialize(int iCount,int iMaxMoveDistance, const RECT *prcWnd)
    {
        m_iCount 
    = iCount;
        m_rcWnd 
    = *prcWnd;
        m_iMaxMoveDistance 
    = iMaxMoveDistance;
        lpBullet 
    = new BULLETDATA[m_iCount];

        
    if(lpBullet == NULL)
        
    {
            
    return FALSE;
        }


        
    //Set the seed for the AverageRandom() function
        srand(GetTickCount());

        
    for(int i = 0; i < m_iCount; i++)
        
    {
            InitializeBullet(
    &lpBullet[i]);
        }


        
    return TRUE;
    }



    //--------------------------------------------------------------------
    //Description:
    //    Initialize the single bullets position
    //--------------------------------------------------------------------
    void CBullets::InitializeBullet(LPBULLETDATA lpBullet)
    {
        
    //Because the return value of AverageRandom() is double type, 
        
    //and chang the value to int. 
        
    //If your using like that: AverageRandom(1,4);
        
    //the number 4 is hard to create !
        int iRandom = (int)AverageRandom(1,5);


        
    //The bullet must begin in the edge
        if(iRandom == 1)
        
    {
            lpBullet
    ->= m_rcWnd.left;
            lpBullet
    ->= (int)AverageRandom(m_rcWnd.top,m_rcWnd.bottom);

            
    //Set the move direction
            lpBullet->iMoveDistX = 1;
            
    int iDirection = (int)AverageRandom(1,3);
            
    if(iDirection == 1)
            
    {
                lpBullet
    ->iMoveDistY = 1;
            }

            
    else
            
    {
                lpBullet
    ->iMoveDistY = -1;
            }

        }

        
    else if(iRandom == 2)
        
    {
            lpBullet
    ->= m_rcWnd.right;
            lpBullet
    ->= (int)AverageRandom(m_rcWnd.top,m_rcWnd.bottom);

            
    //Set the move direction
            lpBullet->iMoveDistX = -1;
            
    int iDirection = (int)AverageRandom(1,3);
            
    if(iDirection == 1)
            
    {
                lpBullet
    ->iMoveDistY = 1;
            }

            
    else
            
    {
                lpBullet
    ->iMoveDistY = -1;
            }

        }

        
    else if(iRandom == 3)
        
    {
            lpBullet
    ->= (int)AverageRandom(m_rcWnd.left,m_rcWnd.right);
            lpBullet
    ->= m_rcWnd.top;

            
    //Set the move direction
            lpBullet->iMoveDistY = 1;
            
    int iDirection = (int)AverageRandom(1,3);
            
    if(iDirection == 1)
            
    {
                lpBullet
    ->iMoveDistX = 1;
            }

            
    else
            
    {
                lpBullet
    ->iMoveDistX = -1;
            }

        }

        
    else if(iRandom == 4)
        
    {
            lpBullet
    ->= (int)AverageRandom(m_rcWnd.left,m_rcWnd.right);
            lpBullet
    ->= m_rcWnd.bottom;

            
    //Set the move direction
            lpBullet->iMoveDistY = -1;
            
    int iDirection = (int)AverageRandom(1,3);
            
    if(iDirection == 1)
            
    {
                lpBullet
    ->iMoveDistX = 1;
            }

            
    else
            
    {
                lpBullet
    ->iMoveDistX = -1;
            }

        }

        

        
    //Set the move distance
        iRandom = (int)AverageRandom(1,m_iMaxMoveDistance);
        lpBullet
    ->iMoveDistX *= iRandom;
        iRandom 
    = (int)AverageRandom(1,m_iMaxMoveDistance);
        lpBullet
    ->iMoveDistY *= iRandom;
    }



    //--------------------------------------------------------------------
    //Description:
    //    Create the random number.Before calling the method , you must set the seed 
    //by using srand() function.
    //
    //Parameters:
    //    dMin: [in] The min number
    //    dMax: [in] The max number
    //--------------------------------------------------------------------
    double CBullets::AverageRandom(double dMin, double dMax)
    {
        
    int iMin = (int)(dMin * 10000);
        
    int iMax = (int)(dMax * 10000);
        
    int iRand = rand() * rand();
        
    int iDiff = iMax - iMin;
        
    double dResult = (iRand % iDiff + iMin) / 10000.0;
        
    return dResult ;
    }




    //--------------------------------------------------------------------
    //Description:
    //    Move the bullets
    //---------------------------------------------------------------------
    void CBullets::Move()
    {
        EnterCriticalSection(
    &m_csBulletData);
        
    for(int i = 0; i < m_iCount; i++)
        
    {
            lpBullet[i].x 
    += lpBullet[i].iMoveDistX;
            lpBullet[i].y 
    += lpBullet[i].iMoveDistY;
                
            
    if(lpBullet[i].x < m_rcWnd.left || lpBullet[i].x > m_rcWnd.right || lpBullet[i].y < m_rcWnd.top || lpBullet[i].y > m_rcWnd.bottom)
            
    {
                InitializeBullet(
    &lpBullet[i]);
            }

        }

        LeaveCriticalSection(
    &m_csBulletData);
    }



    //--------------------------------------------------------------------
    //Description:
    //    Draw the bullet to the DC
    //---------------------------------------------------------------------
    void CBullets::Draw(HDC hdc)
    {
        HBRUSH hBrush 
    = CreateSolidBrush(BULLET_COLOR);
        HGDIOBJ hOldSel 
    = SelectObject(hdc,hBrush);

        RECT rcBullet 
    = {0};
        
    for(int i = 0; i < m_iCount; i++)
        
    {
            rcBullet.left 
    = lpBullet[i].x - BULLET_RADIUS;
            rcBullet.top 
    = lpBullet[i].y - BULLET_RADIUS;
            rcBullet.right 
    = lpBullet[i].x + BULLET_RADIUS;
            rcBullet.bottom 
    = lpBullet[i].y + BULLET_RADIUS;
            Ellipse(hdc,rcBullet.left,rcBullet.top,rcBullet.right,rcBullet.bottom);
        }


        SelectObject(hdc,hOldSel);
        DeleteObject(hBrush);
    }




    //--------------------------------------------------------------------
    //Description:
    //    Destroy the bullet
    //---------------------------------------------------------------------
    void CBullets::Destroy()
    {
        
    if(lpBullet != NULL)
        
    {
            delete [] lpBullet;
            lpBullet 
    = NULL;
        }

    }




    //--------------------------------------------------------------------
    //Description:
    //    Check the collision 
    //
    //Return Values:
    //    TRUE: Collided .
    //    FALSE: No collision
    //---------------------------------------------------------------------
    BOOL CBullets::CheckCollision(const RECT rcArea)
    {
        BOOL bCollide 
    = FALSE;

        
        EnterCriticalSection(
    &m_csBulletData);    
        
    for(int i = 0; i < m_iCount; i++)
        
    {
            
    if(lpBullet[i].x >= rcArea.left && lpBullet[i].x <= rcArea.right && lpBullet[i].y >= rcArea.top && lpBullet[i].y <= rcArea.bottom)