Changeset 5371 for lang/actionscript

Show
Ignore:
Timestamp:
01/24/08 00:52:36 (5 years ago)
Author:
mokehehe
Message:

ソースを分割

Location:
lang/actionscript/misc/mario
Files:
4 added
3 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/misc/mario/Mario.as

    r5326 r5371  
    1414import ResourceManager; 
    1515 
     16import The; 
     17import Map; 
     18import Player; 
     19 
    1620public class Mario extends AppBase { 
    17         private const SCREEN_WIDTH: uint = 256; 
    18         private const SCREEN_HEIGHT: uint = 240; 
    19  
    2021        private var key: KeyState; 
    2122        private var mouse: MouseState; 
     
    2526        private var bgmTransform: SoundTransform; 
    2627 
    27         private var m_x: int; 
    28         private var m_y: int; 
    29         private var m_vx: int; 
    30         private var m_vy: int; 
    31         private var m_chr: int; 
    32         private var m_dir: int; 
    33         private var m_step: int; 
    34         private var m_stand: Boolean; 
    35  
    36         public const ChrW: int          = 14; 
    37         public const ChrH: int          = 16; 
    38         public const ONE: int           = 1<<16; 
    39         public const ACC: int           = ONE / 6; 
    40         public const MAXVX: int         = ONE * 3; 
    41         public const MINVX: int         = ONE / 16; 
    42         public const MAXVY: int         = ChrH * ONE; 
    43         public const GRAVITY: int       = ONE / 2; 
    44         public const JUMP: int          = GRAVITY * -17; 
    45         public const BLOCKW: int        = 16; 
    46         public const BLOCKH: int        = 16; 
    47  
    48         public const eChrSky: uint              = 0; 
    49         public const eChrBlock: uint    = 1; 
    50         public const eChrBlock2: uint   = 2; 
    51         public const eChrBlock3: uint   = 3; 
    52         public const eChrBlock4: uint   = 4; 
    53         public const eChrMountain02: uint       = 5; 
    54         public const eChrMountain11: uint       = 6; 
    55         public const eChrMountain12: uint       = 7; 
    56         public const eChrMountain13: uint       = 8; 
    57         public const eChrMountain22: uint       = 9; 
    58         public const eChrCloud00: uint  = 10; 
    59         public const eChrCloud01: uint  = 11; 
    60         public const eChrCloud02: uint  = 12; 
    61         public const eChrCloud10: uint  = 13; 
    62         public const eChrCloud11: uint  = 14; 
    63         public const eChrCloud12: uint  = 15; 
    64         public const eChr00: uint               = 16; 
    65         public const eChr01: uint               = eChr00 + 1; 
    66         public const eChr02: uint               = eChr00 + 2; 
    67         public const eChr03: uint               = eChr00 + 3; 
    68         public const eChr04: uint               = eChr00 + 4; 
    69         public const eChr10: uint               = eChr00 + 5; 
    70         public const eChr11: uint               = eChr00 + 6; 
    71         public const eChr12: uint               = eChr00 + 7; 
    72         public const eChr13: uint               = eChr00 + 8; 
    73         public const eChr14: uint               = eChr00 + 9; 
    74  
    75         public const eBgmMain: uint             = 0; 
    76         public const eSeJump: uint              = 1; 
    77  
    78         public const map: Array = [ 
    79                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    80                  0,10,11,12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    81                  0,13,14,15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    82                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 
    83                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 
    84                  0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 
    85                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    86                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    87                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    88                  0, 0, 0, 0, 0, 0, 2, 4, 2, 4, 2, 0, 0, 0, 0, 0, 
    89                  0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    90                  0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 
    91                  0, 6, 7, 9, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 
    92                  1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
    93                  1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 
    94         ]; 
     28        private var map: Map; 
     29        private var player: Player; 
    9530 
    9631 
    9732        //コンストラクタ 
    9833        public function Mario() { 
    99                 init(SCREEN_WIDTH, SCREEN_HEIGHT); 
     34                init(The.SCREEN_WIDTH, The.SCREEN_HEIGHT); 
    10035                set_fps(60, onTick); 
    10136 
     
    10843                resmgr = new ResourceManager; 
    10944 
    110                 m_x = (ChrW/2) * ONE; 
    111                 m_y = (SCREEN_HEIGHT - ChrH * 2) * ONE; 
    112                 m_vx = m_vy = 0; 
    113                 m_chr = 2; 
    114                 m_dir = 1; 
    115                 m_step = 0; 
    116                 m_stand = false; 
     45                map = new Map; 
     46                player = new Player; 
    11747 
    11848                bgmTransform = new SoundTransform; 
    11949                bgmTransform.volume = 1; 
    120                 bgmChannel = resmgr.snd[eBgmMain].play(0, 99999, bgmTransform); 
     50                bgmChannel = resmgr.snd[The.eBgmMain].play(0, 99999, bgmTransform); 
    12151        } 
    12252 
    12353        // 定時処理 
    12454        private function onTick(evt: TimerEvent): void { 
    125                 key.update(); 
    12655                update(); 
    12756                render(); 
     
    13059        // 更新 
    13160        private function update(): void { 
    132                         // 横動き 
    133                 if (key.btn & (KeyState.L | KeyState.R)) { 
    134                         var acc: int = ACC; 
    135                         var maxvx: int = MAXVX; 
    136                         if (!m_stand)           acc >>= 1; 
    137                         else if (key.btn & KeyState.B)  { maxvx <<= 1; } 
    138                         if (key.btn & KeyState.L) { 
    139                                 m_dir = 0; 
    140                                 if (m_vx > -maxvx) { 
    141                                         m_vx -= acc; 
    142                                         if (m_vx < -maxvx)      m_vx = -maxvx; 
    143                                 } 
    144                         } 
    145                         if (key.btn & KeyState.R) { 
    146                                 m_dir = 1; 
    147                                 if (m_vx < +maxvx) { 
    148                                         m_vx += acc; 
    149                                         if (m_vx > +maxvx)      m_vx = +maxvx; 
    150                                 } 
    151                         } 
    152                 } else { 
    153                         if (m_stand) { 
    154                                 if (m_vx > ACC) { 
    155                                         m_vx -= ACC; 
    156                                 } else if (m_vx < -ACC) { 
    157                                         m_vx += ACC; 
    158                                 } else { 
    159                                         m_vx = 0; 
    160                                 } 
    161                         } 
    162                 } 
    163                 m_x += m_vx; 
    164                 if (m_stand) { 
    165                         if (m_vx > MINVX || m_vx < -MINVX) { 
    166                                 m_step += Math.abs(m_vx); 
    167                                 if (m_stand) { 
    168                                         if (m_chr == 0) m_chr = 1; 
    169                                         if (m_step >= 6 * ONE) { 
    170                                                 m_step -= 6 * ONE; 
    171                                                 if (++m_chr > 3)        m_chr = 1; 
    172                                         } 
    173                                 } 
    174                         } else { 
    175                                 m_chr = 0; 
    176                         } 
    177                 } 
    178                 if (m_vx <= 0) { 
    179                         side_check(-1); 
    180                 } else { 
    181                         side_check(+1); 
    182                 } 
    183  
    184                         // ジャンプ・落下 
    185                 if (!m_stand) { 
    186                         m_vy += GRAVITY; 
    187                         if (m_vy > MAXVY)       m_vy = MAXVY; 
    188                         m_y += m_vy; 
    189  
    190                         if (m_vy > 0) { 
    191                                 if (is_ground(0)) { 
    192 //                                      m_y = SCREEN_HEIGHT * ONE; 
    193                                         m_vy = 0; 
    194                                         m_stand = true; 
    195                                         m_chr = 0; 
    196                                 } 
    197                         } else if (m_vy < 0) { 
    198                                 if (is_ceil(0)) { 
    199                                         m_vy = 0; 
    200                                 } 
    201                         } 
    202  
    203                         if (m_y > (SCREEN_HEIGHT + ChrH) * ONE) { 
    204                                 m_y = -ChrH * ONE; 
    205                         } 
    206                 } else { 
    207                         if (!is_ground(0)) { 
    208 //                              m_chr = 2; 
    209                                 m_stand = false; 
    210                         } else { 
    211                                 if (key.trg & KeyState.A) { 
    212                                         m_chr = 4; 
    213                                         m_vy = JUMP; 
    214                                         m_stand = false; 
    215  
    216 //                                      resmgr.snd[eSeJump].play(0); 
    217                                 } 
    218                         } 
    219                 } 
    220  
    221                 if (m_x < (ChrW/2)*ONE) { 
    222                         m_x = (ChrW/2)*ONE; 
    223                         if (!m_stand) { 
    224                                 m_vx = 0; 
    225                         } 
    226                 } 
    227                 if (m_x > (SCREEN_WIDTH-ChrW/2)*ONE) { 
    228                         m_x = (SCREEN_WIDTH-ChrW/2)*ONE; 
    229                         if (!m_stand) { 
    230                                 m_vx = 0; 
    231                         } 
    232                 } 
    233         } 
    234  
    235         // マップのキャラ取得 
    236         private function get_map_chr(x: int , y: int): int { 
    237                 return map[x + y * 16]; 
    238         } 
    239  
    240         // ブロック? 
    241         private function is_block(c: int): Boolean { 
    242                 if (eChrBlock <= c && c <= eChrBlock4) 
    243                         return true; 
    244                 else 
    245                         return false; 
    246         } 
    247  
    248         // 地面? 
    249         private function is_ground(ofsx: int): Boolean { 
    250                 var x: int = m_x >> 16; 
    251                 var y: int = m_y >> 16; 
    252                 var c: int = get_map_chr((x + ofsx)/BLOCKW, y/BLOCKH); 
    253                 if (is_block(c)) { 
    254                         m_y = (y - y % BLOCKH) * ONE; 
    255                         return true; 
    256                 } else { 
    257                         return false; 
    258                 } 
    259         } 
    260  
    261         // 横移動のチェック 
    262         private function side_check(dir: int): Boolean { 
    263                 var x: int = m_x >> 16; 
    264                 var y: int = m_y >> 16; 
    265                 var c: int = get_map_chr((x + dir * ChrW/2)/BLOCKW, (y - ChrH/2) / BLOCKH); 
    266                 if (is_block(c)) { 
    267                         m_vx = 0; 
    268                         m_x -= dir * ONE; 
    269                         return true; 
    270                 } else { 
    271                         return false; 
    272                 } 
    273         } 
    274  
    275         // 頭にブロックがある? 
    276         private function is_ceil(ofsx: int): Boolean { 
    277                 var x: int = m_x >> 16; 
    278                 var y: int = m_y >> 16; 
    279                 var c: int = get_map_chr((x + ofsx)/BLOCKW, (y-ChrH)/BLOCKH); 
    280                 if (is_block(c)) { 
    281                         return true; 
    282                 } else { 
    283                         return false; 
    284                 } 
     61                key.update(); 
     62                player.update(key, map); 
    28563        } 
    28664 
     
    28967                //背景の描画 
    29068                g.setColor(RGB(0, 0, 0)); 
    291                 g.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); 
     69                g.fillRect(0, 0, The.SCREEN_WIDTH, The.SCREEN_HEIGHT); 
    29270 
    29371                // マップの描画 
    29472                render_map(); 
    29573 
    296                 //イメージの描画 
    297                 g.drawImage(resmgr.img[eChr00 + m_dir*5 + m_chr], (m_x/ONE)-8, (m_y/ONE)-16); 
    298  
     74                // プレーヤーの描画 
     75                player.render(g, resmgr); 
    29976 
    30077 
     
    30986                        var y: int = i * 16; 
    31087                        for (var j: Number = 0; j < 16; ++j) { 
    311                                 var c: int = get_map_chr(j, i); 
     88                                var c: int = map.get_chr(j, i); 
    31289                                if (c != 0) { 
    31390                                        var x: int = j * 16; 
  • lang/actionscript/misc/mario/MouseState.as

    r5237 r5371  
    11/* 
    2  * $Id: MouseState.as,v 1.1.1.1 2007/04/01 08:25:41 kenta Exp $ 
    3  * 
    4  * Copyright 2006 Kenta Cho. Some rights reserved. 
    52 */ 
    63package { 
  • lang/actionscript/misc/mario/ResourceManager.as

    r5326 r5371  
    3535        [Embed(source='data/image_14.png')]     private static const ImgPanel14: Class; 
    3636 
     37        [Embed(source='data/bar.png')]          private static const ImgBar: Class; 
     38 
    3739        public var b_complete: String; 
    3840 
     
    6769                ImgPanel13, 
    6870                ImgPanel14, 
     71 
     72                ImgBar, 
    6973        ]; 
    7074