root/lang/haskell/nario/Actor/Kuribo.hs @ 20775

Revision 20691, 1.7 kB (checked in by mokehehe, 5 years ago)

敵との当たり判定追加

Line 
1-- クリボー
2
3module Actor.Kuribo (
4        newKuribo
5) where
6
7import Multimedia.SDL (blitSurface, pt)
8
9import Actor (Actor(..), ActorWrapper(..))
10import Const
11import AppUtil
12import Images
13import Player (setPlayerDamage, getPlayerVY, stampPlayer)
14
15
16data Kuribo = Kuribo {
17        x :: Int,
18        y :: Int,
19        vx :: Int,
20        vy :: Int,
21        cnt :: Int
22        }
23
24instance 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
44newKuribo :: Int -> Int -> Kuribo
45newKuribo 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-- 踏みつけられたクリボー
50data StampedKuribo = StampedKuribo {
51        sx :: Int,
52        sy :: Int,
53        ccnt :: Int
54        }
55
56instance 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
65newStampedKuribo sx' sy' = StampedKuribo { sx = sx', sy = sy', ccnt = 0 }
Note: See TracBrowser for help on using the browser.