Revision 207
maybe working
proj/include/graph.h | ||
---|---|---|
29 | 29 |
int (graph_set_pixel) (uint16_t x, uint16_t y, uint32_t color); |
30 | 30 |
int (graph_set_pixel_buffer) (uint16_t x, uint16_t y, uint32_t color, uint8_t *buf, uint16_t W, uint16_t H); |
31 | 31 |
int (graph_set_pixel_alpha_buffer)(uint16_t x, uint16_t y, uint8_t alpha, uint8_t *alp_buf, uint16_t W, uint16_t H); |
32 |
int (graph_set_pixel_alpha) (uint16_t x, uint16_t y, uint32_t color, uint8_t alpha); |
|
32 |
//int (graph_set_pixel_alpha) (uint16_t x, uint16_t y, uint32_t color, uint8_t alpha);
|
|
33 | 33 |
|
34 | 34 |
/// SCREEN |
35 | 35 |
int (graph_clear_screen)(void); |
proj/src/font.c | ||
---|---|---|
201 | 201 |
for(int16_t newy = 0; newy < newH; ++newy){ |
202 | 202 |
for(int16_t newx = 0; newx < newW; ++newx){ |
203 | 203 |
uint8_t a = *(alp_new_buf+newx+newy*newW); |
204 |
graph_set_pixel_alpha(initx+newx,inity+newy,p->color, a);
|
|
204 |
if(a < 0x7F) graph_set_pixel(initx+newx,inity+newy,p->color);
|
|
205 | 205 |
} |
206 | 206 |
} |
207 | 207 |
free(alp_new_buf); |
proj/src/graph.c | ||
---|---|---|
275 | 275 |
memcpy(alp_buf + pos, &alpha, 1); |
276 | 276 |
return SUCCESS; |
277 | 277 |
} |
278 |
/* |
|
278 | 279 |
int (graph_set_pixel_alpha)(uint16_t x, uint16_t y, uint32_t color, uint8_t alpha){ |
279 | 280 |
if (x >= vbe_mem_info.XResolution || y >= vbe_mem_info.YResolution) { |
280 | 281 |
//printf("%s: invalid pixel.\n", __func__); |
... | ... | |
286 | 287 |
float a = 1.0-(alpha&0xFF)/(float)0xFF; |
287 | 288 |
uint8_t r = GET_RED(color)*a + GET_RED(color_)*(1.0-a); |
288 | 289 |
uint8_t g = GET_GRE(color)*a + GET_GRE(color_)*(1.0-a); |
289 |
uint8_t b = GET_BLU(color)*a + GET_BLU(color_)*(1.0-a); |
|
290 |
return graph_set_pixel(x,y,SET_RGB(r,g,b)); |
|
291 |
//return set_pixel(x,y,color); |
|
290 |
uint8_t b = GET_BLU(color)*a + GET_BLU(color_)*(1.0-a); (void)(r*g*b); |
|
291 |
//return graph_set_pixel(x,y,SET_RGB(r,g,b)); |
|
292 |
color = SET_RGB(r,g,b); |
|
293 |
//unsigned int pos = (x + y * W) * graph_get_bytes_pixel(); |
|
294 |
memcpy(video_buf + pos, &color, graph_get_bytes_pixel()); |
|
295 |
return SUCCESS; |
|
292 | 296 |
} |
293 |
|
|
297 |
*/ |
|
294 | 298 |
int (graph_clear_screen)(void){ |
295 | 299 |
//return graph_paint_screen(BLACK); |
296 | 300 |
memset(video_buf, 0, graph_get_vram_size()); |
proj/src/proj.c | ||
---|---|---|
24 | 24 |
#include "pistol.h" |
25 | 25 |
#include "nothing.h" |
26 | 26 |
#include "bullet.h" |
27 |
#include "map.h" |
|
27 | 28 |
|
28 | 29 |
int main(int argc, char* argv[]) { |
29 | 30 |
|
... | ... | |
127 | 128 |
graph_draw(); |
128 | 129 |
|
129 | 130 |
uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
131 |
|
|
132 |
basic_sprite_t *bsp_pink = get_map(); |
|
133 |
sprite_t *pink = sprite_ctor(bsp_pink); |
|
134 |
basic_sprite_dtor(bsp_pink); |
|
130 | 135 |
#endif |
131 | 136 |
|
132 | 137 |
/// loop stuff |
... | ... | |
156 | 161 |
if (no_interrupts % refresh_count_value == 0) { |
157 | 162 |
update_movement(shooter1); |
158 | 163 |
update_scale(); |
159 |
ent_set_origin(bullet_get_x(bullet)-ent_get_XLength()/2.0,
|
|
160 |
bullet_get_y(bullet)-ent_get_YLength()/2.0);
|
|
164 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
|
|
165 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0);
|
|
161 | 166 |
|
162 | 167 |
sprite_set_pos(sp_crosshair, get_mouse_X(), get_mouse_Y()); |
163 | 168 |
double angle = get_mouse_angle(shooter1); |
164 | 169 |
gunner_set_angle(shooter1, angle - M_PI_2); |
165 | 170 |
graph_clear_screen(); |
171 |
|
|
172 |
clock_t t = clock(); |
|
173 |
|
|
174 |
sprite_draw(pink); |
|
166 | 175 |
gunner_draw(shooter2); |
167 | 176 |
gunner_draw(shooter1); |
168 | 177 |
bullet_draw(bullet); |
178 |
|
|
179 |
t = clock()-t; printf("%d\n", (t*1000)/CLOCKS_PER_SEC); |
|
180 |
|
|
169 | 181 |
sprite_draw(sp_crosshair); |
170 | 182 |
graph_draw(); |
171 | 183 |
} |
... | ... | |
193 | 205 |
|
194 | 206 |
#ifdef TELMO |
195 | 207 |
gunner_dtor(shooter1); shooter1 = NULL; |
208 |
sprite_dtor(pink); pink = NULL; |
|
196 | 209 |
#endif |
197 | 210 |
|
198 | 211 |
basic_sprite_dtor(bsp_crosshair); bsp_crosshair = NULL; |
proj/src/sprite.c | ||
---|---|---|
44 | 44 |
struct sprite{ |
45 | 45 |
const basic_sprite_t *bsp; |
46 | 46 |
int16_t x, y; //position in screen |
47 |
double theta; |
|
47 |
double theta, s, c;
|
|
48 | 48 |
double scale; |
49 | 49 |
}; |
50 | 50 |
|
... | ... | |
54 | 54 |
ret->bsp = bsp; |
55 | 55 |
ret->x = 0; |
56 | 56 |
ret->y = 0; |
57 |
ret->theta = 0.0;
|
|
57 |
sprite_set_angle(ret, 0.0);
|
|
58 | 58 |
ret->scale = 1.0; |
59 | 59 |
return ret; |
60 | 60 |
} |
... | ... | |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
void (sprite_set_pos) (sprite_t *p, int16_t x , int16_t y ){ p->x = x; p->y = y; } |
67 |
void (sprite_set_angle) (sprite_t *p, double angle ){ p->theta = angle; } |
|
67 |
void (sprite_set_angle) (sprite_t *p, double angle ){ p->theta = angle; p->c = fm_cos(p->theta); p->s = fm_sin(p->theta); }
|
|
68 | 68 |
void (sprite_set_scale) (sprite_t *p, double scale ){ p->scale = scale; } |
69 | 69 |
int16_t (sprite_get_x)(const sprite_t *p){ return p->x; } |
70 | 70 |
int16_t (sprite_get_y)(const sprite_t *p){ return p->y; } |
71 | 71 |
|
72 | 72 |
void (sprite_src2pic)(const sprite_t *p, int16_t x, int16_t y, int16_t *u, int16_t *v){ |
73 |
double s = fm_sin(p->theta); |
|
74 |
double c = fm_cos(p->theta); |
|
75 | 73 |
double dx = (x - p->x)/p->scale; |
76 | 74 |
double dy = (y - p->y)/p->scale; |
77 |
int16_t du = dx*c - dy*s + 0.5;
|
|
78 |
int16_t dv = dx*s + dy*c + 0.5;
|
|
75 |
int16_t du = dx*p->c - dy*p->s + 0.5;
|
|
76 |
int16_t dv = dx*p->s + dy*p->c + 0.5;
|
|
79 | 77 |
*u = du + basic_sprite_get_u0(p->bsp); |
80 | 78 |
*v = dv + basic_sprite_get_v0(p->bsp); |
81 | 79 |
} |
82 | 80 |
|
83 | 81 |
void (sprite_pic2src)(const sprite_t *p, int16_t u, int16_t v, int16_t *x, int16_t *y){ |
84 |
double s = fm_sin(p->theta); |
|
85 |
double c = fm_cos(p->theta); |
|
86 | 82 |
int16_t du = u - basic_sprite_get_u0(p->bsp); |
87 | 83 |
int16_t dv = v - basic_sprite_get_v0(p->bsp); |
88 |
double dx = du*c + dv*s;
|
|
89 |
double dy = -du*s + dv*c;
|
|
84 |
double dx = du*p->c + dv*p->s;
|
|
85 |
double dy = -du*p->s + dv*p->c;
|
|
90 | 86 |
*x = dx*p->scale + 0.5 + p->x; |
91 | 87 |
*y = dy*p->scale + 0.5 + p->y; |
92 | 88 |
} |
... | ... | |
114 | 110 |
sprite_src2pic(p, x, y, &u, &v); |
115 | 111 |
if(0 <= u && u < w && 0 <= v && v < h){ |
116 | 112 |
uint32_t c = *(uint32_t*)(map + (v*w + u)*4); |
117 |
graph_set_pixel_alpha(x, y, GET_COLOR(c), GET_ALP(c)); |
|
113 |
if(GET_ALP(c) < 0x7F) |
|
114 |
graph_set_pixel(x, y, GET_COLOR(c)); |
|
118 | 115 |
} |
119 | 116 |
} |
120 | 117 |
} |
proj/xpm/map.h | ||
---|---|---|
5 | 5 |
#include "sprite.h" |
6 | 6 |
|
7 | 7 |
basic_sprite_t* get_map(void){ |
8 |
return basic_sprite_ctor((const char **)map, 639, 511);
|
|
8 |
return basic_sprite_ctor((const char **)map_xpm, 0, 0);
|
|
9 | 9 |
} |
10 | 10 |
|
11 | 11 |
#endif /* end of include guard: MAP_H_INCLUDED */ |
Also available in: Unified diff