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

Username:   Password: 
 RegisterRegister   
 Help With Collision,
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Rasta Fella




PostPosted: Mon Jan 16, 2006 9:29 pm   Post subject: Help With Collision,

Well, yeah for my summative I'm making a obstacle type game. I'm not very fluent with the getch/hasch so looked for another alternative. Now I'm doing this movement using Input.Keydown and so what I do is so far all my obstacles have been boxes. So I my commands are like if x,y are in the box cordinate then reset from begining and count as death. Fairly simple, but now the problem is that is it possible to circles without changing my code to hash/getch or without using what dotcolour? Im thinking of doing like timed gates kind of thing that open and close but cant figure out a code.

This is a code for one of my levels, it won't work because i kind of copied and pasted from different places in my code. An because it is my summative....but I will post it after summatives.

Oh yeah...and its my first year in turing so.... i think you get the message.

code:
proc movedot
Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        if y <= 337 then
            y := y + 1
        elsif y>= 337 then
            boom_death_reset           
            x := 20
            y := 60
            tdeaths:= tdeaths +1
            ldeaths:= ldeaths +1   
        end if
    end if
    if chars (KEY_RIGHT_ARROW) then
        if x <= 547 then
            x := x + 1
        elsif x >= 547 then
            boom_death_reset
            x := 20
            y := 60
            tdeaths:= tdeaths +1
            ldeaths:= ldeaths +1
        end if
    end if
    if chars (KEY_LEFT_ARROW) then
        if x >= 13 then
            x := x - 1
        elsif x <= 13 then
            boom_death_reset
            x := 20
            y := 60
            tdeaths:= tdeaths +1
            ldeaths:= ldeaths +1
        end if
    end if
    if chars (KEY_DOWN_ARROW) then
        if y >= 53 then
            y := y - 1
        elsif y<= 53 then
            boom_death_reset           
            x := 20
            y := 60
            tdeaths:= tdeaths +1
            ldeaths:= ldeaths +1
        end if
    if chars (KEY_ENTER) then
            x:=20
            y:=60
            delay(100)
    end if       
    end if
    drawfilloval (x, y, 1, 1, white)
    delay (5)
    drawfilloval (x, y, 1, 1, black)
end movedot
%Screen Size/Background Colour/Borders/Copyright Stuff
    delay(1000)
    drawfillbox(0,0,560,350,black)                                                                  %Black Screen/Reset
    drawbox(3,3,557,347,white)                                                                      %Outside Border
    drawbox(5,5,555,345,white)                                                                      %Inside Border
    Font.Draw ("© 2005-2006", 10,330, (Font.New ("arial:8:bold,")), red)                            %Top Left
    Font.Draw ("Miraj Patel", 495,330, (Font.New ("arial:8:bold,")), red)                           %Top Right

%Level Text 2
    drawfillbox(160,200,390,245,red)
    drawbox(160,200,390,245,white)
    Font.Draw ("THE DOT GAME", 200,255, (Font.New ("arial:15:bold")), white)
    Font.Draw ("THE DOT GAME", 198,257, (Font.New ("arial:15:bold")), red)
    Font.Draw ("-  Mission 3  -", 170,210, (Font.New ("arial:25:bold,")), white)
    Font.Draw ("'Taking The Long Way Home'", 185,150, (Font.New ("arial:10:bold,")), white)
    delay(3500)

%Background Colour/Menu Bar/Button
    drawfillbox (0, 0, maxx, maxy, black)
    drawfillbox (0, 0, 560, 40, red)
    drawbox (0, 0, 560, 40, white)
    drawbox (446, 9, 551, 31, white)
    drawfillbox (447, 10, 550, 30, black)
    Font.Draw ("Exit To Main Menu", 450, 17, (Font.New ("arial:8:bold")), white)

Font.Draw ("Level Deaths:", 150,17, (Font.New ("arial:8:bold,")), white)   
Font.Draw ("Total Deaths:", 10,17, (Font.New ("arial:8:bold,")), white)
Font.Draw ("Current Level:", 290,17, (Font.New ("arial:8:bold,")), white)
locatexy(377,14)
colour(white)
colourback(red)     
put 3..

x := 20
y := 60
ldeaths:=0

loop
    movedot
    drawbox(10,50,550,340,red)
    drawfillbox (75, 50, 100, 300, red)
    drawfillbox (275, 50, 300, 300, red)
    drawfillbox(475,50,500,300,red)
   
    drawfillbox (175, 90, 200, 340, red)
    drawfillbox (375,90,400,340,red)
   
    drawfillbox (530, 320, 540, 330, yellow)
   
    if y >= 50 and y <= 300 and x >= 75 and x <= 100 then
        boom_death_reset
       
    elsif y >= 50 and y <= 300 and x >= 275 and x <= 300 then
        boom_death_reset
       
    elsif y >= 50 and y <= 300 and x >= 475 and x <= 500 then
        boom_death_reset
       
    elsif y >= 90 and y <= 340 and x >= 175 and x <= 200 then
        boom_death_reset 
       
    elsif y >= 90 and y <= 340 and x >= 375 and x <= 400 then
        boom_death_reset       
       
    elsif y >= 320 and y <= 330 and x >= 530 and x <= 540 then
        delay (500)
        exit
    end if

locatexy(90,14)
colourback(red)
colour(white) 
put tdeaths..
locatexy(236,14)
colourback(red)
colour(white) 
put ldeaths..

end loop
Sponsor
Sponsor
Sponsor
sponsor
[Flame][Boy]




PostPosted: Mon Jan 16, 2006 10:36 pm   Post subject: (No subject)

whatdotcolor would probaly be an easy way to do it i dont see why you dont want to use it??
MysticVegeta




PostPosted: Mon Jan 16, 2006 10:40 pm   Post subject: (No subject)

No, Go with Math.Distance (Turing 4.0.5)
If you dont have that then, use the following distance formula

code:
fcn giveDistance (x1, y1, x2, y2) : real
result sqrt( (y2-y1)^2 + (x2-x1)^2 )
end giveDistance


I coulda made a silly error, didnt test yet.
Delos




PostPosted: Tue Jan 17, 2006 12:09 am   Post subject: (No subject)

Even better yet, check out the [Tuts] section. There are a couple of good tuts on collision detection, both regular and circular (which people always have trouble with).
Rasta Fella




PostPosted: Tue Jan 17, 2006 4:30 pm   Post subject: (No subject)

[Flame][Boy] wrote:
whatdotcolor would probaly be an easy way to do it i dont see why you dont want to use it??

Well, first off I'm new to Turing, so I learned simple commands and trying to make a game. Teacher never taught us whatdotcolour, and too late for me to use it now even if I did read up on it.

MysticVegeta wrote:
No, Go with Math.Distance (Turing 4.0.5)
If you dont have that then, use the following distance formula

Yes, I do have Turing 4.0.5 and I am going to read up on Math.Distance today and see how it works.

Delos wrote:
Even better yet, check out the [Tuts] section. There are a couple of good tuts on collision detection, both regular and circular (which people always have trouble with).

I checked Turing Walkthrough and looked at many programs, all I found were things like whatdotcolour. I'll see what I can find.


But thanks for the help from everyone, I appreciate it. I have to say compsci.ca has a very productive forum, maybe someday everyone will have this as their homepage browser.
MiX-MaztA-M8riX




PostPosted: Tue Jan 17, 2006 6:48 pm   Post subject: (No subject)

Ok, from what I've seen here, I can only see examples and Tuts that help with Circle-Circle collision. I'm trying to find out how to make collision detection that won't go in the black areas. It works fine if I'm just working with the Input.KeyDown (if = UP then y+= 1), but now I'm using angles to move the character, and that collision detection doesn't seem to cut it anymore. Is it possible?, or am I running in circles here? Just ask for the code and I'll post it, if it's needed Laughing .

Thanks in advance.
Delos




PostPosted: Tue Jan 17, 2006 7:17 pm   Post subject: (No subject)

MiX-MaztA-M8riX wrote:
...that won't go in the black areas...


Quoi? Please elaborate, such a skeleton description is like trying to light a few with a cat's tail on a rainy day - you're wet, scratched, and have a possibly rabid cat in your hands. Neither are you warm, since the fire didn't start - not enough static electricity. Not a good thing.
Rasta Fella




PostPosted: Tue Jan 17, 2006 7:38 pm   Post subject: (No subject)

Delos wrote:
Quoi? Please elaborate, such a skeleton description is like trying to light a few with a cat's tail on a rainy day - you're wet, scratched, and have a possibly rabid cat in your hands. Neither are you warm, since the fire didn't start - not enough static electricity. Not a good thing.

Umm... quite expressive, yeah MiX-MaztA-M8riX it could be helpful if you post not all but part of your code that you need help on. And if i'm right their is a way to detect diagnol, Check Turing Walkthrough.
Sponsor
Sponsor
Sponsor
sponsor
MiX-MaztA-M8riX




PostPosted: Tue Jan 17, 2006 9:37 pm   Post subject: (No subject)

hahaha, wow, awsome example Laughing

Anywayz! I was kinda going crazy when I posted that, so please excuse my gibberish.

Heres the "Shooter.t" , and the "Arena.txt"



[Turing] Shooter.zip
 Description:
Arena.t + Arena.txt

Download
 Filename:  [Turing] Shooter.zip
 Filesize:  1.47 KB
 Downloaded:  157 Time(s)

MiX-MaztA-M8riX




PostPosted: Wed Jan 18, 2006 6:03 pm   Post subject: (No subject)

so anybody got any insight as to keep the players inside the "arena" and out of the "black" areas. (if you dont know what I mean, run the .t)
pavol




PostPosted: Wed Jan 18, 2006 6:09 pm   Post subject: (No subject)

you could use whatdotcolor and check for black pixles
MiX-MaztA-M8riX




PostPosted: Wed Jan 18, 2006 9:56 pm   Post subject: (No subject)

I already tried that, they still get through, I dunno, maybe its not possible when I'm running around with angles.
jrblast




PostPosted: Wed Jan 18, 2006 10:29 pm   Post subject: (No subject)

MiX-MaztA-M8riX, Why not try getting the users quadrant (as in, where in the txt file the user is on) simply say "x div 10" and "y div 10" the div gives you the max number, and then if you want (just a side note) you can use mod to get the remainder (haven't used remainders in like 6 years though :S) then check if where the user is trying to go is a 1 dont move the user. Understand?

If not, then you can try to use a for loop to detect colision with each 1... i like the first idea better, probably easier to do, harder to understand from my explanation...Rolling Eyes lol

Btw, perhaps add a line coming out of the user so you can see where theyre pointing? control is l1k3 zub3r h4rd!
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  [ 13 Posts ]
Jump to:   


Style:  
Search: