资源简介
使用SDL库,该库可用来编写图形界面的软件,编写了俄罗斯方块的小游戏,游戏虽然简单,但对初学者来说,编写有挑战性

代码片段和文件信息
//函数的具体实现
#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 ];
/*******************************************************/
// 函数一:类之外的函数 //
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个文件信息
- 上一篇:图书管理系统及数据库
- 下一篇:郑丽的C++学生用书
相关资源
- 猜数字游戏 c语言代码
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- LINUX下命令行界面的C语言细胞游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 用C语言实现的一个打字游戏
- C语言版3D魔方游戏源代码
- 使用wxWidgets进行跨平台程序开发
- QT视频播放器(基于FFmpeg)
- 打飞机小游戏57466
- 俄罗斯方块游戏源码(Tetris)
- c++ 猜拳小游戏
- 扫雷游戏.cpp
- 杨中科游戏开发引擎
- 智商超高的中国象棋游戏源码(C++版
- c++ 扫雷游戏源码(控制台)
- C++跑跑卡丁车
- C++“倒忌时”小游戏
- XX游戏客户端源码
- c++小游戏源码.doc
- 俄罗斯方块(c++控制台代码)
- 基于ege图形的推箱子游戏
- C语言ege贪吃蛇游戏
- C++小游戏4款(源码)
- 推箱子小游戏源码
- 五子棋游戏源码(控制台)
- 猜数字游戏.sb3
- C++贪吃蛇控制台小游戏代码
- 俄罗斯方块.cpp
- 扫雷游戏.cpp(较简单)
评论
共有 条评论