
-----------------------------------
jolly50
Mon Nov 19, 2007 9:51 pm

Collision Detection - Help... Again
-----------------------------------
Ok, so i'm restarting this thread because I have a new game and has a lot of upgrade since before...but I have problem with my health bar and collision can someone tell me how I can fix this...

and could you please you please use example bits of code to explain because I am very new to turing and only know basics and what have my peers have helped me with this game...

This game is not stolen from anyone! Just to be clear on that!...i wrote this code word for word with the help of my teacher and friends!...



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