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

Username:   Password: 
 RegisterRegister   
 collision for lots of circles
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
be natural*




PostPosted: Sun Jun 08, 2003 7:33 pm   Post subject: collision for lots of circles

I'm trying to make collision detection work for my game..
there are a lot of circles up on the screen and i'm shooting a circle from a point. when the circle collide any of the circles it will stop & if they have the same colour, they'll disappear.
I've tried making two circles disappear when they collide, but should i use an array for the centres of each circle if i want to use circle collision?
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Sun Jun 08, 2003 7:38 pm   Post subject: (No subject)

you should, but you could also just use whatdotcolor
be natural*




PostPosted: Sun Jun 08, 2003 7:43 pm   Post subject: (No subject)

what's whatdotcolor?
and can u explain how to use it?

thx Smile
Andy




PostPosted: Sun Jun 08, 2003 7:48 pm   Post subject: (No subject)

whatdotcolor checks the color of one pixel
code:

whatdotclor(x,y)

it returns the color of the pixel in integer format
if you are shooting a projectile and the targets you are shooting are simply circles drawn by turing, you can just say
code:

if whatdotcolor(projectilex, projectiley)=circleclr then
%do whatever you want to do here
end if

but using pythagorus is so much easier
code:

for i:1..circlenum
if (circlex-projectilex)**2+(cicley-projectiley)**2>circleradius then
%do your thing here after
end if
end for

if you have turing 4.01 or better, just type in the command and press F9
be natural*




PostPosted: Mon Jun 09, 2003 8:40 am   Post subject: (No subject)

i've tried to make circle collision but it doesn't really work...

can anybody tell me what should i fix in my code?
also, how can i identify the circles that are already disappeared so that the circle that is being shoot can pass through?

i've attached the code below.

code:

setscreen ("graphics:400;600")

var iColor : int
var iX : int := 31
var iY : int := 520
var iShootX : int := 200
var iShootY : int := 91
var rD : array 1 .. 33 of real
var chars : array char of boolean
var b:int

var iMap1x : array 1 .. 33 of int
var iMap1y : array 1 .. 33 of int

for z : 1 .. 33
    iMap1x (z) := iX * z
    if (z >= 13) and (z <= 23) then
        iMap1x (z) := (iX - 15) + (31 * (z - 12))
    elsif (z >= 24) and (z <= 33) then
        iMap1x (z) := iX + (31 * (z - 23))
    end if
end for

for y : 1 .. 33
    iMap1y (y) := iY - 15
    if (y >= 13) and (y <= 23) then
        iMap1y (y) := iY - 42
    elsif (y >= 24) and (y <= 33) then
        iMap1y (y) := iY - 69
    end if
end for

for a : 1 .. 33
    randint (iColor, 1, 5)
    drawfilloval (iMap1x (a), iMap1y (a), 15, 15, iColor)
end for

iColor := 1
loop
    drawfilloval (iShootX, iShootY, 15, 15, iColor)
    Input.KeyDown (chars)
    if chars (KEY_SHIFT) then
        loop
            for a : 1 .. 33
               rD (a) := sqrt ((iMap1x (a) - iShootX) * (iMap1x (a) - iShootX) + (iMap1y (a) - iShootY) * (iMap1y (a) - iShootY))
               exit when rD (a) <= 30
               b:=a
            end for
            drawfilloval (iShootX, iShootY, 15, 15, iColor)
            delay (1)
            drawfilloval (iShootX, iShootY, 15, 15, white)
            iShootY += 1
        end loop
        drawfilloval (iShootX, iShootY, 15, 15, iColor)
       
        if whatdotcolor (iMap1x (b), iMap1y (b)) = iColor then
            drawfilloval (iMap1x (b), iMap1y (b), 15, 15, white)
            drawfilloval (iShootX, iShootY, 15, 15, white)
        end if
        iShootY := 91
        randint (iColor, 1, 5)
    end if
end loop

Prince




PostPosted: Mon Jun 09, 2003 10:01 am   Post subject: (No subject)

http://www.compsci.ca/bbs/viewtopic.php?t=75

tutorial on collision detection... may help u
Asok




PostPosted: Mon Jun 09, 2003 3:40 pm   Post subject: (No subject)

omg, I just got an idea on how to use whatdotcolor for a collision detection game...

PACHINKO! Very Happy
Andy




PostPosted: Mon Jun 09, 2003 5:28 pm   Post subject: (No subject)

its really good if all of your targets are the same color
Sponsor
Sponsor
Sponsor
sponsor
Homer_simpson




PostPosted: Mon Jun 09, 2003 5:44 pm   Post subject: (No subject)

they dont need to be create a new color :

solved!!!
code:

var bgclr := RGB.AddColor (.5, 0.5, 0.6)
RGB.SetColor (bgclr, .01, 0, 0)

colorback (bgclr)
cls
for i : 1 .. 20
    drawfilloval (Rand.Int (1, maxx), Rand.Int (1, maxy), 30, 30, Rand.Int (1, 255))
end for
var mx, my, mb : int
color (white)

put bgclr
loop
    mousewhere (mx, my, mb)
    if whatdotcolor (mx, my) not= bgclr then
        locate (1, 1)
        put "collision detected!!!"
    else
        locate (1, 1)
        put "collision not detected!!!"
    end if
end loop
be natural*




PostPosted: Mon Jun 09, 2003 8:14 pm   Post subject: (No subject)

I got this error message
Quote:
"Array subscript is out of range"
What does this mean?
PaddyLong




PostPosted: Mon Jun 09, 2003 8:19 pm   Post subject: (No subject)

it means you tried to acces an index in your array that isn't there...

let's say you had
var somearray : array 1..10 of int

then you tried to do

somearray (11) := 3

you would get array subscript out of range becuase somearray only goes up to 10 ... therefore there is no index 11
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  [ 11 Posts ]
Jump to:   


Style:  
Search: