reflexion 0.1.8 → 0.1.9
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 +4 -4
- data/.doc/ext/reflex/application.cpp +5 -1
- data/.doc/ext/reflex/arc_shape.cpp +89 -0
- data/.doc/ext/reflex/body.cpp +91 -12
- data/.doc/ext/reflex/contact_event.cpp +90 -0
- data/.doc/ext/reflex/ellipse_shape.cpp +89 -0
- data/.doc/ext/reflex/image_view.cpp +0 -16
- data/.doc/ext/reflex/native.cpp +18 -6
- data/.doc/ext/reflex/rect_shape.cpp +83 -0
- data/.doc/ext/reflex/shape_view.cpp +153 -0
- data/.doc/ext/reflex/view.cpp +63 -26
- data/.doc/ext/reflex/window.cpp +5 -1
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +6 -2
- data/ext/reflex/arc_shape.cpp +94 -0
- data/ext/reflex/body.cpp +101 -13
- data/ext/reflex/contact_event.cpp +95 -0
- data/ext/reflex/ellipse_shape.cpp +94 -0
- data/ext/reflex/image_view.cpp +0 -18
- data/ext/reflex/native.cpp +18 -6
- data/ext/reflex/rect_shape.cpp +86 -0
- data/ext/reflex/shape_view.cpp +161 -0
- data/ext/reflex/view.cpp +71 -30
- data/ext/reflex/window.cpp +5 -1
- data/include/reflex/body.h +42 -12
- data/include/reflex/event.h +27 -1
- data/include/reflex/fixture.h +6 -5
- data/include/reflex/image_view.h +5 -5
- data/include/reflex/ruby/application.h +27 -6
- data/include/reflex/ruby/event.h +11 -0
- data/include/reflex/ruby/shape_view.h +96 -0
- data/include/reflex/ruby/view.h +60 -5
- data/include/reflex/ruby/window.h +12 -3
- data/include/reflex/shape_view.h +146 -0
- data/include/reflex/view.h +17 -5
- data/lib/reflex/application.rb +9 -9
- data/lib/reflex/body.rb +2 -0
- data/lib/reflex/contact_event.rb +38 -0
- data/lib/reflex/image_view.rb +1 -1
- data/lib/reflex/shape_view.rb +25 -0
- data/lib/reflex/view.rb +19 -9
- data/lib/reflex/window.rb +11 -10
- data/lib/reflex.rb +15 -13
- data/lib/reflexion.rb +25 -18
- data/samples/osx/hello/hello/main.cpp +6 -0
- data/samples/physics.rb +22 -12
- data/samples/reflexion/breakout.rb +52 -0
- data/samples/reflexion/hello.rb +5 -7
- data/samples/reflexion/paint.rb +10 -11
- data/samples/reflexion/physics.rb +28 -0
- data/samples/reflexion/pulse.rb +10 -8
- data/samples/shapes.rb +2 -2
- data/src/body.cpp +241 -40
- data/src/event.cpp +32 -2
- data/src/shape_view.cpp +306 -0
- data/src/view.cpp +232 -66
- data/src/world.cpp +110 -30
- data/src/world.h +61 -14
- metadata +24 -7
- data/lib/reflex/arc_shape.rb +0 -20
- data/lib/reflex/ellipse_shape.rb +0 -20
- data/lib/reflex/line_shape.rb +0 -20
- data/lib/reflex/rect_shape.rb +0 -20
- data/lib/reflex/shape.rb +0 -34
@@ -0,0 +1,146 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_SHAPE_VIEW_H__
|
4
|
+
#define __REFLEX_SHAPE_VIEW_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <xot/pimpl.h>
|
8
|
+
#include <reflex/view.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Reflex
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
class ShapeView : public View
|
16
|
+
{
|
17
|
+
|
18
|
+
typedef View Super;
|
19
|
+
|
20
|
+
public:
|
21
|
+
|
22
|
+
ShapeView (const char* name = NULL);
|
23
|
+
|
24
|
+
virtual ~ShapeView ();
|
25
|
+
|
26
|
+
virtual void set_fill (float red, float green, float blue, float alpha = 1);
|
27
|
+
|
28
|
+
virtual void set_fill (const Color& color);
|
29
|
+
|
30
|
+
virtual void no_fill ();
|
31
|
+
|
32
|
+
virtual const Color& fill () const;
|
33
|
+
|
34
|
+
virtual void set_stroke (float red, float green, float blue, float alpha = 1);
|
35
|
+
|
36
|
+
virtual void set_stroke (const Color& color);
|
37
|
+
|
38
|
+
virtual void no_stroke ();
|
39
|
+
|
40
|
+
virtual const Color& stroke () const;
|
41
|
+
|
42
|
+
virtual Point content_size () const;
|
43
|
+
|
44
|
+
virtual void on_draw (DrawEvent* e);
|
45
|
+
|
46
|
+
virtual void on_draw_shape (DrawEvent* e);
|
47
|
+
|
48
|
+
struct Data;
|
49
|
+
|
50
|
+
Xot::PImpl<Data> self;
|
51
|
+
|
52
|
+
};// ShapeView
|
53
|
+
|
54
|
+
|
55
|
+
class RectShape : public ShapeView
|
56
|
+
{
|
57
|
+
|
58
|
+
typedef ShapeView Super;
|
59
|
+
|
60
|
+
public:
|
61
|
+
|
62
|
+
RectShape (const char* name = NULL);
|
63
|
+
|
64
|
+
virtual ~RectShape ();
|
65
|
+
|
66
|
+
virtual void set_round (coord round);
|
67
|
+
|
68
|
+
virtual void set_round (coord width, coord height);
|
69
|
+
|
70
|
+
virtual void set_round (const Point& round);
|
71
|
+
|
72
|
+
virtual const Point& round () const;
|
73
|
+
|
74
|
+
virtual void on_draw_shape (DrawEvent* e);
|
75
|
+
|
76
|
+
struct Data;
|
77
|
+
|
78
|
+
Xot::PImpl<Data> self;
|
79
|
+
|
80
|
+
};// RectShape
|
81
|
+
|
82
|
+
|
83
|
+
class EllipseShape : public ShapeView
|
84
|
+
{
|
85
|
+
|
86
|
+
typedef ShapeView Super;
|
87
|
+
|
88
|
+
public:
|
89
|
+
|
90
|
+
EllipseShape (const char* name = NULL);
|
91
|
+
|
92
|
+
virtual ~EllipseShape ();
|
93
|
+
|
94
|
+
virtual void set_radius_min (coord radius);
|
95
|
+
|
96
|
+
virtual coord radius_min () const;
|
97
|
+
|
98
|
+
virtual void set_nsegment (uint num_of_segments);
|
99
|
+
|
100
|
+
virtual uint nsegment() const;
|
101
|
+
|
102
|
+
virtual void make_body ();
|
103
|
+
|
104
|
+
virtual void on_draw_shape (DrawEvent* e);
|
105
|
+
|
106
|
+
struct Data;
|
107
|
+
|
108
|
+
Xot::PImpl<Data> self;
|
109
|
+
|
110
|
+
};// EllipseShape
|
111
|
+
|
112
|
+
|
113
|
+
class ArcShape : public EllipseShape
|
114
|
+
{
|
115
|
+
|
116
|
+
typedef EllipseShape Super;
|
117
|
+
|
118
|
+
public:
|
119
|
+
|
120
|
+
ArcShape (const char* name = NULL);
|
121
|
+
|
122
|
+
virtual ~ArcShape ();
|
123
|
+
|
124
|
+
virtual void set_angle_from (float degree);
|
125
|
+
|
126
|
+
virtual float angle_from () const;
|
127
|
+
|
128
|
+
virtual void set_angle_to (float degree);
|
129
|
+
|
130
|
+
virtual float angle_to () const;
|
131
|
+
|
132
|
+
virtual void make_body ();
|
133
|
+
|
134
|
+
virtual void on_draw_shape (DrawEvent* e);
|
135
|
+
|
136
|
+
struct Data;
|
137
|
+
|
138
|
+
Xot::PImpl<Data> self;
|
139
|
+
|
140
|
+
};// ArcShape
|
141
|
+
|
142
|
+
|
143
|
+
}// Reflex
|
144
|
+
|
145
|
+
|
146
|
+
#endif//EOH
|
data/include/reflex/view.h
CHANGED
@@ -154,6 +154,8 @@ namespace Reflex
|
|
154
154
|
|
155
155
|
virtual const Bounds& frame () const;
|
156
156
|
|
157
|
+
virtual float angle () const;
|
158
|
+
|
157
159
|
virtual void scroll_to (coord x, coord y, coord z = 0);
|
158
160
|
|
159
161
|
virtual void scroll_to (const Point& scroll);
|
@@ -180,11 +182,9 @@ namespace Reflex
|
|
180
182
|
|
181
183
|
virtual const Body* body () const;
|
182
184
|
|
183
|
-
virtual
|
184
|
-
|
185
|
-
virtual void set_friction (float friction);
|
185
|
+
virtual float meter2pixel (float meter = 1, bool create_world = true);
|
186
186
|
|
187
|
-
virtual
|
187
|
+
virtual float meter2pixel (float meter = 1) const;
|
188
188
|
|
189
189
|
virtual void set_gravity (coord x, coord y);
|
190
190
|
|
@@ -192,9 +192,13 @@ namespace Reflex
|
|
192
192
|
|
193
193
|
virtual Point gravity () const;
|
194
194
|
|
195
|
+
virtual Body* wall ();
|
196
|
+
|
197
|
+
virtual const Body* wall () const;
|
198
|
+
|
195
199
|
virtual void set_debug (bool state);
|
196
200
|
|
197
|
-
virtual bool
|
201
|
+
virtual bool debugging () const;
|
198
202
|
|
199
203
|
virtual Point from_parent (const Point& point) const;
|
200
204
|
|
@@ -224,6 +228,8 @@ namespace Reflex
|
|
224
228
|
|
225
229
|
virtual void on_resize (FrameEvent* e);
|
226
230
|
|
231
|
+
virtual void on_rotate (FrameEvent* e);
|
232
|
+
|
227
233
|
virtual void on_scroll (ScrollEvent* e);
|
228
234
|
|
229
235
|
virtual void on_focus (FocusEvent* e);
|
@@ -248,6 +254,12 @@ namespace Reflex
|
|
248
254
|
|
249
255
|
virtual void on_capture (CaptureEvent* e);
|
250
256
|
|
257
|
+
virtual void on_contact (ContactEvent* e);
|
258
|
+
|
259
|
+
virtual void on_contact_begin (ContactEvent* e);
|
260
|
+
|
261
|
+
virtual void on_contact_end (ContactEvent* e);
|
262
|
+
|
251
263
|
virtual operator bool () const;
|
252
264
|
|
253
265
|
virtual bool operator ! () const;
|
data/lib/reflex/application.rb
CHANGED
@@ -18,21 +18,21 @@ module Reflex
|
|
18
18
|
def initialize (opts = {}, &block)
|
19
19
|
super()
|
20
20
|
set opts
|
21
|
-
@
|
22
|
-
end
|
23
|
-
|
24
|
-
def on_start (e)
|
25
|
-
if @on_start
|
26
|
-
Xot::BlockUtil.instance_eval_or_block_call self, &@on_start
|
27
|
-
@on_start = nil
|
28
|
-
end
|
29
|
-
on_start! e
|
21
|
+
@start_block = block if block
|
30
22
|
end
|
31
23
|
|
32
24
|
def self.start (*args, &block)
|
33
25
|
self.new(*args, &block).start
|
34
26
|
end
|
35
27
|
|
28
|
+
private
|
29
|
+
|
30
|
+
def call_start_block ()
|
31
|
+
return unless @start_block
|
32
|
+
Xot::BlockUtil.instance_eval_or_block_call self, &@start_block
|
33
|
+
@start_block = nil
|
34
|
+
end
|
35
|
+
|
36
36
|
end# Application
|
37
37
|
|
38
38
|
|
data/lib/reflex/body.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'reflex/ext'
|
5
|
+
|
6
|
+
|
7
|
+
module Reflex
|
8
|
+
|
9
|
+
|
10
|
+
class ContactEvent
|
11
|
+
|
12
|
+
def type ()
|
13
|
+
TYPE2SYM[get_type] || :none
|
14
|
+
end
|
15
|
+
|
16
|
+
def begin? ()
|
17
|
+
get_type == TYPE_BEGIN
|
18
|
+
end
|
19
|
+
|
20
|
+
def end? ()
|
21
|
+
get_type == TYPE_END
|
22
|
+
end
|
23
|
+
|
24
|
+
def inspect ()
|
25
|
+
"#<Reflex::ContactEvent type:#{type} view:#{view}>"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
TYPE2SYM = {
|
31
|
+
TYPE_BEGIN => :begin,
|
32
|
+
TYPE_END => :end,
|
33
|
+
}
|
34
|
+
|
35
|
+
end# ContactEvent
|
36
|
+
|
37
|
+
|
38
|
+
end# Reflex
|
data/lib/reflex/image_view.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'reflex/view'
|
5
|
+
|
6
|
+
|
7
|
+
module Reflex
|
8
|
+
|
9
|
+
|
10
|
+
class ShapeView
|
11
|
+
|
12
|
+
def fill= (*args)
|
13
|
+
set_fill Color.color *args
|
14
|
+
fill
|
15
|
+
end
|
16
|
+
|
17
|
+
def stroke= (*args)
|
18
|
+
set_stroke Color.color *args
|
19
|
+
stroke
|
20
|
+
end
|
21
|
+
|
22
|
+
end# ShapeView
|
23
|
+
|
24
|
+
|
25
|
+
end# Reflex
|
data/lib/reflex/view.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
+
require 'forwardable'
|
4
5
|
require 'xot/setter'
|
5
6
|
require 'xot/block_util'
|
6
7
|
require 'reflex/ext'
|
@@ -19,14 +20,23 @@ module Reflex
|
|
19
20
|
include HasFrame
|
20
21
|
include HasTags
|
21
22
|
|
23
|
+
extend Forwardable
|
24
|
+
|
25
|
+
def_delegators :body,
|
26
|
+
:static=, :static?, :dynamic=, :dynamic?,
|
27
|
+
:linear_velocity=, :linear_velocity,
|
28
|
+
:angular_velocity=, :angular_velocity,
|
29
|
+
:density=, :density, :friction=, :friction, :restitution=, :restitution
|
30
|
+
|
22
31
|
alias add add_child
|
23
32
|
alias remove remove_child
|
24
33
|
alias find find_children
|
34
|
+
alias meter meter2pixel
|
25
35
|
|
26
36
|
def initialize (opts = {}, &block)
|
27
37
|
super()
|
28
38
|
set opts
|
29
|
-
@
|
39
|
+
@attach_block = block if block
|
30
40
|
end
|
31
41
|
|
32
42
|
def children ()
|
@@ -64,18 +74,18 @@ module Reflex
|
|
64
74
|
end
|
65
75
|
end
|
66
76
|
|
67
|
-
def on_attach (e)
|
68
|
-
on_attach! e
|
69
|
-
if @on_attach
|
70
|
-
Xot::BlockUtil.instance_eval_or_block_call self, &@on_attach
|
71
|
-
@on_attach = nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
77
|
def self.has_model ()
|
76
78
|
include ModelView
|
77
79
|
end
|
78
80
|
|
81
|
+
private
|
82
|
+
|
83
|
+
def call_attach_block ()
|
84
|
+
return unless @attach_block
|
85
|
+
Xot::BlockUtil.instance_eval_or_block_call self, &@attach_block
|
86
|
+
@attach_block = nil
|
87
|
+
end
|
88
|
+
|
79
89
|
end# View
|
80
90
|
|
81
91
|
|
data/lib/reflex/window.rb
CHANGED
@@ -20,7 +20,8 @@ module Reflex
|
|
20
20
|
extend Forwardable
|
21
21
|
|
22
22
|
def_delegators :root,
|
23
|
-
:add_child, :remove_child, :find_children, :style
|
23
|
+
:add_child, :remove_child, :find_children, :style, :meter2pixel, :meter,
|
24
|
+
:gravity=, :gravity, :wall, :debug=, :debug?
|
24
25
|
|
25
26
|
alias add add_child
|
26
27
|
alias remove remove_child
|
@@ -29,25 +30,25 @@ module Reflex
|
|
29
30
|
def initialize (opts = {}, &block)
|
30
31
|
super()
|
31
32
|
set opts
|
32
|
-
@
|
33
|
+
@show_block = block if block
|
33
34
|
end
|
34
35
|
|
35
36
|
def paint (&block)
|
36
37
|
painter.begin &block
|
37
38
|
end
|
38
39
|
|
39
|
-
def on_show (e)
|
40
|
-
if @on_show
|
41
|
-
Xot::BlockUtil.instance_eval_or_block_call self, &@on_show
|
42
|
-
@on_show = nil
|
43
|
-
end
|
44
|
-
on_show! e
|
45
|
-
end
|
46
|
-
|
47
40
|
def self.show (*args, &block)
|
48
41
|
new(*args, &block).show
|
49
42
|
end
|
50
43
|
|
44
|
+
private
|
45
|
+
|
46
|
+
def call_show_block ()
|
47
|
+
return unless @show_block
|
48
|
+
Xot::BlockUtil.instance_eval_or_block_call self, &@show_block
|
49
|
+
@show_block = nil
|
50
|
+
end
|
51
|
+
|
51
52
|
end# Window
|
52
53
|
|
53
54
|
|
data/lib/reflex.rb
CHANGED
@@ -17,24 +17,13 @@ require 'reflex/painter'
|
|
17
17
|
|
18
18
|
require 'reflex/reflex'
|
19
19
|
require 'reflex/helper'
|
20
|
-
|
21
|
-
require 'reflex/window'
|
22
|
-
require 'reflex/view'
|
23
|
-
require 'reflex/body'
|
24
|
-
require 'reflex/fixture'
|
25
|
-
require 'reflex/selector'
|
26
|
-
require 'reflex/shape'
|
27
|
-
require 'reflex/line_shape'
|
28
|
-
require 'reflex/rect_shape'
|
29
|
-
require 'reflex/ellipse_shape'
|
30
|
-
require 'reflex/arc_shape'
|
31
|
-
require 'reflex/model'
|
32
|
-
require 'reflex/model_owner'
|
20
|
+
|
33
21
|
require 'reflex/selector'
|
34
22
|
require 'reflex/style'
|
35
23
|
require 'reflex/style_length'
|
36
24
|
require 'reflex/style_length2'
|
37
25
|
require 'reflex/style_length4'
|
26
|
+
|
38
27
|
require 'reflex/update_event'
|
39
28
|
require 'reflex/draw_event'
|
40
29
|
require 'reflex/frame_event'
|
@@ -44,7 +33,20 @@ require 'reflex/key_event'
|
|
44
33
|
require 'reflex/pointer_event'
|
45
34
|
require 'reflex/wheel_event'
|
46
35
|
require 'reflex/capture_event'
|
36
|
+
require 'reflex/contact_event'
|
37
|
+
|
38
|
+
require 'reflex/body'
|
39
|
+
require 'reflex/fixture'
|
40
|
+
|
41
|
+
require 'reflex/model'
|
42
|
+
require 'reflex/model_owner'
|
43
|
+
|
44
|
+
require 'reflex/application'
|
45
|
+
require 'reflex/window'
|
46
|
+
require 'reflex/view'
|
47
47
|
|
48
48
|
require 'reflex/button'
|
49
49
|
require 'reflex/text_view'
|
50
50
|
require 'reflex/image_view'
|
51
|
+
|
52
|
+
require 'reflex/shape_view'
|
data/lib/reflexion.rb
CHANGED
@@ -17,80 +17,87 @@ module Reflexion
|
|
17
17
|
}
|
18
18
|
|
19
19
|
|
20
|
-
class
|
20
|
+
class MainWindow < Window
|
21
21
|
|
22
22
|
attr_accessor :update, :draw, :key, :pointer
|
23
23
|
|
24
24
|
attr_reader :setup
|
25
25
|
|
26
|
+
attr_reader :event
|
27
|
+
|
26
28
|
def setup= (block)
|
27
29
|
@setup = block
|
28
|
-
|
30
|
+
call_event nil, self, &@setup
|
29
31
|
end
|
30
32
|
|
31
33
|
def on_update (e)
|
32
34
|
super
|
33
35
|
redraw
|
34
|
-
|
36
|
+
call_event e, e, &@update
|
35
37
|
end
|
36
38
|
|
37
39
|
def on_draw (e)
|
38
40
|
super
|
39
|
-
|
41
|
+
call_event e, e.painter, &@draw
|
40
42
|
end
|
41
43
|
|
42
44
|
def on_key (e)
|
43
45
|
super
|
44
|
-
|
46
|
+
call_event e, e, &@key
|
45
47
|
end
|
46
48
|
|
47
49
|
def on_pointer (e)
|
48
50
|
super
|
49
|
-
|
51
|
+
call_event e, e, &@pointer
|
50
52
|
end
|
51
53
|
|
52
|
-
def
|
54
|
+
def call_event (event, *args, &block)
|
55
|
+
@event = event
|
53
56
|
Xot::BlockUtil.instance_eval_or_block_call *args, &block if block
|
54
57
|
end
|
55
58
|
|
56
|
-
end#
|
59
|
+
end# MainWindow
|
57
60
|
|
58
61
|
|
59
62
|
module_function
|
60
63
|
|
61
|
-
@@
|
64
|
+
@@window = MainWindow.new DEFAULTS
|
65
|
+
|
66
|
+
def window ()
|
67
|
+
@@window
|
68
|
+
end
|
62
69
|
|
63
|
-
def
|
64
|
-
|
70
|
+
def event ()
|
71
|
+
window.event
|
65
72
|
end
|
66
73
|
|
67
74
|
def setup (&block)
|
68
|
-
|
75
|
+
window.setup = block
|
69
76
|
end
|
70
77
|
|
71
78
|
def update (&block)
|
72
|
-
|
79
|
+
window.update = block
|
73
80
|
end
|
74
81
|
|
75
82
|
def draw (&block)
|
76
|
-
|
83
|
+
window.draw = block
|
77
84
|
end
|
78
85
|
|
79
86
|
def key (&block)
|
80
|
-
|
87
|
+
window.key = block
|
81
88
|
end
|
82
89
|
|
83
90
|
def pointer (&block)
|
84
|
-
|
91
|
+
window.pointer = block
|
85
92
|
end
|
86
93
|
|
87
94
|
def start ()
|
88
|
-
|
95
|
+
window.show
|
89
96
|
Reflex.start
|
90
97
|
end
|
91
98
|
|
92
99
|
def quit ()
|
93
|
-
|
100
|
+
window.close
|
94
101
|
end
|
95
102
|
|
96
103
|
|
@@ -40,6 +40,7 @@ class App : public Application
|
|
40
40
|
win->show();
|
41
41
|
|
42
42
|
win->root()->set_gravity(0, 9.8);
|
43
|
+
win->root()->set_debug(true);
|
43
44
|
|
44
45
|
Image image(32, 32);
|
45
46
|
Painter painter = image.painter();
|
@@ -67,6 +68,11 @@ class App : public Application
|
|
67
68
|
view->body()->set_dynamic(true);
|
68
69
|
view->body()->set_density(1);
|
69
70
|
}
|
71
|
+
|
72
|
+
View* ground = new View();
|
73
|
+
ground->set_frame(10, 400, 300, 10);
|
74
|
+
win->root()->add_child(ground);
|
75
|
+
ground->body()->set_static(true);
|
70
76
|
}
|
71
77
|
|
72
78
|
};// App
|
data/samples/physics.rb
CHANGED
@@ -12,26 +12,36 @@ Reflex.start name: "Physics" do |app|
|
|
12
12
|
Reflex::Window.show title: app.name, frame: [100, 100, 500, 500] do
|
13
13
|
root.set gravity: Reflex::Point.new(0, 9.8), debug: true
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
add_dynamic = -> size = 50, x = rand(10..400), y = rand(10..100) do
|
16
|
+
add Reflex::EllipseShape.new {
|
17
|
+
set :fill, [:red, :green, :blue, :yellow, :cyan, :magenta, :gray].sample
|
18
|
+
set :pos, [x, y]
|
19
|
+
set :size, [rand(5..size)] * 2
|
20
|
+
body.set dynamic: true, density: 1
|
21
|
+
}
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
add Reflex::ImageView.new {
|
27
|
-
set image: image, size: image.size, pos: [40 * n, 20 * n]
|
28
|
-
body.set dynamic: true, density: 1
|
24
|
+
add_static = -> size = 50 do
|
25
|
+
add Reflex::RectShape.new {
|
26
|
+
set :fill, :white
|
27
|
+
set :pos, [rand(10..400), rand(200..400)]
|
28
|
+
set :size, [rand(5..(size * 2)), rand(5..size)]
|
29
|
+
body.set static: true
|
29
30
|
}
|
30
31
|
end
|
31
32
|
|
33
|
+
50.times {|n| add_dynamic.call}
|
34
|
+
5.times {|n| add_static.call}
|
35
|
+
|
32
36
|
after :draw do |e|
|
33
37
|
e.painter.fill :white
|
34
38
|
e.painter.text "#{e.fps.to_i} FPS", 10, 10
|
35
39
|
end
|
40
|
+
|
41
|
+
on :pointer do |e|
|
42
|
+
if e.down? || e.drag?
|
43
|
+
add_dynamic.call 50, *e.pos.to_a
|
44
|
+
end
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[xot rays reflex]
|
5
|
+
.map {|s| File.expand_path "../../../../#{s}/lib", __FILE__}
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
7
|
+
|
8
|
+
require 'reflexion/include'
|
9
|
+
|
10
|
+
|
11
|
+
$garbages = []
|
12
|
+
|
13
|
+
class View
|
14
|
+
def setup (frame: [0, 0, 100, 100], color: :white, type: :static)
|
15
|
+
set frame: frame, fill: color, density: 1, friction: 0, restitution: 1, type => true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
setup do
|
20
|
+
set size: [600, 400]
|
21
|
+
wall.set friction: 0
|
22
|
+
5.times do |y|
|
23
|
+
10.times do |x|
|
24
|
+
add RectShape.new {
|
25
|
+
setup frame: [(x + 1) * 50, (y + 1) * 20, 30, 10], color: [:white, :red, :green, :blue, :yellow][y]
|
26
|
+
on(:contact) {$garbages << self}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
$bar = add RectShape.new {
|
31
|
+
setup frame: [0, 350, 100, 20], color: :blue
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
update do
|
36
|
+
$garbages.uniq.each {|o| o.parent.remove o}
|
37
|
+
$garbages.clear
|
38
|
+
end
|
39
|
+
|
40
|
+
draw do
|
41
|
+
text "#{event.fps.to_i} FPS", 10, 10
|
42
|
+
end
|
43
|
+
|
44
|
+
pointer do |e|
|
45
|
+
$bar.x = e.x - $bar.w / 2
|
46
|
+
if e.down?
|
47
|
+
window.add [EllipseShape, RectShape].sample.new {
|
48
|
+
setup frame: [e.x, $bar.y - 20, 20, 20], type: :dynamic
|
49
|
+
set :linear_velocity, Point.new(rand(-1.0..1.0), -1).normal * 500
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|