
-----------------------------------
bgmrk
Fri Jan 27, 2006 10:18 am

WhatDotColour help
-----------------------------------
ok i'm trying to make a tag game... only i can't seem to try to get the whatdotcolour to work to know when the two balls collide. I tried to come up with my own methode but it is rather glitchy as you will tell. can some please point me in the right direction. Whether my math is wrong or another method to do this thanx

var gamewindow : int := Window.Open ("graphics:800;500,position:truemiddle;center,nobuttonbar")
View.Set ("offscreenonly")
var col1 : int := 2
var col2 := 4
var chars : array char of boolean
var x1, y1 : int
var x2, y2 : int
x1 := 50
y1 := 255
x2 := 750
y2 := 255
var it := true
var randit : int

%%game
%board
locate (1, 45)
put "GAME!"
locate (3, 10)
put "Player 1" : 55, "Player 2"

%%%%game
randint (randit, 1, 2)
loop
    %Draw characters
    Draw.FillOval (x1, y1, 10, 10, col1)
    Draw.FillOval (x2, y2, 10, 10, col2)
    %%%board redraw
    Draw.Line (1, 450, 799, 450, 3)
    Draw.Line (1, 1, 1, 450, 3)
    Draw.Line (1, 1, 799, 1, 3)
    Draw.Line (799, 1, 799, 450, 3)
    Draw.FillBox (350, 200, 400, 250, 3)
    Draw.FillBox (100, 300, 150, 350, 3)
    Draw.FillBox (700, 50, 750, 100, 3)
    Draw.FillBox (500, 240, 550, 290, 3)
    Draw.FillBox (150, 100, 200, 150, 3)
    Draw.FillBox (700, 375, 750, 425, 3)
    %%whos it
    % if randit = 1 then
    %        it := true
    %  elsif randit = 2 then
    %       it := false
    % end if
    if it = true then
        Draw.FillBox (558, 488, 533, 468, white)
        Font.Draw ("(IT)", 85, 470, defFontID, green)
    elsif it = false then
        Draw.FillBox (85, 465, 115, 485, white)
        Font.Draw ("(IT)", 530, 470, defFontID, green)
    end if

    %%Charcter Movement
    Input.KeyDown (chars)
    %player1
    if chars (KEY_UP_ARROW) then
        y1 := y1 + 1
    end if
    if chars (KEY_DOWN_ARROW) then
        y1 := y1 - 1
    end if
    if chars (KEY_LEFT_ARROW) then
        x1 := x1 - 1
    end if
    if chars (KEY_RIGHT_ARROW) then
        x1 := x1 + 1
    end if
    if whatdotcolour (x1 - 2, y1 - 2) = 3 then
        x1 := x1
        y1 := y1
    end if
    %%%Player 2
    if chars ('w') then
        y2 := y2 + 1
    end if
    if chars ('s') then
        y2 := y2 - 1
    end if
    if chars ('a') then
        x2 := x2 - 1
    end if
    if chars ('d') then
        x2 := x2 + 1
    end if
    View.Update
    Draw.FillBox (0, 450, 800, 0, white)
    %%tag
    %player one
    if it = true then
        if x1 >= x2 - 10 and y1 = x2 + 10 and y1 >= y2 + 10 then
            it := false

        elsif x1 >= x2 - 10 and y1 >= y2 + 10 then
            it := false
        elsif x1 >= x2 + 10 and y1 = x1 - 10 and y2 >= y1 - 10 then
            it := true

        elsif x2 >= x1 + 10 and y2 = x1- 10 and y2 = x1 + 10 and y2 >= y1 - 10 then
            it := true
        end if
    end if
    %%pause
    if chars ('p') then
        loop
            Input.KeyDown (chars)
            Font.Draw ("PAUSED", 400, 250, defFontID, red)
            exit when chars ('p')
        end loop
    end if
end loop


-----------------------------------
bgmrk
Fri Jan 27, 2006 11:55 am


-----------------------------------
oo and another problem i forgot to mention is that i can't seem to get the whatdotcolour to work probably with the borders and the box's on the game map... I've tried but i can't seem to get the object to stop moving. here's what i tried to do...
View.Set ("offcreenonly")
var x,y : int :=100
loop
Draw.FillOval (x,y,10,10,black)
Draw.Box (300,50,400,100,green)
x := x + 1
if whatdotcolour (x,y) = green then
x := x - 1
y := y - 1
end if
cls
View.Update
end loop

i want it so the circle just stops moving. and dosen't go around it[/code]

-----------------------------------
Saad85
Fri Jan 27, 2006 2:15 pm


-----------------------------------
    if whatdotcolour (x1 - 2, y1 - 2) = 3 then
        x1 := x1
        y1 := y1

thats the only use of whatdotcolor i see, and it doesn't do anything, it just makes the variable equal to themselves. 


in ur second post, why did you make y=y-1? that makes no sense if you dont want it to go around

