Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
5235 alpine 1
#include "rsgamedraw.h"
2
#include "rsgametext.h"
3
#include "rsgamemenu.h"
4
 
5237 alpine 5
#include "rsgentex.h"
6
#include "rs/rsplatform.h"
7
 
5235 alpine 8
#include "rskos.h"
9
 
10
#include "rsnoise.h"
11
 
12
#include "strings.h"
13
 
14
 
15
void game_draw() {
16
 
17
	int w = GAME_WIDTH;
18
	int h = GAME_HEIGHT;
19
 
5237 alpine 20
	if (game.need_redraw) {
5235 alpine 21
 
5237 alpine 22
 
5235 alpine 23
 
5237 alpine 24
        if ( (game.status == STATUS_MENU) || (game.status == STATUS_LOADING) ) {
25
 
26
            texture_draw(&game.framebuffer, &game.tex_bg, 0, 0, DRAW_MODE_REPLACE);
27
 
28
            if (game.menu_index == MENU_MAIN) {
29
 
30
                if (game.status == STATUS_LOADING) {
31
                    game_textout( GAME_WIDTH/2 - 192, 240, 0, "        L0ADING```      " );
32
                }
33
                else {
5235 alpine 34
 
5237 alpine 35
                    texture_draw( &game.framebuffer, &game.tex_logo, 0, 50, DRAW_MODE_ALPHA );
5235 alpine 36
 
5237 alpine 37
                    if (game.time) {
38
 
39
                        game_textout( GAME_WIDTH/2 - 192, 230, 3, "     LEVEL PA55ED     " );
40
 
41
                        char s[] = "     TIME: 000         ";
42
                        int time_sec = game.time / 25;
43
                        s[11] = '0' + (( time_sec / 100 ) % 10);
44
                        s[12] = '0' + (( time_sec / 10 ) % 10);
45
                        s[13] = '0' + (( time_sec / 1 ) % 10);
46
                        game_textout( GAME_WIDTH/2 - 192, 260, 3, s );
47
                    };
5235 alpine 48
 
5237 alpine 49
                    game_textout( GAME_WIDTH/2 - 192, 300, 0, "     CLICK T0 5TART     " );
5235 alpine 50
 
51
 
52
                };
53
 
5237 alpine 54
                game_textout( 2, GAME_HEIGHT-10, 2,  "DEVEL0PED BY R0MAN 5HUVAL0V");
55
            };
56
 
57
        }
58
        else {
5235 alpine 59
 
5237 alpine 60
            texture_draw(&game.framebuffer, &game.tex_bg_gameplay, 0, 0, DRAW_MODE_REPLACE);
5235 alpine 61
 
5237 alpine 62
            int i, j;
63
            for (i = 0; i < FIELD_HEIGHT; i++) {
64
                for (j = 0; j < FIELD_WIDTH; j++) {
65
                    if ( IS_BIT_SET( game.field[i*FIELD_WIDTH + j], CRYSTAL_VISIBLE_BIT )) {
66
                        texture_draw( &game.framebuffer, &game.tex_crystals[ game.field[i*FIELD_WIDTH + j] & CRYSTAL_INDEX_MASK ], FIELD_X0+ j*CRYSTAL_SIZE, FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA );
67
                        if (game.selected) {
68
                            if ( (j == game.selected_x) && (i == game.selected_y) ) {
69
                                texture_draw( &game.framebuffer, &game.tex_cursor, FIELD_X0+ j*CRYSTAL_SIZE, FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA );
70
                            };
5235 alpine 71
                        };
72
                    };
73
                };
74
            };
5237 alpine 75
 
76
            for (i = 0; i < game.explosions_count; i++) {
77
                texture_draw( &game.framebuffer, &(game.tex_explosion[  (game.explosions[i]>>16) & 0xFF  ]),
78
                    FIELD_X0 + CRYSTAL_SIZE*( game.explosions[i] & 0xFF) - (EXPLOSION_SIZE-CRYSTAL_SIZE)/2 ,
79
                    FIELD_Y0 + CRYSTAL_SIZE*( (game.explosions[i]>>8) & 0xFF) - (EXPLOSION_SIZE-CRYSTAL_SIZE)/2 ,
80
                    DRAW_MODE_ALPHA);
81
            };
82
 
83
 
84
            char str[] = "TIME: 999    ";
85
            int time_sec = game.time / 25;
86
            str[6] = '0' + ( (time_sec / 100) % 10);
87
            str[7] = '0' + ( (time_sec / 10) % 10);
88
            str[8] = '0' + ( (time_sec / 1) % 10);
89
 
90
            game_textout( 56, 32, 3, str );
91
 
92
            char sstr[] = "5C0RE: 000 0F 100   ";
93
            sstr[7] = '0' + ( (game.score / 100) % 10);
94
            sstr[8] = '0' + ( (game.score / 10) % 10);
95
            sstr[9] = '0' + ( (game.score / 1) % 10);
96
 
97
            game_textout( 56, 64, 3, sstr );
98
 
5235 alpine 99
        };
100
 
101
 
5237 alpine 102
        rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, game.scaled_framebuffer);
103
	};
