
-----------------------------------
Azzy123
Sat May 09, 2009 1:15 pm

Game help (moving circle)
-----------------------------------
What is it you are trying to achieve?
I need to make it so that when my bigger yellow circle passes over the smaller circles, the smaller circles completely disappear- currently only parts of them are erased. 


What is the problem you are having?
I have the distance formula, but no matter where I put it in my code, it's never called on/ never works. 

Describe what you have tried to solve this problem
I've tried changing the formula a bit. I've also placed it nearly everywhere in my code. 

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I've tried using this as my formula:

if sqrt ((x - a) ** 2 + (y - b) ** 2) = 0 + 11) then

        x := x - step
    end if
    % RIGHT--------------------------------------------------
    if chars (KEY_RIGHT_ARROW) and x = 500 then
        if isredcookie then
            drawfilloval (a, b, 5, 5, 16)



            isredcookie := false
        else
            randint (a, 5, maxx - 5)
            randint (b, 5, maxy - 5)
            drawfilloval (a, b, 5, 5, brightred)

            isredcookie := true


        end if
        counter := 0
    else
        counter := counter + 1
    end if
    %greencookie
    if counter >= 500 then
        if isgreencookie then
            drawfilloval (c, d, 5, 5, 16)
            isgreencookie := false
        else
            randint (c, 5, maxx - 5)
            randint (d, 5, maxy - 5)
            drawfilloval (c, d, 5, 5, brightgreen)
            isgreencookie := true
        end if
        counter := 0
    else
        counter := counter + 1

    end if

    %orangecookie
    if counter >= 500 then
        if isorangecookie then
            drawfilloval (e, f, 5, 5, 16)
            isorangecookie := false
        else
            randint (e, 5, maxx - 5)
            randint (f, 5, maxy - 5)
            drawfilloval (e, f, 5, 5, 42)
            isorangecookie := true
        end if
        counter := 0
    else

        counter := counter + 1
    end if
    %cyancookie
    if counter >= 500 then
        if iscyancookie then
            drawfilloval (g, h, 5, 5, 16)
            iscyancookie := false
        else
            randint (g, 5, maxx - 5)
            randint (h, 5, maxy - 5)
            drawfilloval (g, h, 5, 5, 52)
            iscyancookie := true
        end if
        counter := 0
    else
        counter := counter + 1
    end if
    %magentacookie
    if counter >= 500 then
        if ismagentacookie then
            drawfilloval (i, j, 5, 5, 16)
            ismagentacookie := false
        else
            randint (i, 5, maxx - 5)
            randint (j, 5, maxy - 5)
            drawfilloval (i, j, 5, 5, 36)
            ismagentacookie := true
        end if
        counter := 0
    else
        counter := counter + 1
    end if

    delay (10)


    View.Update

end loop



Please specify what version of Turing you are using
4.1

Edit: Sorry if it's a bit messy / impractical. It's my first attempt and I don't want to change it.

-----------------------------------
Azzy123
Sat May 09, 2009 3:24 pm

RE:Game help (moving circle)
-----------------------------------
Bump.. This is urgent, thanks.

-----------------------------------
Kharybdis
Sat May 09, 2009 5:22 pm

