Subversion Repositories Kolibri OS

Rev

Rev 5232 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5232 Rev 5238
Line 1... Line 1...
1
#include "game.h"
1
#include "game.h"
Line 2... Line 2...
2
 
2
 
3
struct {
3
struct {
4
    rect    new_game_button;// new game button place
4
    rect    reset_button;   // new game button place
5
    rect    highscore_rect; // highscore place
5
    rect    highscore_rect; // highscore place
-
 
6
    rect    score_rect;     // score place
6
    rect    score_rect;     // score place
7
    rect    over_rect;      // game over window
7
    __u8    over;           // flag for game over
8
    __u8    over;           // flag for game over
Line 8... Line 9...
8
} game;
9
} game;
9
 
10
 
10
void game_draw_top()
-
 
11
{
-
 
12
    if (game.over)
11
void game_draw_ui()
13
    {
12
{
14
        __menuet__make_button(game.new_game_button.x,
13
    __menuet__make_button(game.reset_button.x,
15
                              game.new_game_button.y,
14
                          game.reset_button.y,
16
                              game.new_game_button.width,
15
                          game.reset_button.width,
17
                              game.new_game_button.height,
16
                          game.reset_button.height,
18
                              NEW_GAME_BUTTON,
17
                          NEW_GAME_BUTTON,
19
                              BOARD_BG_COLOR);
-
 
Line 20... Line 18...
20
        rect_draw_text(&game.new_game_button,"NEW GAME",8,GAME_BG_COLOR);
18
                          BOARD_BG_COLOR);
21
    }
19
    rect_draw_text(&game.reset_button,"Restart",7,GAME_BG_COLOR,0);
Line 22... Line 20...
22
 
20
 
23
    rect_draw(&game.highscore_rect,BOARD_BG_COLOR);
21
    rect_draw(&game.highscore_rect,BOARD_BG_COLOR);
-
 
22
    rect_draw_value(&game.highscore_rect,board_highscore(),GAME_BG_COLOR,0);
-
 
23
 
-
 
24
    rect_draw(&game.score_rect,BOARD_BG_COLOR);
-
 
25
    rect_draw_value(&game.score_rect,board_score(),GAME_BG_COLOR,0);
-
 
26
 
-
 
27
    if (game.over)
-
 
28
    {
-
 
29
        __u16 line_step = FONT_HEIGHT * 2;
-
 
30
        rect_draw(&game.over_rect,BOARD_BG_COLOR);
-
 
31
 
-
 
32
        rect line_rect = {
-
 
33
            .x = game.over_rect.x,
-
 
34
            .y = game.over_rect.y + line_step,
-
 
35
            .width = game.over_rect.width,
-
 
36
            .height = line_step
-
 
37
        };
-
 
38
 
-
 
39
        rect_draw_text(&line_rect,"It looks like there is",22,0xFFFFFF,0);
-
 
40
 
-
 
41
        line_rect.y += line_step;
-
 
42
        rect_draw_text(&line_rect,"no more moves",13,0xFFFFFF,0);
24
    rect_draw_value(&game.highscore_rect,board_highscore(),GAME_BG_COLOR);
43
 
Line 25... Line 44...
25
 
44
        line_rect.y += line_step;
26
    rect_draw(&game.score_rect,BOARD_BG_COLOR);
45
        rect_draw_text(&line_rect,"available",9,0xFFFFFF,0);
27
    rect_draw_value(&game.score_rect,board_score(),GAME_BG_COLOR);
46
    }
Line 39... Line 58...
39
 
58
 
40
    __menuet__define_window((screen_w - WND_WIDTH) / 2,
59
    __menuet__define_window((screen_w - WND_WIDTH) / 2,
41
                            (screen_h - WND_HEIGHT) / 2,
60
                            (screen_h - WND_HEIGHT) / 2,
42
                            WND_WIDTH,
61
                            WND_WIDTH,
43
                            WND_HEIGHT,
62
                            WND_HEIGHT,
44
                            GAME_BG_COLOR,
63
                            0x34 << 24 | GAME_BG_COLOR,
45
                            0,
64
                            0,
Line 46... Line 65...
46
                            (__u32)header);
65
                            (__u32)header);
47
 
66
 
Line 66... Line 85...
66
        av_area.width = av_area.height;
85
        av_area.width = av_area.height;
67
    }
86
    }
Line 68... Line 87...
68
 
87
 
Line -... Line 88...
-
 
88
    board_init(&av_area);
69
    board_init(&av_area);
89
 
70
 
90
    rect top_base = {
71
    game.new_game_button.x = av_area.x;
91
        .x = av_area.x,
72
    game.new_game_button.y = (av_area.y - SCORE_HEIGHT) / 2;
92
        .y = (av_area.y - SCORE_HEIGHT) / 2,
-
 
93
        .width = (av_area.width - BOARD_SPACING * 2) / 3,
-
 
94
        .height = SCORE_HEIGHT
-
 
95
    };
