bitterharvest’s diary

A Bitter Harvestは小説の題名。作者は豪州のPeter Yeldham。苦闘の末に勝ちえた偏見からの解放は命との引換になったという悲しい物語

シューティングゲーム手習い:複数投石(一石二鳥ならぬ二石一鳥)

1.複数の石を同時に投げる

今回はこの動画のように複数の石、といっても二つだが、を投げる場合を考える。

プログラムの修正はそれほど難しくはない。鳥と石の軌跡を計算しているupdateに新たな石を加える(三行目が新たに加わった石で、鳥には当たらず鳥を通り過ぎさせてしまう)。

update :: SF () ((Pos, Vel), (Pos, Vel), (Pos, Vel))
update = proc () -> do
  (pos1, vel1) <- throwingStone ((-8), 0) (1, 15) -< ()
  (pos2, vel2) <- throwingStone ((-8), 0) (4, 17) -< ()
  (pos3, vel3) <- bird ((-8), 10) (4, 0) -< ()
  returnA  -<  ((pos1, vel1), (pos2, vel2), (pos3, vel3)) 

これに伴って描画の部分drawとclearAndRenderにも新たな石を加える。

draw :: SF ((Pos, Vel), (Pos, Vel), (Pos, Vel)) (IO ())
draw = arr clearAndRender
clearAndRender :: ((Pos, Vel), (Pos, Vel), (Pos, Vel)) -> IO ()
clearAndRender ((pos1, vel1), (pos2, vel2), (pos3, vel3)) = do
    clear [ ColorBuffer, DepthBuffer ]
    loadIdentity
    renderPlayer $ vector3 (unsafeCoerce (fst pos1)) (unsafeCoerce (snd pos1)) (-30)
    renderPlayer $ vector3 (unsafeCoerce (fst pos2)) (unsafeCoerce (snd pos2)) (-30)
    renderPlayer $ vector3 (unsafeCoerce (fst pos3)) (unsafeCoerce (snd pos3)) (-30)