青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 96  文章 - 255  trackbacks - 0
<2008年2月>
272829303112
3456789
10111213141516
17181920212223
2425262728291
2345678

E-mail:zbln426@163.com QQ:85132383 長期尋找對戰略游戲感興趣的合作伙伴。

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關網站

我的個人網頁

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 495367
  • 排名 - 39

最新評論

閱讀排行榜

評論排行榜

作者:龍飛

6.1:用bool作為命令是不是畫蛇添足了?

        不知道為什么,我總覺得總是用if結構來調用命令讓人讀起程序來很不連貫。所以,我決定重新修改下,并且異常拋出改為使用類對象,這樣是不是更C++一點呢?:)

6.2:修改后的代碼。
//FileName: SurfaceClass.h

#ifndef SURFACE_CLASS_H
#define SURFACE_CLASS_H

#include 
<iostream>
#include 
<string>
#include 
"SDL/SDL.h"

using std::string;

class ScreenSurface
{
private:
    
static int screenNum;
    
int width;
    
int height;
    
int bpp;
    Uint32 flags;
    SDL_Surface
* pScreen;
public:
    ScreenSurface();
    ScreenSurface(
int w, int h, int b = 0, Uint32 f = 0);
    
~ScreenSurface();
    SDL_Surface
* point() const;
    
void flip() const;
};

