資源簡介
使用SDL庫,該庫可用來編寫圖形界面的軟件,編寫了俄羅斯方塊的小游戲,游戲雖然簡單,但對初學(xué)者來說,編寫有挑戰(zhàn)性

代碼片段和文件信息
//函數(shù)的具體實現(xiàn)
#include?“tetris.h“
//定義變量
bool?author_back?=?false;?????????????//檢測子菜單返回按鈕
bool?hero_back?=?false;???????????????//檢測子菜單返回按鈕
bool?quit?=?false;????????????????????//Quit?flag
//The?surfaces
SDL_Surface?*screen?=?NULL;?????????????//屏幕
SDL_Surface?*background?=?NULL;?????????//背景
SDL_Surface?*buttonsheet?=?NULL;????????//裁剪樣圖1
SDL_Surface?*buttonsheet_two?=?NULL;????//裁剪樣圖2
SDL_Surface?*buttonsheet_three?=?NULL;??//裁剪樣圖3
//SDL_Surface?*message?=?NULL;????????????//文字信息
SDL_Surface?*screen_author?=?NULL;??????//屏幕菜單顯示作者
//The?event?structure
SDL_Event?event;
//The?clip?regions?of?the?sprite?sheet
SDL_Rect?clips[?5?][?2?];
/*******************************************************/
//?????????????????函數(shù)一:類之外的函數(shù)????????????????//
SDL_Surface?*load_image(?std::string?filename?)
{
????//The?image?that‘s?loaded
????SDL_Surface*?loadedImage?=?NULL;
????//The?optimized?surface?that?will?be?used
????SDL_Surface*?optimizedImage?=?NULL;
????//Load?the?image
????loadedImage?=?IMG_Load(?filename.c_str()?);
????//If?the?image?loaded
????if(?loadedImage?!=?NULL?)
????{
????????//Create?an?optimized?surface
????????optimizedImage?=?SDL_DisplayFormat(?loadedImage?);
????????//Free?the?old?surface
????????SDL_FreeSurface(?loadedImage?);
????????//If?the?surface?was?optimized
????????if(?optimizedImage?!=?NULL?)
????????{
????????????//Color?key?surface
????????????SDL_SetColorKey(?optimizedImage?SDL_SRCCOLORKEY?SDL_MapRGB(?optimizedImage->format?0?0xFF?0xFF?)?);
????????}
????}
????//Return?the?optimized?surface
????return?optimizedImage;
}
void?apply_surface(?int?x?int?y?SDL_Surface*?source?SDL_Surface*?destination?SDL_Rect*?clip??)
{
????//Holds?offsets
????SDL_Rect?offset;
????//Get?offsets
????offset.x?=?x;
????offset.y?=?y;
????//Blit
????SDL_BlitSurface(?source?clip?destination?&offset?);
}
bool?init()
{
????//Initialize?all?SDL?subsystems----------------------------所有引擎
????if(?SDL_Init(?SDL_INIT_EVERYTHING?)?==?-1?)
????{
????????return?false;
????}
????//Set?up?the?screen
????screen?=?SDL_SetVideoMode(?SCREEN_WIDTH?SCREEN_HEIGHT?SCREEN_BPP?SDL_SWSURFACE?);
????//If?there?was?an?error?in?setting?up?the?screen
????if(?screen?==?NULL?)
????{
????????return?false;
????}
????if(?(?load_score(?&total?&h_score?)?)?==?false?)?return?false;
????//Set?the?window?caption
????SDL_WM_SetCaption(?“TETRIS?“?NULL?);
????//If?everything?initialized?fine
????return?true;
}
bool?load_files()
{
????//載入背景圖片
????background?=?load_image(?“tetris_background.png“?);
????//載入選項覆蓋圖片
????buttonsheet?=?load_image(?“button.png“?);
????buttonsheet_two?=?load_image(?“button2.png“?);
????buttonsheet_three?=?load_image(?“back.png“?);
????//If?there?was?an?problem?loading?the?sprite?map
????if(?background?==?NULL?||?buttonsheet?==?NULL?||
????????buttonsheet_two?==?NULL?||buttonsheet_three?==?NULL?)
????{
????????return?fa
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-07-11?17:43??俄羅斯\
?????文件???????15376??2014-07-01?13:34??俄羅斯\author.png
?????文件????????7726??2014-07-01?13:34??俄羅斯\back.png
?????文件??????730844??2014-07-02?21:39??俄羅斯\bj.png
?????文件???????13549??2014-07-01?18:25??俄羅斯\button.cpp
?????文件????????5699??2014-07-01?13:34??俄羅斯\button.png
?????文件????????9045??2014-07-01?13:34??俄羅斯\button2.png
?????文件?????7393768??2013-12-27?14:01??俄羅斯\canon.wav
?????文件?????????656??2014-07-01?13:34??俄羅斯\check.png
?????文件???????19335??2014-07-01?13:34??俄羅斯\fangkuai.cpp
?????文件????????3322??2014-07-01?13:34??俄羅斯\fk.png
?????文件?????????964??2014-07-01?13:34??俄羅斯\font.cpp
?????文件??????421556??2014-07-01?13:34??俄羅斯\game_begin.wav
?????文件?????????635??2014-07-01?18:01??俄羅斯\Game_main.cpp
?????文件??????303452??2014-07-01?13:34??俄羅斯\game_over.wav
?????文件????????8225??2014-07-01?13:34??俄羅斯\game_play.cpp
?????文件???????????5??2014-07-11?17:42??俄羅斯\game_save
?????文件??????328192??2014-07-01?13:34??俄羅斯\libFLAC-8.dll
?????文件??????461824??2014-07-01?13:34??俄羅斯\libfreetype-6.dll
?????文件??????204288??2014-07-01?13:34??俄羅斯\libjpeg-8.dll
?????文件??????263168??2014-07-01?13:34??俄羅斯\libmikmod-2.dll
?????文件???????24064??2014-07-01?13:34??俄羅斯\libogg-0.dll
?????文件??????151552??2014-07-01?13:34??俄羅斯\libpng15-15.dll
?????文件??????408064??2014-07-01?13:34??俄羅斯\libtiff-5.dll
?????文件??????163840??2014-07-01?13:34??俄羅斯\libvorbis-0.dll
?????文件???????36352??2014-07-01?13:34??俄羅斯\libvorbisfile-3.dll
?????文件??????180224??2014-07-01?13:34??俄羅斯\libwebp-2.dll
?????文件????????2108??2014-07-01?13:34??俄羅斯\music.cpp
?????文件??????134790??2014-07-01?13:34??俄羅斯\score.png
?????文件???????80388??2014-07-01?13:34??俄羅斯\score.TTF
?????文件??????303616??2014-07-01?13:34??俄羅斯\SDL.dll
............此處省略9個文件信息
評論
共有 條評論