Revision 179
changed stuff
proj/include/proj_macros.h | ||
---|---|---|
1 | 1 |
#ifndef PROJ_MACROS_H_INCLUDED |
2 | 2 |
#define PROJ_MACROS_H_INCLUDED |
3 | 3 |
|
4 |
#include "graph_macros.h" |
|
5 |
|
|
4 | 6 |
// WASD Movement Keys |
5 | 7 |
#define W_MAKE_CODE 0x11 /** @brief W Make Code */ |
6 | 8 |
#define W_BREAK_CODE 0x91 /** @brief W Break Code */ |
proj/include/rectangle.h | ||
---|---|---|
7 | 7 |
rectangle_t* (rectangle_ctor)(int16_t x, int16_t y, uint16_t w, uint16_t h); |
8 | 8 |
void (rectangle_dtor)(rectangle_t *p); |
9 | 9 |
|
10 |
void (rectangle_set_pos) (rectangle_t *p, int16_t x, int16_t y); |
|
11 |
void (rectangle_set_size) (rectangle_t *p, uint16_t w, uint16_t h); |
|
12 |
void (rectangle_set_fill_color) (rectangle_t *p, uint32_t color); |
|
13 |
void (rectangle_set_outline_color)(rectangle_t *p, uint32_t color); |
|
14 |
void (rectangle_set_outline_width)(rectangle_t *p, int16_t width); |
|
15 |
|
|
16 |
int16_t (rectangle_get_x)(const rectangle_t *p); |
|
17 |
int16_t (rectangle_get_y)(const rectangle_t *p); |
|
18 |
uint16_t (rectangle_get_w)(const rectangle_t *p); |
|
19 |
uint16_t (rectangle_get_h)(const rectangle_t *p); |
|
20 |
|
|
21 |
void (rectangle_draw)(const rectangle_t *p); |
|
22 |
|
|
10 | 23 |
#endif //RECTANGLE_H_INCLUDED |
proj/include/sprite.h | ||
---|---|---|
7 | 7 |
sprite_t* (sprite_ctor)(const char **xpm, int u0, int v0); |
8 | 8 |
void (sprite_dtor)(sprite_t *p); |
9 | 9 |
|
10 |
void (sprite_set_x) (sprite_t *p, int16_t x); |
|
11 |
void (sprite_set_y) (sprite_t *p, int16_t y); |
|
12 | 10 |
void (sprite_set_pos) (sprite_t *p, int16_t x, int16_t y); |
13 | 11 |
void (sprite_set_angle) (sprite_t *p, double angle); |
14 | 12 |
void (sprite_set_center)(sprite_t *p, int16_t u0, int16_t v0); |
proj/src/proj.c | ||
---|---|---|
2 | 2 |
#include <lcom/proj.h> |
3 | 3 |
#include <lcom/liblm.h> |
4 | 4 |
|
5 |
#include <stdbool.h> |
|
6 |
#include <stdint.h> |
|
7 |
|
|
8 |
#include "i8254.h" |
|
9 |
#include "kbc_macros.h" |
|
10 |
#include "graph_macros.h" |
|
11 |
#include "mouse_macros.h" |
|
12 | 5 |
#include "proj_macros.h" |
13 |
#include "errors.h"
|
|
6 |
#include "proj_func.h"
|
|
14 | 7 |
|
15 |
#include "sprite.h" |
|
16 | 8 |
#include "kbc.h" |
17 |
#include "graph.h" |
|
18 | 9 |
#include "timer.h" |
19 | 10 |
#include "keyboard.h" |
20 | 11 |
#include "mouse.h" |
21 |
#include "utils.h" |
|
22 | 12 |
#include "interrupts_func.h" |
23 |
#include "proj_func.h" |
|
24 | 13 |
|
25 |
#include "fast_math.h" |
|
26 |
#include <math.h> |
|
14 |
#include "graph.h" |
|
15 |
#include "sprite.h" |
|
16 |
#include "rectangle.h" |
|
27 | 17 |
|
28 | 18 |
#ifdef DIOGO |
29 | 19 |
#include "shooter.h" |
30 |
#include "pistol.xpm" |
|
31 | 20 |
#endif |
32 | 21 |
#ifdef TELMO |
33 | 22 |
#include "crosshair.h" |
... | ... | |
78 | 67 |
printf("Time taken: %d/%d \n", t, CLOCKS_PER_SEC); |
79 | 68 |
sprite_dtor(shooter1); |
80 | 69 |
*/ |
70 |
/* |
|
71 |
rectangle_t *rect = rectangle_ctor(100, 100, 100, 100); |
|
72 |
rectangle_set_fill_color (rect, 0x0000FF); |
|
73 |
rectangle_set_outline_color(rect, 0xFF0000); |
|
74 |
rectangle_set_outline_width(rect, 0); |
|
75 |
rectangle_draw(rect); |
|
76 |
rectangle_set_pos(rect, 205, 100); |
|
77 |
rectangle_set_outline_width(rect, 1); |
|
78 |
rectangle_draw(rect); |
|
79 |
rectangle_set_pos(rect, 310, 100); |
|
80 |
rectangle_set_outline_width(rect, 2); |
|
81 |
rectangle_draw(rect); |
|
82 |
rectangle_set_pos(rect, 415, 100); |
|
83 |
rectangle_set_outline_width(rect, 3); |
|
84 |
rectangle_draw(rect); |
|
85 |
|
|
86 |
graph_draw(); |
|
87 |
*/ |
|
81 | 88 |
#endif |
82 | 89 |
|
83 | 90 |
#ifdef TELMO |
... | ... | |
92 | 99 |
message msg; |
93 | 100 |
int good = 1; |
94 | 101 |
|
95 |
#ifdef DIOGO |
|
96 |
good = 0; |
|
97 |
#endif |
|
98 |
|
|
99 | 102 |
while (good) { |
100 | 103 |
/* Get a request message. */ |
101 | 104 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
proj/src/rectangle.c | ||
---|---|---|
2 | 2 |
|
3 | 3 |
#include "rectangle.h" |
4 | 4 |
|
5 |
#include "graph.h" |
|
6 |
#include "utils.h" |
|
7 |
|
|
5 | 8 |
struct rectangle{ |
6 |
int16_t x, y; |
|
9 |
int16_t x, y;
|
|
7 | 10 |
uint16_t w, h; |
8 | 11 |
uint32_t fill_color; |
9 | 12 |
uint32_t outline_color; |
10 |
uint16_t outline_width;
|
|
13 |
int16_t outline_width;
|
|
11 | 14 |
}; |
12 | 15 |
|
13 | 16 |
rectangle_t* (rectangle_ctor)(int16_t x, int16_t y, uint16_t w, uint16_t h){ |
14 | 17 |
rectangle_t *ret = (rectangle_t*)malloc(sizeof(rectangle_t)); |
15 |
|
|
18 |
if(ret == NULL) return NULL; |
|
19 |
ret->x = x; |
|
20 |
ret->y = y; |
|
21 |
ret->w = w; |
|
22 |
ret->h = h; |
|
23 |
ret->fill_color = 0xFFFFFF; |
|
24 |
ret->outline_color = 0x000000; |
|
25 |
ret->outline_width = 0; |
|
16 | 26 |
return ret; |
17 | 27 |
} |
18 |
void (rectangle_dtor)(rectangle_t *p){
|
|
28 |
void (rectangle_dtor)(rectangle_t *p){ |
|
19 | 29 |
if(p == NULL) return; |
20 | 30 |
free(p); |
21 | 31 |
} |
32 |
|
|
33 |
void (rectangle_set_pos) (rectangle_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; } |
|
34 |
void (rectangle_set_size) (rectangle_t *p, uint16_t w, uint16_t h){ p->w = w; p->h = h; } |
|
35 |
void (rectangle_set_fill_color) (rectangle_t *p, uint32_t color ){ p->fill_color = color; } |
|
36 |
void (rectangle_set_outline_color)(rectangle_t *p, uint32_t color ){ p->outline_color = color; } |
|
37 |
void (rectangle_set_outline_width)(rectangle_t *p, int16_t width ){ p->outline_width = width; } |
|
38 |
|
|
39 |
int16_t (rectangle_get_x)(const rectangle_t *p){ return p->x; } |
|
40 |
int16_t (rectangle_get_y)(const rectangle_t *p){ return p->y; } |
|
41 |
uint16_t (rectangle_get_w)(const rectangle_t *p){ return p->w; } |
|
42 |
uint16_t (rectangle_get_h)(const rectangle_t *p){ return p->h; } |
|
43 |
|
|
44 |
static void (rectangle_draw_hline)(int16_t x, int16_t y, int16_t l, uint32_t color){ |
|
45 |
if(l < 0){ rectangle_draw_hline(x+l, y, -l, color); return; } |
|
46 |
for(int16_t x_ = max(0,x); x_ < min(x+l,graph_get_XRes()); ++x_){ |
|
47 |
graph_set_pixel(x_, y, color); |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
static void (rectangle_draw_vline)(int16_t x, int16_t y, int16_t l, uint32_t color){ |
|
52 |
if(l < 0){ rectangle_draw_vline(x, y+l, -l, color); return; } |
|
53 |
for(int16_t y_ = max(0,y); y_ < min(y+l,graph_get_YRes()); ++y_){ |
|
54 |
graph_set_pixel(x, y_, color); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
void (rectangle_draw)(const rectangle_t *p){ |
|
59 |
for(int16_t y = max(p->y,0); y < min(p->y+p->h, graph_get_YRes()); ++y) |
|
60 |
rectangle_draw_hline(p->x, y, p->w, p->fill_color); |
|
61 |
|
|
62 |
int16_t step = (p->outline_width > 0 ? 1 : -1); |
|
63 |
int16_t l = p->x, r = p->x+p->w, t = p->y, b = p->y+p->h; |
|
64 |
if(step > 0){ |
|
65 |
--l; ++r; --t; ++b; |
|
66 |
} |
|
67 |
for(int16_t i = 0; i != p->outline_width; i += step, l -= step, r += step, t -= step, b += step){ |
|
68 |
rectangle_draw_hline(l , t , r-l, p->outline_color); |
|
69 |
rectangle_draw_hline(l , b-1, r-l, p->outline_color); |
|
70 |
rectangle_draw_vline(l , t , b-t, p->outline_color); |
|
71 |
rectangle_draw_vline(r-1, t , b-t, p->outline_color); |
|
72 |
} |
|
73 |
} |
proj/src/sprite.c | ||
---|---|---|
40 | 40 |
free(p); |
41 | 41 |
} |
42 | 42 |
|
43 |
void (sprite_set_x) (sprite_t *p, int16_t x){ p->x = x; } |
|
44 |
void (sprite_set_y) (sprite_t *p, int16_t y){ p->y = y; } |
|
45 |
void (sprite_set_pos) (sprite_t *p, int16_t x, int16_t y){ sprite_set_x(p, x); sprite_set_y(p, y); } |
|
43 |
void (sprite_set_pos) (sprite_t *p, int16_t x, int16_t y){ p->x = x; p->y = y; } |
|
46 | 44 |
void (sprite_set_angle) (sprite_t *p, double angle){ p->theta = angle; } |
47 | 45 |
void (sprite_set_center)(sprite_t *p, int16_t u0, int16_t v0){ p->u0 = u0; p->v0 = v0; } |
48 | 46 |
|
Also available in: Unified diff