73
    game.new_game_button.width = (av_area.width - BOARD_SPACING) / 3;
96
 
74
    game.new_game_button.height = SCORE_HEIGHT;
97
    game.reset_button = top_base;
75
 
98
 
-
 
99
    top_base.x += top_base.width + BOARD_SPACING;
76
    game.highscore_rect.x = av_area.x + (av_area.width + BOARD_SPACING) / 3;
100
    game.highscore_rect = top_base;
77
    game.highscore_rect.y = (av_area.y - SCORE_HEIGHT) / 2;
101
 
78
    game.highscore_rect.width = (av_area.width - BOARD_SPACING) / 3;
102
    top_base.x += top_base.width + BOARD_SPACING;
79
    game.highscore_rect.height = SCORE_HEIGHT;
103
    game.score_rect = top_base;
80
 
104
 
81
    game.score_rect.x = av_area.x + (av_area.width + BOARD_SPACING) * 2 / 3;
105
    av_area.x += av_area.width / 4;
-
 
106
    av_area.y += av_area.height / 4;
-
 
107
    av_area.width /= 2;
82
    game.score_rect.y = (av_area.y - SCORE_HEIGHT) / 2;
108
    av_area.height /= 2;
Line 83... Line 109...
83
    game.score_rect.width = (av_area.width - BOARD_SPACING) / 3;
109
 
Line 84... Line 110...
84
    game.score_rect.height = SCORE_HEIGHT;
110
    game.over_rect = av_area;
85
 
111
 
Line 86... Line 112...
86
    game_draw_top();
112
    game_draw_ui();
Line 102... Line 128...
102
 
128
 
103
    __menuet__define_window(0,              // __u16 x1     : ignored
129
    __menuet__define_window(0,                          // __u16 x1     : ignored
104
                            0,              // __u16 y1     : ignored
130
                            0,                          // __u16 y1     : ignored
105
                            0,              // __u16 xsize  : ignored
131
                            0,                          // __u16 xsize  : ignored
106
                            0,              // __u16 ysize  : ignored
132
                            0,                          // __u16 ysize  : ignored
107
                            GAME_BG_COLOR,  // __u32 body_color
133
                            0x34 << 24 | GAME_BG_COLOR, // __u32 body_color
108
                            0,              // __u32 grab_color
134
                            0,                          // __u32 grab_color
Line 109... Line 135...
109
                            (__u32)header); // __u32 frame_color or header
135
                            (__u32)header);             // __u32 frame_color or header
110
 
136
 
Line 111... Line 137...
111
    game_draw_top();
137
    game_draw_ui();
112
    board_redraw();
138
    board_redraw();
113
 
139
 
Line 122... Line 148...
122
        board_redraw();
148
        board_redraw();
123
        __u8 added = board_add_random_tile();
149
        __u8 added = board_add_random_tile();
124
        board_redraw();
150
        board_redraw();
Line 125... Line 151...
125
 
151
 
126
        game.over = !added || !board_has_moves();
152
        game.over = !added || !board_has_moves();
127
        game_draw_top();
153
        game_draw_ui();
128
    }
154
    }
Line 129... Line 155...
129
}
155
}
130
 
156
 
Line 135... Line 161...
135
        board_redraw();
161
        board_redraw();
136
        __u8 added = board_add_random_tile();
162
        __u8 added = board_add_random_tile();
137
        board_redraw();
163
        board_redraw();
Line 138... Line 164...
138
 
164
 
139
        game.over = !added || !board_has_moves();
165
        game.over = !added || !board_has_moves();
140
        game_draw_top();
166
        game_draw_ui();
141
    }
167
    }
Line 142... Line 168...
142
}
168
}
143
 
169
 
Line 148... Line 174...
148
        board_redraw();
174
        board_redraw();
149
        __u8 added = board_add_random_tile();
175
        __u8 added = board_add_random_tile();
150
        board_redraw();
176
        board_redraw();
Line 151... Line 177...
151
 
177
 
152
        game.over = !added || !board_has_moves();
178
        game.over = !added || !board_has_moves();
153
        game_draw_top();
179
        game_draw_ui();
154
    }
180
    }
Line 155... Line 181...
155
}
181
}
156
 
182
 
Line 161... Line 187...
161
        board_redraw();
187
        board_redraw();
162
        __u8 added = board_add_random_tile();
188
        __u8 added = board_add_random_tile();
163
        board_redraw();
189
        board_redraw();
Line 164... Line 190...
164
 
190
 
165
        game.over = !added || !board_has_moves();
191
        game.over = !added || !board_has_moves();
166
        game_draw_top();
192
        game_draw_ui();
167
    }
193
    }