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

隨筆 - 96  文章 - 255  trackbacks - 0
<2008年3月>
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

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

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關網站

我的個人網頁

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 495175
  • 排名 - 39

最新評論

閱讀排行榜

評論排行榜

 

//UVi Soft (2008)
//Long Fei (lf426), E-mail: zbln426@163.com

//FileName: SurfaceClass.h

#ifndef SURFACE_CLASS_H
#define SURFACE_CLASS_H

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

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;
    
void fillColor(Uint8 r = 0, Uint8 g = 0, Uint8 b = 0const;
};

class DisplaySurface
{
private:
    std::
string fileName;
    SDL_Surface
* pSurface;
    SDL_Surface
* pScreen;
public:
    DisplaySurface(
const std::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 = 0int delta_y = 0const;
    
void colorKey(Uint8 r = 0, Uint8 g = 0xFF, Uint8 b = 0xFF, Uint32 flag = SDL_SRCCOLORKEY);
};

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

#endif

//UVi Soft (2008)
//Long Fei (lf426), E-mail: zbln426@163.com

#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());
}


void ScreenSurface::fillColor(Uint8 r, Uint8 g, Uint8 b) const
{
     
if ( SDL_FillRect(pScreen, 0, SDL_MapRGB(pScreen->format, r, g, b)) < 0 )
         
throw ErrorInfo(SDL_GetError());
}

//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
//class DisplaySurface

DisplaySurface::DisplaySurface(
const std::string& file_name, const ScreenSurface& screen):
fileName(file_name)
{
    SDL_Surface
* pSurfaceTemp = IMG_Load(file_name.c_str());
    
if ( pSurfaceTemp == 0 )
        
throw ErrorInfo(SDL_GetError());
    pSurface 
= SDL_DisplayFormat(pSurfaceTemp);
    
if ( pSurface == 0 )
        
throw ErrorInfo(SDL_GetError());
    SDL_FreeSurface(pSurfaceTemp);
    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::colorKey(Uint8 r, Uint8 g, Uint8 b, Uint32 flag)
{
    Uint32 colorkey 
= SDL_MapRGB(pSurface->format, r, g, b);
    
if ( SDL_SetColorKey(pSurface, flag, colorkey ) < 0 )
        
throw ErrorInfo(SDL_GetError());
}

//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

//UVi Soft (2008)
//Long Fei (lf426), E-mail: zbln426@163.com

#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);
    
//Fill background with white.(default is black)
    screen.fillColor(0xFF0xFF0xFF);

    
//Load a sprite pic, and colorkey.(default color: R=0,G=0xFF,B=0xFF)
    DisplaySurface sprite("dots.png", screen);
    sprite.colorKey();

    
//the 4 dots's coordinate.
    int atX[4= {05400540};
    
int atY[4= {00380380};
    
//the 4 dots's clip coordinate.
    int fromX[4= {01000 ,100};
    
int fromY[4= {00100100};
    
//dots's size.
    const int IMG_WIDTH = 100;
    
const int IMG_HEIGHT = 100;
    
//clip dots.
    for ( int i = 0; i < 4; i++ )
        sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT);
    
//Draw dots and screen.
    screen.flip();
    
    
//press ESC or click X to quit.
    bool gameOver = false;
    SDL_Event gameEvent;
    
while( gameOver == false ){
        
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;
                }
            }
        }
    }

    
return 0;
}
posted on 2008-03-20 12:46 lf426 閱讀(2980) 評論(5)  編輯 收藏 引用 所屬分類: SDL入門教程

FeedBack:
# re: SDL入門教程(八):2、裁剪精靈圖片的完整源代碼[未登錄] 2008-09-24 14:51 伊凡
做點小改動,結果小球運動的時候出現難看的“軌跡”
不知道如何修改才能正常
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);
//Fill background with white.(default is black)
screen.fillColor(0xFF, 0xFF, 0xFF);

//Load a sprite pic, and colorkey.(default color: R=0,G=0xFF,B=0xFF)
DisplaySurface sprite("dots.png", screen);
sprite.colorKey();

//the 4 dots's coordinate.
int atX[4] = {0, 590, 0, 590};
int atY[4] = {0, 0, 430, 430};
//the 4 dots's clip coordinate.
int fromX[4] = {0, 270, 0 ,270};
int fromY[4] = {0, 0, 190, 190};
//mouse's coordinate.
int px = 0;
int py = 0;
//dots's size.
const int IMG_WIDTH = 50;
const int IMG_HEIGHT = 50;
//clip dots.
for ( int i = 0; i < 4; i++ )
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT);
//Draw dots and screen.
screen.flip();

