
-----------------------------------
caldrium
Tue Jan 24, 2006 12:37 pm

Dont know how to do collission with pictures
-----------------------------------
well i looked at just about all of the collission things, in the collission detection post, i changed all the variables according to what i used, but it still didnt work. If anyone can fill in the spot with code,or tell how to do it, that would be sick. I have turing 4.0.2 if that makes any difference, and this is the last thing i need for my program. Thanks in advance for your help.

P.S. Download the game if you want it to run cause of graphics, or you can just look at my code

P.P.S The spot where im putting the collission is the last for (empty right now) at the bottom.


var fish, sharkout, level, fishdirection, sprint, score : int
var distance:real
var buttons : array char of boolean
var maxX, maxY : int := 200
var sharkx : array 1 .. 1000 of int
var sharky : array 1 .. 1000 of int
var s : int := 50
level := 1
score := 0
fishdirection := 0
sprint := 500
sharkout := 2

for xx : 1 .. 1000
    sharkx (xx) := maxx
end for

for xx : 1 .. 1000
    sharky (xx) := 500
end for
setscreen ("offscreenonly")
var sharkPic := Pic.FileNew ("shark.jpg")
var fishPic := Pic.FileNew ("fish.jpg")
var fishPic2 := Pic.FileNew ("fish2.jpg")
Pic.Draw (fishPic, maxX, maxY, picMerge)

proc fishSpawn
    randint (fish, (level * 2), 100)
    if (fish = 100) then
        sharkout := sharkout + 1
        for xx : sharkout .. sharkout
            randint (sharky (xx), 1, maxy)
            Pic.Draw (sharkPic, sharkx (xx), sharky (xx), picMerge)
        end for

    end if
end fishSpawn

proc scoreBoard
    score := score + 10
    delay (0)
    locate (1, 1)
    if score >= 10000 then
        score := 0
        level := level + 1
    end if
    put "LEVEL ", level, " " : 23, "SWIM POWER: ", sprint, " " : 13, "NEXT LEVEL(10k): ", score
end scoreBoard


loop
    fishSpawn
    scoreBoard
    Input.KeyDown (buttons)
    drawline (550, 0, 550, maxy, 2)

    %fishMove
    % Draw.FillOval (maxX, maxY, 20, 20, 5)

    for xx : 1 .. sharkout
        sharkx (xx) := sharkx (xx) - 3
        Pic.Draw (sharkPic, sharkx (xx), sharky (xx), picMerge)
    end for

    
    if fishdirection = 0 then
        Pic.Draw (fishPic, maxX, maxY, picMerge)
    else
        Pic.Draw (fishPic2, maxX, maxY, picMerge)
    end if
    View.Update
    %FISH MOVEMENT RESTRICTIONS
    if (maxX = 440) then  %if you try to pass the line
        maxX := 440 %restrict you from moving further
    end if

    if (maxY = 350) then      %if you go to far up
        maxY := 350 %restrict you from moving further
    end if

    %FISH MOVEMENT
    %NORMAL MOVEMENT
    if buttons (KEY_UP_ARROW) then %if the up arrow is pressed
        maxY := maxY + 6 %move up
    elsif buttons (KEY_DOWN_ARROW) then %if the down arrow is pressed
        maxY := maxY - 6 %move down
    elsif buttons (KEY_LEFT_ARROW) then %if the left arrow is pressed
        maxX := maxX - 6 %move left
        fishdirection := 0 %face fish left
    elsif buttons (KEY_RIGHT_ARROW) then %if the right arrow is pressed
        maxX := maxX + 6 %move right
        fishdirection := 1 %face fish right
    end if

    %SWIM POWER USAGE
    if buttons (KEY_SHIFT) and sprint not= 0 then %if they hold shift down
        sprint := sprint - 1 %lower their Swim Power
        delay (0)
    end if

    %SWIM POWER MOVEMENT
    if buttons (KEY_UP_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then    %if the up arrow +shift key is pressed
        maxY := maxY + 9 %move up fast
    elsif buttons (KEY_DOWN_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the down arrow +shift key is pressed
        maxY := maxY - 9 %move down fast
    elsif buttons (KEY_LEFT_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the left arrow  +shift keyis pressed
        maxX := maxX - 9 %move left fast
        fishdirection := 0 % face fish left
    elsif buttons (KEY_RIGHT_ARROW) and buttons (KEY_SHIFT) and sprint not= 0 then %if the right arrow  +shift keyis pressed
        maxX := maxX + 9 %move right fast
        fishdirection := 1 %face fish right
    end if


    for xx : 1 .. sharkout  %POST COLLISSION HERE

    end for
    
    colorback (11)     %backround colour
    delay (30)
    cls
end loop



-----------------------------------
caldrium
Tue Jan 24, 2006 1:14 pm


-----------------------------------
i dont think the attachment thing worked. sorry for the 2x post

-----------------------------------
Albrecd
Tue Jan 24, 2006 2:19 pm


-----------------------------------
Okay, in order to detect colision:

%For our purposes here, X1 and Y1 will be the coordinates of
%one picture: Pic1, and X2 and Y2 will be the coordinates of the other: Pic2.

if X1 >= X2 and X1 = Y2 and Y1 