cyross-ruby-miyako 2.0.5.1 → 2.1.0
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.
- data/README +1092 -929
- data/Rakefile +7 -7
- data/defines.h +144 -144
- data/extern.h +29 -29
- data/install_miyako.rb +87 -87
- data/lib/Miyako/API/audio.rb +572 -198
- data/lib/Miyako/API/basic_data.rb +825 -573
- data/lib/Miyako/API/bitmap.rb +534 -507
- data/lib/Miyako/API/choices.rb +481 -475
- data/lib/Miyako/API/collision.rb +486 -460
- data/lib/Miyako/API/diagram.rb +586 -561
- data/lib/Miyako/API/drawing.rb +151 -151
- data/lib/Miyako/API/exceptions.rb +105 -0
- data/lib/Miyako/API/fixedmap.rb +462 -428
- data/lib/Miyako/API/font.rb +430 -403
- data/lib/Miyako/API/input.rb +456 -447
- data/lib/Miyako/API/layout.rb +636 -433
- data/lib/Miyako/API/map.rb +583 -529
- data/lib/Miyako/API/map_event.rb +222 -198
- data/lib/Miyako/API/modules.rb +357 -109
- data/lib/Miyako/API/movie.rb +166 -154
- data/lib/Miyako/API/parts.rb +276 -189
- data/lib/Miyako/API/plane.rb +205 -166
- data/lib/Miyako/API/screen.rb +341 -325
- data/lib/Miyako/API/shape.rb +443 -443
- data/lib/Miyako/API/sprite.rb +771 -752
- data/lib/Miyako/API/sprite_animation.rb +490 -481
- data/lib/Miyako/API/sprite_list.rb +1135 -0
- data/lib/Miyako/API/spriteunit.rb +168 -147
- data/lib/Miyako/API/story.rb +350 -300
- data/lib/Miyako/API/textbox.rb +770 -725
- data/lib/Miyako/API/utility.rb +419 -388
- data/lib/Miyako/API/viewport.rb +189 -139
- data/lib/Miyako/API/yuki.rb +1226 -996
- data/lib/Miyako/EXT/miyako_cairo.rb +62 -62
- data/lib/Miyako/EXT/raster_scroll.rb +138 -138
- data/lib/Miyako/EXT/slides.rb +157 -157
- data/lib/Miyako/miyako.rb +201 -171
- data/lib/Miyako/miyako_require_only.rb +35 -0
- data/miyako_basicdata.c +590 -590
- data/miyako_bitmap.c +1225 -1225
- data/miyako_collision.c +403 -403
- data/miyako_drawing.c +187 -187
- data/miyako_font.c +334 -334
- data/miyako_hsv.c +830 -830
- data/miyako_input_audio.c +254 -0
- data/miyako_layout.c +191 -191
- data/miyako_no_katana.c +1078 -1074
- data/miyako_sprite2.c +431 -0
- data/miyako_transform.c +438 -438
- data/miyako_utility.c +288 -288
- data/sample/Animation1/m1ku.rb +68 -68
- data/sample/Animation2/lex.rb +96 -96
- data/sample/Diagram_sample/diagram_sample_yuki2.rb +328 -386
- data/sample/Room3/blue.rb +297 -297
- data/sample/Room3/ending.rb +180 -180
- data/sample/Room3/green.rb +220 -220
- data/sample/Room3/main.rb +119 -119
- data/sample/Room3/main_component.rb +59 -59
- data/sample/Room3/red.rb +227 -227
- data/sample/Room3/room3.rb +25 -27
- data/sample/Room3/title.rb +184 -184
- data/sample/ball_action_sample.rb +204 -204
- data/sample/blit_rop.rb +70 -70
- data/sample/cairo_sample.rb +25 -25
- data/sample/circle_collision_test.rb +66 -66
- data/sample/collision_test.rb +33 -33
- data/sample/collision_test2.rb +108 -108
- data/sample/fixed_map_test/fixed_map_sample.rb +140 -140
- data/sample/fixed_map_test/readme.txt +72 -72
- data/sample/map_test/chara.rb +58 -58
- data/sample/map_test/main_parts.rb +69 -69
- data/sample/map_test/main_scene.rb +153 -153
- data/sample/map_test/map_manager.rb +75 -75
- data/sample/map_test/map_test.rb +23 -23
- data/sample/map_test/oasis.rb +71 -71
- data/sample/map_test/readme.txt +89 -89
- data/sample/map_test/route.rb +157 -157
- data/sample/map_test/town.rb +74 -74
- data/sample/polygon_test.rb +35 -35
- data/sample/rasterscroll.rb +24 -24
- data/sample/takahashi.rb +42 -42
- data/sample/textbox_sample.rb +189 -189
- data/sample/transform.rb +54 -54
- data/sample/utility_test.rb +73 -73
- data/sample/utility_test2.rb +61 -61
- data/sample/utility_test3.rb +64 -64
- data/sample/utility_test4.rb +73 -73
- data/uninstall_miyako.rb +19 -19
- data/win/miyako_no_katana.so +0 -0
- metadata +7 -2
data/sample/Room3/room3.rb
CHANGED
@@ -1,27 +1,25 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
#! /usr/bin/ruby
|
3
|
-
# Sample Adventure "Room 3"
|
4
|
-
|
5
|
-
$miyako_debug_mode = true
|
6
|
-
|
7
|
-
require 'Miyako/miyako'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
require '
|
19
|
-
require '
|
20
|
-
require '
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
r3 = Story.new
|
27
|
-
r3.run(Title)
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#! /usr/bin/ruby
|
3
|
+
# Sample Adventure "Room 3"
|
4
|
+
|
5
|
+
$miyako_debug_mode = true
|
6
|
+
|
7
|
+
require 'Miyako/miyako'
|
8
|
+
|
9
|
+
include Miyako
|
10
|
+
|
11
|
+
Miyako.setTitle("Room 3")
|
12
|
+
Screen.set_size(640, 480)
|
13
|
+
|
14
|
+
require 'main_component'
|
15
|
+
require 'title'
|
16
|
+
require 'main'
|
17
|
+
require 'red'
|
18
|
+
require 'green'
|
19
|
+
require 'blue'
|
20
|
+
require 'ending'
|
21
|
+
|
22
|
+
r3 = Story.new
|
23
|
+
r3.run(Title)
|
24
|
+
#for debug
|
25
|
+
#r3.run(MainScene)
|
data/sample/Room3/title.rb
CHANGED
@@ -1,184 +1,184 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
class Title
|
3
|
-
include Story::Scene
|
4
|
-
|
5
|
-
def self.scene_type
|
6
|
-
return :scene
|
7
|
-
end
|
8
|
-
|
9
|
-
def init
|
10
|
-
font = Font.sans_serif
|
11
|
-
font.size = 24
|
12
|
-
font.color = Color[:white]
|
13
|
-
@push_key = Shape.text(:text=>"Push Any Key", :font=>font)
|
14
|
-
@push_key.center
|
15
|
-
|
16
|
-
@copy_right = Shape.text(:text=>"2006-2008 Cyross Makoto", :font=>font)
|
17
|
-
@copy_right.center
|
18
|
-
|
19
|
-
@visible = false
|
20
|
-
|
21
|
-
@title = Sprite.new(:file=>"image/mittsu_no_oheya.png", :type=>:ck)
|
22
|
-
|
23
|
-
@exec = self.method(:view_in)
|
24
|
-
end
|
25
|
-
|
26
|
-
def setup
|
27
|
-
@title.move_to(Screen.w, 0)
|
28
|
-
end
|
29
|
-
|
30
|
-
def view_in
|
31
|
-
if @title.x > 0
|
32
|
-
@title.move(-8, 0)
|
33
|
-
return @now
|
34
|
-
end
|
35
|
-
@visible = true
|
36
|
-
@exec = self.method(:waiting)
|
37
|
-
return @now
|
38
|
-
end
|
39
|
-
|
40
|
-
def waiting
|
41
|
-
if Input.pushed_any? || Input.click?(:left)
|
42
|
-
@exec = self.method(:view_out)
|
43
|
-
@visible = false
|
44
|
-
end
|
45
|
-
return @now
|
46
|
-
end
|
47
|
-
|
48
|
-
def view_out
|
49
|
-
if @title.x > -Screen.w
|
50
|
-
@title.move(-8, 0)
|
51
|
-
return @now
|
52
|
-
end
|
53
|
-
return TitleCall
|
54
|
-
end
|
55
|
-
|
56
|
-
def update
|
57
|
-
return nil if (Input.pushed_any?(:esc) || Input.quit?)
|
58
|
-
return @exec.call
|
59
|
-
end
|
60
|
-
|
61
|
-
def render
|
62
|
-
@title.render
|
63
|
-
if @visible
|
64
|
-
@push_key.render
|
65
|
-
@copy_right.render
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class TitleCall
|
71
|
-
include Story::Scene
|
72
|
-
include MainComponent
|
73
|
-
|
74
|
-
def init
|
75
|
-
@yuki = Yuki.new(message_box[:box]){|box|
|
76
|
-
select_textbox(box)
|
77
|
-
}
|
78
|
-
@man = Sprite.new(:file=>"image/start.png", :type=>:ck)
|
79
|
-
@man.center
|
80
|
-
@alpha = 0.0
|
81
|
-
@wait = WaitCounter.new(0.2)
|
82
|
-
@exec = self.method(:view_in)
|
83
|
-
end
|
84
|
-
|
85
|
-
def setup
|
86
|
-
@yuki.setup(plot){|plot|
|
87
|
-
select_plot(plot)
|
88
|
-
}
|
89
|
-
@yuki.vars[:next] = MainScene
|
90
|
-
@wait.start
|
91
|
-
end
|
92
|
-
|
93
|
-
def update
|
94
|
-
return nil if (Input.pushed_any?(:esc) || Input.quit?)
|
95
|
-
return @exec.call
|
96
|
-
end
|
97
|
-
|
98
|
-
def final
|
99
|
-
message_box.stop
|
100
|
-
end
|
101
|
-
|
102
|
-
def view_in
|
103
|
-
if @wait.finish?
|
104
|
-
if @alpha == 1.0
|
105
|
-
@yuki.start_plot
|
106
|
-
@exec = self.method(:exec_yuki)
|
107
|
-
message_box.start
|
108
|
-
return @now
|
109
|
-
end
|
110
|
-
@alpha += 0.15
|
111
|
-
@alpha = 1.0 if @alpha >= 1.0
|
112
|
-
@wait.start
|
113
|
-
end
|
114
|
-
return @now
|
115
|
-
end
|
116
|
-
|
117
|
-
def exec_yuki
|
118
|
-
message_box.update_animation
|
119
|
-
@yuki.update
|
120
|
-
return @yuki.result ? @yuki.result : @now
|
121
|
-
end
|
122
|
-
|
123
|
-
def plot
|
124
|
-
yuki_plot do
|
125
|
-
text("「レディ〜ス エ〜ン ジェントルメ〜ン!」").pause.cr
|
126
|
-
text("「本日も、視聴者参加バラエティー").cr
|
127
|
-
text(" 『ルーム3』の時間がは〜じまりま〜した〜!」").pause.clear
|
128
|
-
text("「司会はわたくし、").cr
|
129
|
-
wait 0.3
|
130
|
-
text(" サミュエル・ボチボチデンナーが").cr
|
131
|
-
text(" お送りしま〜す!」").pause.clear
|
132
|
-
text("「本日も、難関を乗り越え、").cr
|
133
|
-
text(" 豪華賞品をゲットするだけ!").cr
|
134
|
-
wait 0.5
|
135
|
-
text(" カンタン!」").pause.clear
|
136
|
-
text("「ルールもカンタン!").cr
|
137
|
-
text(" 3つの部屋にいる住人からヒントを得て、").pause.cr
|
138
|
-
text(" 合言葉を見つけるだけ!").cr
|
139
|
-
wait 0.5
|
140
|
-
text(" ほら、カンタンでしょ?」").pause.clear
|
141
|
-
text("「でも、これらの部屋にいる住人、").cr
|
142
|
-
text(" 一筋縄じゃ合い言葉を教えてくれない。").cr
|
143
|
-
wait 0.5
|
144
|
-
text(" いろいろ話して、").cr
|
145
|
-
text(" 合い言葉をゲットしてくれ!」").pause.clear
|
146
|
-
text "「さぁ、最初の挑戦者だ。"
|
147
|
-
wait 0.5
|
148
|
-
text "お名前は?"
|
149
|
-
wait 1.5
|
150
|
-
cr
|
151
|
-
text " ・・・おおー、元気いいねー!"
|
152
|
-
wait 0.5
|
153
|
-
cr
|
154
|
-
text " じゃあ、どっから来たの?"
|
155
|
-
wait 1.0
|
156
|
-
cr
|
157
|
-
text(" ・・・オーケイ、よくできました!」").pause.clear
|
158
|
-
text "「じゃ、ルールは分かるよね?"
|
159
|
-
wait 0.5
|
160
|
-
cr
|
161
|
-
text " ・・・よし」"
|
162
|
-
pause.clear
|
163
|
-
text "「ドキドキするねぇ、"
|
164
|
-
wait 0.5
|
165
|
-
cr
|
166
|
-
text " ワクワクするねぇ"
|
167
|
-
pause.cr
|
168
|
-
text " それじゃ、元気よく、"
|
169
|
-
cr
|
170
|
-
text " 目の前のドアから入ってみよう。」"
|
171
|
-
pause.clear
|
172
|
-
text "「よーい、"
|
173
|
-
wait 0.5
|
174
|
-
text "スタート!」"
|
175
|
-
pause.clear
|
176
|
-
vars[:next]
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def render
|
181
|
-
Bitmap.dec_alpha(@man, Screen, @alpha)
|
182
|
-
message_box.render if @exec == self.method(:exec_yuki)
|
183
|
-
end
|
184
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
class Title
|
3
|
+
include Story::Scene
|
4
|
+
|
5
|
+
def self.scene_type
|
6
|
+
return :scene
|
7
|
+
end
|
8
|
+
|
9
|
+
def init
|
10
|
+
font = Font.sans_serif
|
11
|
+
font.size = 24
|
12
|
+
font.color = Color[:white]
|
13
|
+
@push_key = Shape.text(:text=>"Push Any Key", :font=>font)
|
14
|
+
@push_key.center!.bottom!{|body| (0.1).ratio(body) }
|
15
|
+
|
16
|
+
@copy_right = Shape.text(:text=>"2006-2008 Cyross Makoto", :font=>font)
|
17
|
+
@copy_right.center!.bottom!{|body| (0.05).ratio(body) }
|
18
|
+
|
19
|
+
@visible = false
|
20
|
+
|
21
|
+
@title = Sprite.new(:file=>"image/mittsu_no_oheya.png", :type=>:ck)
|
22
|
+
|
23
|
+
@exec = self.method(:view_in)
|
24
|
+
end
|
25
|
+
|
26
|
+
def setup
|
27
|
+
@title.move_to!(Screen.w, 0)
|
28
|
+
end
|
29
|
+
|
30
|
+
def view_in
|
31
|
+
if @title.x > 0
|
32
|
+
@title.move!(-8, 0)
|
33
|
+
return @now
|
34
|
+
end
|
35
|
+
@visible = true
|
36
|
+
@exec = self.method(:waiting)
|
37
|
+
return @now
|
38
|
+
end
|
39
|
+
|
40
|
+
def waiting
|
41
|
+
if Input.pushed_any? || Input.click?(:left)
|
42
|
+
@exec = self.method(:view_out)
|
43
|
+
@visible = false
|
44
|
+
end
|
45
|
+
return @now
|
46
|
+
end
|
47
|
+
|
48
|
+
def view_out
|
49
|
+
if @title.x > -Screen.w
|
50
|
+
@title.move!(-8, 0)
|
51
|
+
return @now
|
52
|
+
end
|
53
|
+
return TitleCall
|
54
|
+
end
|
55
|
+
|
56
|
+
def update
|
57
|
+
return nil if (Input.pushed_any?(:esc) || Input.quit?)
|
58
|
+
return @exec.call
|
59
|
+
end
|
60
|
+
|
61
|
+
def render
|
62
|
+
@title.render
|
63
|
+
if @visible
|
64
|
+
@push_key.render
|
65
|
+
@copy_right.render
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class TitleCall
|
71
|
+
include Story::Scene
|
72
|
+
include MainComponent
|
73
|
+
|
74
|
+
def init
|
75
|
+
@yuki = Yuki.new(message_box[:box]){|box|
|
76
|
+
select_textbox(box)
|
77
|
+
}
|
78
|
+
@man = Sprite.new(:file=>"image/start.png", :type=>:ck)
|
79
|
+
@man.center!.bottom!
|
80
|
+
@alpha = 0.0
|
81
|
+
@wait = WaitCounter.new(0.2)
|
82
|
+
@exec = self.method(:view_in)
|
83
|
+
end
|
84
|
+
|
85
|
+
def setup
|
86
|
+
@yuki.setup(plot){|plot|
|
87
|
+
select_plot(plot)
|
88
|
+
}
|
89
|
+
@yuki.vars[:next] = MainScene
|
90
|
+
@wait.start
|
91
|
+
end
|
92
|
+
|
93
|
+
def update
|
94
|
+
return nil if (Input.pushed_any?(:esc) || Input.quit?)
|
95
|
+
return @exec.call
|
96
|
+
end
|
97
|
+
|
98
|
+
def final
|
99
|
+
message_box.stop
|
100
|
+
end
|
101
|
+
|
102
|
+
def view_in
|
103
|
+
if @wait.finish?
|
104
|
+
if @alpha == 1.0
|
105
|
+
@yuki.start_plot
|
106
|
+
@exec = self.method(:exec_yuki)
|
107
|
+
message_box.start
|
108
|
+
return @now
|
109
|
+
end
|
110
|
+
@alpha += 0.15
|
111
|
+
@alpha = 1.0 if @alpha >= 1.0
|
112
|
+
@wait.start
|
113
|
+
end
|
114
|
+
return @now
|
115
|
+
end
|
116
|
+
|
117
|
+
def exec_yuki
|
118
|
+
message_box.update_animation
|
119
|
+
@yuki.update
|
120
|
+
return @yuki.result ? @yuki.result : @now
|
121
|
+
end
|
122
|
+
|
123
|
+
def plot
|
124
|
+
yuki_plot do
|
125
|
+
text("「レディ〜ス エ〜ン ジェントルメ〜ン!」").pause.cr
|
126
|
+
text("「本日も、視聴者参加バラエティー").cr
|
127
|
+
text(" 『ルーム3』の時間がは〜じまりま〜した〜!」").pause.clear
|
128
|
+
text("「司会はわたくし、").cr
|
129
|
+
wait 0.3
|
130
|
+
text(" サミュエル・ボチボチデンナーが").cr
|
131
|
+
text(" お送りしま〜す!」").pause.clear
|
132
|
+
text("「本日も、難関を乗り越え、").cr
|
133
|
+
text(" 豪華賞品をゲットするだけ!").cr
|
134
|
+
wait 0.5
|
135
|
+
text(" カンタン!」").pause.clear
|
136
|
+
text("「ルールもカンタン!").cr
|
137
|
+
text(" 3つの部屋にいる住人からヒントを得て、").pause.cr
|
138
|
+
text(" 合言葉を見つけるだけ!").cr
|
139
|
+
wait 0.5
|
140
|
+
text(" ほら、カンタンでしょ?」").pause.clear
|
141
|
+
text("「でも、これらの部屋にいる住人、").cr
|
142
|
+
text(" 一筋縄じゃ合い言葉を教えてくれない。").cr
|
143
|
+
wait 0.5
|
144
|
+
text(" いろいろ話して、").cr
|
145
|
+
text(" 合い言葉をゲットしてくれ!」").pause.clear
|
146
|
+
text "「さぁ、最初の挑戦者だ。"
|
147
|
+
wait 0.5
|
148
|
+
text "お名前は?"
|
149
|
+
wait 1.5
|
150
|
+
cr
|
151
|
+
text " ・・・おおー、元気いいねー!"
|
152
|
+
wait 0.5
|
153
|
+
cr
|
154
|
+
text " じゃあ、どっから来たの?"
|
155
|
+
wait 1.0
|
156
|
+
cr
|
157
|
+
text(" ・・・オーケイ、よくできました!」").pause.clear
|
158
|
+
text "「じゃ、ルールは分かるよね?"
|
159
|
+
wait 0.5
|
160
|
+
cr
|
161
|
+
text " ・・・よし」"
|
162
|
+
pause.clear
|
163
|
+
text "「ドキドキするねぇ、"
|
164
|
+
wait 0.5
|
165
|
+
cr
|
166
|
+
text " ワクワクするねぇ"
|
167
|
+
pause.cr
|
168
|
+
text " それじゃ、元気よく、"
|
169
|
+
cr
|
170
|
+
text " 目の前のドアから入ってみよう。」"
|
171
|
+
pause.clear
|
172
|
+
text "「よーい、"
|
173
|
+
wait 0.5
|
174
|
+
text "スタート!」"
|
175
|
+
pause.clear
|
176
|
+
vars[:next]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def render
|
181
|
+
Bitmap.dec_alpha(@man, Screen, @alpha)
|
182
|
+
message_box.render if @exec == self.method(:exec_yuki)
|
183
|
+
end
|
184
|
+
end
|
@@ -1,204 +1,204 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# 自由落下運動サンプル
|
3
|
-
# 2009.4.19 Cyross Makoto
|
4
|
-
|
5
|
-
require 'Miyako/miyako'
|
6
|
-
|
7
|
-
include Miyako
|
8
|
-
|
9
|
-
# 基本オブジェクト
|
10
|
-
class Obj
|
11
|
-
include Layout
|
12
|
-
|
13
|
-
attr_reader :collision, :position
|
14
|
-
|
15
|
-
def initialize(size)
|
16
|
-
init_layout
|
17
|
-
set_layout_size(*size.to_a)
|
18
|
-
|
19
|
-
# スプライトの生成
|
20
|
-
@sprite = Sprite.new(size: size, type: :ac)
|
21
|
-
|
22
|
-
# コリジョンの生成
|
23
|
-
@collision = Collision.new(Rect.new(0, 0, *size.to_a))
|
24
|
-
|
25
|
-
# 位置情報の生成
|
26
|
-
@position = Point.new(0, 0)
|
27
|
-
end
|
28
|
-
|
29
|
-
def update_layout_position
|
30
|
-
# 画像はマージンが掛かっている可能性があるため、
|
31
|
-
# 補正を掛けておく
|
32
|
-
@
|
33
|
-
|
34
|
-
@position.move_to(*@layout.pos
|
35
|
-
end
|
36
|
-
|
37
|
-
# スプライトとコリジョン間でマージンを設定
|
38
|
-
def margin(dx, dy)
|
39
|
-
@sprite.move(dx, dy)
|
40
|
-
return self
|
41
|
-
end
|
42
|
-
|
43
|
-
# 衝突判定
|
44
|
-
def collision?(col, pos)
|
45
|
-
return @collision.collision?(@position, col, pos)
|
46
|
-
end
|
47
|
-
|
48
|
-
# 画面へ描画
|
49
|
-
def render
|
50
|
-
@sprite.render
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# ボール
|
55
|
-
class Ball < Obj
|
56
|
-
V0 = [
|
57
|
-
VX = [1, -1].cycle
|
58
|
-
G = 9.8
|
59
|
-
|
60
|
-
# 初速度の取得
|
61
|
-
attr_reader :v0
|
62
|
-
|
63
|
-
def initialize
|
64
|
-
size = Size.new(32, 32)
|
65
|
-
super(size)
|
66
|
-
Drawing.circle(@sprite,
|
67
|
-
[size.w/2,size.h/2],
|
68
|
-
size.w/2,
|
69
|
-
[255,255,255],
|
70
|
-
true)
|
71
|
-
|
72
|
-
# ジャンプ中?
|
73
|
-
@jumping = false
|
74
|
-
# y基準位置
|
75
|
-
@by = 0.0
|
76
|
-
# 元y
|
77
|
-
@oy = 0.0
|
78
|
-
# 速度
|
79
|
-
@v = 0.0
|
80
|
-
# 初速度
|
81
|
-
@v0 = 0.0
|
82
|
-
# 時間
|
83
|
-
@t = 0.0
|
84
|
-
# 時間刻み
|
85
|
-
@dt = 0.01
|
86
|
-
# 床の跳ね返り係数
|
87
|
-
# 0.9や0.8にすると永遠に跳ねる
|
88
|
-
@e = 0.5
|
89
|
-
# 拡大率
|
90
|
-
@zoom = 1.0 / @dt
|
91
|
-
# ウェイト
|
92
|
-
@wait = WaitCounter.new(@dt)
|
93
|
-
end
|
94
|
-
|
95
|
-
# ボールの更新
|
96
|
-
# 床(floor)を引数に取る
|
97
|
-
def update(floor)
|
98
|
-
if @jumping
|
99
|
-
# 放物運動の公式より。
|
100
|
-
# 当たり判定のテストも兼ねていることから、
|
101
|
-
# 整数単位の値が必要だったため、時間刻みを元に値を拡大している
|
102
|
-
y = (@v0 * @t - G * (@t ** 2) / 2) * @zoom
|
103
|
-
# 移動量の算出
|
104
|
-
dy = y - @oy
|
105
|
-
# 床とぶつかる?
|
106
|
-
# 移動範囲を作成
|
107
|
-
rect = Rect.new(@position.x,
|
108
|
-
@position.y,
|
109
|
-
1, -dy)
|
110
|
-
# 所定の間隔で床と衝突判定
|
111
|
-
if Utility.product_liner_f(rect, floor.h).any?{|pos|
|
112
|
-
@collision.collision?(pos,
|
113
|
-
floor.collision,
|
114
|
-
floor.position)
|
115
|
-
}
|
116
|
-
# 床にぶつかれば跳ね返る
|
117
|
-
self.move_to(self.x, @by)
|
118
|
-
# 跳ね返り時の速度を求める。
|
119
|
-
# 実数にすると何故か永遠にはねるため、整数化して強制的に値を少なくしている
|
120
|
-
@v0 = -((@v0 - G * @t) * @e).to_i
|
121
|
-
@t = @dt
|
122
|
-
@oy = 0.0
|
123
|
-
@wait.start
|
124
|
-
elsif @wait.finish?
|
125
|
-
# ぶつからなければ移動
|
126
|
-
self.move_to(self.x, @by - y.to_i)
|
127
|
-
@t = @t + @dt
|
128
|
-
@oy = y
|
129
|
-
@wait.start
|
130
|
-
end
|
131
|
-
# 初速度がゼロ?(止まった?)
|
132
|
-
if @v0 == 0.0
|
133
|
-
# ジャンプの終了
|
134
|
-
@wait.stop
|
135
|
-
@jumping = false
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# 飛び上がれ!
|
141
|
-
def jumpup
|
142
|
-
return if @jumping
|
143
|
-
# y基準位置の決定
|
144
|
-
@by = self.y.to_f
|
145
|
-
# 初速度の決定
|
146
|
-
@v0 = V0.next
|
147
|
-
@jumping = true
|
148
|
-
@t = @dt
|
149
|
-
@wait.start
|
150
|
-
end
|
151
|
-
|
152
|
-
# ジャンプ中?
|
153
|
-
def jumping?
|
154
|
-
return @jumping
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
# 床
|
159
|
-
class Floor < Obj
|
160
|
-
def initialize
|
161
|
-
size = Size.new(640, 16)
|
162
|
-
super(size)
|
163
|
-
Drawing.fill(@sprite, [255,64,64])
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
# ボールの用意
|
168
|
-
@ball = Ball.new
|
169
|
-
|
170
|
-
# 床の用意
|
171
|
-
@floor = Floor.new
|
172
|
-
|
173
|
-
# 床の初期位置設定
|
174
|
-
@floor.center
|
175
|
-
|
176
|
-
# ボールの初期位置設定
|
177
|
-
@ball.center
|
178
|
-
|
179
|
-
# フォントの用意
|
180
|
-
@font = Font.serif
|
181
|
-
@font.size = 16
|
182
|
-
|
183
|
-
# 情報表示用スプライトの用意
|
184
|
-
@speed = Sprite.new(size: Size.new(640, 16), type: :ac)
|
185
|
-
@info = Shape.text(font: @font, text: "1ボタンを押せばボールが跳ね上がります")
|
186
|
-
@info.snap(@speed).left
|
187
|
-
|
188
|
-
Miyako.main_loop do
|
189
|
-
break if Input.quit_or_escape?
|
190
|
-
@ball.update(@floor)
|
191
|
-
# 1ボタンを押した時、ボールのジャンプを始める
|
192
|
-
@ball.jumpup if Input.pushed_any?(:btn1)
|
193
|
-
|
194
|
-
# 初速度表示スプライトの更新
|
195
|
-
@speed.clear!
|
196
|
-
@font.draw_text(@speed, "初速度:#{@ball.v0}", 0, 0)
|
197
|
-
|
198
|
-
# 画面への描画
|
199
|
-
@floor.render
|
200
|
-
@ball.render
|
201
|
-
@speed.render
|
202
|
-
# ジャンプ中でなければ説明を表示
|
203
|
-
@info.render unless @ball.jumping?
|
204
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
# 自由落下運動サンプル
|
3
|
+
# 2009.4.19 Cyross Makoto
|
4
|
+
|
5
|
+
require 'Miyako/miyako'
|
6
|
+
|
7
|
+
include Miyako
|
8
|
+
|
9
|
+
# 基本オブジェクト
|
10
|
+
class Obj
|
11
|
+
include Layout
|
12
|
+
|
13
|
+
attr_reader :collision, :position
|
14
|
+
|
15
|
+
def initialize(size)
|
16
|
+
init_layout
|
17
|
+
set_layout_size(*size.to_a)
|
18
|
+
|
19
|
+
# スプライトの生成
|
20
|
+
@sprite = Sprite.new(size: size, type: :ac)
|
21
|
+
|
22
|
+
# コリジョンの生成
|
23
|
+
@collision = Collision.new(Rect.new(0, 0, *size.to_a))
|
24
|
+
|
25
|
+
# 位置情報の生成
|
26
|
+
@position = Point.new(0, 0)
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_layout_position
|
30
|
+
# 画像はマージンが掛かっている可能性があるため、
|
31
|
+
# 補正を掛けておく
|
32
|
+
pos = @layout.pos.move(-@position[0],-@position[1])
|
33
|
+
@sprite.move!(*pos)
|
34
|
+
@position.move_to!(*@layout.pos)
|
35
|
+
end
|
36
|
+
|
37
|
+
# スプライトとコリジョン間でマージンを設定
|
38
|
+
def margin(dx, dy)
|
39
|
+
@sprite.move!(dx, dy)
|
40
|
+
return self
|
41
|
+
end
|
42
|
+
|
43
|
+
# 衝突判定
|
44
|
+
def collision?(col, pos)
|
45
|
+
return @collision.collision?(@position, col, pos)
|
46
|
+
end
|
47
|
+
|
48
|
+
# 画面へ描画
|
49
|
+
def render
|
50
|
+
@sprite.render
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# ボール
|
55
|
+
class Ball < Obj
|
56
|
+
V0 = [8.0, 12.0].cycle
|
57
|
+
VX = [1, -1].cycle
|
58
|
+
G = 9.8
|
59
|
+
|
60
|
+
# 初速度の取得
|
61
|
+
attr_reader :v0
|
62
|
+
|
63
|
+
def initialize
|
64
|
+
size = Size.new(32, 32)
|
65
|
+
super(size)
|
66
|
+
Drawing.circle(@sprite,
|
67
|
+
[size.w/2,size.h/2],
|
68
|
+
size.w/2,
|
69
|
+
[255,255,255],
|
70
|
+
true)
|
71
|
+
|
72
|
+
# ジャンプ中?
|
73
|
+
@jumping = false
|
74
|
+
# y基準位置
|
75
|
+
@by = 0.0
|
76
|
+
# 元y
|
77
|
+
@oy = 0.0
|
78
|
+
# 速度
|
79
|
+
@v = 0.0
|
80
|
+
# 初速度
|
81
|
+
@v0 = 0.0
|
82
|
+
# 時間
|
83
|
+
@t = 0.0
|
84
|
+
# 時間刻み
|
85
|
+
@dt = 0.01
|
86
|
+
# 床の跳ね返り係数
|
87
|
+
# 0.9や0.8にすると永遠に跳ねる
|
88
|
+
@e = 0.5
|
89
|
+
# 拡大率
|
90
|
+
@zoom = 1.0 / @dt
|
91
|
+
# ウェイト
|
92
|
+
@wait = WaitCounter.new(@dt)
|
93
|
+
end
|
94
|
+
|
95
|
+
# ボールの更新
|
96
|
+
# 床(floor)を引数に取る
|
97
|
+
def update(floor)
|
98
|
+
if @jumping
|
99
|
+
# 放物運動の公式より。
|
100
|
+
# 当たり判定のテストも兼ねていることから、
|
101
|
+
# 整数単位の値が必要だったため、時間刻みを元に値を拡大している
|
102
|
+
y = (@v0 * @t - G * (@t ** 2) / 2) * @zoom
|
103
|
+
# 移動量の算出
|
104
|
+
dy = y - @oy
|
105
|
+
# 床とぶつかる?
|
106
|
+
# 移動範囲を作成
|
107
|
+
rect = Rect.new(@position.x,
|
108
|
+
@position.y,
|
109
|
+
1, -dy)
|
110
|
+
# 所定の間隔で床と衝突判定
|
111
|
+
if Utility.product_liner_f(rect, floor.h).any?{|pos|
|
112
|
+
@collision.collision?(pos,
|
113
|
+
floor.collision,
|
114
|
+
floor.position)
|
115
|
+
}
|
116
|
+
# 床にぶつかれば跳ね返る
|
117
|
+
self.move_to!(self.x, @by)
|
118
|
+
# 跳ね返り時の速度を求める。
|
119
|
+
# 実数にすると何故か永遠にはねるため、整数化して強制的に値を少なくしている
|
120
|
+
@v0 = -((@v0 - G * @t) * @e).to_i
|
121
|
+
@t = @dt
|
122
|
+
@oy = 0.0
|
123
|
+
@wait.start
|
124
|
+
elsif @wait.finish?
|
125
|
+
# ぶつからなければ移動
|
126
|
+
self.move_to!(self.x, @by - y.to_i)
|
127
|
+
@t = @t + @dt
|
128
|
+
@oy = y
|
129
|
+
@wait.start
|
130
|
+
end
|
131
|
+
# 初速度がゼロ?(止まった?)
|
132
|
+
if @v0 == 0.0
|
133
|
+
# ジャンプの終了
|
134
|
+
@wait.stop
|
135
|
+
@jumping = false
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# 飛び上がれ!
|
141
|
+
def jumpup
|
142
|
+
return if @jumping
|
143
|
+
# y基準位置の決定
|
144
|
+
@by = self.y.to_f
|
145
|
+
# 初速度の決定
|
146
|
+
@v0 = V0.next
|
147
|
+
@jumping = true
|
148
|
+
@t = @dt
|
149
|
+
@wait.start
|
150
|
+
end
|
151
|
+
|
152
|
+
# ジャンプ中?
|
153
|
+
def jumping?
|
154
|
+
return @jumping
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# 床
|
159
|
+
class Floor < Obj
|
160
|
+
def initialize
|
161
|
+
size = Size.new(640, 16)
|
162
|
+
super(size)
|
163
|
+
Drawing.fill(@sprite, [255,64,64])
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# ボールの用意
|
168
|
+
@ball = Ball.new
|
169
|
+
|
170
|
+
# 床の用意
|
171
|
+
@floor = Floor.new
|
172
|
+
|
173
|
+
# 床の初期位置設定
|
174
|
+
@floor.center!.bottom!
|
175
|
+
|
176
|
+
# ボールの初期位置設定
|
177
|
+
@ball.center!.bottom!{|b| @floor.size.h }
|
178
|
+
|
179
|
+
# フォントの用意
|
180
|
+
@font = Font.serif
|
181
|
+
@font.size = 16
|
182
|
+
|
183
|
+
# 情報表示用スプライトの用意
|
184
|
+
@speed = Sprite.new(size: Size.new(640, 16), type: :ac)
|
185
|
+
@info = Shape.text(font: @font, text: "1ボタンを押せばボールが跳ね上がります")
|
186
|
+
@info.snap(@speed).left!.outside_bottom!
|
187
|
+
|
188
|
+
Miyako.main_loop do
|
189
|
+
break if Input.quit_or_escape?
|
190
|
+
@ball.update(@floor)
|
191
|
+
# 1ボタンを押した時、ボールのジャンプを始める
|
192
|
+
@ball.jumpup if Input.pushed_any?(:btn1)
|
193
|
+
|
194
|
+
# 初速度表示スプライトの更新
|
195
|
+
@speed.clear!
|
196
|
+
@font.draw_text(@speed, "初速度:#{@ball.v0}", 0, 0)
|
197
|
+
|
198
|
+
# 画面への描画
|
199
|
+
@floor.render
|
200
|
+
@ball.render
|
201
|
+
@speed.render
|
202
|
+
# ジャンプ中でなければ説明を表示
|
203
|
+
@info.render unless @ball.jumping?
|
204
|
+
end
|