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

Username:   Password: 
 RegisterRegister   
 collision detection
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2, 3, 4  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
McKenzie




PostPosted: Sun Feb 01, 2004 5:35 pm   Post subject: (No subject)

your checks are wrong. e.g. you have:
code:
elsif chars (KEY_LEFT_ARROW) then
        if whatdotcolor (circley, circlex + radius + 2) = 12 then

if you are looking left it should be the point (circlex - radius -1, circley)
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Sun Feb 01, 2004 5:36 pm   Post subject: (No subject)

I got my whatdotcolor collision working, it works fine.
code:

setscreen ("offscreenonly")
var x, y : int
x := 100
y := 100
var addx, addy : int := 0
var chars : array char of boolean

loop
    drawfillbox (0, 0, maxx, maxy, black)
    drawfillbox (10, 10, maxx - 10, maxy - 10, 0)

    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        if whatdotcolor (x, y + 11 + addy) = 0
                then
            y := y + 5
        end if
    end if
    if chars (KEY_RIGHT_ARROW) then
        if whatdotcolor (x + 11 + addx, y) = 0 then
            x := x + 5
        end if
    end if
    if chars (KEY_LEFT_ARROW) then
        if whatdotcolor (x - 11 - addx, y) = 0 then
            x := x - 5
        end if
    end if
    if chars (KEY_DOWN_ARROW) then
        if whatdotcolor (x, y - 11 - addy) = 0 then
            y := y - 5
        end if
    end if

    drawfilloval (x, y, addx + 10, addy + 10, red)
    View.Update
    delay (10)
    cls
    if chars (KEY_ENTER) then
        addx := addx + 5
        addy := addy + 5
    end if
    if chars (KEY_BACKSPACE) then
        addx := addx - 5
        addy := addy - 5
    end if
end loop

Mine grows and shrinks too Laughing

Edit
I deleted the below post because I feared the wrath of AsianSensation.
Cervantes




PostPosted: Sun Feb 01, 2004 5:36 pm   Post subject: (No subject)

collisions with whatdotcolour are the first way I learned to do them..
however, whatdotcolour isn't as good as going it with coords in some instances, in other instances whatdotcolour is the only way to go Smile

to make it go diagonal..

code:
var chars : array char of boolean
var circlex, circley : int := 100
var radius : int := 20

setscreen ("offscreenonly")
setscreen ("graphics:400;400")
colorback (black)
cls

loop
    View.Update
    drawfillbox (20, 20, maxx - 20, maxy - 20, 12)
    drawfilloval (circlex, circley, radius, radius, white)
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        if whatdotcolor (circlex + radius + 1, circley + radius + 1) not= 7 then
            circley := circley + 1
        else
            circley := circley - 1
        end if
    end if
    if chars (KEY_DOWN_ARROW) then
        if whatdotcolor (circlex + radius + 1, circley - radius - 1) not= 7 then
            circley := circley - 1
        else
            circley := circley + 1
        end if
    end if
    if chars (KEY_LEFT_ARROW) then
        if whatdotcolor (circley - radius - 1, circlex - radius - 1) not= 7 then
            circlex := circlex - 1
        else
            circlex := circlex + 1
        end if
    end if
    if chars (KEY_RIGHT_ARROW) then
        if whatdotcolor (circley + radius + 1, circlex + radius + 1) not= 7 then
            circlex := circlex + 1
        else
            circlex := circlex - 1
        end if
    end if
end loop


the difference being that I got rid of the elsif's and replaces them with if's. before, if the uparrow was being pressed, it would never ask whether any of the other keys were being pressed. this way it will Smile
McKenzie




PostPosted: Sun Feb 01, 2004 5:37 pm   Post subject: (No subject)

Embarassed I type too slow.
Paul




PostPosted: Sun Feb 01, 2004 5:47 pm   Post subject: (No subject)

I tried to get the growing shrinking thing to be restricted by the wall too, using the same principle, but it didn't work.
jonos




PostPosted: Sun Feb 01, 2004 5:51 pm   Post subject: (No subject)

thanks mckenzie, that really helped, don't know why i didn't see it Embarassed

for the growing circle couldn't you just go:
[code]
if circlex+radius+1 or circlex -radius-1 or circley+radius +1 or circley -radius -1 = [the wall color] then
radius-1 or radius+1
else
do nothing
end if

that may not be right haven't tested it.l
Cervantes




PostPosted: Sun Feb 01, 2004 5:53 pm   Post subject: (No subject)

where you have the
code:
    if chars (KEY_ENTER) then
        addx := addx + 5
        addy := addy + 5
    end if


you should alter add an if statement in there
code:

    if chars (KEY_ENTER) then
        addx := addx + 5
        addy := addy + 5
        if x > maxx - 20 then
              x -= 5
        end if
        if x < 20 then
              x += 5
        end if
        if y > maxy - 20 then
              y -= 5
        end if
        if y < 20 then
              y += 5
        end if
    end if


do the same thing with y

if you want to do collisions with whatdotcolour then you can do that as well, you just have to implement it into the spots in that code up there where I put things like "if y > maxx - 20 then"

Cheers
Cervantes




PostPosted: Sun Feb 01, 2004 5:56 pm   Post subject: (No subject)

jonos wrote:

if circlex+radius+1 or circlex -radius-1 or circley+radius +1 or circley -radius -1 = [the wall color] then
radius-1 or radius+1
else
do nothing
end if


jonos an if statement does not need to have an else. ex of that is your code modified by me so that it can go on a diagonal. sometimes else is useful though, but if its
code:
else
   do nothing
end if

then just ditch the else.

Cheers
Sponsor
Sponsor
Sponsor
sponsor
jonos




PostPosted: Sun Feb 01, 2004 6:06 pm   Post subject: (No subject)

yeah, i know that, don't know why i put that. i probably though of putting something there but then decided against it.
Paul




PostPosted: Sun Feb 01, 2004 6:07 pm   Post subject: (No subject)

I tried it, using and instead of or and it works!
code:

setscreen ("offscreenonly")
var x, y : int
x := 100
y := 100
var addx, addy : int := 0
var chars : array char of boolean

loop
    drawfillbox (0, 0, maxx, maxy, black)
    drawfillbox (10, 10, maxx - 10, maxy - 10, 0)

    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        if whatdotcolor (x, y + 11 + addy) = 0
                then
            y := y + 5
        end if
    end if
    if chars (KEY_RIGHT_ARROW) then
        if whatdotcolor (x + 11 + addx, y) = 0 then
            x := x + 5
        end if
    end if
   if chars (KEY_LEFT_ARROW) then
        if whatdotcolor (x-11-addx, y ) = 0 then
            x := x - 5
        end if
    end if
    if chars (KEY_DOWN_ARROW) then
        if whatdotcolor (x, y - 11 - addy) = 0 then
            y := y - 5
        end if
    end if

    if chars (KEY_ENTER) then
        if whatdotcolor (x + addx + 6, y) = 0 and whatdotcolor (x - addx - 6, y) = 0 and
                whatdotcolor (x, y + addy + 6) = 0 and whatdotcolor (x, y - addy - 6) = 0 then
            addx := addx + 5
            addy := addy + 5
        end if
    end if
    if chars (KEY_BACKSPACE) then
        if whatdotcolor (x + addx + 6, y) = 0 and whatdotcolor (x - addx - 6, y) = 0 and
                whatdotcolor (x, y + addy + 6) = 0 and whatdotcolor (x, y - addy - 6) = 0 then
            addx := addx - 5
            addy := addy - 5
        end if
    end if
    drawfilloval (x, y, addx + 10, addy + 10, red)
    View.Update
    delay (10)
    cls
end loop


He didn't delete, I just deleted it, fearing his wrath.
jonos




PostPosted: Sun Feb 01, 2004 6:13 pm   Post subject: (No subject)

there are still things wrong with it, and i can't find it and don't want to spend time doing it. if you blow it up and move it left, then it can still get through, as well as if you keep playing around with it it will do the same for the other walls. ahhhh, this is confusing Very Happy
Cervantes




PostPosted: Sun Feb 01, 2004 6:14 pm   Post subject: (No subject)

oh lol, I just deleted my post sense i saw your post reappear.

(you can delete this and 2 bits if you want Asian Eh)
Paul




PostPosted: Sun Feb 01, 2004 6:15 pm   Post subject: (No subject)

yea, I noticed that left wall thing to, I fixed that line.
Cervantes




PostPosted: Sun Feb 01, 2004 6:20 pm   Post subject: (No subject)

for things like this I prefer to use coordinates rather than whatdotcolour in terms of collision
code:
setscreen ("offscreenonly")
var x, y : int
x := 100
y := 100
var addx, addy : int := 0
var chars : array char of boolean

loop
    drawfillbox (0, 0, maxx, maxy, black)
    drawfillbox (10, 10, maxx - 10, maxy - 10, 0)

    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        if whatdotcolor (x, y + 11 + addy) = 0
                then
            y := y + 5
        end if
    end if
    if chars (KEY_RIGHT_ARROW) then
        if whatdotcolor (x + 11 + addx, y) = 0 then
            x := x + 5
        end if
    end if
    if chars (KEY_LEFT_ARROW) then
        if whatdotcolor (x - 11 + addx, y) = 0 then
            x := x - 5
        end if
    end if
    if chars (KEY_DOWN_ARROW) then
        if whatdotcolor (x, y - 11 - addy) = 0 then
            y := y - 5
        end if
    end if
    if chars (KEY_ENTER) then
        addx := addx + 5
        addy := addy + 5
        if x > maxx - x - addx - 15 then
            x -= 5
        end if
        if x < 0 + x + addx + 15 then
            x += 5
        end if
        if y > maxy - y - addy - 15 then
            y -= 5
        end if
        if y < 0 + y + addy + 15 then
            y += 5
        end if
    end if

    if chars (KEY_BACKSPACE) then
        addx := addx - 5
        addy := addy - 5
    end if

    drawfilloval (x, y, addx + 10, addy + 10, red)
    View.Update
    delay (10)


    cls
end loop


that's still slightly buggy..

the + 15 or the - 15 in this part
code:

        if x > maxx - x - addx - 15 then
            x -= 5
        end if


10 because you did drawfilloval (x,y,addx + 10, addy + 10, red) and 5 because that's how much you add every time enter or backspace is hit. the 5 is prevention.

Keep playing around with it and we can iron out all the bugs.

EDIT: the bug in this code is that it works fine for the first wall that you got to, but then any of the other walls you go to its buggy...
Andy




PostPosted: Sun Feb 01, 2004 6:25 pm   Post subject: (No subject)

Cervantes wrote:
however, whatdotcolour isn't as good as going it with coords in some instances, in other instances whatdotcolour is the only way to go Smile


cervantes, how much bits do u want to lose? whatdotcolor is ALWAYS i repeat ALWAYSE the way to go!!!! and not in some instances, nonono, in ALL i repeat ALL instances, whatdotcolor is the only way to not go, LIVE.

-5 bits btw
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 2 of 4  [ 49 Posts ]
Goto page Previous  1, 2, 3, 4  Next
Jump to:   


Style:  
Search: