import GUI
 
  
 
setscreen ("graphics:1010;400")
 
View.Set ("offscreenonly")
 
 
var mario_x1, mario_y1, mario_x2, mario_y2: int
 
var luigi_x1, luigi_y1, luigi_x2, luigi_y2: int
 
var vx, vy :int
 
var chars :array char of boolean
 
var timeLast := Time.Elapsed
 
var proj : flexible array 1 .. 0 of
 
    record
 
        x, y, vx, vy : real
 
    end record
 
var finished: boolean:= false
 
var left: int
 
 
 
var goomba_x1, goomba_x2, goomba_y1, goomba_y2 :int
 
var koopa_x1, koopa_x2, koopa_y1, koopa_y2, koopa_vy: int
 
var bowser_x1, bowser_x2, bowser_y1, bowser_y2, bowser_vy, bowser_vx: int
 
 
var playerdirection: int:=0
 
 
var CurrentFrame:int:= Pic.FileNew ("Mario1.bmp")
 
var CurrentFrameLeft:int:=Pic.Mirror (CurrentFrame)
 
var RunningRight:int:= Pic.FileNew ("mario_run_right.bmp")
 
var RunningLeft:int:= Pic.Mirror (RunningRight)
 
var MarioJumpRight:int:=Pic.FileNew ("mario_jump.bmp")
 
var MarioJumpLeft:int:= Pic.Mirror (MarioJumpRight)
 
var mariocrouch:int:= Pic.FileNew ("mario_crouch.bmp")
 
var fireball:int:= Pic.FileNew ("fireball.bmp")
 
 
var goomba:int:= Pic.FileNew ("Goomba.bmp")
 
var Koopa:int:= Pic.FileNew ("Koopa.bmp")
 
var bowser:int:= Pic.FileNew ("Bowser.bmp")
 
 
var luigicurrentframe:int:=Pic.FileNew ("luigi_sprite.bmp")
 
var luigirunningright:int:=Pic.FileNew ("luigi_run.bmp")
 
var luigirunningleft:int:=Pic.Mirror (luigirunningright)
 
var luigijumpright:int:=Pic.FileNew ("luigi_jump.bmp")
 
var luigijumpleft:int:=Pic.Mirror (luigijumpright)
 
var luigicrouch:int:=Pic.FileNew ("luigi_crouch.bmp")
 
var luigifireball:int:=Pic.FileNew ("luigi_fireball.bmp")
 
 
mario_x1:=15
 
mario_y1:=25
 
%mario_x2:=mario_x1+Pic.Width(CurrentFrame)
 
%mario_y2:=mario_y1+Pic.Height(CurrentFrame)
 
 
luigi_x1:=15
 
luigi_y1:=25
 
luigi_x2:=luigi_x1+Pic.Width(luigicurrentframe)
 
luigi_y2:=luigi_y1+Pic.Height(luigicurrentframe)
 
 
left:=70
 
 
 
goomba_x1:= maxx
 
goomba_y1:= 31
 
goomba_x2:=goomba_x1+Pic.Width(goomba)
 
goomba_y2:=goomba_y1+Pic.Height(goomba)
 
 
 
koopa_x1:= maxx
 
koopa_y1:=31
 
koopa_vy:=20
 
koopa_x2:=koopa_x1+Pic.Width(Koopa)
 
koopa_y2:=koopa_y1+Pic.Height(Koopa)
 
 
 
bowser_x1:=maxx
 
bowser_y1:=31
 
bowser_vy:=15
 
bowser_vx:=10
 
bowser_x2:=bowser_x1+Pic.Width(bowser)
 
bowser_y2:=bowser_y1+Pic.Height(bowser)
 
 
var mariosprite: int
 
mariosprite:=Sprite.New(CurrentFrame)
 
 
var luigisprite: int
 
luigisprite:=Sprite.New(luigicurrentframe)
 
 
var goombasprite: int
 
goombasprite:=Sprite.New(goomba)
 
 
var koopasprite: int
 
koopasprite:=Sprite.New(Koopa)
 
 
var bowsersprite: int
 
bowsersprite:=Sprite.New(bowser)
 
 
var mariorunright:int
 
mariorunright:=Sprite.New(RunningRight)
 
 
var jumping: boolean:= false
 
 
const gravity:=-1
 
 
 
Sprite.SetPosition (luigisprite,luigi_x1,luigi_y1,false)
 
 
Sprite.SetPosition (mariosprite,mario_x1,mario_y1,false)
 
 
Sprite.Show (goombasprite)
 
 
Sprite.SetPosition (goombasprite,goomba_x1,goomba_y1,false)
 
 
Sprite.Show (koopasprite)
 
 
Sprite.SetPosition (koopasprite,koopa_x1,koopa_y1,false)
 
 
Sprite.Show (bowsersprite)
 
 
Sprite.SetPosition (bowsersprite,bowser_x1,bowser_y1,false)
 
 
function cooldown (timeDelay : int) : boolean
 
    if Time.Elapsed - timeLast >= timeDelay then
 
        timeLast := Time.Elapsed
 
        result true
 
    end if
 
    result false
 
end cooldown
 
 
process PlayBackgroundMusic (file : string)
 
 
    loop
 
        Music.PlayFile (file)
 
        exit when finished
 
    end loop
 
    
 
end PlayBackgroundMusic
 
 
fork PlayBackgroundMusic ("Mario_Theme.MP3")
 
 
process fireballsound (file:string)
 
 
    Music.PlayFile (file)
 
end fireballsound
 
 
process jumpingsound (file:string)
 
 
    Music.PlayFile (file)
 
 
end jumpingsound
 
 
procedure controls
 
 
 
 
    Input.KeyDown (chars)
 
    
 
        if chars (KEY_RIGHT_ARROW) then
 
            mario_x1+=4
 
            playerdirection:=0
 
        end if
 
        
 
        if chars (KEY_LEFT_ARROW) then
 
            mario_x1-=4
 
            playerdirection:=180
 
        end if
 
        
 
        if chars (KEY_DOWN_ARROW) then
 
            mario_y1-=2
 
            Sprite.ChangePic (mariosprite,mariocrouch)
 
        end if
 
        
 
        if chars (KEY_DOWN_ARROW) and jumping then
 
            Sprite.ChangePic (mariosprite,mariocrouch)
 
        end if
 
        
 
        if not chars(KEY_DOWN_ARROW) then
 
            Sprite.ChangePic(mariosprite,CurrentFrame)
 
        end if
 
        
 
        if chars (KEY_UP_ARROW) and not jumping and mario_y1=27 then
 
            jumping:=true
 
            vy:=15
 
            Sprite.ChangePic (mariosprite, MarioJumpRight)
 
            fork jumpingsound ("mario jump.wav")
 
        end if
 
        
 
        if chars (' ') then
 
            fork fireballsound ("fireball.wav")
 
        end if
 
        
 
        if chars (' ') then
 
        if cooldown (300) then
 
            new proj, upper (proj) + 1
 
            if playerdirection=0 then
 
                proj (upper (proj)).x:= mario_x1+50
 
            elsif playerdirection=180 then
 
                proj (upper (proj)).x:= mario_x1
 
            end if
 
            
 
            proj (upper (proj)).y:= mario_y1+50
 
            
 
            if playerdirection=0 then
 
                proj (upper (proj)).vx:=16
 
            elsif playerdirection=180 then
 
                proj (upper(proj)).vx:=-16
 
            end if
 
            
 
            proj (upper (proj)).vy := 8
 
            timeLast:= Time.Elapsed
 
         end if
 
     end if
 
     
 
        if jumping then
 
            mario_x1+=0
 
            mario_y1+=vy
 
            vy+=gravity
 
            Sprite.ChangePic (mariosprite, MarioJumpRight)
 
       
 
            if mario_y1<= 27 then
 
                jumping:=false
 
                mario_y1:=27
 
                Sprite.ChangePic (mariosprite,CurrentFrame)
 
            end if
 
        end if
 
        
 
        if chars (KEY_LEFT_ARROW) and playerdirection=0 then
 
            CurrentFrame:=RunningRight
 
        end if
 
        
 
        if mario_y1<27 then
 
            mario_y1:=27
 
        end if
 
        
 
        if mario_x1>1370then
 
            mario_x1:=1370
 
        end if
 
        
 
        if mario_x1<0 then
 
            mario_x1:=0
 
        end if
 
        
 
        if chars (KEY_LEFT_ARROW) and jumping then
 
            Sprite.ChangePic (mariosprite, MarioJumpLeft)
 
        end if
 
            
 
    
 
    Sprite.SetPosition (mariosprite,mario_x1,mario_y1,false)
 
    
 