//press ESC or click X to quit.
bool gameOver = false;
SDL_Event gameEvent;
while( gameOver == false ){
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;
}
}
//mouse event
if ( gameEvent.type == SDL_MOUSEMOTION ) {
px = gameEvent.motion.x;
py = gameEvent.motion.y;
}
}
for(int i = 0 ; i < 4 ;i++)
{
if ( atX[i] < px )
atX[i]++;
if ( atX[i] > px )
atX[i]--;
if ( atY[i] < py )
atY[i]++;
if ( atY[i] > py )
atY[i]--;
}
//clip dots.
for ( int i = 0; i < 4; i++ )
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT,2,2);
//Draw dots and screen.
screen.flip();
}

return 0;
}  回復  更多評論
  
# re: SDL入門教程(八):2、裁剪精靈圖片的完整源代碼[未登錄] 2008-09-25 11:29 lf426
每次畫圖前先清屏哈。最后一個循環改成:
for ( int i = 0; i < 4; i++ ) {
screen.fillColor(0xFF, 0xFF, 0xFF);
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT,2,2);
}
試試  回復  更多評論
  
# re: SDL入門教程(八):2、裁剪精靈圖片的完整源代碼[未登錄] 2008-09-27 09:55 伊凡
非常感謝你的回答,我試了下,結果是這樣才正常
//clip dots.
for ( int i = 0; i < 4; i++ )
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT,2,2);

//Draw dots and screen.
screen.flip();
screen.fillColor(0xFF, 0xFF, 0xFF);  回復  更多評論
  
# re: SDL入門教程(八):2、裁剪精靈圖片的完整源代碼[未登錄] 2008-09-27 09:56 伊凡
如果這樣寫
for ( int i = 0; i < 4; i++ ) {
screen.fillColor(0xFF, 0xFF, 0xFF);
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT,2,2);
}

就變成只有一個球了,也不太理解為什么會這樣。。。  回復  更多評論
  
