|
Revision 22619, 1.1 kB
(checked in by mokehehe, 5 years ago)
|
|
Change comment to englist
|
| Line | |
|---|
| 1 | -- -*- mode: haskell; Encoding: UTF-8 -*- |
|---|
| 2 | -- Block bounce animation |
|---|
| 3 | |
|---|
| 4 | module Actor.AnimBlock ( |
|---|
| 5 | newAnimBlock |
|---|
| 6 | ) where |
|---|
| 7 | |
|---|
| 8 | import Actor (Actor(..)) |
|---|
| 9 | import AppUtil (cellCrd, putimg) |
|---|
| 10 | import Const |
|---|
| 11 | import Field (Cell, chr2img) |
|---|
| 12 | import Event (Event(..)) |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | data AnimBlock = AnimBlock { |
|---|
| 16 | startcy :: Int, |
|---|
| 17 | x :: Int, |
|---|
| 18 | y :: Int, |
|---|
| 19 | vy :: Int, |
|---|
| 20 | chr :: Cell |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | instance Actor AnimBlock where |
|---|
| 24 | update fld self |
|---|
| 25 | | not (bDead self) = (self', ev') |
|---|
| 26 | | otherwise = (self, []) |
|---|
| 27 | |
|---|
| 28 | where |
|---|
| 29 | vy' = vy self + gravity |
|---|
| 30 | y' = y self + vy' |
|---|
| 31 | self' = self { vy = vy', y = y' } |
|---|
| 32 | ev' = if bDead self' |
|---|
| 33 | then [EvSetField (cellCrd $ x self) (startcy self) $ chr self] |
|---|
| 34 | else [] |
|---|
| 35 | |
|---|
| 36 | render self imgres scrx sur = |
|---|
| 37 | putimg sur imgres (chr2img $ chr self) (x self `div` one - scrx) (y self `div` one - 8) |
|---|
| 38 | |
|---|
| 39 | bDead self = vy self > 0 && y self >= startcy self * chrSize * one |
|---|
| 40 | |
|---|
| 41 | newAnimBlock :: Int -> Int -> Cell -> AnimBlock |
|---|
| 42 | newAnimBlock cx cy c = |
|---|
| 43 | AnimBlock { startcy = cy, x = cx * chrSize * one, y = cy * chrSize * one, vy = -3 * one, chr = cc } |
|---|
| 44 | where |
|---|
| 45 | cc = case c of |
|---|
| 46 | '?' -> '#' |
|---|
| 47 | 'K' -> '#' |
|---|
| 48 | x -> x |
|---|