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

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

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

常用鏈接

留言簿(21)

隨筆分類

隨筆檔案

SDL相關網(wǎng)站

我的個人網(wǎng)頁

我的小游戲

資源下載

搜索

  •  

積分與排名

  • 積分 - 496239
  • 排名 - 39

最新評論

閱讀排行榜

評論排行榜

作者:龍飛

5.1:準備工作。

一張640*480大小的bmp文件作為背景,命名為:bg.bmp;
一張128*128大小的bmp文件作為要在背景上移動的圖片,命名為:image.bmp。

5.2:頭文件SurfaceClass.h
//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;
    
bool 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;
    
bool blit() const;
    
bool blit(int at_x, int at_y) const;
    
bool blit(int at_x, int at_y,
                
int from_x, int from_y, int w, int h,
                
int delta_x = 2int delta_y = 2const;
    
bool blitToSurface(const DisplaySurface& dst_surface,
                        
int at_x = 0int at_y = 0const;
    
bool 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;
};

#endif

5.3:類方法的實現(xiàn)文件:SurfaceClass.cpp
#include "SurfaceClass.h"

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
//class ScreenSurface

int ScreenSurface::screenNum = 0;

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

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

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

bool ScreenSurface::flip() const
{
    
if ( SDL_Flip(pScreen) < 0 )
        
return false;
    
else return true;
}

//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 SDL_GetError();
    pScreen 
= screen.point();
}

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

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

bool DisplaySurface::blit() const
{
    
if ( SDL_BlitSurface(pSurface, 0, pScreen, 0< 0 )
        
return false;
    
else return true;
}


bool 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 )
        
return false;
    
else return true;
}

bool 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 )
        
return false;
    
else return true;
}

bool 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 "Cannot blit surface to itself!";

    
if ( SDL_BlitSurface(pSurface, 0, dst_surface.point(), &offset) < 0 )
        
return false;
    
else return true;
}

bool 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 "Cannot blit surface to itself!";

    
if ( SDL_BlitSurface(pSurface, &dest, dst_surface.point(), &offset) < 0 )
        
return false;
    
else return true;
}

//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

5.4:演示文件main.cpp
#include "SurfaceClass.h"

void game();
int main(int argc ,char* argv[])
{
    
try {
        game();
    }
    
catch ( const char* s ) {
        std::cerr 
<< s << std::endl;
        
return -1;
    }
    
    
return 0;
}

void game()
{
    
//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.
    if ( backGround.blit() == false )
        
throw SDL_GetError();
    
if ( screen.flip() == false )
        
throw SDL_GetError();

    
//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".
        if ( backGround.blit(xpos, ypos, xpos, ypos, IMG_WIDTH, IMG_HEIGHT) == false )
            
throw SDL_GetError();
        
//Blit the image to screen.
        if ( frontImage.blit(xpos, ypos) == false )
            
throw SDL_GetError();
        
//Flip the screen
        if ( screen.flip() == false )
            
throw SDL_GetError();
        
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

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

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

    
return;
}
posted on 2008-02-21 15:22 lf426 閱讀(3078) 評論(4)  編輯 收藏 引用 所屬分類: SDL入門教程

FeedBack:
# re: SDL入門教程(五):5、本章范例的完整源代碼[未登錄] 2008-09-16 09:21 伊凡
我把
//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;
}

改成
//key event to move image.
keys = SDL_GetKeyState(0);
if ( keys[SDLK_UP] || keys[SDLK_w] ){
ypos -= 3;
}
if ( keys[SDLK_DOWN]|| keys[SDLK_s] ){
ypos += 3;
}
if ( keys[SDLK_LEFT]|| keys[SDLK_a] ){
xpos -= 3;
}
if ( keys[SDLK_RIGHT]|| keys[SDLK_d] ){
xpos += 3;
}
以后出現(xiàn)疊影。如果用變量來代替數(shù)字來實現(xiàn)變速疊影效果就更明顯。
我想知道是為什么?顯卡刷新速度不夠快么?  回復  更多評論
  
# re: SDL入門教程(五):5、本章范例的完整源代碼[未登錄] 2008-09-16 11:17 lf426
增加delta_x和delta_y的值。  回復  更多評論
  
# re: SDL入門教程(五):5、本章范例的完整源代碼[未登錄] 2008-09-16 14:39 伊凡
謝謝你的回答
還有這里是不是寫多了?
if ( SDL_Init(SDL_INIT_VIDEO < 0 ) )
throw SDL_GetError();
難道不是
if ( SDL_Init(SDL_INIT_VIDEO )< 0 )
throw SDL_GetError();

  回復  更多評論
  
