Computer Science Canada

For Statement with Colision Detection?

Author:  Pacman [ Mon Nov 27, 2006 7:23 pm ]
Post subject:  For Statement with Colision Detection?

Ok, So another problem with my pacman program. ^-^ I create my dots with drawfilloval and then use my colision detection so pacman can eat it...for example

code:

var distance_between_centres : real
var ydot1x, ydot1y, yellrad : int
        yellrad := 5
        ydot1x := 30
        ydot1y := 55
        var yellow1 := 1

distance_between_centres := sqrt ((ydot1x - x) ** 2 + (ydot1y - y) ** 2)
            if distance_between_centres <= pacrad + yellrad then
                if yellow1 = 1 then
                    pacscore := pacscore + 10
                end if
                drawfilloval (ydot1x, ydot1y, yellrad, yellrad, black)
                yellow1 := 0
            end if


Ok, so this makes the dot given able to be eaten, if pacman runs over it the "score" will have an added 10 points. It works Yes, Its Fine Yes!

BUT

This is were my problem comes in, Wich is when a straight line in the maze comes i use a for statement to draw it straight across to the end for example
code:
for draw1 : 1 .. 15
            drawfilloval (30 * draw1, 30, 5, 5, yellow) % cant do yet
        end for


Well, Now i want to be able to make that "for draw1" with the colision code im using, Im trying alot of different things but getting no were... Im hoping its possible because drawing all the dots would take to long lmao and if this is possible it shortens my time alot, Any ideas or suggestions or even just a straight up how to do it would be very appreciated. Thanks!!!

Author:  Ultrahex [ Tue Nov 28, 2006 6:55 pm ]
Post subject: 

Probably the best way to do this without getting object orientated programming in Turing is using an Array of Values (Flexible Array if you dont know how many dots there will be)

The Values could be of type X, and another of type Y
another way you could do is an array of your own type

for example

type pacdots :
record
x : int
y : int
end record

var eatables : array 1..10 of pacdots
eatables(1).x := 5 %Set X value to 5 in data type
eatables(1).y := 10 %Set Y value to 10 in data type

then you do a for loop of size of the array to check for collision etc...

hope this helps a little, and if you dont mind; i probably wont respond and help you if you keep on posting new topics about the same/close to the exact same problem. You may also want to check your spelling (sorry if english isnt your first language)


: