Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Collision Detection, please help.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Dinosaurus




PostPosted: Fri Jan 08, 2010 9:20 pm   Post subject: Collision Detection, please help.

What is it you are trying to achieve?
I'm trying to program collision detection.


What is the problem you are having?
I have no idea where to begin


Describe what you have tried to solve this problem
Make the frog coordinates (fx,fy) if they equal car coordinates then exit loop. I've tried but I don't know exactly how to do it.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


%By Matt
import GUI
View.Set ("graphics:800;480,noecho")
var fx, fy : int %staring point for frog
var c1x, c1y : int
var getkey : array char of boolean %keyboard input
var pic : int := Pic.FileNew ("pictures/frog.bmp") %Imports Frog
Pic.SetTransparentColor (pic, grey) %Makes the bmp.s transparent
var bgid : int %"Pic.Free"
%cars
var pic4 : int := Pic.FileNew ("pictures/carblue.bmp")

%Draws Background
Draw.FillBox (0, 48, 800, 0, 118)
Draw.FillBox (0, 96, 800, 48, grey)
Draw.FillBox (0, 144, 800, 96, grey)
Draw.FillBox (0, 192, 800, 144, grey)
Draw.FillBox (0, 240, 800, 192, grey)
Draw.FillBox (0, 288, 800, 240, 119)
Draw.FillBox (0, 336, 800, 288, 54)
Draw.FillBox (0, 384, 800, 336, 54)
Draw.FillBox (0, 432, 800, 384, 54)
Draw.FillBox (0, 480, 800, 432, 120)
View.Update

process frog
    var x, y := 0
    loop
        bgid := Pic.New (x, y, x + 48, y + 48) %takes picture of background
        Pic.Draw (pic, x, y, picMerge) %Draws Frog
        delay (10)
        Pic.Draw (bgid, x, y, picMerge) %Draws background over frog
        Pic.Free (bgid) %frees the background

        %Movement
        Input.KeyDown (getkey)
        if getkey (KEY_UP_ARROW) then
            y := y + 48
            delay (200)
        end if
        if getkey (KEY_DOWN_ARROW) then
            y := y - 48
            delay (200)
        end if
        if getkey (KEY_RIGHT_ARROW) then
            x := x + 2
        end if
        if getkey (KEY_LEFT_ARROW) then
            x := x - 2
        end if
        fx := x
        fy := y
    end loop
end frog

%car movemnet
process car1
    var x := -100 %road 1 cars
    loop
        %delays cars
        delay (10)
        %Cars Row 1
        Pic.Draw (pic4, x, 48, picMerge)
        x := x + 2
        %Sets cars back to left side Row 1
        if x >= 800 then
            x := -100
        end if
        c1x := x
        c1y := 48
    end loop
end car1

%calls cars out
fork frog
fork car1
delay (1200)
fork car1
delay (1200)
fork car1
delay (1200)
fork car1



Please specify what version of Turing you are using
Turing 4.1.1



frog.bmp
 Description:
 Filesize:  6.8 KB
 Viewed:  869 Time(s)

frog.bmp



carblue.bmp
 Description:
 Filesize:  14.12 KB
 Viewed:  48 Time(s)

carblue.bmp


Sponsor
Sponsor
Sponsor
sponsor
Ktomislav




PostPosted: Sat Jan 09, 2010 12:32 pm   Post subject: Re: Collision Detection, please help.

First of all you have to make global variables for coordinates so you can use them from outside of processes.
So for forg it would be x_frog, y_frog.
After you've done that use this tutorial: http://compsci.ca/v3/viewtopic.php?t=13661
And collision detection put inside car1 process.

Hope this helps.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: