Subversion Repositories Kolibri OS

Rev

Rev 5310 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5225 alpine 1
#include "rsgamemenu.h"
2
 
3
#include "rsgame.h"
4
 
5
#include "rskos.h"
6
 
5243 alpine 7
#include "strings.h"
8
 
5225 alpine 9
PRSFUNC0 menu_actions[] = {
10
    /* a */ &menu_action_start,
11
    /* b */ &menu_action_exit,
5291 alpine 12
    /* c */ &menu_action_change_window_scale,
5310 alpine 13
    /* d */ &menu_action_resume
5225 alpine 14
};
15
 
16
char window_scale_str[] = "c< 2X >";
5315 alpine 17
char level_passed_score_str[] = " 0000   ";
5225 alpine 18
 
5243 alpine 19
/*
20
    First char:
21
    - letter a...z means action (a = 0th, b = 1st, c = 2nd, see menu_actions[] above)
22
    - number 0...9 means goto menu #0, #1, #2... see menu_titles[] below
23
    - space ' ' means no action, menu item is unselectable
24
    - empty string "" is now allowed and can cause segfault
25
    String from second char is label of menu item
26
 
27
*/
28
 
29
 
5225 alpine 30
char* menu_main_titles[] = {
5243 alpine 31
    "a"L_START,
32
    "1"L_SETTINGS,
33
    "2"L_ABOUT,
34
    "b"L_QUIT,
5225 alpine 35
 
36
};
37
 
38
char* menu_settings_titles[] = {
5243 alpine 39
    " "L_WINDOW_SCALE,
5225 alpine 40
    window_scale_str,
41
    " ",
5243 alpine 42
    "0"L_DONE,
5225 alpine 43
 
44
};
45
 
46
char* menu_about_titles[] = {
5243 alpine 47
    " "L_DEVELOPED_BY,
48
    " "L_ROMAN_SHUVALOV,
5225 alpine 49
    " ",
5291 alpine 50
    "0"L_BACK,
5225 alpine 51
 
52
};
53
 
5315 alpine 54
char* menu_game_over_titles[] = {
55
    " "L_GAME_OVER,
5291 alpine 56
    " "L_YOUR_SCORE,
57
    level_passed_score_str,
58
    " ",
59
    "0"L_BACK,
60
 
61
};
62
 
5315 alpine 63
//char* menu_game_over_titles[] = {
64
//    " "L_GAME_OVER,
65
//    " ",
66
//    "0"L_BACK,
67
//    0
68
//};
5291 alpine 69
 
5310 alpine 70
char* menu_pause_titles[] = {
71
    " "L_PAUSE,
72
    " ",
73
    "d"L_RESUME,
74
    "0"L_EXIT_TO_MAIN_MENU,
75
 
76
};
5291 alpine 77
 
78
 
5225 alpine 79
char **menu_titles[] = {
80
    /* 0 */ menu_main_titles,
81
    /* 1 */ menu_settings_titles,
82
    /* 2 */ menu_about_titles,
5315 alpine 83
//    /* 3 */ menu_level_passed_titles,
84
    /* 3 */ menu_game_over_titles,
85
    /* 4 */ menu_pause_titles,
5225 alpine 86
 
87
};
88
 
89
 
90
void menu_cursor_down() {
91
    int new_index = game.menu_item_index+1;
92
    while ( (menu_titles[game.menu_index][new_index]) ) {
93
        if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
94
            game.menu_item_index = new_index;
95
            game_ding(1);
96
            return;
97
        };
98
        new_index++;
99
    };
100
};
101
 
102
void menu_cursor_up() {
103
    int new_index = game.menu_item_index-1;
104
    while ( new_index+1 ) {
105
        if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
106
            game.menu_item_index = new_index;
107
            game_ding(1);
108
            return;
109
        };
110
        new_index--;
111
    };
112
};
113
 
114
void menu_open(int i) {
5310 alpine 115
 
5315 alpine 116
    if ( ((game.menu_index == MENU_PAUSE) && (i != MENU_PAUSE)) || (i == MENU_GAME_OVER) ) {
5310 alpine 117
        soundbuf_play( &game.sound_music, SND_MODE_LOOP );
118
    };
5302 alpine 119
 
5225 alpine 120
    game.menu_index = i;
121
 
122
    game.menu_item_index = -1;
123
    // (menu_cursor_down without sound)
124
    int new_index = game.menu_item_index+1;
125
    while ( (menu_titles[game.menu_index][new_index]) ) {
126
        if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
127
            game.menu_item_index = new_index;
128
            return;
129
        };
130
        new_index++;
131
    };
132
 
133
};
134
 
135
void menu_cursor_click() {
136
 
137
    char c = menu_titles[game.menu_index][game.menu_item_index][0];
138
 
139
    game_ding(0);
140
 
141
    if (c > '9') {
142
        // action: call function
143
        menu_actions[c - 'a']();
144
    }
145
    else {
146
        // action: navigate to menu
147
        menu_open(c - '0');
148
    };
149
 
150
//    DEBUG10f("click: %c \n", c);
151
 
152
};
153
 
154
void menu_action_start() {
155
    game.status = STATUS_PLAYING;
156
 
5291 alpine 157
    game.player_x = GAME_WIDTH/2 - 50;
158
    game.player_y = GAME_HEIGHT/2 - 10;
5225 alpine 159
 
5291 alpine 160
    game.stage = 0;
161
    game.stage_timer = 0;
162
 
163
    game.health = GAME_HEALTH_MAX;
164
    game.ammo = GAME_AMMO_MAX;
165
 
166
    game.shoot_delay = 0;
167
    game.shoot_keypressed = 0;
168
    game.shoot_restore_delay = 0;
169
 
170
    game.score = 0;
171
    game.flags = 0;
172
 
5315 alpine 173
    game.stage_level = 0;
174
 
5291 alpine 175
    game.objs_count = 0;
176
 
5298 alpine 177
    game.bg_color = COLOR_BLACK;
178
 
5302 alpine 179
    soundbuf_stop( &game.sound_music );
180
 
5225 alpine 181
};
182
 
183
void menu_action_exit() {
5243 alpine 184
    #ifdef RS_KOS
5225 alpine 185
        GameTerm();
186
    #endif
187
    rskos_exit();
188
};
189
 
190
void menu_action_change_window_scale() {
191
    game_change_window_scale(1);
192
};
5310 alpine 193
 
194
void menu_action_resume() {
195
 
196
    game.status = STATUS_PLAYING;
197
 
198
};