Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
5225 alpine 1
#include "rsgamedraw.h"
2
#include "rsgametext.h"
3
#include "rsgamemenu.h"
4
 
5
#include "rskos.h"
6
 
7
#include "rsnoise.h"
8
 
5243 alpine 9
#include "strings.h"
5225 alpine 10
 
11
 
12
void game_draw() {
13
 
14
	int w = 320;
15
	int h = 180;
16
 
17
 
18
	int kk = 20; // (rskos_get_time()/1) % 160;
19
 
20
 
5298 alpine 21
    texture_clear(&game.framebuffer, game.bg_color );
22
 
23
    game.bg_color = COLOR_BLACK;
24
 
5225 alpine 25
 
26
    int i, c, c2, c3;
27
    for (i = 0; i < 100; i++) {
28
        c = (0.5+0.45*rs_noise(kk+150, kk+i))*255;
29
        c2 = c + 0.05*rs_noise(kk+150, kk+i)*255;
30
        c3 = c2; // (0.5+0.49*rs_noise(kk+150, kk+i+2))*255;
31
        texture_set_pixel(&game.framebuffer, (0.5+0.49*rs_noise(kk+1100, kk+i))*GAME_WIDTH, (0.5+0.49*rs_noise(kk+1200, kk+i+1300))*GAME_HEIGHT,
32
                          c + (c2<<8) + (c3<<16) + 0xFF000000);
33
    };
34
 
35
    texture_clear(&game.tex_ground, COLOR_TRANSPARENT);
36
    rs_perlin_configure(47, 4, 0.5, 1000, 256);
37
    for (i = 0; i < game.tex_ground.w; i++) {
38
        texture_draw_vline(&game.tex_ground, i, 25 + rs_perlin(0,i+game.tz)*25, 2, 0xFF113300);
39
        texture_draw_vline(&game.tex_ground, i, 25 + rs_perlin(0,i+game.tz)*25 + 2, 999, 0xFF000000);
40
    };
41
 
42
 
43
 
44
    if (game.status == STATUS_MENU) {
45
 
46
        char **title = menu_titles[game.menu_index];
47
        int y = (game.menu_index == MENU_MAIN) ? 80 : 50;
48
        texture_draw(&game.framebuffer, &game.tex_gui_line, 0, y+15*game.menu_item_index, DRAW_MODE_ALPHA);
49
        while (*title) {
50
            game_textout(20, y, (*(title))[0]==' ' ? 3 : 0 , (*(title))+1 );  // first (zero) char defines action, title starts from second (1st) char
51
            title++;
52
            y+=15;
53
        };
54
 
55
        if (game.menu_index == MENU_MAIN) {
56
 
5291 alpine 57
            for (i = 0; i < 3; i++) {
5225 alpine 58
                texture_draw(&game.framebuffer, &game.tex_rocks[i], 250+80*rs_noise(i,150), 60+60*rs_noise(i,1110), DRAW_MODE_ADDITIVE );
59
            };
60
 
5243 alpine 61
            game_textout( GAME_WIDTH/2 - 100, 40, 1,  "HELI0THRYX");
5291 alpine 62
//            game_textout( GAME_WIDTH/2 - 8, 58, 3,  "TECHDEM0");
5243 alpine 63
            game_textout( 2, GAME_HEIGHT-10, 2,  L_BOTTOM_LINE_DEVELOPER_INFO);
5225 alpine 64
        };
65
 
66
    }
67
    else {
68
 
5291 alpine 69
        int i, j;
70
        game_obj_t *obj;
71
        for (i = 0; i < game.objs_count; i++) {
72
            obj = &(game.objs[i]);
73
 
74
            if (obj->obj_type == OBJ_BULLET) {
75
 
76
                texture_set_pixel(&game.framebuffer, obj->x-4, obj->y, 0xFF00BB00);
77
                texture_set_pixel(&game.framebuffer, obj->x-3, obj->y, 0xFF00CC00);
78
                texture_set_pixel(&game.framebuffer, obj->x-2, obj->y, 0xFF00DD00);
79
                texture_set_pixel(&game.framebuffer, obj->x-1, obj->y, 0xFF00EE00);
80
                texture_set_pixel(&game.framebuffer, obj->x-0, obj->y, 0xFF00FF00);
81
 
82
            }
83
            else if (obj->obj_type == OBJ_RED_BULLET) {
84
 
85
                texture_set_pixel(&game.framebuffer, obj->x-1, obj->y-0, 0xFFFF0000);
86
                texture_set_pixel(&game.framebuffer, obj->x-1, obj->y-1, 0xFFFF6600);
87
                texture_set_pixel(&game.framebuffer, obj->x-1, obj->y-0, 0xFFFF0000);
88
                texture_set_pixel(&game.framebuffer, obj->x-0, obj->y-1, 0xFFFF0000);
89
                texture_set_pixel(&game.framebuffer, obj->x-0, obj->y-0, 0xFFFF6600);
90
                texture_set_pixel(&game.framebuffer, obj->x+1, obj->y-1, 0xFFFF0000);
91
                texture_set_pixel(&game.framebuffer, obj->x+1, obj->y-0, 0xFFFF6600);
92
 
93
            }
94
            else if (obj->obj_type == OBJ_EXPLOSION) {
95
                texture_draw( &game.framebuffer, &game.tex_explosions[ obj->t ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ALPHA );
96
            }
5316 alpine 97
            else if (obj->obj_type == OBJ_HUGE_EXPLOSION) {
98
                texture_draw( &game.framebuffer, &game.tex_huge_explosions[ obj->t ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ALPHA );
99
            }
5291 alpine 100
            else if (obj->obj_type == OBJ_ROCK) {
101
                texture_draw( &game.framebuffer, &game.tex_rocks[ obj->tag ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ALPHA );
102
            }
103
            else if (obj->obj_type == OBJ_MINIROCK) {
104
                texture_draw( &game.framebuffer, &game.tex_minirocks[ obj->tag ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ALPHA );
105
            }
106
            else if (obj->obj_type == OBJ_TURRET) {
107
                texture_draw( &game.framebuffer, &game.tex_rocks[ 0 ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ALPHA );
108
                texture_draw( &game.framebuffer, &game.tex_rocks[ 0 ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ADDITIVE );
109
 
110
                for (j = 0; j < 1 + (obj->tag)/6; j++) {
111
                    texture_draw_vline(&game.framebuffer, obj->x - obj->radius + j*4 + 0, obj->y - obj->radius - 16, 8, 0xFF993333 );
112
                    texture_draw_vline(&game.framebuffer, obj->x - obj->radius + j*4 + 1, obj->y - obj->radius - 16, 8, 0xFF993333 );
113
                    texture_draw_vline(&game.framebuffer, obj->x - obj->radius + j*4 + 2, obj->y - obj->radius - 16, 8, 0xFF993333 );
114
                };
115
 
116
            }
117
 
118
        };
5225 alpine 119
 
5291 alpine 120
 
121
        texture_draw(&game.framebuffer, &game.tex_ship[0], game.player_x-8, game.player_y-4, DRAW_MODE_ALPHA);
122
        texture_draw(&game.framebuffer, &game.tex_ship[1], game.player_x-8, game.player_y-4, DRAW_MODE_ALPHA);
123
        texture_draw(&game.framebuffer, &game.tex_ship[2], game.player_x, game.player_y-4, DRAW_MODE_ALPHA);
124
        texture_draw(&game.framebuffer, &game.tex_ship[3], game.player_x, game.player_y-4, DRAW_MODE_ALPHA);
125
 
126
 
127
        if ( game.stage == 0 ) {
5315 alpine 128
 
129
            int stage_label_y = GAME_HEIGHT/3 - (game.stage_timer - 25)*(game.stage_timer - 25)*(game.stage_timer - 25)/100;
130
 
131
            //game_textout_at_center( 0, GAME_HEIGHT + 50 - game.stage_timer*(GAME_HEIGHT+50)/50, 1, "LEVEL 1" );
5291 alpine 132
 
5315 alpine 133
            char stage_str[] = "5TAGE xx";
134
            char *stage_num = &stage_str[6];
5291 alpine 135
 
5315 alpine 136
            if ( (game.stage_level+1) > 9 ) {
137
                stage_num[0] = '0' + (game.stage_level+1)/10;
138
                stage_num[1] = '0' + (game.stage_level+1)%10;
139
            }
140
            else {
141
                stage_num[0] = '0' + (game.stage_level+1)%10;
142
                stage_num[1] = 0;
143
            };
5291 alpine 144
 
5315 alpine 145
            game_textout_at_center( -10, stage_label_y, 1, stage_str );
5291 alpine 146
 
5315 alpine 147
            if ( IS_BIT_CLEARED ( game.flags, GAME_FLAG_INSTRUCTIONS_PASSED ) ) {
148
                game_textout_at_center( 0, GAME_HEIGHT*3/4, 2, L_TECHDEMO_LINE1 );
149
            };
150
        }
5225 alpine 151
 
5315 alpine 152
        char s_score[] = "0000";
153
        s_score[0] += (game.score / 1000) % 10;
154
        s_score[1] += (game.score / 100) % 10;
155
        s_score[2] += (game.score / 10) % 10;
156
        s_score[3] += (game.score / 1) % 10;
5225 alpine 157
 
5315 alpine 158
        game_textout_at_center(0, 10, 3, s_score);
5291 alpine 159
 
160
 
5315 alpine 161
 
162
 
5291 alpine 163
        char s_health[] = "HEALTH: 0 ";
164
        char s_ammo[] = "AMM0: 00 ";
165
 
166
        s_health[8] += game.health;
167
        s_ammo[6] += game.ammo / 10;
168
        s_ammo[7] += game.ammo % 10;
169
 
170
        game_textout(8, 8, 2, s_health);
171
        game_textout(GAME_WIDTH - 12 - GAME_AMMO_MAX*2 - 1, 8, 2, s_ammo);
172
 
173
        for (i = 0; i < game.ammo; i++) {
174
            texture_draw_vline(&game.framebuffer, GAME_WIDTH - 12 - GAME_AMMO_MAX*2 + i*2, 20, 8, 0xFF3366FF );
175
        };
176
 
177
        int health_color = 0xFF339933;
178
        if (game.health < 5) {
179
            health_color = 0xFF808010;
180
        };
181
        if (game.health < 3) {
182
            health_color = 0xFFFF3300;
183
        };
184
 
185
        for (i = 0; i < game.health; i++) {
186
            texture_draw_vline(&game.framebuffer, 8 + i*4 + 0, 20, 8, health_color  );
187
            texture_draw_vline(&game.framebuffer, 8 + i*4 + 1, 20, 8, health_color  );
188
            texture_draw_vline(&game.framebuffer, 8 + i*4 + 2, 20, 8, health_color  );
189
        };
190
 
191
 
192
 
5225 alpine 193
    };
194
 
5291 alpine 195
    texture_draw(&game.tex_ground, &game.tex_clouds, game.tz, 0, /* game.tx, game.ty, */ DRAW_MODE_ADDITIVE | DRAW_TILED_FLAG );
196
    texture_draw(&game.framebuffer, &game.tex_ground, 0, GAME_HEIGHT-50, DRAW_MODE_ALPHA);
5225 alpine 197
 
5291 alpine 198
 
5225 alpine 199
	rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, game.scaled_framebuffer);
200
 
201
};
202