104
 
105
	game.need_redraw = 0;
106
 
107
};
108
 
109
 
110
 
111
void game_textures_init_stage1() {
112
 
113
    int i;
114
 
115
    texture_init(&game.framebuffer, GAME_WIDTH, GAME_HEIGHT);
116
 
117
//    texture_init(&game.tex, 64, 64);
118
//    rs_gen_init(1, 64);
119
//    rs_gen_func_set(0, 0.0);
120
//    rs_gen_func_cell(0, 1200, 10, NULL, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0);
121
//    rs_gen_func_normalize(0, 0.0, 1.0);
122
//    rs_gen_func_posterize(0, 5);
123
//    rs_gen_tex_out_rgba(0, 0, 0, -1, 1.0, 1.0, 1.0, 1.0);
124
//    memcpy(game.tex.data, rs_gen_reg.tex_out, 64*64*4 );
125
//    rs_gen_term();
126
 
127
    texture_init(&game.tex_clouds, 128, 128);
128
    rs_gen_init(1, 128);
129
    rs_gen_func_perlin(0, 8, 5, 0.5, 1100);
130
    rs_gen_func_normalize(0, 0.0, 1.0);
131
    rs_gen_func_posterize(0, 6);
132
    rs_gen_func_mult_add_value(0, 0, 0.6, 0.4);
133
//    rs_gen_func_set(0, 1.0);
134
    rs_gen_tex_out_rgba(0, 0, 0, -1, 1.0, 1.0, 1.0, 1.0);
135
    memcpy(game.tex_clouds.data, rs_gen_reg.tex_out, 128*128*4 );
136
    rs_gen_term();
137
 
138
 
139
 
140
 
141
    texture_init(&game.tex_logo, GAME_WIDTH, 128);
142
    texture_clear(&game.tex_logo, COLOR_TRANSPARENT);
143
 
144
    game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192, 3, 1, DRAW_MODE_REPLACE, "MARBLE");
145
    game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192, 63, 1, DRAW_MODE_REPLACE, "MATCH3");
146
    texture_draw(&game.tex_logo, &game.tex_clouds, 0, 0, DRAW_MODE_MULT | DRAW_TILED_FLAG);
147
    game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192 - 4, 0, 1, DRAW_MODE_MULT, "MARBLE");
148
    game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192 - 4, 60, 1, DRAW_MODE_MULT, "MATCH3");
149
 
150
 
151
 
152
    texture_init(&game.tex_bg, 512, 512);
153
    texture_clear(&game.tex_bg, COLOR_SILVER);
154
 
155
    texture_init(&game.tex_bg_gameplay, 512, 512);
156
    texture_clear(&game.tex_bg_gameplay, COLOR_SILVER);
157
 
158
    texture_init(&game.tex_cursor, CRYSTAL_SIZE, CRYSTAL_SIZE);
159
    rs_gen_init(2, CRYSTAL_SIZE);
160
 
161
    rs_gen_func_set(0, 0.0); // inner
162
    rs_gen_func_radial(0, 0.5, 0.5, 0.5, 1.0, 2.0);
163
    rs_gen_func_clamp(0, 0.1, 0.5);
