⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mario.asm

📁 超级马力``大家喜欢的游戏```有原代码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
.386
.model flat,stdcall
option casemap:none

include Mario.inc
include Gates.inc

.const
   STBAR_GRIDS  equ  4
   ;-- Margin 
   LEFT_MARGIN  equ 1
   TOP_MARGIN   equ 1
   ;-- leading actor mov ;-- Back Scroll Mov
   ACTOR_LOW_SPEED  equ 2
   ACTOR_HIGH_SPEED equ 4
   ACTOR_DROP_SPEED equ 4
   ACTOR_JUMP_SPEED equ 4 + ACTOR_DROP_SPEED
   ;-- Jump Height 
   MAX_JUMP_HEIGHT  equ 5
   ;-- Back Movie Time Interval
   BACK_MOVIE_INTERVAL  equ 800
   FRAME_MOVIE_INTERVAL equ 20
   JUMP_MAX_TIME        equ 350
   ;-- Game State --
   GS_PLAY     equ  1000   ;-- Player can playing
   GS_STARTGAME equ 1001
   GS_PAUSE    equ  1002   ;-- Pause
   GS_SELECT   equ  1003   ;-- Select Control
   GS_GAMEOVER equ  1004   ;-- Game over
   GS_INFO     equ  1005   ;-- Show Information
   
.data 
   szMessage db 'Message Hooked!!!',0
   
   Stbar_Parts dd  150,250,375,550
   
   FpsFmtStr db 'FPS = %d',0
   SmallFontName  db 'Courier New',0
   
   szKeyDown db 'Key Down',0
   szKeyUp db 'Key Up',0
.data?
   ;-- Sprite ---
   Sprite CSprite <?>
   ;-- Key State 
   KeyState CKeyState <?>
   ;-- Gate Data Information ---
   GateInfo CGateInfo <?>
   ;-- Game State ---
   GameState dd ?
   ;-- Back Buffer
   hBackDc     dd ?
   hBackBmp    dd ?
   hBigFont    dd ?
   hSmallFont  dd ?
   ;-- Map Images 
   hImagesBmp    dd ?
   hImagesDc     dd ?
   ;--- Map Mask Images
   hImagesMaskBmp dd ?
   hImagesMaskDc  dd ?
   ;-- Actor Images 
   hActorDc  dd ?
   hActorBmp dd ? 
   ;-- Actor Mask Images
   hActorMaskDc  dd ?
   hActorMaskBmp dd ?
   
   ;--- Calc Frame Peer Second
   FrameCount  dd ?
   TimeLamp1   dd ?
   szFpsBuffer    db 256 dup(?)
   
   ;-- sence background movie control
   TimeBackMovieLamp  dd ?
   CurrentBack        dd ?
   
   ;-- sence control
   x_Detail dd ?
   x_Index  dd ?
   x_nPos   dd ?
   
.code

start:

	invoke GetModuleHandle,NULL
	mov    hInstance,eax
	invoke GetCommandLine
	invoke InitCommonControls
	invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
	invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL bQuit :DWORD
 
	LOCAL	wc:WNDCLASSEX
	LOCAL	msg:MSG

	mov		wc.cbSize,SIZEOF WNDCLASSEX
	mov		wc.style,CS_HREDRAW or CS_VREDRAW
	mov		wc.lpfnWndProc,OFFSET WndProc
	mov		wc.cbClsExtra,NULL
	mov		wc.cbWndExtra,DLGWINDOWEXTRA
	push	hInst
	pop		wc.hInstance
	mov		wc.hbrBackground,COLOR_BTNFACE+1
	mov		wc.lpszMenuName,OFFSET MenuName
	mov		wc.lpszClassName,OFFSET ClassName
	invoke LoadIcon,NULL,IDI_APPLICATION
	mov		wc.hIcon,eax
	mov		wc.hIconSm,eax
	invoke LoadCursor,NULL,IDC_ARROW
	mov		wc.hCursor,eax
    invoke RtlZeroMemory,Addr Sprite,SizeOf(CSprite)
	invoke RegisterClassEx,addr wc
	invoke CreateDialogParam,hInstance,addr DlgName,NULL,addr WndProc,NULL
	mov hWnd,eax
	invoke ShowWindow,hWnd,SW_SHOWNORMAL
	invoke UpdateWindow,hWnd
	
	invoke InitApp
	mov bQuit ,FALSE 
	.while !(bQuit)
	
	    invoke PeekMessage,addr msg,NULL,0,0,PM_REMOVE
	    .if (eax)
	       .if (msg.message == WM_QUIT )
	          mov bQuit ,TRUE  
	       .else
              invoke TranslateMessage,addr msg
              invoke DispatchMessage,addr msg
           .endif   
	    .else
	        ; Game Loop
	        .if (bActive)
               invoke GameLoop
            .else
               invoke WaitMessage
            .endif       
	    .endif        
	.endw
	
	invoke FreeRes
	mov		eax,msg.wParam
	ret

WinMain endp

WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

	mov		eax,uMsg
	.if eax==WM_INITDIALOG
	    push hWin
	    pop  hWnd
        invoke GetDC,hWin
        mov hDc,eax 
        invoke LoadRes
        invoke SelectGate,1
		push TRUE 
		pop  bActive 
	.elseif eax==WM_COMMAND
		mov		eax,wParam
		and		eax,0FFFFh
		.if eax==IDM_FILE_EXIT
			invoke SendMessage,hWin,WM_CLOSE,0,0
		.elseif eax==IDM_HELP_ABOUT
			invoke ShellAbout,hWin,addr AppName,addr AboutMsg,NULL
		.endif
;	.elseif eax==WM_SIZE
	.elseif eax==WM_CLOSE
	    push   FALSE 
	    pop    bActive
	    invoke ReleaseDC,hWin,hDc
		invoke DestroyWindow,hWin
	.elseif uMsg==WM_DESTROY
		invoke PostQuitMessage,NULL
	.else
		invoke DefWindowProc,hWin,uMsg,wParam,lParam
		ret
	.endif
	xor    eax,eax
	ret

WndProc endp

GameLoop proc 
  .if GameState != GS_GAMEOVER  
     invoke KeyProc
     invoke CheckDrop
     invoke UpdateWnd
     invoke CheckGameOver
  .endif
  
  invoke Flip
  invoke CalcFps
  ret

GameLoop endp


LoadRes proc
LOCAL lf:LOGFONT
  ; Create BackBuffer
  invoke CreateCompatibleBitmap,hDc,17*32,12*32
  mov hBackBmp,eax
  
  invoke CreateCompatibleDC,hDc
  mov  hBackDc,eax
  
  invoke SelectObject,hBackDc,hBackBmp  
  ;invoke SetTextColor,hBackDc,0h
  invoke SetBkMode,hBackDc,TRANSPARENT
  
  invoke RtlZeroMemory,Addr lf,SizeOf(LOGFONT)
  mov lf.lfHeight ,20
  mov lf.lfWidth ,12
  mov lf.lfWeight ,500
  ;invoke lstrcpy,Addr lf.lfFaceName,Addr SmallFontName
  invoke CreateFontIndirect,Addr lf
  mov hBigFont,eax
  mov lf.lfHeight ,15
  mov lf.lfWidth,10
  invoke CreateFontIndirect,Addr lf
  mov hSmallFont,eax
  invoke SelectObject,hBackDc,hSmallFont
  invoke DeleteObject,eax
  ; Create Map Images Buffer
  invoke LoadBitmap,hInstance,BM_IMAGES
  mov hImagesBmp,eax
    
  invoke CreateCompatibleDC,hDc
  mov  hImagesDc,eax
  
  invoke SelectObject,hImagesDc,hImagesBmp

  ; Create Map Mask Buffer
  invoke CreateCompatibleDC,hDc
  mov hImagesMaskDc,eax
  
  invoke LoadBitmap,hInstance,BM_IMAGES_MASK
  mov hImagesMaskBmp,eax
  
  invoke SelectObject,hImagesMaskDc,hImagesMaskBmp
  
  ; Create Actor Buffer
  invoke CreateCompatibleDC,hDc
  mov hActorDc,eax
  invoke LoadBitmap,hInstance,BM_ACTOR
  mov hActorBmp ,eax
  invoke SelectObject,hActorDc,hActorBmp
  
  ; Create Actor Mask Buffer 
  invoke CreateCompatibleDC,hDc
  mov hActorMaskDc,eax
  invoke LoadBitmap,hInstance,BM_ACTOR_MASK
  mov hActorMaskBmp,eax
  invoke SelectObject,hActorMaskDc,hActorMaskBmp
  
  push 0
  pop  FrameCount
  invoke GetTickCount
  mov TimeLamp1,eax
  mov TimeBackMovieLamp ,eax
  push 0
  pop CurrentBack
  
  mov eax ,0
  mov x_Detail,eax
  mov x_Index,eax
  mov x_nPos,eax
  
  ret

LoadRes endp

FreeRes proc
  invoke DeleteObject,hBigFont
  invoke DeleteObject,hImagesBmp
  invoke DeleteObject,hBackBmp
  invoke DeleteObject,hImagesMaskBmp
  invoke DeleteObject,hActorBmp
  invoke DeleteObject,hActorMaskBmp
  
  invoke DeleteDC,hBackDc  
  invoke DeleteDC,hImagesDc
  invoke DeleteDC,hImagesMaskDc
  invoke DeleteDC,hActorDc
  invoke DeleteDC,hActorMaskDc
  ret

FreeRes endp

KeyProc proc
    
  invoke GetAsyncKeyState,27
  .if eax >80000000h
      invoke SendMessage,hWnd,WM_CLOSE,0,0
  .endif  
  
  invoke GetAsyncKeyState,'W' ; Up
  .if eax > 80000000h  ; Key Down
     ; invoke MessageBox,hWnd,Addr szMessage,addr AppName,MB_OK
      push TRUE 
      pop  KeyState.bKeyWDown
  .else
      .if KeyState.bKeyWDown
         invoke MessageBox,hWnd,Addr szKeyUp,addr AppName,MB_OK
         push FALSE 
         pop  KeyState.bKeyWDown
      .endif
  .endif
  
  invoke GetAsyncKeyState,'S'
  .if eax > 80000000h
      invoke MessageBox,hWnd,Addr szMessage,Addr AppName,MB_OK
  .endif
  
  invoke GetAsyncKeyState,'A'  ; left
  .if eax > 80000000h
      invoke CanMoveLeft
      .if eax
         invoke SpriteMoveLeft
      .endif
      push TRUE 
      pop  KeyState.bKeyADown
  .else
     .if KeyState.bKeyADown
        push 5
        pop  Sprite.Frame
        push FALSE
        pop  KeyState.bKeyADown
      .endif
  .endif
  
  invoke GetAsyncKeyState,'D'  ; Right
  .if eax > 80000000h
      invoke CanMoveRight
      .if eax
         invoke SpriteMoveRight
      .endif
      push TRUE 
      pop  KeyState.bKeyDDown
  .else
     .if KeyState.bKeyDDown
         push 0 
         pop  Sprite.Frame
         push FALSE 
         pop  KeyState.bKeyDDown
     .endif
  .endif
  
  invoke GetAsyncKeyState,'J' ; Jump
  .if eax > 80000000h
      ; Key Down
      .if !KeyState.bKeyJDown 
          .if Sprite.bOnLine 
             invoke GetTickCount
             mov Sprite.JumpTimeLamp,eax
             push  Sprite.y
             pop   Sprite.JumpBaseY
             ;invoke MessageBox,hWnd,Addr AppName,Addr AppName,MB_OK
          .endif
      .endif
      invoke JumpProc
      push TRUE 
      pop  KeyState.bKeyJDown
  .else
      .if KeyState.bKeyJDown ;-- Key Up
          
          push FALSE
          pop  KeyState.bKeyJDown
      .endif
  .endif
 
  invoke GetAsyncKeyState,'K'
  .if eax > 80000000h
      invoke MessageBox,hWnd,Addr szMessage,Addr AppName,MB_OK
  .endif
  
  invoke GetAsyncKeyState,VK_CONTROL ; Turbo
  .if eax > 80000000h
      push ACTOR_HIGH_SPEED
      pop  Sprite.Speed
  .else
      push ACTOR_LOW_SPEED
      pop  Sprite.Speed
  .endif
  
  ret

KeyProc endp

SpriteMoveLeft proc

   .if Sprite.x >0
       mov eax,Sprite.x_Detail
       sub eax,Sprite.Speed
       mov Sprite.x_Detail,eax
       cmp eax,0
       jg @@Other 
       ;Sprite.x_Detail <0
         add Sprite.x_Detail,32
         dec Sprite.x
      @@Other: 
         ;Sprite.x_Detail >0
       
   .else
      mov eax,Sprite.x_Detail
      sub eax,Sprite.Speed
      mov Sprite.x_Detail,eax
      cmp eax,0
      jg @@NotDo
         ; Sprite.x_Detail <0
         push 0
         pop  Sprite.x_Detail
     @@NotDo:
   .endif
    
   mov eax,Sprite.x
   sub eax,x_Index
   .if eax <7   
      .if x_Index > 0 ; Left Scroll Background
          mov eax,x_Detail
          sub eax ,Sprite.Speed
          mov x_Detail,eax
          cmp eax,0  
          jg @@1 
              ; x_Detail <0
              sub x_nPos ,12
              dec x_Index
              mov ebx ,x_Detail
              not ebx
              inc ebx
              mov eax,32
              sub eax,ebx
              mov x_Detail,eax
          @@1:
      .elseif x_Index == 0
         .if x_Detail > 0 
             mov eax, x_Detail
             sub eax ,Sprite.Speed
             mov x_Detail,eax
         .endif
      .endif    
   .endif    
  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -