Skip to content
Snippets Groups Projects
game.h 3.6 KiB
Newer Older
Jin Zijun's avatar
Jin Zijun committed
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

Jin Zijun's avatar
Jin Zijun committed

Jin Zijun's avatar
Jin Zijun committed
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>

Jin Zijun's avatar
Jin Zijun committed
/*
Jin Zijun's avatar
Jin Zijun committed
typedef union SDL_Event
{
Jin Zijun's avatar
Jin Zijun committed
    Uint8 type; //事件类型
    SDL_ActiveEvent active; //窗口焦点、输入焦点及鼠标焦点的失去和得到事件
    SDL_KeyboardEvent key; //键盘事件,键盘按下和释放
    SDL_MouseMotionEvent motion; //鼠标移动事件
    SDL_MouseButtonEvent button; //鼠标按键事件
    SDL_QuitEvent quit; //退出事件
    SDL_SysWMEvent syswm; //平台相关的系统事件
}SDL_Event;*/


//typedef enum
//{
    //SDL_NOEVENT = 0, /* 未使用 */
    //SDL_ACTIVEEVENT, /* 应用程序失去焦点或得到焦点*/
    //SDL_KEYDOWN, /* 按下某键 */
    //SDL_KEYUP, /* 松开某键 */
    //SDL_MOUSEMOTION, /* 鼠标移动 */
    //SDL_MOUSEBUTTONDOWN, /* 鼠标键按下 */
    //SDL_MOUSEBUTTONUP, /* 鼠标键松开 */
    //SDL_QUIT, /*离开 */
    //SDL_SYSWMEVENT, /* 系统事件 */
    //SDL_EVENT_RESERVEDA, /* 保留 */
    //SDL_EVENT_RESERVEDB, /* 保留 */
    //SDL_VIDEORESIZE, /* 用户改变视频模式 */
    //SDL_VIDEOEXPOSE, /* 屏幕重画 */
    //SDL_EVENT_RESERVED2, /* 保留*/
    //SDL_EVENT_RESERVED3, /* 保留 */
    //SDL_EVENT_RESERVED4, /* 保留 */
    //SDL_EVENT_RESERVED5, /* 保留 */
    //SDL_EVENT_RESERVED6, /* 保留*/
    //SDL_EVENT_RESERVED7, /* 保留 */
    //SDL_USEREVENT = 24, /* 用户自定义事件 */
    //SDL_NUMEVENTS = 32
//}SDL_EventType;

//typedef struct SDL_MouseButtonEvent
//{
//    Uint8 type;    /* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
//    Uint8 which;    /* The mouse device index */
//    Uint8 button;    /* 鼠标按键,左、右、中三个键*/
//    Uint8 state;    /* SDL_PRESSED按下 or SDL_RELEASED松开 */
//    Uint16 x, y;    /* 鼠标按下时的坐标 */
//}SDL_MouseButtonEvent;

//typedef struct SDL_MouseMotionEvent
//{
//    Uint8 type;    /* SDL_MOUSEMOTION */
//    Uint8 which;    /* The mouse device index */
//    Uint8 state;    /* 鼠标状态 */
//    Uint16 x, y;    /* 鼠标当前坐标 */
//    Sint16 xrel;    /* 鼠标在x方向的位移 */
//    Sint16 yrel;    /* 鼠标在y方向的位移*/
//} SDL_MouseMotionEvent;

typedef enum {LEFT,RIGHT}BUTTONPOS; //枚举按钮在精灵图中的编号
typedef enum {un,deux,OTHER}BUTTONFLAG; //枚举按钮
Jin Zijun's avatar
Jin Zijun committed

#ifndef FONT_H
#define FONT_H

typedef  int BOOL;
#define TRUE  1
#define FALSE 0

//表面声明
Jin Zijun's avatar
Jin Zijun committed
SDL_Surface *gpBackground; //背景表面
SDL_Surface *gpScreen; //显示表面
SDL_Surface *gpMessage[2]; //文字表面
Jin Zijun's avatar
Jin Zijun committed

//事件声明
extern SDL_Event myEvent;

// 字体声明
extern TTF_Font *font;

Jin Zijun's avatar
Jin Zijun committed
const SDL_Color RGB_Black;
const SDL_Color RGB_Red;
const SDL_Color RGB_Green;
const SDL_Color RGB_Blue;
const SDL_Color RGB_Cyan;
const SDL_Color RGB_Magenta;
const SDL_Color RGB_Yellow;
const SDL_Color RGB_White;
const SDL_Color RGB_Gray;
const SDL_Color RGB_Grey;
const SDL_Color RGB_Maroon ;
const SDL_Color RGB_Darkgreen;
const SDL_Color RGB_Navy;
const SDL_Color RGB_Teal;
const SDL_Color RGB_Purple;
const SDL_Color RGB_Olive;
const SDL_Color RGB_Noname;
Jin Zijun's avatar
Jin Zijun committed


int isOnButton(int aX,int aY, int aIndex);
Jin Zijun's avatar
Jin Zijun committed
void changeButton(BUTTONPOS aPos,int aNo,SDL_Rect *aDst);
BOOL init(char* aCaption,char * aIcon);
SDL_Surface *loadImage( char * filename );
Jin Zijun's avatar
Jin Zijun committed
void applySurface( int x, int y, SDL_Surface *source, SDL_Surface *destination );
SDL_Surface *TTF_RenderText_Solid(TTF_Font *font, const char *text, SDL_Color fg);
Jin Zijun's avatar
Jin Zijun committed
void cleanup();
char *localeToUTF8(char *src);
wchar_t* cstringToUnicode(char * aSrc);
void handle_input(char *str, SDL_Surface *text);
void show_centered(SDL_Surface *text);

#endif