end controls
 
 
procedure luigicontrols
 
 
 
 
    Input.KeyDown (chars)
 
    
 
        if chars (KEY_RIGHT_ARROW) then
 
            luigi_x1+=4
 
            playerdirection:=0
 
        end if
 
        
 
        if chars (KEY_LEFT_ARROW) then
 
            luigi_x1-=4
 
            playerdirection:=180
 
        end if
 
        
 
        if chars (KEY_DOWN_ARROW) then
 
            luigi_y1-=2
 
            Sprite.ChangePic (luigisprite,luigicrouch)
 
        end if
 
        
 
        if chars (KEY_DOWN_ARROW) and jumping then
 
            Sprite.ChangePic (luigisprite,luigicrouch)
 
        end if
 
        
 
        if not chars(KEY_DOWN_ARROW) then
 
            Sprite.ChangePic(luigisprite,luigicurrentframe)
 
        end if
 
        
 
        if chars (KEY_UP_ARROW) and not jumping and luigi_y1=27 then
 
            jumping:=true
 
            vy:=15
 
            Sprite.ChangePic (luigisprite, luigijumpright)
 
            fork jumpingsound ("mario jump.wav")
 
        end if
 
        
 
        if chars (' ') then
 
            fork fireballsound ("fireball.wav")
 
        end if
 
        
 
        if chars (' ') then
 
        if cooldown (300) then
 
            new proj, upper (proj) + 1
 
            if playerdirection=0 then
 
                proj (upper (proj)).x:= luigi_x1+50
 
            elsif playerdirection=180 then
 
                proj (upper (proj)).x:= luigi_x1
 
            end if
 
            
 
            proj (upper (proj)).y:= luigi_y1+50
 
            
 
            if playerdirection=0 then
 
                proj (upper (proj)).vx:=16
 
            elsif playerdirection=180 then
 
                proj (upper(proj)).vx:=-16
 
            end if
 
            
 
            proj (upper (proj)).vy := 8
 
            timeLast:= Time.Elapsed
 
         end if
 
     end if
 
     
 
        if jumping then
 
            luigi_x1+=0
 
            luigi_y1+=vy
 
            vy+=gravity
 
            Sprite.ChangePic (luigisprite, luigijumpright)
 
       
 
            if luigi_y1<= 27 then
 
                jumping:=false
 
                luigi_y1:=27
 
                Sprite.ChangePic (luigisprite,luigicurrentframe)
 
            end if
 
        end if
 
        
 
        if chars (KEY_LEFT_ARROW) and playerdirection=0 then
 
            luigicurrentframe:=luigirunningright
 
        end if
 
        
 
        if luigi_y1<27 then
 
            luigi_y1:=27
 
        end if
 
        
 
        if luigi_x1>1370then
 
            luigi_x1:=1370
 
        end if
 
        
 
        if luigi_x1<0 then
 
            luigi_x1:=0
 
        end if
 
        
 
        if chars (KEY_LEFT_ARROW) and jumping then
 
            Sprite.ChangePic (luigisprite, luigijumpleft)
 
        end if
 
            
 
    
 
    Sprite.SetPosition (luigisprite,luigi_x1,luigi_y1,false)
 
    
 
end luigicontrols
 
 
procedure Goomba
 
    goomba_x1:=goomba_x1-7
 
        if goomba_x1<0 then
 
            goomba_x1:=maxx
 
        end if
 
end Goomba
 
 
procedure EnemyKoopa
 
    koopa_x1:=koopa_x1-5
 
    koopa_y1+=koopa_vy
 
    koopa_vy+=gravity
 
        if koopa_x1<0 then
 
            koopa_x1:=maxx
 
        end if
 
        if koopa_y1<27 then
 
            koopa_y1:=27
 
        end if
 
        if koopa_y1<=27 then
 
            koopa_vy:=20
 
        end if
 
        
 
end EnemyKoopa
 
 
procedure Bowser
 
    if bowser_x1>= maxx then
 
        bowser_vx :=-10
 
    elsif bowser_x1<235 then
 
        bowser_vx:=10
 
    elsif bowser_x1>=675 then
 
        bowser_vx:=-10
 
    end if
 
    bowser_y1+=bowser_vy
 
    bowser_vy+=gravity
 
    bowser_x1+=bowser_vx
 
        
 
       if bowser_y1<27 then
 
            bowser_y1:=27
 
       end if
 
       if bowser_y1<=27 then
 
            bowser_vy:=15
 
       end if
 
        
 
end Bowser
 
 
procedure MarioRun
 
  
 
    if chars (KEY_RIGHT_ARROW)and not jumping then
 
        Sprite.ChangePic (mariosprite,RunningRight)
 
    end if
 
    
 
    if chars (KEY_LEFT_ARROW)and not jumping then
 
        Sprite.ChangePic (mariosprite,RunningLeft)
 
    end if
 
   
 
end MarioRun
 
 
procedure LuigiRun
 
  
 
    if chars (KEY_RIGHT_ARROW)and not jumping then
 
        Sprite.ChangePic (luigisprite,luigirunningright)
 
    end if
 
    
 
    if chars (KEY_LEFT_ARROW)and not jumping then
 
        Sprite.ChangePic (luigisprite,luigirunningleft)
 
    end if
 
   
 
end LuigiRun
 
 
procedure updateproj
 
 
for i : 1 .. upper (proj)
 
        proj (i).vy += gravity
 
        proj (i).x += proj (i).vx
 
        proj (i).y += proj (i).vy
 
    end for
 
 
    for i : 1 .. upper (proj)
 
        if proj (i).x > maxx or proj (i).y < 0 or proj (i).x < 0 then
 
            proj (i) := proj (upper (proj))
 
            new proj, upper (proj) - 1
 
            exit 
 
        end if
 
    end for
 
 for i : 1 .. upper (proj)
 
        Pic.Draw (fireball,round (proj (i).x), round (proj (i).y),picCopy) 
 
    end for
 
 
