-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.c
117 lines (96 loc) · 2.32 KB
/
mainwindow.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "blackship.h"
typedef enum {
EXIT = -1,
NONE = 0,
PARTS = 1,
DEPLOY = 2,
} ActionCommand;
SDL_Window *window;
SDL_Renderer *render;
SDL_Texture *mainBG;
void mainWinEvent();
ActionCommand getMainAction();
int InitWindow(void)
{
/* SDL_image初期化 */
if (IMG_INIT_PNG != IMG_Init(IMG_INIT_PNG)) {
return -1;
}
/** メインのウインドウ(表示画面)とレンダラーの作成 **/
window = SDL_CreateWindow("shoot", 80, 50, WINDOW_WIDTH, WINDOW_HEIGHT, 0);
if (window == NULL)
return -1;
render = SDL_CreateRenderer(window, -1, 0);
if (render == NULL)
return -1;
return 0;
}
/* ウインドウの終了処理 */
void DestroyWindow(void)
{
SDL_DestroyRenderer(render);
SDL_DestroyWindow(window);
}
int initMainWin()
{
SDL_Surface *s = IMG_Load(MAIN_WINDOW_BG);
if (s == NULL) {
return -1;
}
mainBG = SDL_CreateTextureFromSurface(render, s);
SDL_FreeSurface(s);
if (mainBG == NULL) {
return -1;
}
/** ウインドウへの描画 **/
drawMainWin();
/* image利用終了(テクスチャに転送後はゲーム中に使わないので) */
IMG_Quit();
return 0;
}
void drawMainWin()
{
SDL_Rect mainBGSrc = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
SDL_Rect mainWinTarget = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
SDL_RenderCopy(render, mainBG, &mainBGSrc, &mainWinTarget);
SDL_RenderPresent(render);
mainWinEvent();
return;
}
void mainWinEvent()
{
if (inputInfo.mouseL) {
switch (getMainAction()) {
case DEPLOY:
gameMode = ACTION_WINDOW;
break;
case PARTS:
gameMode = PARTS_WINDOW;
break;
case EXIT:
gameMode = EXIT_GAME;
break;
default:
break;
}
}
}
ActionCommand getMainAction()
{
int x = inputInfo.mouseX;
int y = inputInfo.mouseY;
ActionCommand actionCmd = NONE;
if (20 < x && x < 425 && 70 < y && y < 240) {
actionCmd = DEPLOY;
} else if (455 < x && x < 605 && 230 < y && y < 290) {
actionCmd = PARTS;
} else if (515 < x && x < 615 && 8 < y && y < 55) {
actionCmd = EXIT;
}
return actionCmd;
}
void destroyMainWin()
{
SDL_DestroyTexture(mainBG);
return;
}