📄 sdlframe.cpp
字号:
// ============================================================================
// Data Structures For Game Programmers
// Ron Penton
// SDLFrame.cpp
// This is a basic SDL Framework that I've set up for use with the game demos
// I've used in the book.
// ============================================================================
#include "SDL.h"
// ============================================================================
// Global Constants
// ============================================================================
const char PROGRAM_NAME[] = "INSERT PROGRAM NAME HERE";
const int WIDTH = 640;
const int HEIGHT = 480;
// ============================================================================
// Global Variables
// ============================================================================
// this is the main window for the framework
SDL_Surface* g_window = 0;
int main( int argc, char* argv[] )
{
// declare coordinates.
int x, y;
// declare event holder
SDL_Event event;
// initialize the video system.
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
SDL_WM_SetCaption( PROGRAM_NAME, 0);
// set our at exit function
atexit( SDL_Quit );
// set the video mode.
g_window = SDL_SetVideoMode( WIDTH, HEIGHT, 0, SDL_ANYFORMAT );
while( 1 )
{
//look for an event
if( SDL_PollEvent( &event ) )
{
//an event was found
if( event.type == SDL_QUIT )
break;
if( event.type == SDL_MOUSEBUTTONDOWN )
{
// get the mouse state.
SDL_GetMouseState( &x, &y );
}
if( event.type == SDL_MOUSEBUTTONUP )
{
// get the mouse state.
SDL_GetMouseState( &x, &y );
}
if( event.type == SDL_KEYDOWN )
{
// a key was pressed.
if( event.key.keysym.sym == SDLK_ESCAPE )
{
// if ESC was pressed, quit the program.
SDL_Event quit;
quit.type = SDL_QUIT;
SDL_PushEvent( &quit );
}
}
} // end event loop.
// do all game-related stuff here.
// update the entire window.
SDL_UpdateRect( g_window, 0, 0, 0, 0 );
}
// do game cleanup here
// done
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -