red_bird 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 815c82919387f7aaa0a34ec4e50faf885c3d43f1be1e2b5533c939e907af6aea
|
4
|
+
data.tar.gz: 397c6e509536b737bb87bfeafe9e6e7e30490449b4977f12e9dc469e98f96939
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 327d4193f540b20a82f9650f011c695ea8aacfb708e2488578cf30470177a3f22aa2bb3f829113f0940f51c73b7dffe2848df03b866e769bc7e159e8414a57eb
|
7
|
+
data.tar.gz: 35ed309150aab1a128c98e9a66f5506b633f2f6e8628798a4057c90d0b55e90387a2bfa37c108b6456f7a532fc963476d1542670a52548254991b15f63a2de09
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
red_bird (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rake (13.0.1)
|
10
|
+
rake-compiler (1.0.8)
|
11
|
+
rake
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (>= 2.0)
|
18
|
+
rake (>= 10.0)
|
19
|
+
rake-compiler
|
20
|
+
red_bird!
|
21
|
+
|
22
|
+
BUNDLED WITH
|
23
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Frederico Linhares
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# RedBird
|
2
|
+
|
3
|
+
RedBird is a 2D game engine for Ruby, it is designed to make game development quick and easy.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
RedBird gem links against libSDL2 and libSDL2_ttf, so before installing RedBird into a machine, ensure that development libraries for SDL are installed.
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'red_bird'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install red_bird
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
To crate a minimal code using RedBird you need to call {RedBird::Engine.run}
|
26
|
+
and pass to it a code block that returns a {RedBird::Stage}:
|
27
|
+
|
28
|
+
require 'red_bird'
|
29
|
+
require 'red_bird/stage'
|
30
|
+
|
31
|
+
class Stage < RedBird::Stage
|
32
|
+
def initialize(global_data)
|
33
|
+
super(global_data)
|
34
|
+
@controller = RedBird::Controller.new
|
35
|
+
@input_device = RedBird::InputDevice.new(@controller)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
RedBird::Engine.run(nil) { |global_data| Stage.new(global_data) }
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at [bitbucket.org/fredlinhares/red_bird](https://bitbucket.org/fredlinhares/red_bird)
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/setup
ADDED
data/ext/red_bird/bird.c
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
#include "bird.h"
|
3
|
+
|
4
|
+
/*
|
5
|
+
Document-module: RedBird
|
6
|
+
|
7
|
+
This module exist to prevent name clashes.
|
8
|
+
|
9
|
+
@author Frederico Linhares
|
10
|
+
*/
|
11
|
+
void
|
12
|
+
Init_red_bird_module(void)
|
13
|
+
{
|
14
|
+
bird_m = rb_define_module("RedBird");
|
15
|
+
}
|
data/ext/red_bird/bird.h
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
#include "color.h"
|
3
|
+
|
4
|
+
/*
|
5
|
+
Document-class: RedBird::Color
|
6
|
+
A color represented by red, green, blue, and alpha (transparency) values.
|
7
|
+
*/
|
8
|
+
VALUE bird_cColor;
|
9
|
+
|
10
|
+
/*
|
11
|
+
Basic functions all Ruby classes need.
|
12
|
+
*/
|
13
|
+
|
14
|
+
void
|
15
|
+
bird_free_color(void* obj)
|
16
|
+
{
|
17
|
+
struct bird_color_data *ptr = obj;
|
18
|
+
|
19
|
+
free(ptr);
|
20
|
+
}
|
21
|
+
|
22
|
+
size_t
|
23
|
+
bird_memsize_color(const void* obj)
|
24
|
+
{
|
25
|
+
// TODO
|
26
|
+
return 0;
|
27
|
+
}
|
28
|
+
|
29
|
+
static const rb_data_type_t
|
30
|
+
bird_color_type = {
|
31
|
+
"red_bird_color",
|
32
|
+
{0, bird_free_color, bird_memsize_color,},
|
33
|
+
0, 0,
|
34
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
35
|
+
};
|
36
|
+
|
37
|
+
VALUE
|
38
|
+
bird_alloc_color(VALUE klass)
|
39
|
+
{
|
40
|
+
VALUE obj;
|
41
|
+
struct bird_color_data *ptr;
|
42
|
+
|
43
|
+
obj = TypedData_Make_Struct(klass, struct bird_color_data, &bird_color_type,
|
44
|
+
ptr);
|
45
|
+
|
46
|
+
return obj;
|
47
|
+
}
|
48
|
+
|
49
|
+
/*
|
50
|
+
Create a new color based in the RGBA color model.
|
51
|
+
|
52
|
+
@param red [Integer] the amount of red (between 0 and 255).
|
53
|
+
@param green [Integer] the amount of green (between 0 and 255).
|
54
|
+
@param blue [Integer] the amount of blue (between 0 and 255).
|
55
|
+
@param alpha [Integer] the amount of transparency (between 0 and 255). 0 is
|
56
|
+
transparent, 255 is opaque.
|
57
|
+
*/
|
58
|
+
VALUE
|
59
|
+
bird_cColor_initialize(VALUE self, VALUE red, VALUE green, VALUE blue,
|
60
|
+
VALUE alpha)
|
61
|
+
{
|
62
|
+
struct bird_color_data *ptr;
|
63
|
+
|
64
|
+
RB_INTEGER_TYPE_P(red);
|
65
|
+
RB_INTEGER_TYPE_P(green);
|
66
|
+
RB_INTEGER_TYPE_P(blue);
|
67
|
+
RB_INTEGER_TYPE_P(alpha);
|
68
|
+
|
69
|
+
TypedData_Get_Struct(self, struct bird_color_data, &bird_color_type, ptr);
|
70
|
+
|
71
|
+
ptr->data.r = NUM2UINT(red);
|
72
|
+
ptr->data.g = NUM2UINT(green);
|
73
|
+
ptr->data.b = NUM2UINT(blue);
|
74
|
+
ptr->data.a = NUM2UINT(alpha);
|
75
|
+
|
76
|
+
return self;
|
77
|
+
}
|
78
|
+
|
79
|
+
struct bird_color_data*
|
80
|
+
bird_cColor_get_data(VALUE self)
|
81
|
+
{
|
82
|
+
struct bird_color_data *ptr;
|
83
|
+
|
84
|
+
TypedData_Get_Struct(self, struct bird_color_data, &bird_color_type, ptr);
|
85
|
+
|
86
|
+
return ptr;
|
87
|
+
}
|
88
|
+
|
89
|
+
void
|
90
|
+
Init_red_bird_color(void)
|
91
|
+
{
|
92
|
+
bird_cColor = rb_define_class_under(bird_m, "Color", rb_cData);
|
93
|
+
rb_define_alloc_func(bird_cColor, bird_alloc_color);
|
94
|
+
rb_define_method(bird_cColor, "initialize", bird_cColor_initialize, 4);
|
95
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
#ifndef RED_BIRD_COLOR_H
|
3
|
+
#define RED_BIRD_COLOR_H 1
|
4
|
+
|
5
|
+
#include "main.h"
|
6
|
+
|
7
|
+
extern VALUE bird_cColor;
|
8
|
+
|
9
|
+
struct bird_color_data
|
10
|
+
{
|
11
|
+
SDL_Color data;
|
12
|
+
};
|
13
|
+
|
14
|
+
VALUE
|
15
|
+
bird_alloc_color(VALUE klass);
|
16
|
+
|
17
|
+
VALUE
|
18
|
+
bird_cColor_initialize(VALUE self, VALUE red, VALUE green, VALUE blue,
|
19
|
+
VALUE aplha);
|
20
|
+
|
21
|
+
struct bird_color_data*
|
22
|
+
bird_cColor_get_data(VALUE self);
|
23
|
+
|
24
|
+
void
|
25
|
+
Init_red_bird_color(void);
|
26
|
+
|
27
|
+
#endif /* RED_BIRD_COLOR_H */
|
@@ -0,0 +1,163 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
#include "dynamic_sprite.h"
|
3
|
+
|
4
|
+
#include "engine.h"
|
5
|
+
#include "texture.h"
|
6
|
+
|
7
|
+
VALUE bird_cDynamicSprite;
|
8
|
+
|
9
|
+
static ID id_at_texture;
|
10
|
+
static VALUE id_flip;
|
11
|
+
static VALUE id_vertical;
|
12
|
+
static VALUE id_horizontal;
|
13
|
+
static VALUE id_both;
|
14
|
+
|
15
|
+
// TODO: make this class inherit from RedBird::Sprite.
|
16
|
+
|
17
|
+
/*
|
18
|
+
Basic functions that all Ruby classes need.
|
19
|
+
*/
|
20
|
+
|
21
|
+
void
|
22
|
+
bird_free_dynamic_sprite(void* obj)
|
23
|
+
{
|
24
|
+
struct bird_dynamic_sprite_data *ptr = obj;
|
25
|
+
|
26
|
+
free(ptr);
|
27
|
+
}
|
28
|
+
|
29
|
+
size_t
|
30
|
+
bird_memsize_dynamic_sprite(const void* obj)
|
31
|
+
{
|
32
|
+
// TODO
|
33
|
+
return 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
static const rb_data_type_t
|
37
|
+
bird_dynamic_sprite_type = {
|
38
|
+
"red_bird_dynamic_sprite",
|
39
|
+
{0, bird_free_dynamic_sprite, bird_memsize_dynamic_sprite,},
|
40
|
+
0, 0,
|
41
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
42
|
+
};
|
43
|
+
|
44
|
+
VALUE
|
45
|
+
bird_alloc_dynamic_sprite(VALUE klass)
|
46
|
+
{
|
47
|
+
VALUE obj;
|
48
|
+
struct bird_dynamic_sprite_data *ptr;
|
49
|
+
|
50
|
+
obj = TypedData_Make_Struct(klass, struct bird_dynamic_sprite_data,
|
51
|
+
&bird_dynamic_sprite_type, ptr);
|
52
|
+
|
53
|
+
return obj;
|
54
|
+
}
|
55
|
+
|
56
|
+
/*
|
57
|
+
@param texture [RedBird::Texture]
|
58
|
+
@param x [Integer]
|
59
|
+
@param y [Integer]
|
60
|
+
@param width [Integer]
|
61
|
+
@param height [Integer]
|
62
|
+
@param mods [Hash]
|
63
|
+
*/
|
64
|
+
VALUE
|
65
|
+
bird_cDynamicSprite_initialize(VALUE self, VALUE texture, VALUE x, VALUE y,
|
66
|
+
VALUE width, VALUE height, VALUE mods)
|
67
|
+
{
|
68
|
+
struct bird_dynamic_sprite_data *ptr;
|
69
|
+
|
70
|
+
VALUE hash_val;
|
71
|
+
|
72
|
+
if(!rb_obj_is_kind_of(texture, bird_cTexture))
|
73
|
+
rb_raise(rb_eTypeError, "%s",
|
74
|
+
"texture must be an instance of RedBird::Texture");
|
75
|
+
RB_INTEGER_TYPE_P(x);
|
76
|
+
RB_INTEGER_TYPE_P(y);
|
77
|
+
RB_INTEGER_TYPE_P(width);
|
78
|
+
RB_INTEGER_TYPE_P(height);
|
79
|
+
|
80
|
+
TypedData_Get_Struct(self, struct bird_dynamic_sprite_data,
|
81
|
+
&bird_dynamic_sprite_type, ptr);
|
82
|
+
|
83
|
+
rb_ivar_set(self, id_at_texture, texture);
|
84
|
+
ptr->rect.x = NUM2INT(x);
|
85
|
+
ptr->rect.y = NUM2INT(y);
|
86
|
+
ptr->rect.w = NUM2INT(width);
|
87
|
+
ptr->rect.h = NUM2INT(height);
|
88
|
+
|
89
|
+
ptr->angle = 0;
|
90
|
+
ptr->center.x = 0;
|
91
|
+
ptr->center.y = 0;
|
92
|
+
|
93
|
+
// Get 'flip'.
|
94
|
+
ptr->flip = SDL_FLIP_NONE; // By default do not flip.
|
95
|
+
hash_val = rb_hash_aref(mods, id_flip);
|
96
|
+
if(SYMBOL_P(hash_val))
|
97
|
+
{
|
98
|
+
if(hash_val == id_vertical)
|
99
|
+
ptr->flip = SDL_FLIP_VERTICAL;
|
100
|
+
else if(hash_val == id_horizontal)
|
101
|
+
ptr->flip = SDL_FLIP_HORIZONTAL;
|
102
|
+
else if(hash_val == id_both)
|
103
|
+
ptr->flip = SDL_FLIP_VERTICAL | SDL_FLIP_HORIZONTAL;
|
104
|
+
}
|
105
|
+
|
106
|
+
return self;
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
Render itself directly to the screen.
|
111
|
+
|
112
|
+
@param x [Integer] x coordinate of the screen.
|
113
|
+
@param y [Integer] y coordinate of the screen.
|
114
|
+
@return [RedBird::DynamicSprite] self
|
115
|
+
@author Frederico Linhares
|
116
|
+
*/
|
117
|
+
VALUE
|
118
|
+
bird_cDynamicSprite_render_to_screen(VALUE self, VALUE x, VALUE y)
|
119
|
+
{
|
120
|
+
SDL_Rect dst_rect;
|
121
|
+
|
122
|
+
struct bird_dynamic_sprite_data *ptr;
|
123
|
+
struct bird_texture_data *texture_ptr;
|
124
|
+
|
125
|
+
VALUE texture;
|
126
|
+
|
127
|
+
RB_INTEGER_TYPE_P(x);
|
128
|
+
RB_INTEGER_TYPE_P(y);
|
129
|
+
|
130
|
+
texture = rb_ivar_get(self, id_at_texture);
|
131
|
+
|
132
|
+
TypedData_Get_Struct(self, struct bird_dynamic_sprite_data,
|
133
|
+
&bird_dynamic_sprite_type, ptr);
|
134
|
+
texture_ptr = bird_cTexture_get_data(texture);
|
135
|
+
|
136
|
+
dst_rect.x = NUM2INT(x);
|
137
|
+
dst_rect.y = NUM2INT(y);
|
138
|
+
dst_rect.w = ptr->rect.w;
|
139
|
+
dst_rect.h = ptr->rect.h;
|
140
|
+
|
141
|
+
SDL_RenderCopyEx(bird_core.renderer, texture_ptr->data, &ptr->rect,
|
142
|
+
&dst_rect, ptr->angle, &ptr->center, ptr->flip);
|
143
|
+
|
144
|
+
return self;
|
145
|
+
}
|
146
|
+
|
147
|
+
void
|
148
|
+
Init_red_bird_dynamic_sprite(void)
|
149
|
+
{
|
150
|
+
id_at_texture = rb_intern("@texture");
|
151
|
+
id_flip = ID2SYM(rb_intern("flip"));
|
152
|
+
id_vertical = ID2SYM(rb_intern("vertical"));
|
153
|
+
id_horizontal = ID2SYM(rb_intern("horizontal"));
|
154
|
+
id_both = ID2SYM(rb_intern("both"));
|
155
|
+
|
156
|
+
bird_cDynamicSprite = rb_define_class_under(bird_m, "DynamicSprite",
|
157
|
+
rb_cData);
|
158
|
+
rb_define_alloc_func(bird_cDynamicSprite, bird_alloc_dynamic_sprite);
|
159
|
+
rb_define_method(bird_cDynamicSprite, "initialize",
|
160
|
+
bird_cDynamicSprite_initialize, 6);
|
161
|
+
rb_define_method(bird_cDynamicSprite, "render_to_screen",
|
162
|
+
bird_cDynamicSprite_render_to_screen, 2);
|
163
|
+
}
|