end updateproj
 
 
procedure luigiupdateproj
 
 
for i : 1 .. upper (proj)
 
        proj (i).vy += gravity
 
        proj (i).x += proj (i).vx
 
        proj (i).y += proj (i).vy
 
    end for
 
 
    for i : 1 .. upper (proj)
 
        if proj (i).x > maxx or proj (i).y < 0 or proj (i).x < 0 then
 
            proj (i) := proj (upper (proj))
 
            new proj, upper (proj) - 1
 
            exit 
 
        end if
 
    end for
 
 for i : 1 .. upper (proj)
 
        Pic.Draw (luigifireball,round (proj (i).x), round (proj (i).y),picCopy) 
 
    end for
 
 
end luigiupdateproj
 
 
 
 
procedure MarioGame
 
 
Sprite.Show (mariosprite)
 
 
loop    
 
    cls
 
    drawfillbox (0,0,maxx,30,green)
 
    % Health Bar and Collision Detection
 
 
    mario_x2:=mario_x1+Pic.Width(CurrentFrame)
 
    mario_y2:=mario_y1+Pic.Height(CurrentFrame)
 
    if mario_x2 > goomba_x1 and mario_x1 < goomba_x2 and mario_y2 > goomba_y1 and mario_y1 < goomba_y2 then
 
          drawfillbox (0,380,70,maxy,brightblue)
 
    end if
 
    Input.KeyDown (chars)
 
    controls
 
    MarioRun
 
    updateproj
 
    Goomba
 
    %EnemyKoopa
 
    %Bowser
 
    Sprite.SetPosition (mariosprite,mario_x1,mario_y1,false)
 
    Sprite.SetPosition (goombasprite,goomba_x1,goomba_y1,false)
 
    Sprite.SetPosition (koopasprite,koopa_x1,koopa_y1,false)
 
    Sprite.SetPosition (bowsersprite,bowser_x1,bowser_y1,false)
 
    View.Update
 
    delay (15)
 
end loop
 
 
end MarioGame
 
 
procedure LuigiGame
 
 
Sprite.Show (luigisprite)
 
 
loop
 
    cls
 
    drawfillbox (0,0,maxx,30,green)
 
    drawfillbox (0,380,70,maxy,brightblue)
 
    Input.KeyDown (chars)
 
    luigicontrols
 
    LuigiRun
 
    luigiupdateproj
 
    %EnemyKoopa
 
    Goomba
 
    Sprite.SetPosition (luigisprite,luigi_x1,luigi_y1,false)
 
    Sprite.SetPosition (goombasprite,goomba_x1,goomba_y1,false)
 
    Sprite.SetPosition (koopasprite,koopa_x1,koopa_y1,false)
 
    Sprite.SetPosition (bowsersprite,bowser_x1,bowser_y1,false)
 
    % Some collision detection
 
        if luigi_x2 > goomba_x1 and luigi_x1 < goomba_x2 and luigi_y2 > goomba_y1 and luigi_y1 < goomba_y2 then
 
           drawfillbox (70,maxy,60,380,white)
 
        end if
 
    View.Update
 
    delay (15)
 
end loop
 
end LuigiGame
 
 
procedure HelpMenu
 
cls
 
put "To 'Jump' Press the UP arrow key"
 
put " "
 
put "To 'Run' press the LEFT and RIGHT arrow keys"
 
put " "
 
put "To 'Crouch' press the DOWN arrow key"
 
put " "
 
put "To 'Shoot Fireballs' press the SPACEBAR"
 
put " "
 
put "To Play, Please click on one of the following buttons to play as either Mario or Luigi!"
 
put " "
 
put "Enjoy The Game :)"
 
var button1:int:=GUI.CreateButton (250,150,0, "Play Game as Mario", MarioGame)
 
var button2:int:=GUI.CreateButton (400,150,0, "Play Game as Luigi", LuigiGame)
 
 
end HelpMenu
 
 
 
 
var backgroundpicture:int:=Pic.FileNew ("Super_Mario_64_box_cover copy2.jpg")
 
 
Pic.Draw (backgroundpicture,225,0,0)
 
 
var button1:int:=GUI.CreateButton (250,5,0, "Play Game as Mario", MarioGame)
 
var button2:int:=GUI.CreateButton (400,5,0, "Play Game as Luigi", LuigiGame)
 
var button3:int:=GUI.CreateButton (550,5,0, "Instructions", HelpMenu)
 
loop
 
    exit when GUI.ProcessEvent
 
end loop
 
 
  |