def move_right
if @block1.sprite.x == 220+ELS::PX or @block2.sprite.x == 220+ELS::PX or
@block3.sprite.x == 220+ELS::PX or @block4.sprite.x == 220+ELS::PX
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([@block1.sprite.x+20,@block1.sprite.y,1])
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([@block2.sprite.x+20,@block2.sprite.y,1])
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([@block3.sprite.x+20,@block3.sprite.y,1])
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([@block4.sprite.x+20,@block4.sprite.y,1])
$game_system.se_play($data_system.buzzer_se)
return
end
@x += ELS::W
@block1.sprite.x += 20
@block2.sprite.x += 20
@block3.sprite.x += 20
@block4.sprite.x += 20
return
end
def move_left
if @block1.sprite.x == ELS::PX or @block2.sprite.x == ELS::PX or
@block3.sprite.x == ELS::PX or @block4.sprite.x == ELS::PX
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([@block1.sprite.x-20,@block1.sprite.y,1])
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([@block2.sprite.x-20,@block2.sprite.y,1])
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([@block3.sprite.x-20,@block3.sprite.y,1])
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([@block4.sprite.x-20,@block4.sprite.y,1])
$game_system.se_play($data_system.buzzer_se)
return
end
@x -= ELS::W
@block1.sprite.x -= 20
@block2.sprite.x -= 20
@block3.sprite.x -= 20
@block4.sprite.x -= 20
return
end
def move_down
y1 = @block1.sprite.y
y2 = @block2.sprite.y
y3 = @block3.sprite.y
y4 = @block4.sprite.y
y11 = 0
y22 = 0
y33 = 0
y44 = 0
for i in (@block1.sprite.y-ELS::PY)/20..21
if $scene.table.include?([@block1.sprite.x,y1+20,0])
y1 += 20
y11 += 20
else
break
end
end
for i in (@block2.sprite.y-ELS::PY)/20..21
if $scene.table.include?([@block2.sprite.x,y2+20,0])
y2 += 20
y22 += 20
else
break
end
end
for i in (@block3.sprite.y-ELS::PY)/20..21
if $scene.table.include?([@block3.sprite.x,y3+20,0])
y3 += 20
y33 += 20
else
break
end
end
for i in (@block4.sprite.y-ELS::PY)/20..21
if $scene.table.include?([@block4.sprite.x,y4+20,0])
y4 += 20
y44 += 20
else
break
end
end
yl = min(y11,y22,y33,y44)
@y += yl
@block1.sprite.y += yl
@block2.sprite.y += yl
@block3.sprite.y += yl
@block4.sprite.y += yl
change_to_1
Audio.se_play("Audio/SE/down",100,100)
return
end
def block_auto_down
if @block1.sprite.y == 420+ELS::PY or @block2.sprite.y == 420+ELS::PY or
@block3.sprite.y == 420+ELS::PY or @block4.sprite.y == 420+ELS::PY
change_to_1
return
end
if $scene.table.include?([@block1.sprite.x,@block1.sprite.y+20,1])
change_to_1
return
end
if $scene.table.include?([@block2.sprite.x,@block2.sprite.y+20,1])
change_to_1
return
end
if $scene.table.include?([@block3.sprite.x,@block3.sprite.y+20,1])
change_to_1
return
end
if $scene.table.include?([@block4.sprite.x,@block4.sprite.y+20,1])
change_to_1
return
end
@y += 20
@block1.sprite.y += 20
@block2.sprite.y += 20
@block3.sprite.y += 20
@block4.sprite.y += 20
end
oldY[2] += 20
oldX[3] -= 20
elsif @shape == 1
oldX[0] -= 40
oldY[0] -= 20
oldX[1] -= 20
oldY[2] -= 20
oldX[3] += 20
end
when 6
if @shape == 2
@shape = 0
end
if @shape == 0
oldX[0] -= 20
oldY[0] += 20
oldX[2] += 20
oldY[2] += 20
oldX[3] += 40
elsif @shape == 1
oldX[0] += 20
oldY[0] -= 20
oldX[2] -= 20
oldY[2] -= 20
oldX[3] -= 40
end
end
if oldX[0] < ELS::PX or oldX[1] < ELS::PX or oldX[2] < ELS::PX or oldX[3] < ELS::PX
$game_system.se_play($data_system.buzzer_se)
return
end
if oldX[0] > 220+ELS::PX or oldX[1] > 220+ELS::PX or oldX[2] > 220+ELS::PX or oldX[3] > 220+ELS::PX
$game_system.se_play($data_system.buzzer_se)
return
end
if oldY[0] > 420 + ELS::PY or oldY[1] > 420 + ELS::PY or oldY[2] > 420 + ELS::PY or oldY[3] > 420 + ELS::PY
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([oldX[0],oldY[0],1])
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([oldX[1],oldY[1],1])
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([oldX[2],oldY[2],1])
$game_system.se_play($data_system.buzzer_se)
return
end
if $scene.table.include?([oldX[3],oldY[3],1])
$game_system.se_play($data_system.buzzer_se)
return
end
@block1.sprite.x = oldX[0]
@block1.sprite.y = oldY[0]
@block2.sprite.x = oldX[1]
@block2.sprite.y = oldY[1]
@block3.sprite.x = oldX[2]
@block3.sprite.y = oldY[2]
@block4.sprite.x = oldX[3]
@block4.sprite.y = oldY[3]
@shape += 1
end
def change_to_1
$scene.table[getI(@block1.sprite.x,@block1.sprite.y)][2] = 1
$scene.table[getI(@block2.sprite.x,@block2.sprite.y)][2] = 1
$scene.table[getI(@block3.sprite.x,@block3.sprite.y)][2] = 1
$scene.table[getI(@block4.sprite.x,@block4.sprite.y)][2] = 1
# 转换成小方块,为了便于消去
$scene.small_block.push([@block1.sprite.x,@block1.sprite.y,$scene.block_nums,1])
$scene.small_block.push([@block2.sprite.x,@block2.sprite.y,$scene.block_nums,2])
$scene.small_block.push([@block3.sprite.x,@block3.sprite.y,$scene.block_nums,3])
$scene.small_block.push([@block4.sprite.x,@block4.sprite.y,$scene.block_nums,4])
# 判断一排是否已经满
array = []
if need_dispose(@block1.sprite.y)
array.push(@block1.sprite.y)
end
if need_dispose(@block2.sprite.y)
unless array.include?(@block2.sprite.y)
array.push(@block2.sprite.y)
end
end
if need_dispose(@block3.sprite.y)
unless array.include?(@block3.sprite.y)
array.push(@block3.sprite.y)
end
end
if need_dispose(@block4.sprite.y)
unless array.include?(@block4.sprite.y)
array.push(@block4.sprite.y)
end
end
unless array.size == 0
array.sort!
case array.size
when 1
$game_variables[ELS::ID] += 100
Audio.se_play("Audio/SE/1f",100,100)
when 2
$game_variables[ELS::ID] += 300
Audio.se_play("Audio/SE/2f",100,100)
when 3
$game_variables[ELS::ID] += 800
Audio.se_play("Audio/SE/3f",100,100)
when 4
$game_variables[ELS::ID] += 1500
Audio.se_play("Audio/SE/4f",100,100)
end
for i in array
if need_dispose(i)
dispose(i)
end
end
end
$scene.next_block_switch = true
$scene.time = 0
end
def if_end?
if $scene.table.include?([@block1.sprite.x,@block1.sprite.y+20,1])
return true
end
if $scene.table.include?([@block2.sprite.x,@block2.sprite.y+20,1])
return true
end
if $scene.table.include?([@block3.sprite.x,@block3.sprite.y+20,1])
return true
end
if $scene.table.include?([@block4.sprite.x,@block4.sprite.y+20,1])
return true
end
return false
end
def need_dispose(y)
for i in 0..11
if $scene.table[getI(i*20+ELS::PX,y)][2] == 0
return false
end
end
return true
end
def dispose(y)
# 消除
for i in 0..11
for j in 0...$scene.small_block.size
if $scene.small_block[j][1] == y and $scene.small_block[j][0] == i*20+ELS::PX
k = j
break
end
end
case $scene.small_block[k][3]
when 1
$scene.now_block[$scene.small_block[k][2]].block1.dispose
when 2
$scene.now_block[$scene.small_block[k][2]].block2.dispose
when 3
$scene.now_block[$scene.small_block[k][2]].block3.dispose
when 4
$scene.now_block[$scene.small_block[k][2]].block4.dispose
end
$scene.table[getI($scene.small_block[k][0],$scene.small_block[k][1])][2] = 0
$scene.small_block.delete_at(k)
for k in 0..21
if 420+ELS::PY-k*20<y
if $scene.table[getI(i*20+ELS::PX,420+ELS::PY-k*20)][2] == 1
$scene.table[getI(i*20+ELS::PX,420+ELS::PY-k*20)][2] = 0
$scene.table[getI(i*20+ELS::PX,420+ELS::PY-k*20+20)][2] = 1
end
end
end
end
# 下落
for i in 0...$scene.small_block.size
if $scene.small_block[1]<y
$scene.small_block[1] += 20
case $scene.small_block[3]
when 1
$scene.now_block[$scene.small_block[2]].block1.sprite.y += 20
when 2
$scene.now_block[$scene.small_block[2]].block2.sprite.y += 20
when 3
$scene.now_block[$scene.small_block[2]].block3.sprite.y += 20
when 4
$scene.now_block[$scene.small_block[2]].block4.sprite.y += 20
end
end
end
end
def min(a,b,c,d)
if a > b
a = b
end
if a > c
a = c
end
if a > d
a = d
end
return a
end
def max(a,b,c,d)
if d < a
d = a
end
if d < b
d = b
end
if d < c
d = c
end
return d
end
def getI(x,y)
return 12*((y-ELS::PY)/20)+(x-ELS::PX)/20
end
end
class Scene_Els
attr_accessor :score
attr_accessor :speed
attr_accessor :table
attr_accessor :time
attr_accessor :next_block_switch
attr_accessor :small_block
attr_accessor :block_nums
attr_accessor :now_block
attr_accessor :next_block
attr_accessor :game_over
def initialize(level=1,sc=10000)
$game_variables[ELS::ID] = 0 @Game_oveR = false
@score = sc
@initial_speed = level
@speed = level @Time = 0
@next_block_switch = false
@small_block = []
@block_nums = 1
@now_block = [nil]
@next_block = nil
@table = []
for i in 0..21
for j in 0..11
@table.push([j*ELS::W+ELS::PX,i*ELS::W+ELS::PY,0])
end
end
end
def main
# 背景
@bg = Sprite.new
@bg.bitmap = RPG::Cache.picture("background")
@result = Window_Result.new
# 初始化当前方块
@now_block[@block_nums] = Group_Block.new
if @now_block[@block_nums].w%2 == 0
@mx = (240-@now_block[@block_nums].w*20)/2
else
@mx = (240-(@now_block[@block_nums].w+1)*20)/2
end
@now_block[@block_nums].block1.sprite.x += ELS::PX+@mx
@now_block[@block_nums].block1.sprite.y += ELS::PY
@now_block[@block_nums].block2.sprite.x += ELS::PX+@mx
@now_block[@block_nums].block2.sprite.y += ELS::PY
@now_block[@block_nums].block3.sprite.x += ELS::PX+@mx
@now_block[@block_nums].block3.sprite.y += ELS::PY
@now_block[@block_nums].block4.sprite.x += ELS::PX+@mx
@now_block[@block_nums].block4.sprite.y += ELS::PY
# 初始化next方块
@next_block = Group_Block.new
@px = (80-@next_block.w*20)/2+273
@py = (80-@next_block.h*20)/2+203
if @next_block.w%2 == 0
@mx = (240-@next_block.w*20)/2
else
@mx = (240-(@next_block.w+1)*20)/2
end
@next_block.block1.sprite.x += ELS::PX+@px
@next_block.block1.sprite.y += ELS::PY+@py
@next_block.block2.sprite.x += ELS::PX+@px
@next_block.block2.sprite.y += ELS::PY+@py
@next_block.block3.sprite.x += ELS::PX+@px
@next_block.block3.sprite.y += ELS::PY+@py
@next_block.block4.sprite.x += ELS::PX+@px
@next_block.block4.sprite.y += ELS::PY+@py
# bgm
Audio.bgm_play("Audio/BGM/017-Theme06",100,100)
# 执行过渡
Graphics.transition
# 主循环
loop do
Graphics.update
Input.update
@result.update
# 速度计算
@speed = $game_variables[ELS::ID]/10000+1+@initial_speed
if @next_block_switch
@next_block_switch = false
@block_nums += 1
# 获取当前方块
@now_block[@block_nums] = @next_block
@now_block[@block_nums].block1.sprite.x = @next_block.block1.sprite.x-@px+@mx
@now_block[@block_nums].block1.sprite.y = @next_block.block1.sprite.y-@py
@now_block[@block_nums].block2.sprite.x = @next_block.block2.sprite.x-@px+@mx
@now_block[@block_nums].block2.sprite.y = @next_block.block2.sprite.y-@py
@now_block[@block_nums].block3.sprite.x = @next_block.block3.sprite.x-@px+@mx
@now_block[@block_nums].block3.sprite.y = @next_block.block3.sprite.y-@py
@now_block[@block_nums].block4.sprite.x = @next_block.block4.sprite.x-@px+@mx
@now_block[@block_nums].block4.sprite.y = @next_block.block4.sprite.y-@py
if @now_block[@block_nums].if_end?
# $scene = Scene_Gameover.new
Audio.me_play("Audio/ME/005-Defeat01",100,100)
$game_switches[ELS::WIN_ID] = false
$scene = Scene_Map.new
end
# 产生下一方块
@next_block = Group_Block.new
@px = (80-@next_block.w*20)/2+273
@py = (80-@next_block.h*20)/2+203
@mx = (240-@next_block.w*20)/2
if @next_block.w%2 == 0
@mx = (240-@next_block.w*20)/2
else
@mx = (240-(@next_block.w+1)*20)/2
end
@next_block.block1.sprite.x += ELS::PX+@px
@next_block.block1.sprite.y += ELS::PY+@py
@next_block.block2.sprite.x += ELS::PX+@px
@next_block.block2.sprite.y += ELS::PY+@py
@next_block.block3.sprite.x += ELS::PX+@px
@next_block.block3.sprite.y += ELS::PY+@py
@next_block.block4.sprite.x += ELS::PX+@px
@next_block.block4.sprite.y += ELS::PY+@py
end
if $scene != self
break
end
# 自动下落计时
@time += 1
if @time == (200/(@speed+9)).to_i
@now_block[@block_nums].block_auto_down
@time = 0
end
if Input.trigger?(Input::UP)
@now_block[@block_nums].change_direction
$game_system.se_play($data_system.decision_se)
end
if Input.trigger?(Input::DOWN)
@now_block[@block_nums].move_down
$game_system.se_play($data_system.decision_se)
end
if Input.repeat?(Input::LEFT)
@now_block[@block_nums].move_left
$game_system.se_play($data_system.decision_se)
end
if Input.repeat?(Input::RIGHT)
@now_block[@block_nums].move_right
$game_system.se_play($data_system.decision_se)
end
if Input.trigger?(Input::C)
Audio.se_play("Audio/SE/start",100,100)
start
end
if Input.trigger?(Input::B)
# 胜利音效
Audio.me_play("Audio/ME/005-Defeat01",100,100)
$game_switches[ELS::WIN_ID] = false
$scene = Scene_Map.new
end
# judge win?
if $game_variables[ELS::ID]>=@score
# 胜利音效
Audio.me_play("Audio/ME/001-Victory01",100,100)
$game_switches[ELS::WIN_ID] = true
$scene = Scene_Map.new
end
if $scene != self
break
end
end
Graphics.freeze
# 释放方块
for i in 0...@small_block.size
case @small_block[3]
when 1
@now_block[@small_block[2]].block1.dispose
when 2
@now_block[@small_block[2]].block2.dispose
when 3
@now_block[@small_block[2]].block3.dispose
when 4
@now_block[@small_block[2]].block4.dispose
end
end
@now_block[@block_nums].block1.dispose
@now_block[@block_nums].block2.dispose
@now_block[@block_nums].block3.dispose
@now_block[@block_nums].block4.dispose
@next_block.block1.dispose
@next_block.block2.dispose
@next_block.block3.dispose
@next_block.block4.dispose
# 释放背景
@bg.dispose
# 释放窗口
@result.dispose
end
def start
loop do
Graphics.update
Input.update
if Input.trigger?(Input::C)
Audio.se_play("Audio/SE/start",100,100)
break
end
end
end
end
class Window_Result < Window_Base
def initialize
super(440, 0, 200, 480)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = ["楷体_GB2312","黑体"]
self.opacity = 0
refresh
end
def refresh
self.contents.clear
if not $scene.is_a?(Scene_Els)
return
end
@n1 = $game_variables[ELS::ID]
@n2 = $scene.speed
cx1 = contents.text_size(@n1.to_s).width
cx2 = contents.text_size(@n2.to_s).width
self.contents.font.size = 22
self.contents.font.color = Color.new(255,20,20)
self.contents.font.bold = false
self.contents.draw_text(80,36,64,32,@n1.to_s)
self.contents.font.size = 42
self.contents.font.color = Color.new(255,20,20)
self.contents.font.bold = true
self.contents.draw_text(80,116,64,42,@n2.to_s,1)
end
def update
super
if not $scene.is_a?(Scene_Els)
return
end
if @n1 != $game_variables[ELS::ID] or @n2 != $scene.speed
refresh
end
end
end