# re: SDL入門教程(五):5、本章范例的完整源代碼[未登錄] 2008-09-16 22:37 lf426
是我寫錯了,謝謝提醒。教程里面的源代碼還很不成熟,更進一步的代碼請在“mySDL_GameEngine”中察看。  回復  更多評論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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在线免费| 亚洲一区二区动漫| 午夜精品久久99蜜桃的功能介绍| 欧美一级视频一区二区| 免费不卡亚洲欧美| 欧美日韩在线不卡一区| 国产一区二区精品| 99在线|亚洲一区二区| 99视频精品全部免费在线| 亚洲国产日韩欧美综合久久| 亚洲视频在线播放| 欧美在线你懂的| 亚洲激情欧美| 久久久xxx| 国产精品jizz在线观看美国| 国产一区日韩一区| 亚洲性夜色噜噜噜7777| 欧美成人精品一区二区三区| 欧美jizz19hd性欧美| 国产欧美日韩精品专区| 在线综合亚洲欧美在线视频| 欧美国产一区二区在线观看| 性欧美1819性猛交| 国产精品美女久久久久久免费| 在线播放豆国产99亚洲| 午夜精品999| 亚洲看片免费| 美国成人毛片| 亚洲影视九九影院在线观看| 亚洲精品国产视频| 欧美jizz19性欧美| 欧美在线视频观看| 欧美阿v一级看视频| 亚洲精品视频在线播放| 免费成人网www| 久久久天天操| 在线成人小视频| 亚洲视频在线视频| 亚洲精品久久久久久久久久久久久| 中文欧美日韩| 国产麻豆精品久久一二三| 亚洲综合色在线| 嫩草国产精品入口| 久久国产毛片| 久久久久国产精品午夜一区| 在线视频一区二区| 免费成人高清| 久久久免费av| 久久久精品欧美丰满| 亚洲欧美在线免费观看| 欧美另类99xxxxx| 一区二区三区欧美日韩| 久久亚洲春色中文字幕| 亚洲精品一区二区三区樱花| 久久久999精品| 久久露脸国产精品| 国产精品乱码一区二区三区| 亚洲精品日韩欧美| 亚洲精品在线观看免费| 一区二区三区日韩欧美精品| 国产人成一区二区三区影院| aa成人免费视频| 国产亚洲免费的视频看| 亚洲一区二区在线视频 | 亚洲一区三区视频在线观看| 99热这里只有成人精品国产| 欧美成人精品一区| 亚洲第一精品夜夜躁人人躁| 欧美a一区二区| 欧美激情第三页| 91久久久久久| 中日韩美女免费视频网址在线观看 | 99精品欧美一区二区三区综合在线| 日韩视频中文字幕| 国内精品久久久久伊人av| 亚洲欧美激情视频| 亚洲精品一区在线观看香蕉| 美国成人毛片| 亚洲黄色免费电影| 亚洲麻豆av| 欧美日韩一区二区欧美激情| 99国产精品自拍| 午夜一区二区三区不卡视频| 免费精品99久久国产综合精品| 欧美va亚洲va香蕉在线| 亚洲人精品午夜| 欧美午夜精品久久久久久孕妇 | 欧美激情影音先锋| 99视频一区二区| 国产欧美va欧美不卡在线| 久久福利资源站| 亚洲一区二区三区免费观看| 国产精品激情偷乱一区二区∴| 亚洲国产成人在线播放| 中文在线资源观看网站视频免费不卡 | 久久经典综合| 亚洲福利在线观看| 欧美一区二区三区免费观看| 欧美成人黑人xx视频免费观看| 亚洲欧洲一区| 国产美女精品免费电影| 美女黄色成人网| 一区二区高清视频在线观看| 久久久在线视频| 中日韩美女免费视频网址在线观看| 国产精品午夜电影| 中文亚洲欧美| 欧美电影电视剧在线观看| 国产一区视频网站| 欧美人与性禽动交情品 | 麻豆精品在线播放| 狠狠色丁香婷综合久久| 性伦欧美刺激片在线观看| 欧美国产日韩一区二区三区| 欧美一区二区| 国产色产综合色产在线视频| 亚洲社区在线观看| 欧美国产欧美亚州国产日韩mv天天看完整| 国产精品99久久久久久久久| 在线免费观看成人网| 美脚丝袜一区二区三区在线观看 | 久久精品一区二区国产| 国产欧美一区二区精品性色| 欧美激情亚洲精品| 久久久久国色av免费看影院| 国产精品99久久久久久宅男| 亚洲国产精品999| 久久综合九色99| 亚洲电影下载| 国产一区二区精品在线观看| 欧美日韩你懂的| 欧美精品久久一区二区| 久久久久成人精品| 先锋影音久久久| 亚洲一区二区三区视频播放| 亚洲最新在线视频| 亚洲精品日韩欧美| 91久久亚洲| 亚洲日本成人| 亚洲人成在线观看一区二区| 亚洲人成77777在线观看网| 男女精品视频| 欧美国产日产韩国视频| 免费久久精品视频| 免费成人av在线| 女女同性女同一区二区三区91| 久久伊伊香蕉| 美女999久久久精品视频| 毛片基地黄久久久久久天堂| 久久综合电影一区| 欧美成人三级在线| 欧美大成色www永久网站婷| 欧美电影打屁股sp| 亚洲国产精品久久久久婷婷老年| 亚洲国内精品在线| 99爱精品视频| 亚洲欧美激情四射在线日 | 免费成人av在线| 亚洲成色www久久网站| 一本大道久久a久久综合婷婷| 一二三四社区欧美黄| 这里只有精品丝袜| 午夜精品久久久久影视| 久久精品av麻豆的观看方式| 久久久五月婷婷| 亚洲国产精品久久久久秋霞不卡| 最新国产乱人伦偷精品免费网站| 亚洲精品资源美女情侣酒店| 亚洲午夜视频在线观看| 久久福利精品| 欧美片在线观看| 国产视频一区在线| 亚洲国产天堂久久综合| 国产日韩欧美黄色| 在线播放亚洲| 亚洲在线成人| 老司机精品导航| 一本久道久久综合婷婷鲸鱼| 欧美一级一区| 欧美日本韩国一区| 国产综合久久| 一区二区三区精品国产| 久久精品理论片| 亚洲人体偷拍| 久久久久久噜噜噜久久久精品| 欧美国产日韩xxxxx| 欧美插天视频在线播放| 欧美性事免费在线观看| 韩日视频一区| 亚洲欧美综合一区| 亚洲国产精品美女| 欧美在线播放| 性色一区二区三区| 欧美日韩xxxxx| 国产精品福利在线观看网址| 亚洲夫妻自拍| 久久99伊人| 亚洲一区在线播放|