-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu.c
115 lines (100 loc) · 3.33 KB
/
menu.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
#include<math.h>
#include "./cnsglib/include/cnsg.h"
#include "./include/common.h"
#include "./include/menu.h"
#include "./include/title.h"
#include "./include/race.h"
static Window *previousWindow;
static Window menuWindow;
static View menuView;
static Scene menuScene;
static Node foregroundNode;
static Node menuNode;
static int isMenuOpened;
static MenuItem menuSelect;
static float width, height;
static float transitionRatio;
static int selected;
static void escapeEvent(void) {
isMenuOpened = FALSE;
}
static void upArrowEvent(void) {
if(isMenuOpened) menuSelect = menuSelect <= 0 ? 2 : menuSelect - 1;
}
static void downArrowEvent(void) {
if(isMenuOpened) menuSelect = menuSelect >= 2 ? 0 : menuSelect + 1;
}
static void enterKeyEvent(void) {
if(isMenuOpened) {
if(menuSelect == QUIT) {
deinitCNSG();
} else {
isMenuOpened = FALSE;
selected = TRUE;
}
}
}
static int menuBehaviour(Node *node, float elapsed) {
switch(menuSelect) {
case 0:
drawTextSJIS(&node->texture, &shnm12, 0, 0, ">タイトルへ\n 再走する\n ゲーム終了");
break;
case 1:
drawTextSJIS(&node->texture, &shnm12, 0, 0, " タイトルへ\n>再走する\n ゲーム終了");
break;
case 2:
drawTextSJIS(&node->texture, &shnm12, 0, 0, " タイトルへ\n 再走する\n>ゲーム終了");
break;
}
return TRUE;
}
static void menuSceneBehaviour(Scene *scene, float elapsed) {
if(transitionRatio <= 1.0F) {
scene->camera.fov = PI / 2.0F + PI / 3.0F * transitionRatio;
foregroundNode.position[0] = width * 0.75F * transitionRatio;
foregroundNode.angle[1] = PI / 24.0F * transitionRatio;
transitionRatio += 10.0F * (isMenuOpened - transitionRatio) * elapsed;
}
if(!isMenuOpened && transitionRatio < 0.01F) {
if(selected) {
if(menuSelect == GO_TO_TITLE) startTitle();
else if(menuSelect == RETRY) restartRace();
} else {
setWindow(rootManager, previousWindow, NULL, 0.0F);
}
}
}
void initMenu(void) {
menuWindow = initWindow();
menuView = initView(&menuScene);
push(&menuWindow.views, &menuView);
menuScene = initScene();
menuScene.camera.target[2] = 100.0F;
menuScene.behaviour = menuSceneBehaviour;
initControllerEvent(&menuScene.camera.controllerList, VK_ESCAPE, NULL, escapeEvent);
initControllerEvent(&menuScene.camera.controllerList, VK_UP, NULL, upArrowEvent);
initControllerEvent(&menuScene.camera.controllerList, VK_DOWN, NULL, downArrowEvent);
initControllerEvent(&menuScene.camera.controllerList, VK_RETURN, NULL, enterKeyEvent);
foregroundNode = initNode("foreground", NO_IMAGE);
foregroundNode.useFakeZ = TRUE;
foregroundNode.fakeZ = 0.0F;
foregroundNode.position[2] = 100.0F;
height = 2.0F * foregroundNode.position[2] * tanf(PI / 4.0F);
width = height * ((float)SCREEN_WIDTH / SCREEN_HEIGHT);
foregroundNode.shape = initShapePlaneV(width, height, BLACK);
push(&menuScene.nodes, &foregroundNode);
menuNode = initNodeText("menu", 6.0F, 0.0F, LEFT, CENTER, 66, 36, menuBehaviour);
menuNode.useFakeZ = TRUE;
menuNode.fakeZ = 10.0F;
push(&menuScene.nodes, &menuNode);
}
void startMenu(void) {
if(foregroundNode.texture.data) freeImage(&foregroundNode.texture);
getScreenShot(&foregroundNode.texture);
previousWindow = rootManager->currentWindow;
transitionRatio = 0.0F;
isMenuOpened = TRUE;
menuSelect = 0;
selected = FALSE;
setWindow(rootManager, &menuWindow, NULL, 0.0F);
}