赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 5 |
经验 | 13891 |
最后登录 | 2021-4-14 |
在线时间 | 329 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 524
- 在线时间
- 329 小时
- 注册时间
- 2013-5-16
- 帖子
- 740
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 恶魔般的天使 于 2013-6-17 17:09 编辑
俄罗斯方块 module ELS
W = 20
PX = 270
PY = 20
PIC = true
ID = 1000
WIN_ID = 1000
end
=begin
基本: 变换 转点(相对与基本的)
■■
■■ → 无 不需
■■■■ → ■ 2
■
■
■
■ ■ ■
■■■ → ■■ ■■■ ■■ 2
■ ■ ■
■ ■■■ ■■
■ →■ ■ ■ 2
■■ ■ ■■■
■ ■■
■ →■ ■ ■■■ 2
■■ ■■■ ■ ■
■
■■ → ■■ 2
■ ■■
■
■■ →■■ 2
■ ■■
=end
class Small_Block
attr_accessor :block
def initialize(color)
case color
when 0
@BLock = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(240,200,64))
@block.fill_rect(20-1,0, 1, 20, Color.new(240,200,64))
@block.fill_rect(0, 0, 20, 1, Color.new(240,200,64))
@block.fill_rect(0,20-1, 20, 1, Color.new(240,200,64))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(250,161,7))
when 1
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(231,81,81))
@block.fill_rect(20-1,0, 1, 20, Color.new(231,81,81))
@block.fill_rect(0, 0, 20, 1, Color.new(231,81,81))
@block.fill_rect(0,20-1, 20, 1, Color.new(231,81,81))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(211,35,35))
when 2
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(209,28,242))
@block.fill_rect(20-1,0, 1, 20, Color.new(209,28,242))
@block.fill_rect(0, 0, 20, 1, Color.new(209,28,242))
@block.fill_rect(0,20-1, 20, 1, Color.new(209,28,242))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(189,28,242))
when 3
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(202,241,44))
@block.fill_rect(20-1,0, 1, 20, Color.new(202,241,44))
@block.fill_rect(0, 0, 20, 1, Color.new(202,241,44))
@block.fill_rect(0,20-1, 20, 1, Color.new(202,241,44))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(163,203,5))
when 4
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(81,201,231))
@block.fill_rect(20-1,0, 1, 20, Color.new(81,201,231))
@block.fill_rect(0, 0, 20, 1, Color.new(81,201,231))
@block.fill_rect(0,20-1, 20, 1, Color.new(81,201,231))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(81,180,231))
when 5
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(73,188,46))
@block.fill_rect(20-1,0, 1, 20, Color.new(73,188,46))
@block.fill_rect(0, 0, 20, 1, Color.new(73,188,46))
@block.fill_rect(0,20-1, 20, 1, Color.new(73,188,46))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(33,156,4))
when 6
@block = Bitmap.new(20,20)
@block.fill_rect(0, 0, 1, 20, Color.new(84,121,241))
@block.fill_rect(20-1,0, 1, 20, Color.new(84,121,241))
@block.fill_rect(0, 0, 20, 1, Color.new(84,121,241))
@block.fill_rect(0,20-1, 20, 1, Color.new(84,121,241))
@block.fill_rect(1,1, 20-2, 20-2, Color.new(44,91,241))
end
end
end
class Big_Block
attr_accessor :sprite
attr_accessor :x
attr_accessor :y
def initialize(x,y,color)
@sprite = Sprite.new
if ELS::PIC
@sprite.bitmap = Bitmap.new(20,20)
@sprite.bitmap.blt(0,0,RPG::Cache.picture("block"),Rect.new(color*20,0,20,20))
else
@sprite.bitmap = Small_Block.new(color).block
end
@sprite.x=x
@sprite.y=y
end
def dispose
@sprite.dispose
end
end
class Group_Block
attr_accessor :x # 方块组 左上 角那个小方块的 x
attr_accessor :y # 方块组 左上 角那个小方块的 y
attr_accessor :w
attr_accessor :h
attr_accessor :block1
attr_accessor :block2
attr_accessor :block3
attr_accessor :block4
attr_accessor :blockgroup
attr_accessor :type
def initialize
@type = rand(7)
case @type
when 0
@block1 = Big_Block.new(0,0,0)
@block2 = Big_Block.new(ELS::W,0,0)
@block3 = Big_Block.new(0,ELS::W,0)
@block4 = Big_Block.new(ELS::W,ELS::W,0)
@x=0
@y=0
@w=2
@h=2
@shape = 0
when 1
case rand(2)
when 0
@block1 = Big_Block.new(0,0,1)
@block2 = Big_Block.new(ELS::W,0,1)
@block3 = Big_Block.new(ELS::W*2,0,1)
@block4 = Big_Block.new(ELS::W*3,0,1)
@x=0
@y=0
@w=4
@h=1
@shape = 0
when 1
@block1 = Big_Block.new(0,0,1)
@block2 = Big_Block.new(0,20,1)
@block3 = Big_Block.new(0,40,1)
@block4 = Big_Block.new(0,60,1)
@x=0
@y=0
@w=1
@h=4
@shape = 1
end
when 2
case rand(4)
when 0
@block1 = Big_Block.new(ELS::W,0,2)
@block2 = Big_Block.new(0,ELS::W,2)
@block3 = Big_Block.new(ELS::W,ELS::W,2)
@block4 = Big_Block.new(ELS::W*2,ELS::W,2)
@x=ELS::W
@y=0
@w=3
@h=2
@shape = 0
when 1
@block1 = Big_Block.new(20,20,2)
@block2 = Big_Block.new(0,0,2)
@block3 = Big_Block.new(0,ELS::W,2)
@block4 = Big_Block.new(0,40,2)
@x=20
@y=20
@w=2
@h=3
@shape = 1
when 2
@block1 = Big_Block.new(ELS::W,20,2)
@block2 = Big_Block.new(40,0,2)
@block3 = Big_Block.new(ELS::W,0,2)
@block4 = Big_Block.new(0,0,2)
@x=20
@y=20
@w=3
@h=2
@shape = 2
when 3
@block1 = Big_Block.new(0,20,2)
@block2 = Big_Block.new(20,40,2)
@block3 = Big_Block.new(ELS::W,ELS::W,2)
@block4 = Big_Block.new(20,0,2)
@x=0
@y=20
@w=2
@h=3
@shape = 3
end
when 3
case rand(4)
when 0
@block1 = Big_Block.new(0,0,3)
@block2 = Big_Block.new(0,ELS::W,3)
@block3 = Big_Block.new(0,ELS::W*2,3)
@block4 = Big_Block.new(ELS::W,ELS::W*2,3)
@x=0
@y=0
@w=2
@h=3
@shape = 0
when 1
@block1 = Big_Block.new(40,0,3)
@block2 = Big_Block.new(20,0,3)
@block3 = Big_Block.new(0,0,3)
@block4 = Big_Block.new(0,20,3)
@x=40
@y=0
@w=3
@h=2
@shape = 1
when 2
@block1 = Big_Block.new(20,40,3)
@block2 = Big_Block.new(20,20,3)
@block3 = Big_Block.new(20,0,3)
@block4 = Big_Block.new(0,0,3)
@x=20
@y=40
@w=2
@h=3
@shape = 2
when 3
@block1 = Big_Block.new(0,20,3)
@block2 = Big_Block.new(20,20,3)
@block3 = Big_Block.new(40,20,3)
@block4 = Big_Block.new(40,0,3)
@x=0
@y=20
@w=3
@h=2
@shape = 3
end
when 4
case rand(4)
when 0
@block1 = Big_Block.new(ELS::W,0,4)
@block2 = Big_Block.new(ELS::W,ELS::W,4)
@block3 = Big_Block.new(ELS::W,ELS::W*2,4)
@block4 = Big_Block.new(0,ELS::W*2,4)
@x=20
@y=0
@w=2
@h=3
@shape = 0
when 1
@block1 = Big_Block.new(40,20,4)
@block2 = Big_Block.new(20,20,4)
@block3 = Big_Block.new(0,20,4)
@block4 = Big_Block.new(0,0,4)
@x=40
@y=20
@w=3
@h=2
@shape = 1
when 2
@block1 = Big_Block.new(0,40,4)
@block2 = Big_Block.new(0,20,4)
@block3 = Big_Block.new(0,0,4)
@block4 = Big_Block.new(20,0,4)
@x=0
@y=40
@w=2
@h=3
@shape = 2
when 3
@block1 = Big_Block.new(0,0,4)
@block2 = Big_Block.new(20,0,4)
@block3 = Big_Block.new(40,0,4)
@block4 = Big_Block.new(40,20,4)
@x=0
@y=0
@w=3
@h=2
@shape = 3
end
when 5
case rand(2)
when 0
@block1 = Big_Block.new(0,0,5)
@block2 = Big_Block.new(0,ELS::W,5)
@block3 = Big_Block.new(ELS::W,ELS::W,5)
@block4 = Big_Block.new(ELS::W,ELS::W*2,5)
@x=0
@y=0
@w=2
@h=3
@shape = 0
when 1
@block1 = Big_Block.new(40,0,5)
@block2 = Big_Block.new(20,0,5)
@block3 = Big_Block.new(20,20,5)
@block4 = Big_Block.new(0,20,5)
@x=40
@y=0
@w=3
@h=2
@shape = 1
end
when 6
case rand(2)
when 0
@block1 = Big_Block.new(ELS::W,0,6)
@block2 = Big_Block.new(ELS::W,ELS::W,6)
@block3 = Big_Block.new(0,ELS::W,6)
@block4 = Big_Block.new(0,ELS::W*2,6)
@x=20
@y=0
@w=2
@h=3
@shape = 0
when 1
@block1 = Big_Block.new(0,0,6)
@block2 = Big_Block.new(20,0,6)
@block3 = Big_Block.new(20,20,6)
@block4 = Big_Block.new(40,20,6)
@x=0
@y=0
@w=3
@h=2
@shape = 1
end
end
end
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
def change_direction
# 哎,这几天头昏,懒得去想什么算法,有时候觉得直接写还简单一点呢~~~
oldX = [@block1.sprite.x,@block2.sprite.x,@block3.sprite.x,@block4.sprite.x]
oldY = [@block1.sprite.y,@block2.sprite.y,@block3.sprite.y,@block4.sprite.y]
case @type
when 0
return
when 1
if @shape == 2
@shape = 0
end
if @shape == 0
oldX[0] += 40
oldY[0] -= 20
oldX[1] += 20
oldY[2] += 20
oldX[3] -= 20
oldY[3] += 40
elsif @shape == 1
oldX[0] -= 40
oldY[0] += 20
oldX[1] -= 20
oldY[2] -= 20
oldX[3] += 20
oldY[3] -= 40
end
when 2
for i in 0..3
deltaX = oldX-oldX[2]
deltaY = oldY-oldY[2]
oldX = oldX[2]-deltaY
oldY = oldY[2]+deltaX
end
when 3
if @shape == 4
@shape = 0
end
if @shape == 0
oldX[0] += 40
oldX[1] += 20
oldY[1] -= 20
oldY[2] -= 40
oldX[3] -= 20
oldY[3] -= 20
elsif @shape == 1
oldX[0] -= 20
oldY[0] += 40
oldY[1] += 20
oldX[2] += 20
oldY[3] -= 20
elsif @shape == 2
oldX[0] -= 20
oldY[0] -= 20
oldX[2] += 20
oldY[2] += 20
oldX[3] += 40
elsif @shape ==3
oldY[0] -= 20
oldX[1] -= 20
oldX[2] -= 40
oldY[2] += 20
oldX[3] -= 20
oldY[3] += 40
end
when 4
if @shape == 4
@shape = 0
end
if @shape == 0
oldY[0] += 40
oldX[1] -= 20
oldY[1] += 20
oldX[2] -= 40
oldX[3] -= 20
oldY[3] -= 20
elsif @shape == 1
oldX[0] -= 20
oldY[1] -= 20
oldX[2] += 20
oldY[2] -= 40
oldX[3] += 40
oldY[3] -= 20
elsif @shape == 2
oldX[0] -= 20
oldY[0] -= 20
oldX[2] += 20
oldY[2] += 20
oldY[3] += 40
elsif @shape ==3
oldX[0] += 40
oldY[0] -= 20
oldX[1] += 20
oldY[2] += 20
oldX[3] -= 20
end
when 5
if @shape == 2
@shape = 0
end
if @shape == 0
oldX[0] += 40
oldY[0] += 20
oldX[1] += 20
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
|
|