Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3422846
  • 博文数量: 864
  • 博客积分: 14125
  • 博客等级: 上将
  • 技术积分: 10634
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-27 16:53
个人简介

https://github.com/zytc2009/BigTeam_learning

文章分类

全部博文(864)

文章存档

2023年(1)

2021年(1)

2019年(3)

2018年(1)

2017年(10)

2015年(3)

2014年(8)

2013年(3)

2012年(69)

2011年(103)

2010年(357)

2009年(283)

2008年(22)

分类: C/C++

2010-12-27 09:45:12

注意事项:
1、times.ttf文件请到C:\WINDOWS\Fonts下寻找并拷贝到资源目录下。
2、 如果您使用VC2008,请用Release编译。原因是,似乎涉及到vector的操作,Runtime Library在debug的时候必须用Multi-theaded Debug DLL (MDd),而Release时候才用Multi-theaded DLL (MD)。而我们亲爱的SDL必须始终用MD,所以,请Release吧。

这是一个检验TextSurface构造函数和析构函数的好例子。我们每一次的鼠标移动,都会导致一个新的TextSurface对象被建立,然后很快的又消亡。

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

#include 
"SurfaceClass.h"
#include 
"int_to_string.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;
    
const std::string WINDOW_NAME = "Mouse Motion";
    ScreenSurface screen(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_NAME);
    
//Fill background.(default is black)
    screen.fillColor();
    screen.flip();
    
    
//Main loop.Press ESC or click X to quit.
    bool gameOver = false;
    SDL_Event gameEvent;
    
int x;
    
int y;
    
while( gameOver == false ){
        
while ( SDL_PollEvent(&gameEvent) != 0 ){
            
if ( gameEvent.type == SDL_MOUSEMOTION ) {
                x 
= gameEvent.motion.x;
                y 
= gameEvent.motion.y;
                std::
string mouse_at = "Mouse at: ";
                mouse_at 
+= ("x = " + int_to_string(x) + "; y = " + int_to_string(y) + ";");
                TextSurface text(
"text", mouse_at, screen);
                screen.fillColor();
                text.blit();
                screen.flip();
            }
            
if ( gameEvent.type == SDL_QUIT ){
                gameOver 
= true;
            }
            
if ( gameEvent.type == SDL_KEYUP ){
                
if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){
                    gameOver 
= true;
                }
            }
        }
    }

    
return 0;
}
阅读(1025) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~