game.loading do |loader|
loader.add :window, :system => "window"
loader.add :gui_item, :system => "gui_item"
loader.add :bac, 3#背景(まだない)
loader.add :space, 3#左右の空間
loader.add :br, 3#右
loader.add :bl, 3#左
loader.add :bu, 3#上
loader.add :bd, 3#下
loader.add :ball_i, 3#ボール
end
#関数
Variable = {}
def SV(a,b)
Variable[a] = b
end
def GV(a)
Variable[a]
end
game.on_init do
set_window_image :window
set_gui_image :gui_item
scene_change :Setting
end
scene :Setting do |scene|
SV(:ball,[[7, 4, 0, 0 ,0, 0],[9, 6, 0, 0, 0, 0],[8, 9, 0, 0, 0, 0]])
SV(:k,3)
SV(:ball_i,[1,1])
SV(:map,[[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,02,01,03,01,02,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,01,01,01,01,01,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,02,02,01,02,01,02,02,00,00,00,00,00,00,00],
[00,00,00,00,00,00,02,02,02,01,02,02,02,00,00,00,00,00,00,00],
[00,00,00,00,00,00,02,01,02,01,02,01,02,00,00,00,00,00,00,00],
[00,00,00,00,00,00,02,01,01,01,01,01,02,00,00,00,00,00,00,00],
[00,00,00,00,00,00,02,02,02,01,02,02,02,00,00,00,00,00,00,00],
[00,00,00,00,00,00,02,02,01,01,01,02,02,00,00,00,00,00,00,00],
[00,00,00,00,00,00,02,00,00,00,00,00,02,00,00,00,00,00,00,00],
[00,00,00,00,00,00,02,02,02,01,02,02,02,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00]])
SV(:map,[[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,01,01,03,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,01,00,02,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,01,01,01,01,01,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,01,01,01,00,01,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,01,00,01,01,01,02,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,01,01,02,01,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,01,00,01,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,01,01,01,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00],
[00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00]])
SV(:map_i,[[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
scene.add :image, :texture => :bac, :align => :fullscreen#背景の表示
t = scene.text :position => [305, 205]
t.set_text_area_size 258, 32
t.set_font_point_size 28
t.set_color 0, 0, 0, 255
t.set_text "ゲームスタート"
t.event :on_click do |event|
t.delete
speak "転がり行く玉"
scene_change :main
end
end
# メイン
scene :main do |scene|
scene.on_init do
#ステージ生成
y = 0
while y < 15
x = 0
while x < 20
if GV(:map)[y][x] != 0
GV(:map_i)[y][x] = scene.add :image, :template => :ball, :position => [x*30+100,y*30]
GV(:map_i)[y][x].copy_rect GV(:map)[y][x]-1,1
end
x = x + 1
end
y = y + 1
end
#玉画像生成,玉設定
k = GV(:k)
i = 0
while i < k
GV(:ball_i)[i] = scene.add :image, :template => :ball, :position => [(GV(:ball)[i][0]*30)+100,(GV(:ball)[i][1]*30)]
GV(:ball_i)[i].copy_rect GV(:ball)[i][2], 0
i = i + 1
end
gk = 0#ゴールした玉数
nk = 0#なくなった玉数
mx = 0#x移動分(戻る用)
my = 0#y移動分
scene.add :image, :texture => :bac, :align => :fullscreen#背景の表示
#scene.add :image, :name => :menu, :template => :menu_temp, :center_position => [400, 425]
space = scene.add :collision, :texture =>:space, :position => [0, 0], :scale => [1.0, 1.0]
#上.左右.下.やり直す.あきらめる
bu = scene.add :image, :texture =>:bu, :position => [0, 0], :scale => [1.0, 1.0]
bl = scene.add :image, :texture =>:bl, :position => [0, 150], :scale => [1.0, 1.0]
bd = scene.add :image, :texture =>:bd, :position => [0, 300], :scale => [1.0, 1.0]
by = scene.add :image, :texture =>:bd, :position => [700, 0], :scale => [1.0, 1.0]
br = scene.add :image, :texture =>:br, :position => [700, 150], :scale => [1.0, 1.0]
ba = scene.add :image, :texture =>:bd, :position => [700, 300], :scale => [1.0, 1.0]
t = scene.text :position => [105, 35]
t.set_text_area_size 228, 32
t.set_font_point_size 28
t.set_color 0, 0, 0, 255
t.set_text "転がり行く玉"
bu.event :on_touch_down do |event|
mx = 0
my = -1
end
bl.event :on_touch_down do |event|
mx = -1
my = 0
end
bd.event :on_touch_down do |event|
mx = 0
my = 1
end
br.event :on_touch_down do |event|
mx = 1
my = 0
end
by.event :on_touch_down do |event|
scene_change :Setting
end
space.event :on_step do |event|
if mx == 0 && my == 0
else
i = 0
while i < k
if GV(:ball)[i][4] != -1
GV(:ball)[i][0] += mx
GV(:ball)[i][1] += my
GV(:ball)[i][3] = 1#動いた
#画面外には落ちない
if GV(:ball)[i][0] > 19 || GV(:ball)[i][0] < 0 || GV(:ball)[i][1] > 14 || GV(:ball)[i][1] < 0
GV(:ball)[i][0] -= mx
GV(:ball)[i][1] -= my
GV(:ball)[i][3] = 0
end
if GV(:map)[GV(:ball)[i][1]][GV(:ball)[i][0]] == 3
GV(:ball)[i][0] = -1
GV(:ball)[i][1] = -1
GV(:ball)[i][4] = -1
GV(:ball_i)[i].set_position -100,-100
gk = gk + 1
end
if GV(:map)[GV(:ball)[i][1]][GV(:ball)[i][0]] == 0
GV(:ball)[i][0] = -1
GV(:ball)[i][1] = -1
GV(:ball_i)[i].set_position -100, -100
GV(:ball)[i][4] = -1
nk = nk + 1
end
if GV(:map)[GV(:ball)[i][1]][GV(:ball)[i][0]] == 2
GV(:ball)[i][0] -= mx
GV(:ball)[i][1] -= my
GV(:ball)[i][3] = 0
end
end
i = i + 1
end
i = 0
while i < k
#球の重なり判定
lop = true
while lop
i2 = 0
lop = false
while i2 < k
i3 = 0
while i3 < k
if GV(:ball)[i2][0] == GV(:ball)[i3][0] && GV(:ball)[i2][1] == GV(:ball)[i3][1] && GV(:ball)[i2][3] == 1
if i2 != i3
GV(:ball)[i2][0] -= mx
GV(:ball)[i2][1] -= my
GV(:ball)[i2][3] = 0
lop = true
end
end
i3 = i3 + 1
end
i2 = i2 + 1
end
end
if GV(:ball)[i][4] != -1
x = GV(:ball)[i][0]*30+100
y = GV(:ball)[i][1]*30
GV(:ball_i)[i].change_motion :move
#GV(:ball_i)[i].set_position GV(:ball)[i][0]*30+100 ,GV(:ball)[i][1]*30
end
i = i + 1
end
mx = 0
my = 0
end#動きここまで
if gk == GV(:k)
speak "クリア!"
scene_change :Setting
elsif nk + gk == GV(:k)
speak "ゲームオーバー"
scene_change :Setting
end
end
end
end
sprite_template :ball do |st|
st.texture :ball_i
st.src_size 50, 50
st.dest_size 30, 30
st.center_offset 30, 30
st.layer_order 10
st.copy_rect 0, 0
# キャラモーション
st.motion :move do |commands|
commands.loop false
commands.move_to(lambda do |s| x end,
lambda do |s| y end, 20)
end
end