# re: SDL入門教程(八):2、裁剪精靈圖片的完整源代碼[未登錄] 2008-09-27 11:17 lf426
呵呵,我的失誤,忘記flip了。
for ( int i = 0; i < 4; i++ ) {
screen.fillColor(0xFF, 0xFF, 0xFF);
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT,2,2);
screen.flip();
}   回復  更多評論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
              国产亚洲精品aa| 久久久久国产成人精品亚洲午夜| 亚洲欧美日韩一区二区三区在线| 一级成人国产| 亚洲欧美区自拍先锋| 欧美在线二区| 欧美高清你懂得| 日韩视频第一页| 欧美在线观看你懂的| 久久综合影视| 欧美日韩久久久久久| 国产精品永久免费观看| 在线观看日韩www视频免费| 日韩一二三区视频| 欧美一区亚洲一区| 亚洲电影自拍| 一区二区三区欧美在线| 久久国产日韩| 欧美女激情福利| 国产亚洲成av人片在线观看桃 | 亚洲第一视频网站| 亚洲宅男天堂在线观看无病毒| 久久精品女人| 欧美性猛交xxxx乱大交退制版| 狠狠久久五月精品中文字幕| 在线视频欧美日韩| 蜜桃伊人久久| 亚洲欧美中文在线视频| 欧美另类99xxxxx| 亚洲第一黄色网| 久久精品观看| 亚洲专区一二三| 欧美日韩亚洲一区二区三区在线 | 日韩一级在线| 欧美chengren| 午夜久久电影网| 欧美日韩一区二区三区四区在线观看 | 99re热这里只有精品视频| 日韩视频精品在线| 久久成人精品无人区| 日韩午夜高潮| 欧美本精品男人aⅴ天堂| 国产一区二区三区久久精品| 亚洲免费网址| 一区二区三区欧美亚洲| 欧美日本在线播放| 日韩亚洲视频| 亚洲精品1区2区| 久久综合九色| 在线观看亚洲a| 久久中文字幕导航| 欧美专区在线| 黑人操亚洲美女惩罚| 久久精品99国产精品酒店日本| 99国产成+人+综合+亚洲欧美| 欧美成人精品激情在线观看| 亚洲黄色免费电影| 亚洲第一页在线| 欧美1级日本1级| 日韩视频亚洲视频| 99视频精品免费观看| 欧美日本在线看| 亚洲午夜高清视频| 亚洲午夜精品| 国产精品视频内| 久久久www成人免费毛片麻豆| 欧美影院成人| 亚洲国产成人精品久久| 亚洲高清在线播放| 欧美日韩一区在线观看| 亚洲欧美日韩精品久久奇米色影视| 一本一道久久综合狠狠老精东影业 | 欧美大香线蕉线伊人久久国产精品| 欧美中文在线观看| 激情六月综合| 91久久亚洲| 国产精品久久久99| 久久久午夜电影| 欧美激情视频一区二区三区不卡| 夜夜嗨av一区二区三区中文字幕 | 在线观看不卡| 亚洲国产精品第一区二区| 欧美日韩一区二区高清| 亚洲午夜久久久久久久久电影院 | 欧美黄色免费| 亚洲小说欧美另类社区| 欧美一区二区高清在线观看| 亚洲国产精品成人综合色在线婷婷| 亚洲黄页一区| 国产日韩精品久久| 亚洲国产1区| 国产免费成人av| 欧美国产日韩一区| 国产区精品在线观看| 亚洲欧洲精品一区二区精品久久久| 国产精品久久久久久久久免费桃花 | 久久精品人人| 欧美日韩日本国产亚洲在线| 久久久噜噜噜久噜久久| 欧美午夜不卡影院在线观看完整版免费| 欧美一区二区性| 欧美日韩成人综合| 欧美高清在线视频观看不卡| 国产精品色一区二区三区| 欧美电影在线播放| 国产日韩欧美一区二区三区在线观看| 牛牛精品成人免费视频| 国产欧美高清| 亚洲视频在线观看视频| 亚洲人成毛片在线播放| 久久精品欧洲| 久久国产精品99国产精| 欧美色另类天堂2015| 欧美激情第1页| 精品二区视频| 久久成人国产精品| 欧美在线观看视频在线| 欧美三区在线视频| 最近中文字幕mv在线一区二区三区四区| 国产视频欧美| 亚洲欧美怡红院| 亚洲欧美综合一区| 欧美日韩一级大片网址| 91久久在线播放| 日韩天堂在线视频| 欧美国产日韩在线观看| 欧美国产国产综合| 亚洲国产日韩欧美综合久久| 久久久亚洲影院你懂的| 久久躁日日躁aaaaxxxx| 国内偷自视频区视频综合| 午夜精彩国产免费不卡不顿大片| 亚洲欧美日韩精品综合在线观看| 欧美视频免费在线| 在线视频欧美日韩精品| 亚洲欧美综合另类中字| 国产毛片一区| 久久视频在线免费观看| 欧美成人r级一区二区三区| 亚洲国产影院| 女人色偷偷aa久久天堂| 欧美激情亚洲国产| 91久久久久久| 亚洲尤物影院| 国产欧美一区二区白浆黑人| 欧美一区1区三区3区公司| 久久天堂成人| 亚洲人永久免费| 欧美日韩免费一区| 性久久久久久久久久久久| 蜜桃av一区二区在线观看| 亚洲福利在线观看| 欧美日韩国产123区| 一区二区精品| 久久久久久久久伊人| 91久久精品一区二区别| 欧美午夜www高清视频| 欧美伊人久久久久久午夜久久久久| 久久天天躁狠狠躁夜夜av| 最新日韩在线| 国产精品入口66mio| 久久青草福利网站| 99re热这里只有精品免费视频| 欧美一区午夜精品| 亚洲国产综合在线| 国产精品尤物| 欧美插天视频在线播放| aa级大片欧美三级| 欧美成人一区二区| 亚洲午夜精品| 欧美电影在线| 欧美一区二区三区免费看| 亚洲国产日韩欧美在线99 | 亚洲国产另类久久久精品极度| 亚洲一区免费视频| 亚洲电影专区| 国产欧美日韩中文字幕在线| 欧美大香线蕉线伊人久久国产精品| 亚洲午夜视频在线| 欧美激情精品| 久久久噜噜噜久噜久久| 亚洲视频在线观看网站| 亚洲第一在线视频| 国产亚洲aⅴaaaaaa毛片| 欧美日韩午夜剧场| 免费的成人av| 久久九九国产精品怡红院| 亚洲一区二区在线看| 亚洲精品国精品久久99热一| 麻豆91精品| 久久精品人人做人人爽| 亚洲欧美日韩国产成人精品影院 | 亚洲视频在线视频| 亚洲欧洲日韩女同| 一区免费视频| 国产综合视频| 国产一区二区三区在线观看免费| 国产精品每日更新在线播放网址| 欧美精品免费在线| 欧美成人午夜激情在线|