summaryrefslogtreecommitdiff
path: root/apps/plugins/xrick/scr_imain.c
blob: 1d8ad5bc56620a8e0e2888d3ce90c5a6aa6718b0 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * xrick/scr_imain.c
 *
 * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net).
 * Copyright (C) 2008-2014 Pierluigi Vicinanza.
 * All rights reserved.
 *
 * The use and distribution terms for this software are contained in the file
 * named README, which can be found in the root of this distribution. By
 * using this software in any fashion, you are agreeing to be bound by the
 * terms of this license.
 *
 * You must not remove this notice, or any other, from this software.
 */

#include "xrick/screens.h"

#include "xrick/game.h"
#include "xrick/draw.h"
#include "xrick/control.h"
#ifdef GFXST
#include "xrick/data/pics.h"
#endif
#include "xrick/system/system.h"

/*
 * Main introduction
 *
 * return: SCREEN_RUNNING, SCREEN_DONE, SCREEN_EXIT
 */
U8
screen_introMain(void)
{
    static U8 seq = 0;
    static U8 seen = 0;
    static bool first = true;
    static U8 period = 0;
    static U32 tm = 0;

    if (seq == 0) {
        draw_tilesBank = 0;
        if (first)
            seq = 1;
        else
            seq = 4;
        period = game_period;
        game_period = 50;
        game_rects = &draw_SCREENRECT;
#ifdef ENABLE_SOUND
        game_setmusic(soundTune5, -1);
#endif
    }

    switch (seq)
    {
        case 1:  /* display Rick Dangerous title and Core Design copyright */
        {
            sysvid_clear();
            tm = sys_gettime();
#ifdef GFXPC
            /* Rick Dangerous title */
            draw_tllst = (U8 *)screen_imainrdt;
            draw_setfb(32, 16);
            draw_filter = 0xaaaa;
            draw_tilesList();

            /* Core Design copyright + press space to start */
            draw_tllst = (U8 *)screen_imaincdc;
            draw_setfb(64, 80);
            draw_filter = 0x5555;
            draw_tilesList();
#endif
#ifdef GFXST
            draw_pic(pic_splash);
#endif
            seq = 2;
            break;
        }
        case 2:  /* wait for key pressed or timeout */
        {
            if (control_test(Control_FIRE))
                seq = 3;
            else if (sys_gettime() - tm > SCREEN_TIMEOUT) {
                seen++;
                seq = 4;
            }
            break;
        }
        case 3:  /* wait for key released */
        {
            if (!(control_test(Control_FIRE))) {
                if (seen++ == 0)
                    seq = 4;
                else
                    seq = 7;
            }
            break;
        }
        case 4:  /* dispay hall of fame */
        {
            U8 s[32];
            size_t i;

            sysvid_clear();
            tm = sys_gettime();
            /* hall of fame title */
#ifdef GFXPC
            draw_tllst = (U8 *)screen_imainhoft;
            draw_setfb(32, 0);
            draw_filter = 0xaaaa;
            draw_tilesList();
#endif
#ifdef GFXST
            draw_pic(pic_haf);
#endif
            /* hall of fame content */
            draw_setfb(56, 48);
#ifdef GFXPC
            draw_filter = 0x5555;
#endif
            for (i = 0; i < screen_nbr_hiscores; i++) {
                sys_snprintf((char *)s, sizeof(s), "%06d@@@====@@@%s",
                    screen_highScores[i].score, screen_highScores[i].name);
                s[26] = (U8)'\377';
                s[27] = (U8)'\377';
                s[28] = (U8)'\376';
                draw_tllst = s;
                draw_tilesList();
            }
            seq = 5;
            break;
        }
        case 5:  /* wait for key pressed or timeout */
        {
            if (control_test(Control_FIRE))
                seq = 6;
            else if (sys_gettime() - tm > SCREEN_TIMEOUT) {
                seen++;
                seq = 1;
            }
            break;
        }
        case 6:  /* wait for key released */
        {
            if (!(control_test(Control_FIRE))) {
                if (seen++ == 0)
                    seq = 1;
                else
                    seq = 7;
            }
            break;
        }
    }

    if (control_test(Control_EXIT))  /* check for exit request */
        return SCREEN_EXIT;

    if (seq == 7) {  /* we're done */
        sysvid_clear();
        seq = 0;
        seen = 0;
        first = false;
        game_period = period;
        return SCREEN_DONE;
    }
    else
        return SCREEN_RUNNING;
}

/* eof */