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

隨筆 - 96  文章 - 255  trackbacks - 0
<2008年6月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

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

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關(guān)網(wǎng)站

我的個人網(wǎng)頁

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 494500
  • 排名 - 39

最新評論

閱讀排行榜

評論排行榜

作者:龍飛

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

        不知道為什么,我總覺得總是用if結(jié)構(gòu)來調(diào)用命令讓人讀起程序來很不連貫。所以,我決定重新修改下,并且異常拋出改為使用類對象,這樣是不是更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 閱讀(2280) 評論(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>
            香蕉久久久久久久av网站| 亚洲第一精品电影| 欧美日韩视频在线一区二区观看视频| 亚洲欧美大片| 欧美一区二区视频在线观看2020| 亚洲欧美制服中文字幕| 香蕉成人伊视频在线观看 | 亚洲一区二区三区欧美| 亚洲一区在线观看视频 | 亚洲成人资源| 亚洲精品一区二区三| 亚洲一区免费| 久久久久久欧美| 欧美极品在线视频| 国产精品日韩精品欧美精品| 精品成人一区二区三区| 亚洲另类自拍| 欧美中文在线字幕| 欧美激情一区二区三区在线视频 | 乱码第一页成人| 欧美日韩一区二区三区在线| 国产女人水真多18毛片18精品视频| 国产亚洲精品资源在线26u| 亚洲精品五月天| 欧美影院成年免费版| 欧美激情第一页xxx| 亚洲综合日韩在线| 欧美成人一区在线| 国产精品中文在线| 99国产精品国产精品毛片| 久久精品一本| 99热这里只有成人精品国产| 久久精品一二三| 国产精品欧美久久久久无广告| 亚洲高清在线观看| 久久精品天堂| 亚洲一区二区三区三| 欧美激情欧美激情在线五月| 国语精品中文字幕| 欧美在线短视频| 亚洲免费观看在线观看| 久久久久国产精品厨房| 国产精品女主播一区二区三区| 亚洲美女在线国产| 久久精品一二三区| 香蕉av福利精品导航| 国产精品一区二区在线观看不卡| 99视频精品免费观看| 亚洲国产成人porn| 麻豆精品一区二区综合av | 国产伊人精品| 国精品一区二区三区| 中文无字幕一区二区三区| 久久女同互慰一区二区三区| 亚洲自拍偷拍色片视频| 国产精品卡一卡二卡三| 亚洲欧美日韩精品综合在线观看| 日韩一区二区精品视频| 欧美连裤袜在线视频| 99国内精品久久| 免费的成人av| 亚洲欧美另类综合偷拍| 欧美日韩高清在线一区| 亚洲福利一区| 欧美一区二区在线免费观看| 91久久黄色| 欧美一二区视频| 欧美日韩国产影院| 韩国一区二区三区在线观看| 亚洲天堂网在线观看| 免费h精品视频在线播放| 午夜在线不卡| 国产精品久久亚洲7777| 99re热这里只有精品视频| 久久综合狠狠| 欧美一区在线直播| 国产精品久久久久久久久久久久久久| 亚洲天堂黄色| 久久精品国产精品亚洲综合| 亚洲级视频在线观看免费1级| 亚洲人成网站在线播| 国产精品第一页第二页第三页| 午夜精品在线看| 久久亚洲精品一区| 欧美制服丝袜第一页| 久久久久网址| 亚洲另类春色国产| 亚洲一区二区成人| 黄色国产精品一区二区三区| 亚洲国产综合91精品麻豆| 国产精品国产三级国产aⅴ入口 | 亚洲一区三区电影在线观看| 午夜欧美大片免费观看 | 亚洲人成在线观看一区二区| 亚洲精品乱码久久久久久蜜桃91| 国产精品高潮呻吟久久av黑人| 久久精品99国产精品酒店日本| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲天堂激情| 猛干欧美女孩| 久久精品99无色码中文字幕 | 日韩亚洲不卡在线| 久久国产天堂福利天堂| 亚洲免费观看| 久久精品日韩| 午夜精品久久久久久久久久久久| 久久久97精品| 亚洲欧美一区二区激情| 久久国产乱子精品免费女| 亚洲无亚洲人成网站77777| 欧美伊久线香蕉线新在线| 中文在线一区| 欧美激情一区二区三区四区| 欧美专区日韩专区| 欧美视频在线一区二区三区| 欧美国产第二页| 一区视频在线| 欧美在线视频播放| 欧美一区二区在线| 国产精品色一区二区三区| 日韩视频在线免费| 日韩午夜在线播放| 噜噜噜噜噜久久久久久91| 老色批av在线精品| 国产综合香蕉五月婷在线| 亚洲视频免费在线| 中日韩视频在线观看| 欧美国产日本在线| 亚洲国产精品美女| 亚洲欧洲午夜| 欧美精品乱码久久久久久按摩| 亚洲盗摄视频| 亚洲人成啪啪网站| 欧美黄色影院| 亚洲伦理久久| 亚洲影视在线| 国产农村妇女精品一二区| 午夜国产精品影院在线观看 | 国产精品嫩草99a| 亚洲色无码播放| 亚洲欧美一区二区三区极速播放| 欧美激情国产日韩精品一区18| 欧美高清视频在线播放| 亚洲国产综合91精品麻豆| 久久综合久久久久88| 欧美国产免费| 日韩亚洲欧美成人一区| 欧美日韩国产三级| 中文av一区二区| 欧美在线播放视频| 一区二区在线视频播放| 欧美成人精品在线| 99精品热视频只有精品10| 性欧美暴力猛交69hd| 国产亚洲欧美激情| 久久久久久久久久久久久女国产乱 | 亚洲第一偷拍| 欧美日韩 国产精品| 中文成人激情娱乐网| 久久精品男女| 亚洲日韩视频| 蜜臀av性久久久久蜜臀aⅴ四虎| 欧美日韩福利在线观看| 亚洲一区二区三区成人在线视频精品 | 久久嫩草精品久久久久| 亚洲欧洲综合另类| 国产精品a久久久久| 久久黄色级2电影| 亚洲第一网站免费视频| 亚洲一区二区在线免费观看视频 | 亚洲精品久久久久久一区二区| 欧美日韩国产一级片| 亚洲欧美日韩国产综合| 欧美国产视频日韩| 午夜在线成人av| 影音先锋另类| 欧美午夜精品久久久久免费视 | 欧美一区二区视频在线观看| 亚洲高清av在线| 欧美专区在线播放| 夜夜嗨av一区二区三区| 国产欧美日韩精品一区| 欧美成人xxx| 午夜精品久久久久久久久久久| 亚洲高清精品中出| 久久精品国产第一区二区三区最新章节 | 欧美成人午夜影院| 欧美在线观看一区二区三区| 日韩视频免费在线| 免费国产一区二区| 午夜日韩电影| 一区二区欧美国产| 91久久精品国产91性色tv| 国产女主播一区二区三区| 欧美网站在线| 欧美日韩免费一区| 欧美金8天国| 欧美成人免费全部| 久久性色av| 久久先锋影音av|