164
    rs_gen_func_normalize(0, 0.0, 1.0);
165
    rs_gen_func_mult_add_value(0, 0, -1.0, 1.0);
166
 
167
    rs_gen_func_set(1, 0.0); // outer
168
    rs_gen_func_radial(1, 0.5, 0.5, 0.5, 1.0, 2.0);
169
    rs_gen_func_clamp(1, 0.0, 0.2);
170
    rs_gen_func_normalize(1, 0.0, 1.0);
171
 
172
    rs_gen_func_mult(0, 0, 1);
173
 
174
    rs_gen_func_set(1, 1.0);
175
//    rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
176
    rs_gen_tex_out_rgba(1, 1, 1, 0, 1.0, 1.0, 1.0, 1.0);
177
    memcpy(game.tex_cursor.data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
178
    rs_gen_term();
179
 
180
    texture_init(&game.tex_field, FIELD_WIDTH*CRYSTAL_SIZE + 7, FIELD_HEIGHT*CRYSTAL_SIZE + 7);
181
    texture_clear(&game.tex_field, 0xAABBBBBB); // 0x66404060 // 0xAACCCCCC
182
 
183
 
184
//    float cr_r[CRYSTALS_COUNT] = { 0.8, 0.2, 0.1, 0.6, 0.7, 0.0, 0.7 };
185
//    float cr_g[CRYSTALS_COUNT] = { 0.1, 0.6, 0.4, 0.0, 0.6, 0.0, 0.8 };
186
//    float cr_b[CRYSTALS_COUNT] = { 0.1, 0.1, 0.7, 0.7, 0.0, 0.3, 0.9 };
187
 
188
//    float cr_r[CRYSTALS_COUNT] = { 0.9, 0.3, 0.1, 0.7, 0.8, 0.0, 0.8 };
189
//    float cr_g[CRYSTALS_COUNT] = { 0.1, 0.8, 0.5, 0.0, 0.7, 0.0, 0.8 };
190
//    float cr_b[CRYSTALS_COUNT] = { 0.0, 0.1, 0.9, 0.8, 0.0, 0.5, 0.9 };
191
 
192
    float cr_r[CRYSTALS_COUNT] = { 1.0, 0.4, 0.1, 0.9, 0.9, 0.2, 0.8 };
193
    float cr_g[CRYSTALS_COUNT] = { 0.1, 1.0, 0.6, 0.1, 0.8, 0.2, 0.8 };
194
    float cr_b[CRYSTALS_COUNT] = { 0.0, 0.1, 1.0, 1.0, 0.0, 0.9, 0.9 };
195
 
196
 
197
    rs_gen_init(5, CRYSTAL_SIZE);
198
    for (i = 0; i < CRYSTALS_COUNT; i++) {
199
 
200
        texture_init(&(game.tex_crystals[i]), CRYSTAL_SIZE, CRYSTAL_SIZE);
5235 alpine 201
 
5237 alpine 202
        rs_gen_func_set(0, 0.0);
203
        rs_gen_func_radial(0, 0.5, 0.5, 0.5, 0.75, 10.0);
204
 
205
//        rs_gen_func_perlin(2, 33, 4, 0.5, 350+i);
206
//        rs_gen_func_normalize(2, 0.0, 1.0);
207
//        rs_gen_func_posterize(2, 4);
208
//
209
//        rs_gen_func_cell(1, 410+i, 50, NULL, -2.0, 1.0, 1.0, 1.0, 0.0, 1.0);
210
//        rs_gen_func_posterize(1, 2);
211
//        rs_gen_func_normalize(1, 0.0, 1.0);
212
//        rs_gen_func_add(1, 1, 2, 1.0, 0.5);
213
//        rs_gen_func_normalize(1, 0.0, 1.0);
214
//        rs_gen_func_posterize(1, 4);
215
//
216
//        rs_gen_func_add(1, 0, 1, 1.0, 1.0);
217
//        rs_gen_func_normalize(1, 0.0, 1.0);
218
//        rs_gen_func_mult(1, 0, 1);
219
//        rs_gen_func_normalize(1, 0.0, 1.0);
220
//        rs_gen_func_posterize(1, 4);
5235 alpine 221
 
5237 alpine 222
        rs_gen_func_set(1, 0.0);
223
        rs_gen_func_cell(1, 110+100*i, 7+i, NULL, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0);
224
        rs_gen_func_normalize(1, 0.0, 1.0);
225
//        rs_gen_func_mult_add_value(1, 1, 0.9, 0.1);
5235 alpine 226
 
5237 alpine 227
//        rs_gen_func_normalmap(2, 3, 3, 1, 1.0);
228
//        rs_gen_func_mult(1, 1, 2);
5235 alpine 229
 
5237 alpine 230
        //rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
231
        //rs_gen_tex_out_rgba(1, 1, 1, 1, 0.5+ 0.03*(i%2), 0.7+ 0.03*(i%3) , 0.9, 1.0);
232
//        rs_gen_tex_out_rgba_set(0.2 + 0.2*(i/3), 0.2 + 0.1*(i%5), 0.2 + 0.1*(i%7), 0.0);
233
//        rs_gen_tex_out_rgba(1, 1, 1, 1, 0.0, 0.0, 0.0, 1.0);
5235 alpine 234
 
5237 alpine 235
        rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
236
//        rs_gen_tex_out_rgba_set( cr_b[i], cr_g[i], cr_r[i], 0.0);
237
        rs_gen_tex_out_rgba(1, 1, 1, 0, cr_b[i], cr_g[i], cr_r[i], 1.0);
238
 
239
        memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
5235 alpine 240
    };
5237 alpine 241
    rs_gen_term();
242
 
243
 
244
 
245
    rs_gen_init(3, EXPLOSION_SIZE);
246
    for (i = 0; i < EXPLOSION_FRAMES_COUNT; i++) {
247
 
248
        texture_init(&(game.tex_explosion[i]), EXPLOSION_SIZE, EXPLOSION_SIZE);
5235 alpine 249
 
5237 alpine 250
        rs_gen_func_set(0, 1.0);
251
//        rs_gen_func_radial(0, 0.5, 0.5, 0.3 + 0.5*i/EXPLOSION_FRAMES_COUNT, 0.975, 4.0);
252
//        rs_gen_func_set(0, 1.0);
5235 alpine 253
 
5237 alpine 254
        rs_gen_func_set(1, 0.0);
255
        rs_gen_func_radial(1, 0.5, 0.5, 0.1 + 0.4*i/EXPLOSION_FRAMES_COUNT, 1.0 - 1.0*i/EXPLOSION_FRAMES_COUNT, 2.5 + i%5);
5235 alpine 256
 
5237 alpine 257
        rs_gen_tex_out_rgba_set( 0.0, 0.0, 0.0, 0.0);
258
        rs_gen_tex_out_rgba(0, 0, 0, 1, 1.0, 1.0, 1.0, 1.0);
259
 
260
        memcpy(game.tex_explosion[i].data, rs_gen_reg.tex_out, EXPLOSION_SIZE*EXPLOSION_SIZE*4 );
261
    };
262
    rs_gen_term();
5235 alpine 263
};
264
 
