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

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

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

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關網站

我的個人網頁

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 495350
  • 排名 - 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 閱讀(2984) 評論(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>
              久久成人综合网| 免费在线成人av| 欧美激情国产日韩| 久久久久国产精品一区三寸| 亚洲欧洲av一区二区| 亚洲欧美在线观看| 久久精品99| 暖暖成人免费视频| 日韩视频一区二区三区在线播放免费观看 | 一区二区日韩精品| aa国产精品| 欧美亚洲综合久久| 欧美高清视频| 国产精品日韩精品欧美在线| 黄色综合网站| 一本色道久久综合精品竹菊| 亚洲你懂的在线视频| 久久久精品国产免大香伊 | 亚洲一区二区视频在线| 久久激情视频久久| 91久久精品美女高潮| 亚洲全黄一级网站| 欧美一区二区三区免费在线看 | 一本色道久久综合亚洲精品不卡| 亚洲欧美日韩精品久久久久| 美女91精品| 亚洲一区视频在线| 欧美激情视频一区二区三区不卡| 国产精品一区二区久久久久| 亚洲精品欧美激情| 久久久亚洲午夜电影| 一本大道久久精品懂色aⅴ| 久久精品午夜| 国产精品视频1区| 一区二区三区精品视频在线观看| 久久一区二区三区超碰国产精品| 日韩午夜免费视频| 欧美.www| 亚洲国产小视频| 老司机亚洲精品| 欧美一区激情视频在线观看| 影音先锋久久| 久久久噜噜噜久久久| 91久久精品国产| 麻豆久久婷婷| 在线播放豆国产99亚洲| 欧美专区18| 亚洲一区二区三区免费视频| 欧美日本高清一区| 亚洲精品视频二区| 亚洲国产欧美不卡在线观看| 久久精品国产第一区二区三区| 国产精品麻豆成人av电影艾秋| 99国产精品久久久久老师| 欧美激情小视频| 欧美成年人视频| 亚洲人成久久| 亚洲黄色av一区| 欧美精品一区二区精品网| 亚洲片国产一区一级在线观看| 久久艳片www.17c.com| 久久av一区二区三区| 黄色一区二区三区四区| 老司机精品导航| 欧美成人三级在线| 亚洲午夜久久久久久久久电影网| 一本色道久久综合亚洲精品不卡| 欧美午夜久久久| 久久精品国产亚洲aⅴ| 久久精品国产69国产精品亚洲| 在线观看av不卡| 亚洲韩国日本中文字幕| 欧美精品一区二区三区很污很色的| 亚洲国产欧洲综合997久久| 欧美激情aⅴ一区二区三区| 欧美国产免费| 亚洲男人的天堂在线| 香蕉亚洲视频| 亚洲国产综合在线| 99成人在线| 国产区日韩欧美| 免费在线观看精品| 欧美日韩亚洲视频| 久久久久88色偷偷免费| 欧美91大片| 欧美一区二区三区在| 麻豆精品在线视频| 午夜国产精品影院在线观看| 久久精品国亚洲| 一本久道久久综合狠狠爱| 亚洲欧美日韩另类| 亚洲精品之草原avav久久| 亚洲免费一在线| 亚洲欧洲在线看| 欧美伊久线香蕉线新在线| 99国产一区| 久久精品视频免费| 亚洲欧美国产77777| 久久久噜噜噜久久| 亚洲欧美激情一区| 欧美freesex交免费视频| 欧美在线观看视频一区二区| 久久一区二区三区超碰国产精品| 亚洲素人一区二区| 一区二区三区高清| 久久久久看片| 欧美一级视频精品观看| 鲁大师成人一区二区三区| 欧美一区二区| 欧美三级网址| 91久久精品www人人做人人爽| 国产一区二区av| 中文精品视频一区二区在线观看| 1024亚洲| 久久精品一区中文字幕| 欧美一区二区播放| 欧美三区美女| 亚洲欧洲视频在线| 91久久精品www人人做人人爽| 欧美在线www| 久久精品二区亚洲w码| 国产伦理精品不卡| 一本一本久久a久久精品综合妖精| 最新日韩精品| 免费影视亚洲| 欧美激情四色| 亚洲欧洲中文日韩久久av乱码| 久久久999国产| 麻豆久久精品| 亚洲国产mv| 免费不卡在线视频| 欧美大片va欧美在线播放| 在线精品福利| 免费短视频成人日韩| 欧美肥婆bbw| 亚洲黄色在线| 欧美乱妇高清无乱码| 亚洲伦理中文字幕| 亚洲午夜精品17c| 国产乱码精品一区二区三区忘忧草| 日韩视频中文| 性欧美18~19sex高清播放| 国产精品视频成人| 欧美一区二区免费| 模特精品在线| 日韩一级免费| 国产精品久久久久久超碰| 亚洲视频1区| 久久久在线视频| 91久久久久久久久久久久久| 欧美激情在线| 亚洲一区三区视频在线观看| 久久成人一区| 91久久综合| 国产精品白丝jk黑袜喷水| 亚洲欧美制服另类日韩| 美女图片一区二区| 99国产精品久久久久久久成人热| 欧美日韩午夜在线视频| 亚洲欧美国产77777| 美女视频黄 久久| 夜夜精品视频一区二区| 国产欧美日韩综合一区在线播放 | 狠狠色丁香久久婷婷综合_中| 久久在线免费| 一区二区三区高清| 欧美 日韩 国产在线 | 午夜精品久久久久久久蜜桃app| 国产精品色婷婷久久58| 亚洲电影视频在线| 久久中文字幕一区二区三区| 亚洲欧美在线免费观看| 国产午夜精品理论片a级大结局| 久久国产一区二区三区| 亚洲精品乱码久久久久久| 午夜在线精品偷拍| 亚洲人成啪啪网站| 国产精品视频成人| 欧美成人日韩| 久久精品成人欧美大片古装| 亚洲另类在线一区| 免费在线观看成人av| 午夜视频一区| 一本色道久久综合狠狠躁篇的优点| 国产一区二区日韩精品| 欧美日韩成人一区二区| 久久先锋影音av| 亚洲欧美日韩综合| 亚洲美女啪啪| 亚洲福利视频网站| 玖玖精品视频| 欧美一区2区三区4区公司二百 | 亚洲黄网站在线观看| 国产日韩精品久久| 欧美系列精品| 欧美日韩色婷婷| 欧美大片在线观看| 久久蜜桃精品| 久久精品人人做人人爽| 午夜精品久久一牛影视|