RE:Game help (moving circle)
-----------------------------------
Your problem is that when your big circle moves over a small one, the trail of the big circle (you're moving it by increasing/decreasing its x and y position) is overlapping the smaller circle.

To fix it, one way to do it (albeit not an impressive way) is when the x and y of the big circle are in the range defined by the small cookie (of x and y), then assign that small cookie to be black instead of its original colour.

You can use the whatdotcolor function to do this, although i don't think it would be that efficient.

-----------------------------------
Azzy123
Sat May 09, 2009 6:13 pm

RE:Game help (moving circle)
-----------------------------------
Er yeah. As I stated in my original post, that's what I've been trying to do. But it won't work. No idea why.

I've been trying to use if sqrt ((x - a) ** 2 + (y - b) ** 2)  - 10) then [/code]

       This is a simple formula, it gets the sum of the center coordinates of your yellow oval and the centre co-ordinates of your red dot. It then substracts it from each other. It then checks whether the difference is less than 10 or - 10 (10 is the radius of your yellow oval).  

[code] drawfilloval (a, b, 5, 5, 16)
      a := 0
      b := 0 [/code]

When your condition has been met, it will draw another oval over your red dot making it disappear. A and B is set to 0 so that you don't see a grey circle over your yellow oval.  Comment out a := 0 and b := 0 and you'll see what I mean.

Well that is all, hopefully I've helped you. : D

-----------------------------------
TheGuardian001
Sat May 09, 2009 7:02 pm

Re: Game help (moving circle)
-----------------------------------
but you're only drawing it black if it disappears on its own (after the timer).

what you need to do is check if the big yellow circle has hit the cookie, then set isredcookie (or whatever colour cookie) to false.

in pseudo code


if player hit redcookie then
    isredcookie := false
end if

if player hit greencookie then
    isgreencookie := false
end if


and so on.
if you don't know how to do collision detection, I suggest you look
Edit: aw.... ninja'd by OneTwo

-----------------------------------
OneTwo
Sat May 09, 2009 7:19 pm

Re: Game help (moving circle)
-----------------------------------
Sorry very small mistake,

Mistake:
((x+y) - (a-b) > - 10
Corrected:
((x+y) - (a+b) > - 10

-----------------------------------
Azzy123
Sat May 09, 2009 7:49 pm

RE:Game help (moving circle)
-----------------------------------
Hi, sorry, either method still does not work. Where in the code would I need to put it? Thanks a lot for the help so far.  :)

-----------------------------------
OneTwo
Sat May 09, 2009 8:39 pm

Re: Game help (moving circle)
-----------------------------------
Hey, the code works fine as I have just tested it. As for the location of the code, you can put it anywhere so long as it is executed every single time your object (yellow oval) moves. 

Example: it can be right after "loop ..." or even right before "end loop"

OR


[code]...

  elsif ((x + y) - (g + h) < 20) and ((x+y) - (g+h) > - 20) then 
      drawfilloval (g, h, 5, 5, 16) 
      g := 0 
      h := 0  
  elsif ((x + y) - (i + j) < 20) and ((x+y) - (i + j) > - 20) then 
      drawfilloval (i, j, 5, 5, 16) 
      i := 0 
      j := 0  
    end if



    
    delay (10) 
    View.Update 

end loop[/code]

Also note that you must change the variables(a, b) for it to work for the other cookies if you haven't already done so.

-----------------------------------
Azzy123
Sat May 09, 2009 8:57 pm

RE:Game help (moving circle)
-----------------------------------
Hmmmmmmm. I have no idea why mine isn't working. I've done everything you've said, and I understand your formula..  but it the cookie still isn't being eaten. 

:s My brain feels like liquid. Thanks for your patience..

-----------------------------------
OneTwo
Sat May 09, 2009 9:25 pm

Re: Game help (moving circle)
-----------------------------------
Hey, I added my code in to yours and here's the result:

I just changed the BG to gray, no worries you could change it to whatever you want. 


Result:
From:

To:
[code]if ((x + y) - (a + b) = - 10) then[/code]

-----------------------------------
Azzy123
Sat May 09, 2009 9:36 pm

RE:Game help (moving circle)
-----------------------------------
Hey, thanks a lot, but why is the timing so different? The cookies appear too quickly / slowly. Also, sometimes the red cookie appears at the bottom left of the screen (half appears on the screen and the other bit is cut off). The cookies seem to disappear randomly.

Edit: Yeah, they seem to disappear when I approach from their left sides.

-----------------------------------
OneTwo
Sat May 09, 2009 10:05 pm

RE:Game help (moving circle)
-----------------------------------
It seems it has something to do with the way your counter works,so try experimenting with different ways to draw your random ovals. It's getting fairly late, i'll help you more tomorrow if that's fine with you.

-----------------------------------
Azzy123
Sat May 09, 2009 10:07 pm

RE:Game help (moving circle)
-----------------------------------
Yes, I'll keep working on it. Thank you so much.

-----------------------------------
OneTwo
Sun May 10, 2009 12:13 pm

Re: Game help (moving circle)
-----------------------------------
Hey, it looks like my math was way off yesterday. Your formula is correct here is the more accurate code that should be used:

[code]var chars : array char of boolean 
var x, y, a, b, c, d, e, f, g, h, i, j : int := 0 
var radius : int := 10 
var step : int := 2 
var counter : int := 0 
var isredcookie, isgreencookie, isorangecookie, iscyancookie, ismagentacookie : boolean := false 

View.Set ("graphics, nobuttonbar,offscreenonly") 
colorback (24) 
cls 

x := maxx div 2 
y := maxy div 2 

loop 
    Input.KeyDown (chars) 
    drawfilloval (x, y, radius, radius, 24) 
    % UP----------------------------------------------------- 
    if chars (KEY_UP_ARROW) and y = (0 + 14) then 

        y := y - step 
    end if 
    % LEFT--------------------------------------------------- 
    if chars (KEY_LEFT_ARROW) and (x >= 0 + 11) then 

        x := x - step 
    end if 
    % RIGHT-------------------------------------------------- 
    if chars (KEY_RIGHT_ARROW) and x = 500 then 
        if isredcookie then 
            drawfilloval (a, b, 5, 5, 24) 



            isredcookie := false 
        else 
            randint (a, 5, maxx - 5) 
            randint (b, 5, maxy - 5) 
            drawfilloval (a, b, 5, 5, brightred) 

            isredcookie := true 


        end if 
        counter := 0 
    else 
        counter := counter + 1 
    end if 
    %greencookie 
    if counter >= 500 then 
        if isgreencookie then 
            drawfilloval (c, d, 5, 5, 24) 
            isgreencookie := false 
        else 
            randint (c, 5, maxx - 5) 
            randint (d, 5, maxy - 5) 
            drawfilloval (c, d, 5, 5, brightgreen) 
            isgreencookie := true 
        end if 
        counter := 0 
    else 
        counter := counter + 1 

    end if 

    %orangecookie 
    if counter >= 500 then 
        if isorangecookie then 
            drawfilloval (e, f, 5, 5, 24) 
            isorangecookie := false 
        else 
            randint (e, 5, maxx - 5) 
            randint (f, 5, maxy - 5) 
            drawfilloval (e, f, 5, 5, 42) 
            isorangecookie := true 
        end if 
        counter := 0 
    else 

        counter := counter + 1 
    end if 
    %cyancookie 
    if counter >= 500 then 
        if iscyancookie then 
            drawfilloval (g, h, 5, 5, 24) 
            iscyancookie := false 
        else 
            randint (g, 5, maxx - 5) 
            randint (h, 5, maxy - 5) 
            drawfilloval (g, h, 5, 5, 52) 
            iscyancookie := true 
        end if 
        counter := 0 
    else 
        counter := counter + 1 
    end if 
    %magentacookie 
    if counter >= 500 then 
        if ismagentacookie then 
            drawfilloval (i, j, 5, 5, 24) 
            ismagentacookie := false 
        else 
            randint (i, 5, maxx - 5) 
            randint (j, 5, maxy - 5) 
            drawfilloval (i, j, 5, 5, 36) 
            ismagentacookie := true 
        end if 
        counter := 0 
    else 
        counter := counter + 1 
    end if 
    
    
if sqrt ((x - a) ** 2 + (y - b) ** 2) 