Page 1 of 1

mario

Posted: Thu Jul 14, 2011 4:03 pm
by xorc1zt
garbage code i wrote yesterday, first time working with sprites.

you can move right/left and jump.

Image

Sourcecode + sprites:
http://www.mediafire.com/?qqhatmhzsk2h86t
mirror
http://www.filesonic.com/file/1444297781

Code: Select all

;mario basic
;x0rc1zt

; sprites from super mario all stars
; source http://www.nes-snes-sprites.com/SuperMarioAllStarsSMB.html

;mario sprites
#Mario                = 0

;world sprites
#World     = 1


#worldbottom          = 464
#worldtop             = 0
#worldleft            = 0
#worldright           = 624

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Sprite system can't be initialized", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 650, 490, "Mariobasic", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)

  If OpenWindowedScreen(WindowID(0), 5, 5, 640, 480, 0, 0, 0)
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
    End
  EndIf
  
  ;mario
  LoadSprite(#Mario, "mario.bmp", 0)
  ClipSprite(#Mario, 115, 4, 17, 30) ; standing right
 ; ClipSprite(#Mario, 99, 4, 17, 30) ; standing left
 ; ClipSprite(#Mario, 136, 4, 17, 30) ; first step right
 ; ClipSprite(#Mario, 155, 4, 17, 30) ; second step right
 ; ClipSprite(#Mario, 77, 4, 17, 30) ; first step left
 ; ClipSprite(#Mario, 57, 4, 17, 30) ; second step left
 ; ClipSprite(#Mario, 38, 3, 17, 31) ; jumping left
 ; ClipSprite(#Mario, 174, 3, 17, 31) ; jumping right
 
  ;world
  LoadSprite(#World, "mario2.bmp", 0)
  ClipSprite(#World, 81, 257, 17, 16)

  xbot = 1
  ybot = 1
  domove = 0
  Running = 0
  mariostep = 0
  mariox = 30
  limitleft = 0
  limitright = 0
  jumping = 0
  jump = 0
  block = 1
  lastdirection=0
  marioy = #worldbottom-30
  StartTime = ElapsedMilliseconds()             
  StartTime2 = ElapsedMilliseconds()
  
  ; main loop
  
  Repeat
          
    ; window event loop
    Repeat  
      Event = WindowEvent()
    
      Select Event
        Case #PB_Event_CloseWindow
          End 
      EndSelect   
    Until Event = 0
    
    ;keyboard
    ExamineKeyboard()
    
    
    FlipBuffers()
    ClearScreen(RGB(0,0,56))
    
    ; move timer
    ElapsedTime = ElapsedMilliseconds()-StartTime
    If ElapsedTime > 50
      domove = 1   
      StartTime = ElapsedMilliseconds()
    Else
      domove = 0
    EndIf    
    
    If domove
      If KeyboardPushed(#PB_Key_Up) And Not jumping
        jumping = 1
        up = 1
      ElseIf KeyboardPushed(#PB_Key_Right) And Not limitright
        running = 1
        If jumping
          ClipSprite(#Mario, 174, 3, 17, 31) ; jumping right
        ElseIf mariostep = 1
          ClipSprite(#Mario, 136, 4, 17, 30) ; first step right
          mariostep = 2        
        ElseIf mariostep = 2 
          ClipSprite(#Mario, 155, 4, 17, 30) ; second step right
          mariostep = 3
        ElseIf mariostep = 3
          ClipSprite(#Mario, 136, 4, 17, 30) ; first step right
          mariostep =4
        ElseIf  mariostep = 4
          ClipSprite(#Mario, 115, 4, 17, 30) ; standing right
          mariostep = 1
        EndIf
        lastdirection=0
        
        mariox+4
      ElseIf KeyboardPushed(#PB_Key_Left) And Not limitleft
        running = 1
        If jumping
          ClipSprite(#Mario, 38, 3, 17, 31) ; jumping left
        ElseIf mariostep = 1
          ClipSprite(#Mario, 77, 4, 17, 30) ; first step left
          mariostep = 2        
        ElseIf mariostep = 2 
          ClipSprite(#Mario, 57, 4, 17, 30) ; second step left
          mariostep = 3
        ElseIf mariostep = 3
          ClipSprite(#Mario, 77, 4, 17, 30) ; first step left
          mariostep =4
        ElseIf  mariostep = 4
          ClipSprite(#Mario, 99, 4, 17, 30) ; standing left
          mariostep = 1
        EndIf
        mariox-4
        lastdirection=1
      Else
        If jumping And lastdirection
          ClipSprite(#Mario, 38, 3, 17, 31) ; jumping left
        ElseIf jumping
          ClipSprite(#Mario, 174, 3, 17, 31) ; jumping right
        ElseIf lastdirection
          ClipSprite(#Mario, 99, 4, 17, 30) ; standing left
        Else
          ClipSprite(#Mario, 115, 4, 17, 30) ; standing right
        EndIf          
        mariostep = 1
        running = 0
      EndIf
    EndIf
    
    If mariox>#worldright-17
      limitright=1
    ElseIf mariox<#worldleft+16
      limitleft=1
    Else
      limitright=0
      limitleft=0
    EndIf
    
    If up And jump<40
      marioy-2
      jump+1
    ElseIf jump>0
      up=0
      marioy+2
      jump-1
    Else
      jumping=0
    EndIf 
    
    
    ; Draw our sprite
      DisplayTransparentSprite(#Mario, mariox, marioy)
    
      ;draw world     
      Select block
        Case 1
          ClipSprite(#World, 60, 237, 17, 17)
        Case 2
          ClipSprite(#World, 81, 237, 17, 17)
        Case 3
          ClipSprite(#World, 102, 237, 17, 17)
        Case 4
          ClipSprite(#World, 81, 237, 17, 17)    
        Default
          block = 1
          ClipSprite(#World, 81, 237, 17, 17)
      EndSelect
      
      ; ?block timer
      ElapsedTime2 = ElapsedMilliseconds()-StartTime2
      If ElapsedTime2 > 220
        block+1  
        StartTime2 = ElapsedMilliseconds()
      EndIf
      
      DisplayTransparentSprite(#World, 100, 100)
      DisplayTransparentSprite(#World, 118, 100)
      DisplayTransparentSprite(#World, 136, 100)
      DisplayTransparentSprite(#World, 154, 100)
      
     ClipSprite(#World, 81, 257, 17, 16) 
    Repeat
      DisplayTransparentSprite(#World, #worldleft, ybot)
      DisplayTransparentSprite(#World, #worldright, ybot)
      DisplayTransparentSprite(#World, xbot, #worldtop)
      DisplayTransparentSprite(#World, xbot, #worldbottom)
      xbot+16
      ybot+16
    Until xbot>40*16
    
    xbot = 1
    ybot = 1
    
  Until KeyboardPushed(#PB_Key_Escape)
  
Else
  MessageRequester("Error", "Can't open a screen !", 0)
EndIf

End   

Re: mario

Posted: Sat Jul 16, 2011 4:04 pm
by Kwai chang caine
Cool little mario works fine here :D
Thanks for sharing 8)

Re: mario

Posted: Sun Jul 17, 2011 4:50 pm
by Rook Zimbabwe
nice start... now move the blocks down and add collision and you have something!!! :D

Re: mario

Posted: Mon Jul 18, 2011 2:57 am
by electrochrisso
Great start with nice graphics and smooth movement, keep up the good work. 8)