Changeset 19999 for lang/haskell

Show
Ignore:
Timestamp:
09/27/08 09:22:06 (2 months ago)
Author:
mokehehe
Message:

横移動、アニメ追加

Location:
lang/haskell/nario
Files:
4 modified
3 moved

Legend:

Unmodified
Added
Removed
  • lang/haskell/nario/Const.hs

    r19996 r19999  
    22 
    33 
    4 -- �Œ菬���_�ł̂P 
    5 one = 256 
     4-- 固定小数点での1 
     5one = 256 :: Int 
     6 
     7-- 1キャラのサイズ 
     8chrSize = 16 :: Int 
    69 
    710 
    8  
    9 -- �摜 
     11-- 画像 
    1012data ImageType = 
    1113                ImgNario00 | ImgNario01 | ImgNario02 | ImgNario03 | ImgNario04 
  • lang/haskell/nario/Main.hs

    r19996 r19999  
    77import Control.Monad (when) 
    88import Data.IORef (newIORef, readIORef, writeIORef, modifyIORef) 
    9 import Data.Maybe (fromJust) 
    109 
    1110import SDLUtil 
    1211import Util 
    1312import Player 
     13import Const 
    1414 
    1515----------------------------------- 
    16 -- �V�X�e����----------------------------------- 
     16-- システム周り  
     17----------------------------------- 
    1718 
    18 -- ���̒� 
     19-- 種種の定義 
    1920 
    2021wndTitle = "Nario in Haskell" 
    2122wndSize  = sz 256 240 
    2223 
    23 -- �w�i�F 
    24 backColor = 0x2891ff            -- �� 
     24-- 背景色 
     25backColor = 0x2891ff            --  
    2526 
    2627 
     
    2930 
    3031 
    31 -- �}�b�v 
     32-- マップ 
    3233 
    3334fieldMap = [ 
     
    6869 
    6970 
    70 -- ���C�����[�v 
     71-- メインループ 
    7172 
    7273main :: IO () 
     
    107108        sdlQuit 
    108109 
    109 -- �Q�[���̏� 
     110-- ゲームの状態 
    110111data GameState = 
    111112        GameState { 
     
    113114        } 
    114115 
    115 -- �J�n�� 
     116-- 開始状態 
    116117initState :: GameState 
    117118initState = 
     
    121122 
    122123 
    123 -- ���t���[���̏��� 
     124-- 毎フレームの処理 
    124125onProcess :: KeyProc -> GameState -> GameState 
    125126onProcess kp gs 
    126         | otherwise             = gs { pl = updatePlayer (pl gs) kp} 
     127        | otherwise             = gs { pl = updatePlayer kp (pl gs) } 
    127128 
    128129 
    129 -- �`�揈�� 
     130-- 描画処理 
    130131onDraw :: Surface -> ImageResource -> GameState -> IO () 
    131132onDraw sur imgres gs = do 
  • lang/haskell/nario/Player.hs

    r19996 r19999  
    1 module Player where 
     1 
     2-- プレーヤー 
     3 
     4module Player ( 
     5        Player(..), 
     6        newPlayer, 
     7        updatePlayer, 
     8        renderPlayer 
     9) where 
    210 
    311import Multimedia.SDL 
     
    715import Const 
    816 
    9 -- �v���[���[ 
    1017 
    1118data Player = Player { 
    1219        x :: Int, 
    1320        y :: Int, 
    14         lr :: Int 
     21        vx :: Int, 
     22        vy :: Int, 
     23        stand :: Bool, 
     24 
     25        lr :: Int, 
     26        pat :: Int, 
     27        anm :: Int 
    1528        } 
    1629 
    1730newPlayer = Player { 
    18         x = 1 * 16 * one, 
    19         y = 12 * 16 * one, 
    20         lr = 1 
     31        x = 1 * chrSize * one, 
     32        y = 13 * chrSize * one - 1, 
     33        vx = 0, 
     34        vy = 0, 
     35        stand = True, 
     36 
     37        lr = 1, 
     38        pat = 0, 
     39        anm = 0 
    2140        } 
    2241 
    23 updatePlayer :: Player -> KeyProc -> Player 
    24 updatePlayer player kp = 
    25         player { x = x', y = y', lr = lr' } 
     42maxVx = one * 3 
     43acc = one `div` 6 
     44 
     45 
     46patStop = 0 
     47patWalk = 1 
     48walkPatNum = 3 
     49patJump = patWalk + walkPatNum 
     50 
     51imgTable = [ 
     52        [ImgNario00, ImgNario01, ImgNario02, ImgNario03, ImgNario04], 
     53        [ImgNario10, ImgNario11, ImgNario12, ImgNario13, ImgNario14] 
     54        ] 
     55 
     56 
     57-- 横移動 
     58moveLR :: KeyProc -> Player -> Player 
     59moveLR kp player = 
     60        player { x = x', vx = vx', lr = lr', pat = pat', anm = anm' } 
    2661        where 
    27                 x' 
    28                         | isPressed (kp PadL)   = (x player) - 1 * one 
    29                         | isPressed (kp PadR)   = (x player) + 1 * one 
    30                         | otherwise                             = x player 
     62                ax = (-padl + padr) * acc 
     63                vx' 
     64                        | ax /= 0       = rangeadd (vx player) ax (-maxspd) maxspd 
     65                        | otherwise     = friction (vx player) acc 
     66                x' = (x player) + vx' 
     67                padl = if isPressed (kp PadL) then 1 else 0 
     68                padr = if isPressed (kp PadR) then 1 else 0 
     69                maxspd 
     70                        | isPressed (kp PadB)   = maxVx * 2 
     71                        | otherwise                             = maxVx 
     72 
     73                lr' = 
     74                        case (-padl + padr) of 
     75                                0       -> lr player 
     76                                -1      -> 0 
     77                                1       -> 1 
     78                pat' 
     79                        | vx' == 0              = patStop 
     80                        | otherwise             = (anm' `div` anmCnt) + patWalk 
     81                anm' 
     82                        | vx' == 0              = 0 
     83                        | otherwise             = ((anm player) + (abs vx')) `mod` (walkPatNum * anmCnt) 
     84                anmCnt = maxVx * 3 
     85 
     86 
     87-- 縦移動 
     88jumpOrFall :: KeyProc -> Player -> Player 
     89jumpOrFall kp player = 
     90        player { y = y' } 
     91        where 
    3192                y' 
    3293                        | isPressed (kp PadU)   = (y player) - 1 * one 
    3394                        | isPressed (kp PadD)   = (y player) + 1 * one 
    3495                        | otherwise                             = y player 
    35                 lr' 
    36                         | isPressed (kp PadL)   = 0 
    37                         | isPressed (kp PadR)   = 1 
    38                         | otherwise                                     = lr player 
    3996 
    40 renderPlayer sur player imgres = 
    41         blitSurface (getImageSurface imgres chr) Nothing sur pos 
     97 
     98updatePlayer :: KeyProc -> Player -> Player 
     99updatePlayer kp = 
     100        jumpOrFall kp . moveLR kp 
     101 
     102 
     103renderPlayer sur player imgres = do 
     104        blitSurface (getImageSurface imgres imgtype) Nothing sur pos 
    42105        where 
    43                 pos = pt ((x player) `div` one) ((y player) `div` one) 
    44                 chr = if (lr player) == 0 
    45                                 then ImgNario00 
    46                                 else ImgNario10 
     106                pos = pt ((x player) `div` one) ((y player) `div` one - chrSize) 
     107                imgtype = imgTable !! (lr player) !! (pat player) 
  • lang/haskell/nario/README.txt

    r19996 r19999  
    99http://fxp.hp.infoseek.co.jp/haskell/HSDL/ 
    1010 
     11 
     12 
     13������  �J�[�\���L�[, ijkl 
     14                �㉺���E 
     15 
     16        �X�y�[�X�L�[ 
     17                A�{�^�� 
     18 
     19        �V�t�g�L�[ 
     20                B�{�^�� 
     21 
  • lang/haskell/nario/Sound.hs

    r19996 r19999  
    99 
    1010 
    11 -- �‚����c 
     11-- 鳴らない… 
    1212playAudioData ad = do 
    1313        case audioSpec ad of 
  • lang/haskell/nario/Util.hs

    r19996 r19999  
    44import Data.IORef (newIORef, readIORef, writeIORef, modifyIORef) 
    55import Control.Concurrent (threadDelay) 
     6import Data.Maybe (fromJust) 
    67import Multimedia.SDL 
    78 
    89import Const 
    910 
    10 -- �L�[�{�[�h���� 
     11 
     12-- ユーティリティ関数 
     13 
     14-- x に d を加算した結果が x0~x1 の範囲内を超えないようにする 
     15-- もとから範囲外だったときはそれ以上遠ざからないように 
     16rangeadd x d x0 x1 
     17        | d > 0         = if x < x1 then min (x + d) x1 else x 
     18        | d < 0         = if x > x0 then max (x + d) x0 else x 
     19        | otherwise     = x 
     20 
     21 
     22-- 値を0に近づける 
     23friction x d 
     24        | x > d         = x - d 
     25        | x < -d        = x + d 
     26        | otherwise     = 0 
     27 
     28 
     29 
     30-- キーボード処理 
    1131 
    1232data PadBtn = 
     
    4161mapPhyKey PadB = [SDLK_LSHIFT, SDLK_RSHIFT] 
    4262 
    43 -- ���Ԓ��� 
     63-- 時間調節 
    4464 
    4565elapseTime :: Integer -> IO (IO (Int,Bool)) 
     
    6989 
    7090 
    71 -- �摜���\�[�X 
     91-- 画像リソース 
    7292type ImageResource = [(ImageType, Surface)] 
    7393 
    7494 
    75 -- �摜���\�[�X�ǂݍ��� 
     95-- 画像リソース読み込み 
    7696loadImageResource :: IO ImageResource 
    7797loadImageResource = mapM load images