-----------------------------------
iker
Fri Jan 27, 2006 5:22 pm


-----------------------------------
why not use something like

if x1 - 10 < x and x1 + 10 > x then
    collide
..

and do this for both..

-----------------------------------
bgmrk
Fri Jan 27, 2006 6:05 pm


-----------------------------------
    if whatdotcolour (x1 - 2, y1 - 2) = 3 then
        x1 := x1
        y1 := y1

thats the only use of whatdotcolor i see, and it doesn't do anything, it just makes the variable equal to themselves. 


in ur second post, why did you make y=y-1? that makes no sense if you dont want it to go around

ok..that works but wat if i want the circle to be user controled... that x1 := x1 does nothing. it acts like it just ignores it. how would i make it so when it hits it it stops. even though it is user controled

-----------------------------------
RedRogueXIII
Fri Jan 27, 2006 7:14 pm


-----------------------------------
Use math.distance or if your turing doesnt have it make it. It'll help

function distance(x1,y1,x2,y2:int):int
result sqrt((x2-x1)**2+(y2-y1)**2)
end distance

if distance between the two ovals is equal to the radius then you have a hit detection. Its also useful for when you have an irregular line boundary and know every point.

-----------------------------------
bgmrk
Fri Jan 27, 2006 7:36 pm


-----------------------------------
ok i fixed the whole circle colliding thing...however there is a new prob...when i want the circles to touch i want it to change the value of the varible "it" however when ever they collide it just goes back to being true intead of staying on false...how would i fix this here is the new code.
var gamewindow : int := Window.Open ("graphics:800;500,position:truemiddle;center,nobuttonbar")
View.Set ("offscreenonly")
var col1 : int := 2
var col2 := 4
var chars : array char of boolean
var x1, y1 : int
var x2, y2 : int
x1 := 50
y1 := 255
x2 := 750
y2 := 255
var it: boolean
var randit : int
var distance : real
var radious1, radious2 : int := 10
%%game
%board
locate (1, 45)
put "GAME!"
locate (3, 10)
put "Player 1" : 55, "Player 2"

%%%%game
randint (randit, 1, 2)
loop
    %Draw characters
    Draw.FillOval (x1, y1, radious1, radious1, col1)
    Draw.FillOval (x2, y2, radious2, radious2, col2)
    %%%board redraw
    Draw.Line (1, 450, 799, 450, 3)
    Draw.Line (1, 1, 1, 450, 3)
    Draw.Line (1, 1, 799, 1, 3)
    Draw.Line (799, 1, 799, 450, 3)
    Draw.FillBox (350, 200, 400, 250, 3)
    Draw.FillBox (100, 300, 150, 350, 3)
    Draw.FillBox (700, 50, 750, 100, 3)
    Draw.FillBox (500, 240, 550, 290, 3)
    Draw.FillBox (150, 100, 200, 150, 3)
    Draw.FillBox (700, 375, 750, 425, 3)
    %%whos it
     if randit = 1 then
            it := true
      elsif randit = 2 then
           it := false
     end if
    if it = true then
        Draw.FillBox (558, 488, 533, 468, white)
        Font.Draw ("(IT)", 85, 470, defFontID, green)
    elsif it = false then
        Draw.FillBox (85, 465, 115, 485, white)
        Font.Draw ("(IT)", 530, 470, defFontID, green)
    end if

    %%Charcter Movement
    Input.KeyDown (chars)
    %player1
    if chars (KEY_UP_ARROW) then
        y1 := y1 + 1
    end if
    if chars (KEY_DOWN_ARROW) then
        y1 := y1 - 1
    end if
    if chars (KEY_LEFT_ARROW) then
        x1 := x1 - 1
    end if
    if chars (KEY_RIGHT_ARROW) then
        x1 := x1 + 1
    end if
    if whatdotcolour (x1 - 2, y1 - 2) = 3 then
        x1 := x1
        y1 := y1
    end if
    %%%Player 2
    if chars ('w') then
        y2 := y2 + 1
    end if
    if chars ('s') then
        y2 := y2 - 1
    end if
    if chars ('a') then
        x2 := x2 - 1
    end if
    if chars ('d') then
        x2 := x2 + 1
    end if
    View.Update
    Draw.FillBox (0, 450, 800, 0, white)
    %%tag
    distance := ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) ** 0.5
    %player 1
    if it = true then
        if distance < radious1 + radious2 then
            it := false
            x2 := 750
            y2 := 255
       delay (10)
             end if
%player 2
    
    elsif it = false then
        if distance < radious1 + radious2 then
            it := true
            x1 := 50
            y1 := 255
            delay (10)
        end if
    end if
    %%pause
    if chars ('p') then
        loop
            Input.KeyDown (chars)
            Font.Draw ("PAUSED", 400, 250, defFontID, red)
            exit when chars ('p')
        end loop
    end if
end loop

