-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
96 lines (87 loc) · 3.96 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**************************************************************************************\
*** Snake 1.3
*** Desenvolvedor: Abner Cordeiro ( Hellhound )
*** 2014 - Todos os Direitos reservados.
** Arquivo: init.c
** Utiliza a biblioteca FreeImage para carregar as imagens png e converte-a
** utilizando a WinAPI para bitmap,então libera os indentificadores da FreeLibrary.
** Programando mesmo após a morte.
\**************************************************************************************/
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include <windows.h>
#include "FreeImage.h"
#include "main.h"
/**********************----------------------------------------
** Função que converte de FIBITMAP* para HBITMAP.
*********/
HBITMAP FiBitmapToWin32Bitmap(GAME_INF *pGameInf,FIBITMAP* src)
{
HBITMAP hbm = CreateDIBitmap(pGameInf->hDC_Screen,
FreeImage_GetInfoHeader(src),
CBM_INIT,
FreeImage_GetBits(src),
FreeImage_GetInfo(src),
DIB_RGB_COLORS);
return hbm;
}
/**********************----------------------------------------
** Função que carrega uma imagem png e retorna um identificador HBITMAP.
*********/
HBITMAP LoadPNG( GAME_INF *pGameInf,char *szNameFile )
{
FIBITMAP *pFiBitmap = NULL;
HBITMAP hBitmap = NULL;
pFiBitmap = FreeImage_Load(FIF_PNG,szNameFile, PNG_DEFAULT);
hBitmap = FiBitmapToWin32Bitmap(pGameInf,pFiBitmap);
FreeImage_Unload(pFiBitmap);
return hBitmap;
}
/**********************----------------------------------------
** Função que carrega uma imagem png e retorna um identificador HBITMAP.
*********/
HBITMAP LoadPNG_Ex(GAME_INF *pGameInf,char *szNameFile)
{
HBITMAP hBitmap = NULL;
FIBITMAP *pFiBitmap = FreeImage_Load(FIF_PNG,szNameFile, PNG_DEFAULT);
RGBQUAD appColor = { 0, 0, 0, 255 };
FIBITMAP *display_dib_c = FreeImage_Composite(pFiBitmap, TRUE, &appColor,NULL);
hBitmap = FiBitmapToWin32Bitmap(pGameInf,display_dib_c);
FreeImage_Unload(pFiBitmap);
FreeImage_Unload(display_dib_c);
return hBitmap;
}
/**********************----------------------------------------
** Função que carrega todas as imagens do jogo.
*********/
void LoadResources(GAME_INF *pGameInf)
{
pGameInf->hBitmapMenuBack = LoadPNG(pGameInf,"gfx\\menu_back.png" );
pGameInf->hBitmapGameBack = LoadPNG(pGameInf,"gfx\\game_back.png" );
pGameInf->hBitmapMenuNewGame = LoadPNG_Ex(pGameInf,"gfx\\BttnNewGame.png" );
pGameInf->hBitmapMenuQuit = LoadPNG_Ex(pGameInf,"gfx\\BttnQuit.png" );
pGameInf->hBitmapMenuSelect = LoadPNG(pGameInf,"gfx\\select.png" );
pGameInf->hBitmapSnakeHead = LoadPNG(pGameInf,"gfx\\head.png" );
pGameInf->hBitmapSnakeBody = LoadPNG(pGameInf,"gfx\\body.png" );
pGameInf->hBitmapSnakeTail = LoadPNG(pGameInf,"gfx\\tail.png" );
pGameInf->hBitmapFood = LoadPNG(pGameInf,"gfx\\drop.png" );
pGameInf->hBitmapBigFood = LoadPNG(pGameInf,"gfx\\game_drop.png");
pGameInf->hBitmapNumbers = LoadPNG_Ex(pGameInf,"gfx\\numbers.png" );
}
/**********************----------------------------------------
** Função que descarrega todas as imagens do jogo.
*********/
void UnloadResources(GAME_INF *pGameInf)
{
DeleteObject(pGameInf->hBitmapMenuBack );
DeleteObject(pGameInf->hBitmapGameBack );
DeleteObject(pGameInf->hBitmapMenuNewGame);
DeleteObject(pGameInf->hBitmapMenuQuit );
DeleteObject(pGameInf->hBitmapMenuSelect );
DeleteObject(pGameInf->hBitmapSnakeHead );
DeleteObject(pGameInf->hBitmapSnakeBody );
DeleteObject(pGameInf->hBitmapSnakeTail );
DeleteObject(pGameInf->hBitmapFood );
DeleteObject(pGameInf->hBitmapBigFood );
DeleteObject(pGameInf->hBitmapNumbers );
}