| 1 | -- クリボー |
|---|
| 2 | |
|---|
| 3 | module Actor.Kuribo ( |
|---|
| 4 | newKuribo |
|---|
| 5 | ) where |
|---|
| 6 | |
|---|
| 7 | import Multimedia.SDL (blitSurface, pt) |
|---|
| 8 | |
|---|
| 9 | import Actor (Actor(..), ActorWrapper(..)) |
|---|
| 10 | import Const |
|---|
| 11 | import AppUtil |
|---|
| 12 | import Images |
|---|
| 13 | import Player (setPlayerDamage, getPlayerVY, stampPlayer) |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | data Kuribo = Kuribo { |
|---|
| 17 | x :: Int, |
|---|
| 18 | y :: Int, |
|---|
| 19 | vx :: Int, |
|---|
| 20 | vy :: Int, |
|---|
| 21 | cnt :: Int |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | instance Actor Kuribo where |
|---|
| 25 | update fld self = (self { x = x self + vx self, cnt = cnt self + 1 }, []) |
|---|
| 26 | |
|---|
| 27 | render self imgres scrx sur = do |
|---|
| 28 | blitSurface (getImageSurface imgres imgtype) Nothing sur (pt (x self `div` one - chrSize `div` 2 - scrx) (y self `div` one - 15 - 8)) |
|---|
| 29 | return () |
|---|
| 30 | where |
|---|
| 31 | imgtype = [ImgKuri0, ImgKuri1] !! (cnt self `mod` 16 `div` 8) |
|---|
| 32 | |
|---|
| 33 | getHitRect self = Just $ Rect (xx - 8) (yy - 16) (xx + 8) yy |
|---|
| 34 | where |
|---|
| 35 | xx = x self `div` one |
|---|
| 36 | yy = y self `div` one |
|---|
| 37 | |
|---|
| 38 | onHit pl self |
|---|
| 39 | | stamp = (stampPlayer pl, Just $ ActorWrapper $ newStampedKuribo (x self `div` one - chrSize `div` 2) (y self `div` one)) |
|---|
| 40 | | otherwise = (setPlayerDamage pl, Just $ ActorWrapper self) |
|---|
| 41 | where |
|---|
| 42 | stamp = getPlayerVY pl > 0 |
|---|
| 43 | |
|---|
| 44 | newKuribo :: Int -> Int -> Kuribo |
|---|
| 45 | newKuribo cx cy = |
|---|
| 46 | Kuribo { x = cx * chrSize * one + chrSize * one `div` 2, y = (cy+1) * chrSize * one, vx = -one `div` 2, vy = 0, cnt = 0 } |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | -- 踏みつけられたクリボー |
|---|
| 50 | data StampedKuribo = StampedKuribo { |
|---|
| 51 | sx :: Int, |
|---|
| 52 | sy :: Int, |
|---|
| 53 | ccnt :: Int |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | instance Actor StampedKuribo where |
|---|
| 57 | update fld self = (self { ccnt = ccnt self + 1 }, []) |
|---|
| 58 | |
|---|
| 59 | render self imgres scrx sur = do |
|---|
| 60 | blitSurface (getImageSurface imgres ImgKuriDead) Nothing sur (pt (sx self - scrx) (sy self - 7 - 8)) |
|---|
| 61 | return () |
|---|
| 62 | |
|---|
| 63 | bDead self = ccnt self >= frameRate `div` 2 |
|---|
| 64 | |
|---|
| 65 | newStampedKuribo sx' sy' = StampedKuribo { sx = sx', sy = sy', ccnt = 0 } |
|---|