5237 alpine 265
void game_textures_init_stage2() {
266
 
267
//            texture_clear(&game.tex_bg, COLOR_SILVER);
268
//             /*
269
 
270
    rs_gen_init(6, 512);
271
    rs_gen_func_perlin(0, 8, 5, 0.5, 1100);
272
    rs_gen_func_normalize(0, 0.0, 1.0);
273
    rs_gen_func_perlin(1, 8, 5, 0.5, 1700);
274
    rs_gen_func_normalize(1, 0.0, 1.0);
275
    rs_gen_func_cell(2, 1118, 50, NULL, 1.0, 0.887, -0.333, 1.0, 0.0, 4.0); // 1360
276
    rs_gen_func_normalize(2, 0.0, 0.5);
277
 
278
    rs_gen_func_adr(3, 2, 0, 1, 1.0, 0.3);
279
 
280
    rs_gen_func_inv(3, 3, 7.5);
281
    rs_gen_func_normalize(3, 0.0, 1.0);
282
 
283
//            signed short c[] = { 0, 250, 250, 0, 500, 250, 250, 500};
284
    signed short c[] = { 0, 0, 0, 512, 512, 0, 512, 512};
285
//            signed short c[] = { 128, 128, 128, 384, 384, 128, 384, 384};
286
    //rs_gen_func_cell(4, 0, 4, c, 0.0, 0.3, 1.0, 0.5, 0.0, 0.30);
287
    rs_gen_func_cell(4, 0, 4, c, 1.0, 0.3, 0.0, 0.95, 0.0, 0.30);
288
    rs_gen_func_normalize(4, 0.0, 1.0);
289
 
290
//            rs_gen_func_radial(5, 0.5, 0.5, 0.60, 1.0, 4.0);
291
//            rs_gen_func_add(4, 4, 5, 0.5, 0.5);
292
//
293
    rs_gen_func_mult(4, 4, 3);
294
 
295
    // coloring...
296
    rs_gen_func_mult_add_value(0, 4, 0.8, 0.0);
297
    rs_gen_func_add(0, 4, 1, 0.95, 0.05);
298
    rs_gen_func_add(3, 4, 2, 0.95, 0.05);
299
 
300
 
301
    rs_gen_tex_out_rgba(4, 0, 3, -1, 0.9, 0.9, 0.9, 1.0);
302
    memcpy(game.tex_bg.data, rs_gen_reg.tex_out, 512*512*4 );
303
    rs_gen_term();
304
 
305
    // */
306
 
307
    // Background for gameplay
308
 
309
    texture_draw( &game.tex_bg_gameplay, &game.tex_bg, 256, 256, DRAW_MODE_REPLACE | DRAW_TILED_FLAG );
310
    // Bevel
311
    texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 - 5, FIELD_Y0 - 5, FIELD_HEIGHT*CRYSTAL_SIZE + 10, 0xFF404060 );