class DisplaySurface
{
private:
    
string fileName;
    SDL_Surface
* pSurface;
    SDL_Surface
* pScreen;
public:
    DisplaySurface(
string file_name, const ScreenSurface& screen);
    
~DisplaySurface();
    SDL_Surface
* point() const;
    
void blit() const;
    
void blit(int at_x, int at_y) const;
    
void blit(int at_x, int at_y,
                
int from_x, int from_y, int w, int h,
                
int delta_x = 2int delta_y = 2const;
    
void blitToSurface(const DisplaySurface& dst_surface,
                        
int at_x = 0int at_y = 0const;
    
void blitToSurface(const DisplaySurface& dst_surface,
                        
int at_x, int at_y,
                        
int from_x, int from_y, int w, int h,
                        
int delta_x = 2int delta_y = 2const;
};

class ErrorInfo
{
private:
    
string info;
public:
    ErrorInfo():info(
"Unknown ERROR!")
    {}
    ErrorInfo(
const char* c_str)
    {
        info 
= string(c_str);
    }
    ErrorInfo(
const string& str):info(str)
    {}
    
void show() const
    {
        std::cerr 
<< info << std::endl;
    }
};

#endif

#include "SurfaceClass.h"

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
//class ScreenSurface

int ScreenSurface::screenNum = 0;

ScreenSurface::ScreenSurface():
width(
640), height(480), bpp(32), flags(0)
{
    
if ( screenNum > 0 )
        
throw ErrorInfo("DONOT create more than ONE screen!");
    
if ( SDL_Init(SDL_INIT_VIDEO < 0 ) )
        
throw ErrorInfo(SDL_GetError());
    pScreen 
= SDL_SetVideoMode(width, height, bpp, flags);
    screenNum
++;
}

ScreenSurface::ScreenSurface(
int w, int h, int b, Uint32 f):
width(w), height(h), bpp(b), flags(f)
{
    
if ( screenNum > 0 )
        
throw ErrorInfo("DONOT create more than ONE screen!");
    
if ( SDL_Init(SDL_INIT_VIDEO < 0 ) )
        
throw ErrorInfo(SDL_GetError());
    pScreen 
= SDL_SetVideoMode(width, height, bpp, flags);
    screenNum
++;
}

ScreenSurface::
~ScreenSurface()
{
    SDL_Quit();
}

SDL_Surface
* ScreenSurface::point() const
{
    
return pScreen;
}

void ScreenSurface::flip() const
{
    
if ( SDL_Flip(pScreen) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
//class DisplaySurface

DisplaySurface::DisplaySurface(std::
string file_name, const ScreenSurface& screen):
fileName(file_name)
{
    pSurface 
= SDL_LoadBMP(file_name.c_str());
    
if ( pSurface == 0 )
        
throw ErrorInfo(SDL_GetError());
    pScreen 
= screen.point();
}

DisplaySurface::
~DisplaySurface()
{
    SDL_FreeSurface(pSurface);
}

SDL_Surface
* DisplaySurface::point() const
{
    
return pSurface;
}

void DisplaySurface::blit() const
{
    
if ( SDL_BlitSurface(pSurface, 0, pScreen, 0< 0 )
        
throw ErrorInfo(SDL_GetError());
}


void DisplaySurface::blit(int at_x, int at_y) const
{
    SDL_Rect offset;
    offset.x 
= at_x;
    offset.y 
= at_y;

    
if ( SDL_BlitSurface(pSurface, 0, pScreen, &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

void DisplaySurface::blit(int at_x, int at_y,
                          
int from_x, int from_y, int w, int h,
                          
int delta_x, int delta_y) const
{
    SDL_Rect offset;
    offset.x 
= at_x - delta_x;
    offset.y 
= at_y - delta_y;

    SDL_Rect dest;
    dest.x 
= from_x - delta_x;
    dest.y 
= from_y - delta_y;
    dest.w 
= w + delta_x*2;
    dest.h 
= h + delta_y*2;

    
if ( SDL_BlitSurface(pSurface, &dest, pScreen, &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

void DisplaySurface::blitToSurface(const DisplaySurface& dst_surface, int at_x, int at_y) const
{
    SDL_Rect offset;
    offset.x 
= at_x;
    offset.y 
= at_y;

    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");

    
if ( SDL_BlitSurface(pSurface, 0, dst_surface.point(), &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

void DisplaySurface::blitToSurface(const DisplaySurface& dst_surface,
                                    
int at_x, int at_y,
                                    
int from_x, int from_y, int w, int h,
                                    
int delta_x, int delta_y) const
{
    SDL_Rect offset;
    offset.x 
= at_x - delta_x;
    offset.y 
= at_y - delta_y;

    SDL_Rect dest;
    dest.x 
= from_x - delta_x;
    dest.y 
= from_y - delta_y;
    dest.w 
= w + delta_x*2;
    dest.h 
= h + delta_y*2;

    
if ( &dst_surface == this )
        
throw ErrorInfo("Cannot blit surface to itself!");

    
if ( SDL_BlitSurface(pSurface, &dest, dst_surface.point(), &offset) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


 

#include "SurfaceClass.h"

int game(int argc, char* argv[]);
int main(int argc ,char* argv[])
{
    
int mainRtn = 0;
    
try {
        mainRtn 
= game(argc, argv);
    }
    
catch ( const ErrorInfo& info ) {
        info.show();
        
return -1;
    }
    
    
return mainRtn;
}

int game(int argc ,char* argv[])
{
    
//Create a SDL screen.
    const int SCREEN_WIDTH = 640;
    
const int SCREEN_HEIGHT = 480;
    ScreenSurface screen(SCREEN_WIDTH, SCREEN_HEIGHT);

    
//Create 2 SDL surface for the screen that just created.
    DisplaySurface backGround("bg.bmp", screen);
    DisplaySurface frontImage(
"image.bmp", screen);
    
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
    
//way2: If use blitToSurface, must get a copy of backGround.
/*

    DisplaySurface backGroundCopy("bg.bmp", screen);
*/
    
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

    
//Blit backGround surface to screen and flip the screen.
    backGround.blit();
    screen.flip();

    
//variable for main loop.
    
//key event for up, down, left and right.
    Uint8* keys;
    
//moving image's coordinate.
    int xpos = 0;
    
int ypos = 0;
    
//moving image's size.
    const int IMG_WIDTH = 128;
    
const int IMG_HEIGHT = 128;
    
//main loop.
    bool gameOver = false;
    
while( gameOver == false ){
        
//press ESC or click X to quit.
        SDL_Event gameEvent;
        
while ( SDL_PollEvent(&gameEvent) != 0 ){
            
if ( gameEvent.type == SDL_QUIT ){
                gameOver 
= true;
            }
            
if ( gameEvent.type == SDL_KEYUP ){
                
if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){
                    gameOver 
= true;
                }
            }
        }
        
//key event to move image.
        keys = SDL_GetKeyState(0);
        
if ( keys[SDLK_UP] || keys[SDLK_w] ){
            ypos 
-= 1;
        }
        
if ( keys[SDLK_DOWN]|| keys[SDLK_s] ){
            ypos 
+= 1;
        }
        
if ( keys[SDLK_LEFT]|| keys[SDLK_a] ){
            xpos 
-= 1;
        }
        
if ( keys[SDLK_RIGHT]|| keys[SDLK_d] ){
            xpos 
+= 1;
        }

        
//Hold moving image on the backGround area.
        if ( xpos <= 0 )
            xpos 
= 0;
        
if ( xpos >= SCREEN_WIDTH - IMG_WIDTH )
            xpos 
= SCREEN_WIDTH - IMG_WIDTH;
        
if ( ypos <= 0 )
            ypos 
= 0;
        
if ( ypos >= SCREEN_HEIGHT - IMG_HEIGHT )
            ypos 
= SCREEN_HEIGHT - IMG_HEIGHT;

        
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
        
//way1: blit surface to screen
        
//Blit a part of backGround ( a rectangular area ) to screen,
        
//then the original blitted backGround can be "cleaned".
        backGround.blit(xpos, ypos, xpos, ypos, IMG_WIDTH, IMG_HEIGHT);
        
//Blit the image to screen.
        frontImage.blit(xpos, ypos);
        
//Flip the screen
        screen.flip();
        
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

        
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
        
//way2: blit surface to surface, then blit the last surface to screen
/*

        backGroundCopy.blitToSurface(backGround, xpos, ypos, xpos, ypos, IMG_WIDTH, IMG_HEIGHT);
        frontImage.blitToSurface(backGround, xpos, ypos);
        backGround.blit();
        screen.flip();
*/
        
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    }

    
return 0;
}
posted on 2008-02-22 18:15 lf426 閱讀(2281) 評論(0)  編輯 收藏 引用 所屬分類: SDL入門教程
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲看片一区| 亚洲国产综合91精品麻豆| 欧美亚洲三区| 欧美亚洲网站| 久久亚洲一区二区| 免费不卡在线视频| 欧美精品激情blacked18| 欧美日韩福利| 国产精品推荐精品| 一区二区在线视频播放| 亚洲人成网站色ww在线| 亚洲网在线观看| 欧美一区二区视频观看视频| 久久综合九色综合欧美狠狠| 欧美aⅴ99久久黑人专区| 亚洲精品乱码| 亚洲视频你懂的| 久久米奇亚洲| 欧美日韩中文在线| 狠狠久久婷婷| 亚洲网站在线| 免费人成网站在线观看欧美高清| 亚洲国产影院| 性欧美大战久久久久久久免费观看| 久久电影一区| 欧美日韩在线影院| 亚洲福利在线看| 亚洲欧美区自拍先锋| 美女视频黄免费的久久| 一片黄亚洲嫩模| 免费观看欧美在线视频的网站| 国产精品国产亚洲精品看不卡15 | 性欧美办公室18xxxxhd| 免费黄网站欧美| 亚洲香蕉视频| 欧美日韩国产综合视频在线观看| 国产一区二区三区四区三区四| 99精品国产高清一区二区 | 亚洲精品国产精品国产自| 亚洲欧美日韩天堂一区二区| 欧美激情乱人伦| 久久久久久9999| 国产日韩一区欧美| 亚洲一区二区在线播放| 欧美激情一二区| 久久av老司机精品网站导航| 欧美激情第二页| 久久另类ts人妖一区二区| 亚洲婷婷在线| 欧美日韩一区二区免费视频| 亚洲国产岛国毛片在线| 久久亚洲精品视频| 久久国产精品一区二区| 国产欧美在线播放| 欧美在线观看一区二区三区| 欧美午夜视频一区二区| 亚洲精品免费一二三区| 欧美成人一区在线| 久久夜色精品国产欧美乱极品| 国产女主播一区二区三区| 亚洲影院在线观看| 日韩一级黄色大片| 欧美日韩中文在线| 亚洲影院在线观看| 亚洲欧美日韩成人高清在线一区| 国产精品乱码妇女bbbb| 欧美一区二区三区电影在线观看| 一区二区欧美亚洲| 国产精品一区免费在线观看| 欧美怡红院视频| 久久岛国电影| 亚洲欧洲精品成人久久奇米网| 亚洲国产精品久久久久秋霞影院 | 麻豆国产精品777777在线| 红桃视频欧美| 亚洲国产精品久久久久秋霞蜜臀| 欧美精品一线| 亚洲欧美日韩一区二区三区在线观看| 一本色道久久精品| 国产欧美韩日| 美女主播一区| 欧美日韩高清在线一区| 午夜宅男久久久| 久久亚洲图片| 亚洲欧美精品| 久久一二三区| 亚洲一区二区三区精品动漫| 亚洲一区在线观看视频 | 亚洲欧美制服中文字幕| 亚洲欧美国产制服动漫| 国内精品久久久久影院薰衣草| 久久五月天婷婷| 久久精品夜夜夜夜久久| 99在线观看免费视频精品观看| 亚洲一区二区三区免费观看| 一区二区在线视频观看| 亚洲美女91| 黄色一区二区三区四区| 亚洲精品免费在线观看| 亚洲黄色免费| 国产精品户外野外| 久久综合狠狠| 国产精品久久久久久影院8一贰佰| 久久久女女女女999久久| 欧美国产一区二区三区激情无套| 在线亚洲高清视频| 经典三级久久| 亚洲国产一区二区三区青草影视 | 9国产精品视频| 国产欧美一区二区视频| 欧美激情一区二区三区高清视频 | 日韩亚洲在线| 性色av一区二区怡红| 99国产欧美久久久精品| 欧美一区二区日韩一区二区| 999亚洲国产精| 久久蜜臀精品av| 欧美伊人久久大香线蕉综合69| 欧美高清日韩| 老司机免费视频久久| 欧美午夜欧美| 亚洲大片av| 国产综合久久| 欧美在线啊v一区| 久久精品国产一区二区三| 欧美色中文字幕| 亚洲日本中文字幕区| 精品不卡一区二区三区| 亚洲综合日韩在线| 亚洲一区二区在线视频| 男女激情视频一区| 猛男gaygay欧美视频| 国语精品中文字幕| 午夜精品剧场| 另类成人小视频在线| 欧美在线看片| 国产日韩久久| 久久国产夜色精品鲁鲁99| 久久久国产精品一区二区三区| 国产精品蜜臀在线观看| 亚洲午夜av电影| 欧美专区亚洲专区| 国产日韩一区欧美| 午夜精品久久久久影视| 香蕉免费一区二区三区在线观看| 欧美午夜理伦三级在线观看| 日韩视频在线永久播放| 亚洲一区二区三区成人在线视频精品| 欧美日韩aaaaa| 日韩一区二区精品葵司在线| 亚洲精品日产精品乱码不卡| 欧美国产精品专区| 亚洲色诱最新| 久热爱精品视频线路一| 亚洲精品综合| 国产精品美女久久久久久久 | 免费观看成人www动漫视频| 亚洲第一福利在线观看| 免费观看日韩| 9久草视频在线视频精品| 亚洲午夜在线视频| 国产亚洲日本欧美韩国| 久久夜色精品国产亚洲aⅴ| 亚洲片区在线| 久久精品一区二区| 亚洲国产成人av| 欧美日韩一区二区三区在线观看免| 亚洲一区视频在线| 韩日欧美一区二区| 麻豆国产精品va在线观看不卡| 国产一区视频在线看| 久热爱精品视频线路一| 一区二区不卡在线视频 午夜欧美不卡在 | 一区二区av在线| 久久久久久久久久码影片| 亚洲第一网站免费视频| 欧美日韩一区二区三区四区五区| 午夜精品视频网站| 亚洲大胆在线| 欧美一区二区视频在线| 91久久国产综合久久91精品网站| 欧美午夜视频在线| 欧美v日韩v国产v| 亚洲欧美美女| 亚洲精品日韩在线观看| 久久久午夜视频| 亚洲在线一区二区| 亚洲区第一页| 国产亚洲一区精品| 欧美日韩一区二区免费在线观看| 久久久久久久久岛国免费| 亚洲婷婷免费| 99精品欧美一区二区蜜桃免费| 久久免费观看视频| 午夜精品久久久| 亚洲午夜国产成人av电影男同| 亚洲国产成人av| 伊人男人综合视频网| 国产毛片一区二区| 国产精品日韩电影|