さて、あとは、回転時に、
壁めり込むなら移動してみる、
という機能です。
こんな処理をしてみれば、
回避できそうな気がします。
これは、
回転処理をしたあとで、
isHitを使ってずらしてみればよいですね。
procedure TPiece.Main;
begin
(ry
if k_z=1 then begin
SpinLeft;
if isHit(0,0) then SpinRight;
end;
if k_x=1 then begin
SpinRight;
if isHit(0,0) then SpinLeft;
end;
(ry
end;
ここを激しく書き換えます。
procedure TPiece.Main;
begin
(ry
if k_z=1 then begin
SpinLeft;
if isHit(0,0) then
if not isHit(-1,0) then x:=x-1 else
if not isHit(1,0) then x:=x+1 else
if not isHit(-2,0) then x:=x-2 else
if not isHit(2,0) then x:=x+2 else
SpinRight;
end;
if k_x=1 then begin
SpinRight;
if isHit(0,0) then
if not isHit(-1,0) then x:=x-1 else
if not isHit(1,0) then x:=x+1 else
if not isHit(-2,0) then x:=x-2 else
if not isHit(2,0) then x:=x+2 else
SpinLeft;
end;
(ry
end;
たまにはズザーッ って感じに書いてみました。
begin - end; をつけてわかりやすくすると↓
SpinLeft;
if isHit(0,0) then begin
if not isHit(-1,0) then begin
x:=x-1
end else begin
if not isHit(1,0) then begin
x:=x+1
end else begin
if not isHit(-2,0) then begin
x:=x-2
end else begin
if not isHit(2,0) then begin
x:=x+2
end else begin
SpinRight;
end;
end;
end;
end;
end;
わかりやすくNEEEEEEEEEEEEEEEET
感じとしては、
not isHit(xをずらしてみる量,0)
が 真なら、 「xをずらしてみたら当たらない」
ということなので、
then begin - end; で、ずらしてみる量を実際に移動して、
ダメだったらelse begin- end; にすすんで、
再び、違う量をずらしてみる、というように。
「試して当たらないなら移動」
「当たるなら試すのを変える」
を繰り返していって、
もうだめだ!
となると、SpinRightする。
つまり、
試していってどーもだめだったときは、
最初に回転してみた分を元に戻して、移動もしない
ってことです。
これで完成!!!?
コンテンツ
最新の12件
2023-06-12
2021-02-15
2013-06-19
2012-07-14
2012-02-04
2012-01-06
2011-03-31
2010-08-26
2010-03-15
2009-10-21
2009-02-12
2008-11-18
メニュー編集
- counter: 998
- today: 1
- yesterday: 0
- online: 1