312
    texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 5, FIELD_Y0 - 5, FIELD_WIDTH*CRYSTAL_SIZE + 10, 0xFF404060 );
313
    texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 - 4, FIELD_Y0 - 4, FIELD_HEIGHT*CRYSTAL_SIZE + 8, 0xFF606080 );
314
    texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 4, FIELD_Y0 - 4, FIELD_WIDTH*CRYSTAL_SIZE + 8, 0xFF606080 );
315
 
316
    texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 + 4 + FIELD_WIDTH*CRYSTAL_SIZE, FIELD_Y0 - 4, FIELD_HEIGHT*CRYSTAL_SIZE + 8, 0xFFC0C0C0 );
317
    texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 4, FIELD_Y0 + 4 + FIELD_HEIGHT*CRYSTAL_SIZE, FIELD_WIDTH*CRYSTAL_SIZE + 9, 0xFFC0C0C0 );
318
    texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 + 5 + FIELD_WIDTH*CRYSTAL_SIZE, FIELD_Y0 - 5, FIELD_HEIGHT*CRYSTAL_SIZE + 10, 0xFFE0E0E0 );
319
    texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 5, FIELD_Y0 + 5 + FIELD_HEIGHT*CRYSTAL_SIZE, FIELD_WIDTH*CRYSTAL_SIZE + 11, 0xFFE0E0E0 );
320
 
321
    texture_draw( &game.tex_bg_gameplay, &game.tex_field, FIELD_X0 - 3, FIELD_Y0 - 3, DRAW_MODE_ALPHA );
322
 
323
 
324
};
325
 
326
void game_textures_free() {
327
    free(game.scaled_framebuffer);
328
 
329
    //    texture_free(&game.tex_gui_line);
330
 
331
    int i;
332
    for (i = 0; i < CRYSTALS_COUNT; i++) {
333
        texture_free(&game.tex_crystals[i]);
334
    };
335
 
336
    for (i = 0; i < EXPLOSION_FRAMES_COUNT; i++) {
337
        texture_free(&game.tex_explosion[i]);
338
    };
339
 
340
    texture_free(&game.framebuffer);
341
 
342
    texture_free(&game.tex_logo);
343
    texture_free(&game.tex_clouds);
344
 
345
    texture_free(&game.tex_bg);
346
    texture_free(&game.tex_bg_gameplay);
347
};