red_bird 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/bin/setup +8 -0
- data/ext/red_bird/bird.c +15 -0
- data/ext/red_bird/bird.h +10 -0
- data/ext/red_bird/color.c +95 -0
- data/ext/red_bird/color.h +27 -0
- data/ext/red_bird/dynamic_sprite.c +163 -0
- data/ext/red_bird/dynamic_sprite.h +30 -0
- data/ext/red_bird/engine.c +354 -0
- data/ext/red_bird/engine.h +40 -0
- data/ext/red_bird/extconf.rb +9 -0
- data/ext/red_bird/font.c +94 -0
- data/ext/red_bird/font.h +26 -0
- data/ext/red_bird/input_device.c +100 -0
- data/ext/red_bird/input_device.h +15 -0
- data/ext/red_bird/keycode.c +42 -0
- data/ext/red_bird/keycode.h +12 -0
- data/ext/red_bird/loader.c +154 -0
- data/ext/red_bird/loader.h +54 -0
- data/ext/red_bird/main.c +38 -0
- data/ext/red_bird/main.h +12 -0
- data/ext/red_bird/palette.c +132 -0
- data/ext/red_bird/palette.h +23 -0
- data/ext/red_bird/rect.c +257 -0
- data/ext/red_bird/rect.h +20 -0
- data/ext/red_bird/render.c +130 -0
- data/ext/red_bird/render.h +25 -0
- data/ext/red_bird/sprite.c +130 -0
- data/ext/red_bird/sprite.h +27 -0
- data/ext/red_bird/text.c +212 -0
- data/ext/red_bird/text.h +31 -0
- data/ext/red_bird/texture.c +157 -0
- data/ext/red_bird/texture.h +33 -0
- data/ext/red_bird/texture_imp.cpp +49 -0
- data/ext/red_bird/texture_imp.hpp +29 -0
- data/ext/red_bird/timer.c +134 -0
- data/ext/red_bird/timer.h +25 -0
- data/lib/red_bird.rb +15 -0
- data/lib/red_bird/animation.rb +133 -0
- data/lib/red_bird/camera.rb +61 -0
- data/lib/red_bird/controller.rb +44 -0
- data/lib/red_bird/dynamic_sprite.rb +38 -0
- data/lib/red_bird/engine.rb +81 -0
- data/lib/red_bird/entity.rb +74 -0
- data/lib/red_bird/entity_collision.rb +31 -0
- data/lib/red_bird/input_device.rb +86 -0
- data/lib/red_bird/palette.rb +23 -0
- data/lib/red_bird/relative_entity.rb +95 -0
- data/lib/red_bird/sprite.rb +40 -0
- data/lib/red_bird/stage.rb +60 -0
- data/lib/red_bird/tile_map.rb +118 -0
- data/lib/red_bird/tile_set.rb +56 -0
- data/lib/red_bird/uibox.rb +143 -0
- data/lib/red_bird/version.rb +3 -0
- data/lib/red_bird/vertical_menu.rb +110 -0
- data/red_bird.gemspec +37 -0
- metadata +149 -0
data/ext/red_bird/main.h
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
#include "color.h"
|
3
|
+
#include "palette.h"
|
4
|
+
|
5
|
+
/*
|
6
|
+
Document-class: RedBird::Palette
|
7
|
+
A palette consists in a set of 256 colors.
|
8
|
+
|
9
|
+
@author Frederico Linhares
|
10
|
+
*/
|
11
|
+
VALUE bird_cPalette;
|
12
|
+
|
13
|
+
void
|
14
|
+
bird_free_palette(void* obj)
|
15
|
+
{
|
16
|
+
struct bird_palette_data *ptr = obj;
|
17
|
+
|
18
|
+
free(ptr);
|
19
|
+
}
|
20
|
+
|
21
|
+
size_t
|
22
|
+
bird_memsize_palette(const void* obj)
|
23
|
+
{
|
24
|
+
// TODO
|
25
|
+
return 0;
|
26
|
+
}
|
27
|
+
|
28
|
+
static const rb_data_type_t
|
29
|
+
bird_palette_type = {
|
30
|
+
"red_bird_palette",
|
31
|
+
{0, bird_free_palette, bird_memsize_palette,},
|
32
|
+
0, 0,
|
33
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
34
|
+
};
|
35
|
+
|
36
|
+
VALUE
|
37
|
+
bird_alloc_palette(VALUE klass)
|
38
|
+
{
|
39
|
+
VALUE obj;
|
40
|
+
struct bird_palette_data *ptr;
|
41
|
+
|
42
|
+
obj = TypedData_Make_Struct(klass, struct bird_palette_data,
|
43
|
+
&bird_palette_type, ptr);
|
44
|
+
|
45
|
+
return obj;
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
@param colors [Array<RedBird::Color>] an Array with 256 instances of
|
50
|
+
{RedBird::Color}.
|
51
|
+
@author Frederico Linhares
|
52
|
+
*/
|
53
|
+
VALUE
|
54
|
+
bird_cPalette_initialize(VALUE self, VALUE colors)
|
55
|
+
{
|
56
|
+
long ary_index, ary_len;
|
57
|
+
VALUE v_color;
|
58
|
+
struct bird_palette_data *ptr;
|
59
|
+
const char* error_message =
|
60
|
+
"colors must be an Array with 256 instances of RedBird::Color";
|
61
|
+
|
62
|
+
if(!rb_obj_is_kind_of(colors, rb_cArray))
|
63
|
+
rb_raise(rb_eArgError, "%s", error_message);
|
64
|
+
|
65
|
+
ary_len = RARRAY_LEN(colors);
|
66
|
+
if(ary_len != 256)
|
67
|
+
rb_raise(rb_eArgError, "%s", error_message);
|
68
|
+
|
69
|
+
TypedData_Get_Struct(self, struct bird_palette_data, &bird_palette_type,
|
70
|
+
ptr);
|
71
|
+
|
72
|
+
for(ary_index = 0; ary_index < ary_len; ary_index++)
|
73
|
+
{
|
74
|
+
v_color = rb_ary_entry(colors, ary_index);
|
75
|
+
if(!rb_obj_is_kind_of(v_color, bird_cColor))
|
76
|
+
rb_raise(rb_eArgError, "%s", error_message);
|
77
|
+
|
78
|
+
ptr->colors[ary_index] = bird_cColor_get_data(v_color)->data;
|
79
|
+
}
|
80
|
+
|
81
|
+
return self;
|
82
|
+
}
|
83
|
+
|
84
|
+
/*
|
85
|
+
@param index [Integer] color index. Must be between 0 and 255.
|
86
|
+
@return [RedBird::Color] a instance of {RedBird::Color} with values
|
87
|
+
referenced by the index.
|
88
|
+
@author Frederico Linhares
|
89
|
+
*/
|
90
|
+
VALUE
|
91
|
+
bird_cPalette_get_color(VALUE self, VALUE index)
|
92
|
+
{
|
93
|
+
VALUE argv[4];
|
94
|
+
int c_index;
|
95
|
+
struct bird_palette_data *ptr;
|
96
|
+
|
97
|
+
RB_INTEGER_TYPE_P(index);
|
98
|
+
|
99
|
+
c_index = NUM2INT(index);
|
100
|
+
if(c_index < 0 || c_index > 255)
|
101
|
+
rb_raise(rb_eArgError, "%s", "index must be between 0 and 255");
|
102
|
+
|
103
|
+
TypedData_Get_Struct(self, struct bird_palette_data, &bird_palette_type,
|
104
|
+
ptr);
|
105
|
+
|
106
|
+
argv[0] = UINT2NUM(ptr->colors[c_index].r);
|
107
|
+
argv[1] = UINT2NUM(ptr->colors[c_index].g);
|
108
|
+
argv[2] = UINT2NUM(ptr->colors[c_index].b);
|
109
|
+
argv[3] = UINT2NUM(ptr->colors[c_index].a);
|
110
|
+
|
111
|
+
return rb_class_new_instance(4, argv, bird_cColor);
|
112
|
+
}
|
113
|
+
|
114
|
+
struct bird_palette_data*
|
115
|
+
bird_cPalette_get_data(VALUE self)
|
116
|
+
{
|
117
|
+
struct bird_palette_data *ptr;
|
118
|
+
|
119
|
+
TypedData_Get_Struct(self, struct bird_palette_data, &bird_palette_type,
|
120
|
+
ptr);
|
121
|
+
|
122
|
+
return ptr;
|
123
|
+
}
|
124
|
+
|
125
|
+
void
|
126
|
+
Init_red_bird_palette(void)
|
127
|
+
{
|
128
|
+
bird_cPalette = rb_define_class_under(bird_m, "Palette", rb_cData);
|
129
|
+
rb_define_alloc_func(bird_cPalette, bird_alloc_palette);
|
130
|
+
rb_define_method(bird_cPalette, "initialize", bird_cPalette_initialize, 1);
|
131
|
+
rb_define_method(bird_cPalette, "get_color", bird_cPalette_get_color, 1);
|
132
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
#ifndef RED_BIRD_PALETTE_H
|
3
|
+
#define RED_BIRD_PALETTE_H 1
|
4
|
+
|
5
|
+
#include "main.h"
|
6
|
+
|
7
|
+
extern VALUE bird_cPalette;
|
8
|
+
|
9
|
+
struct bird_palette_data
|
10
|
+
{
|
11
|
+
SDL_Color colors[256];
|
12
|
+
};
|
13
|
+
|
14
|
+
VALUE
|
15
|
+
bird_cPalette_initialize(VALUE self, VALUE colors);
|
16
|
+
|
17
|
+
struct bird_palette_data*
|
18
|
+
bird_cPalette_get_data(VALUE self);
|
19
|
+
|
20
|
+
void
|
21
|
+
Init_red_bird_palette(void);
|
22
|
+
|
23
|
+
#endif /* RED_BIRD_PALETTE_H */
|
data/ext/red_bird/rect.c
ADDED
@@ -0,0 +1,257 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
#include "rect.h"
|
3
|
+
|
4
|
+
/*
|
5
|
+
Document-class: RedBird::Rect
|
6
|
+
|
7
|
+
An abstract rectangular object used mainly for collision detection.
|
8
|
+
|
9
|
+
@author Frederico Linhares
|
10
|
+
*/
|
11
|
+
VALUE bird_cRect;
|
12
|
+
|
13
|
+
/*
|
14
|
+
Basic functions all Ruby classes need.
|
15
|
+
*/
|
16
|
+
|
17
|
+
static void
|
18
|
+
bird_free_rect(void* obj)
|
19
|
+
{
|
20
|
+
struct bird_rect_data *ptr = obj;
|
21
|
+
|
22
|
+
free(ptr);
|
23
|
+
}
|
24
|
+
|
25
|
+
static size_t
|
26
|
+
bird_memsize_rect(const void* obj)
|
27
|
+
{
|
28
|
+
// TODO
|
29
|
+
return 0;
|
30
|
+
}
|
31
|
+
|
32
|
+
static const rb_data_type_t
|
33
|
+
bird_rect_type = {
|
34
|
+
"red_bird_rect",
|
35
|
+
{0, bird_free_rect, bird_memsize_rect,},
|
36
|
+
0, 0,
|
37
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
38
|
+
};
|
39
|
+
|
40
|
+
static VALUE
|
41
|
+
bird_alloc_rect(VALUE klass)
|
42
|
+
{
|
43
|
+
VALUE obj;
|
44
|
+
struct bird_rect_data *ptr;
|
45
|
+
|
46
|
+
obj = TypedData_Make_Struct(klass, struct bird_rect_data, &bird_rect_type,
|
47
|
+
ptr);
|
48
|
+
|
49
|
+
return obj;
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
@param x [Integer] coordinate x for the rectangle position.
|
54
|
+
@param y [Integer] coordinate y for the rectangle position.
|
55
|
+
@param width [Integer] rectangle width.
|
56
|
+
@param height [Integer] rectangle height.
|
57
|
+
@author Frederico Linhares
|
58
|
+
*/
|
59
|
+
VALUE
|
60
|
+
bird_cRect_initialize(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
|
61
|
+
{
|
62
|
+
struct bird_rect_data *ptr;
|
63
|
+
|
64
|
+
RB_INTEGER_TYPE_P(x);
|
65
|
+
RB_INTEGER_TYPE_P(y);
|
66
|
+
RB_INTEGER_TYPE_P(width);
|
67
|
+
RB_INTEGER_TYPE_P(height);
|
68
|
+
|
69
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
|
70
|
+
|
71
|
+
ptr->data.x = NUM2INT(x);
|
72
|
+
ptr->data.y = NUM2INT(y);
|
73
|
+
ptr->data.w = NUM2INT(width);
|
74
|
+
ptr->data.h = NUM2INT(height);
|
75
|
+
|
76
|
+
return self;
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
@return [Integer] coordinate x of this rectangle.
|
81
|
+
@author Frederico Linhares
|
82
|
+
*/
|
83
|
+
VALUE
|
84
|
+
bird_cRect_get_x(VALUE self)
|
85
|
+
{
|
86
|
+
struct bird_rect_data *ptr;
|
87
|
+
|
88
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
|
89
|
+
|
90
|
+
return INT2FIX(ptr->data.x);
|
91
|
+
}
|
92
|
+
|
93
|
+
/*
|
94
|
+
@return [Integer] coordinate y of this rectangle.
|
95
|
+
@author Frederico Linhares
|
96
|
+
*/
|
97
|
+
VALUE
|
98
|
+
bird_cRect_get_y(VALUE self)
|
99
|
+
{
|
100
|
+
struct bird_rect_data *ptr;
|
101
|
+
|
102
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
|
103
|
+
|
104
|
+
return INT2FIX(ptr->data.y);
|
105
|
+
}
|
106
|
+
|
107
|
+
/*
|
108
|
+
Set the coordinate x of this rectangle.
|
109
|
+
|
110
|
+
@param x [Integer]
|
111
|
+
@author Frederico Linhares
|
112
|
+
*/
|
113
|
+
VALUE
|
114
|
+
bird_cRect_set_x(VALUE self, VALUE x)
|
115
|
+
{
|
116
|
+
struct bird_rect_data *ptr;
|
117
|
+
|
118
|
+
RB_INTEGER_TYPE_P(x);
|
119
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
|
120
|
+
|
121
|
+
ptr->data.x = FIX2INT(x);
|
122
|
+
|
123
|
+
return x;
|
124
|
+
}
|
125
|
+
|
126
|
+
/*
|
127
|
+
Set the coordinate y of this rectangle.
|
128
|
+
|
129
|
+
@param y [Integer]
|
130
|
+
@author Frederico Linhares
|
131
|
+
*/
|
132
|
+
VALUE
|
133
|
+
bird_cRect_set_y(VALUE self, VALUE y)
|
134
|
+
{
|
135
|
+
struct bird_rect_data *ptr;
|
136
|
+
|
137
|
+
RB_INTEGER_TYPE_P(y);
|
138
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
|
139
|
+
|
140
|
+
ptr->data.y = FIX2INT(y);
|
141
|
+
|
142
|
+
return y;
|
143
|
+
}
|
144
|
+
|
145
|
+
/*
|
146
|
+
@return [Integer] width of this rectangle.
|
147
|
+
@author Frederico Linhares
|
148
|
+
*/
|
149
|
+
VALUE
|
150
|
+
bird_cRect_get_width(VALUE self)
|
151
|
+
{
|
152
|
+
struct bird_rect_data *ptr;
|
153
|
+
|
154
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
|
155
|
+
|
156
|
+
return INT2FIX(ptr->data.w);
|
157
|
+
}
|
158
|
+
|
159
|
+
/*
|
160
|
+
@return [Integer] height of this rectangle.
|
161
|
+
@author Frederico Linhares
|
162
|
+
*/
|
163
|
+
VALUE
|
164
|
+
bird_cRect_get_height(VALUE self)
|
165
|
+
{
|
166
|
+
struct bird_rect_data *ptr;
|
167
|
+
|
168
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
|
169
|
+
|
170
|
+
return INT2FIX(ptr->data.h);
|
171
|
+
}
|
172
|
+
|
173
|
+
/*
|
174
|
+
Set the width of this rectangle.
|
175
|
+
|
176
|
+
@param width [Integer]
|
177
|
+
@author Frederico Linhares
|
178
|
+
*/
|
179
|
+
VALUE
|
180
|
+
bird_cRect_set_width(VALUE self, VALUE width)
|
181
|
+
{
|
182
|
+
struct bird_rect_data *ptr;
|
183
|
+
|
184
|
+
RB_INTEGER_TYPE_P(width);
|
185
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
|
186
|
+
|
187
|
+
ptr->data.w = FIX2INT(width);
|
188
|
+
|
189
|
+
return width;
|
190
|
+
}
|
191
|
+
|
192
|
+
/*
|
193
|
+
Set the height of this rectangle.
|
194
|
+
|
195
|
+
@param height [Integer]
|
196
|
+
@author Frederico Linhares
|
197
|
+
*/
|
198
|
+
VALUE
|
199
|
+
bird_cRect_set_height(VALUE self, VALUE height)
|
200
|
+
{
|
201
|
+
struct bird_rect_data *ptr;
|
202
|
+
|
203
|
+
RB_INTEGER_TYPE_P(height);
|
204
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
|
205
|
+
|
206
|
+
ptr->data.h = FIX2INT(height);
|
207
|
+
|
208
|
+
return height;
|
209
|
+
}
|
210
|
+
|
211
|
+
/*
|
212
|
+
Test if this rectangle collided with another rectangle.
|
213
|
+
|
214
|
+
@param rect [RedBird::Rect]
|
215
|
+
@return [Boolean] true if there is a collision, false if there is no
|
216
|
+
collision.
|
217
|
+
@author Frederico Linhares
|
218
|
+
*/
|
219
|
+
VALUE
|
220
|
+
bird_cRect_collide(VALUE self, VALUE rect)
|
221
|
+
{
|
222
|
+
struct bird_rect_data *ptr1, *ptr2;
|
223
|
+
|
224
|
+
if(!rb_obj_is_kind_of(rect, bird_cRect))
|
225
|
+
rb_raise(rb_eTypeError, "%s",
|
226
|
+
"rect must be an instance of RedBird::Rect");
|
227
|
+
|
228
|
+
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr1);
|
229
|
+
TypedData_Get_Struct(rect, struct bird_rect_data, &bird_rect_type, ptr2);
|
230
|
+
|
231
|
+
if(ptr1->data.x <= ptr2->data.x + ptr2->data.w &&
|
232
|
+
ptr1->data.x + ptr1->data.w >= ptr2->data.x &&
|
233
|
+
ptr1->data.y <= ptr2->data.y + ptr2->data.h &&
|
234
|
+
ptr1->data.y + ptr1->data.h >= ptr2->data.y)
|
235
|
+
return Qtrue;
|
236
|
+
else
|
237
|
+
return Qfalse;
|
238
|
+
}
|
239
|
+
|
240
|
+
void
|
241
|
+
Init_red_bird_rect(void)
|
242
|
+
{
|
243
|
+
bird_cRect = rb_define_class_under(bird_m, "Rect", rb_cData);
|
244
|
+
rb_define_alloc_func(bird_cRect, bird_alloc_rect);
|
245
|
+
rb_define_method(bird_cRect, "initialize", bird_cRect_initialize, 4);
|
246
|
+
|
247
|
+
rb_define_method(bird_cRect, "x", bird_cRect_get_x, 0);
|
248
|
+
rb_define_method(bird_cRect, "y", bird_cRect_get_y, 0);
|
249
|
+
rb_define_method(bird_cRect, "x=", bird_cRect_set_x, 1);
|
250
|
+
rb_define_method(bird_cRect, "y=", bird_cRect_set_y, 1);
|
251
|
+
rb_define_method(bird_cRect, "width", bird_cRect_get_width, 0);
|
252
|
+
rb_define_method(bird_cRect, "height", bird_cRect_get_height, 0);
|
253
|
+
rb_define_method(bird_cRect, "width=", bird_cRect_set_width, 1);
|
254
|
+
rb_define_method(bird_cRect, "height=", bird_cRect_set_height, 1);
|
255
|
+
|
256
|
+
rb_define_method(bird_cRect, "collide?", bird_cRect_collide, 1);
|
257
|
+
}
|
data/ext/red_bird/rect.h
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
#ifndef RED_BIRD_RECT_H
|
3
|
+
#define RED_BIRD_RECT_H 1
|
4
|
+
|
5
|
+
#include "main.h"
|
6
|
+
|
7
|
+
extern VALUE bird_cRect;
|
8
|
+
|
9
|
+
struct bird_rect_data
|
10
|
+
{
|
11
|
+
SDL_Rect data;
|
12
|
+
};
|
13
|
+
|
14
|
+
VALUE
|
15
|
+
bird_cRect_initialize(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height);
|
16
|
+
|
17
|
+
void
|
18
|
+
Init_red_bird_rect(void);
|
19
|
+
|
20
|
+
#endif /* RED_BIRD_RECT_H */
|
@@ -0,0 +1,130 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
#include "render.h"
|
3
|
+
|
4
|
+
#include "color.h"
|
5
|
+
#include "engine.h"
|
6
|
+
|
7
|
+
/*
|
8
|
+
Document-module: RedBird::Render
|
9
|
+
|
10
|
+
This module contains basic rendering functionalities.
|
11
|
+
|
12
|
+
@author Frederico Linhares
|
13
|
+
*/
|
14
|
+
VALUE bird_mRender;
|
15
|
+
|
16
|
+
|
17
|
+
/*
|
18
|
+
Use this method to define the color that will be used by some drawing
|
19
|
+
methods.
|
20
|
+
|
21
|
+
@param color [RedBird::Color]
|
22
|
+
@return [RedBird::Render] self
|
23
|
+
@author Frederico Linhares
|
24
|
+
*/
|
25
|
+
VALUE
|
26
|
+
bird_mRender_set_color(VALUE self, VALUE color)
|
27
|
+
{
|
28
|
+
struct bird_color_data *color_ptr;
|
29
|
+
|
30
|
+
if(!rb_obj_is_kind_of(color, bird_cColor))
|
31
|
+
{
|
32
|
+
rb_raise(rb_eTypeError, "%s",
|
33
|
+
"color must be an instance of RedBird::Color");
|
34
|
+
|
35
|
+
return self;
|
36
|
+
}
|
37
|
+
|
38
|
+
color_ptr = bird_cColor_get_data(color);
|
39
|
+
|
40
|
+
SDL_SetRenderDrawColor(
|
41
|
+
bird_core.renderer, color_ptr->data.r, color_ptr->data.g,
|
42
|
+
color_ptr->data.b, color_ptr->data.a);
|
43
|
+
|
44
|
+
return self;
|
45
|
+
}
|
46
|
+
|
47
|
+
/*
|
48
|
+
Draw a rectangle filled with a color defined by RedBird::Render.set_color.
|
49
|
+
|
50
|
+
@param x [Integer]
|
51
|
+
@param y [Integer]
|
52
|
+
@param width [Integer]
|
53
|
+
@param height [Integer]
|
54
|
+
@return [RedBird::Render] self
|
55
|
+
@see RedBird::Render.set_color
|
56
|
+
@author Frederico Linhares
|
57
|
+
*/
|
58
|
+
VALUE
|
59
|
+
bird_mRender_fill_rect(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
|
60
|
+
{
|
61
|
+
SDL_Rect rect;
|
62
|
+
|
63
|
+
RB_INTEGER_TYPE_P(x);
|
64
|
+
RB_INTEGER_TYPE_P(y);
|
65
|
+
RB_INTEGER_TYPE_P(width);
|
66
|
+
RB_INTEGER_TYPE_P(height);
|
67
|
+
|
68
|
+
rect.x = x;
|
69
|
+
rect.y = y;
|
70
|
+
rect.w = width;
|
71
|
+
rect.h = height;
|
72
|
+
|
73
|
+
SDL_RenderFillRect(bird_core.renderer, &rect);
|
74
|
+
|
75
|
+
return self;
|
76
|
+
}
|
77
|
+
|
78
|
+
/*
|
79
|
+
Fill the entire screen with a single color defined by
|
80
|
+
RedBird::Render.set_color.
|
81
|
+
|
82
|
+
@return [RedBird::Render] self
|
83
|
+
@see RedBird::Render.set_color
|
84
|
+
@author Frederico Linhares
|
85
|
+
*/
|
86
|
+
VALUE
|
87
|
+
bird_mRender_clear_screen(VALUE self)
|
88
|
+
{
|
89
|
+
SDL_RenderClear(bird_core.renderer);
|
90
|
+
|
91
|
+
return self;
|
92
|
+
}
|
93
|
+
|
94
|
+
/*
|
95
|
+
Every time you draw anything, this drawing is not applied directly to the
|
96
|
+
screen; instead, the command draws to a buffer. This procedure allows you to
|
97
|
+
do all the drawing before you present it to the user. After you finish all
|
98
|
+
updates you want into the buffer, you must call this method to send the final
|
99
|
+
buffer to the screen.
|
100
|
+
|
101
|
+
@return [RedBird::Render] self
|
102
|
+
@author Frederico Linhares
|
103
|
+
*/
|
104
|
+
VALUE
|
105
|
+
bird_mRender_update_screen(VALUE self)
|
106
|
+
{
|
107
|
+
SDL_SetRenderTarget(bird_core.renderer, NULL);
|
108
|
+
|
109
|
+
SDL_RenderCopy(bird_core.renderer, bird_core.pre_screen_buffer, NULL,
|
110
|
+
&bird_core.screen_rect);
|
111
|
+
SDL_RenderPresent(bird_core.renderer);
|
112
|
+
|
113
|
+
SDL_SetRenderTarget(bird_core.renderer, bird_core.pre_screen_buffer);
|
114
|
+
|
115
|
+
return self;
|
116
|
+
}
|
117
|
+
|
118
|
+
void
|
119
|
+
Init_red_bird_render(void)
|
120
|
+
{
|
121
|
+
bird_mRender = rb_define_module_under(bird_m, "Render");
|
122
|
+
rb_define_module_function(bird_mRender, "set_color", bird_mRender_set_color,
|
123
|
+
1);
|
124
|
+
rb_define_module_function(bird_mRender, "fill_rect", bird_mRender_fill_rect,
|
125
|
+
4);
|
126
|
+
rb_define_module_function(bird_mRender, "clear_screen",
|
127
|
+
bird_mRender_clear_screen, 0);
|
128
|
+
rb_define_module_function(bird_mRender, "update_screen",
|
129
|
+
bird_mRender_update_screen, 0);
|
130
|
+
}
|