Computer Science Canada

Zomg Ir N00b

Author:  Argus [ Wed Jun 24, 2009 11:39 am ]
Post subject:  Zomg Ir N00b

What is it you are trying to achieve?
Making my own collision detection


What is the problem you are having?
Operands of Boolean operators must be boolean, higlights the variable c in the if statement


Describe what you have tried to solve this problem
changed variable c to boolean, didnt work


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Code tehre

Turing:


var superman : int := Pic.FileNew ("Superman.gif")
var ssprite : int := Sprite.New (superman)
var boulder : int := Pic.FileNew ("rock.gif")
var bsprite : int := Sprite.New (boulder)
var chars : array char of boolean
var x, y, a, b, c, d, e : int

x := 100
y := 100
d := 400
e := 400

Sprite.SetPosition (ssprite, 100, 100, true)
Sprite.Show (ssprite)
Sprite.SetPosition (bsprite, 400, 400, true)
Sprite.Show (bsprite)

loop
    a := 30
    b := 60
    c := 40
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        y := y + 5
    end if
    if chars (KEY_RIGHT_ARROW) then 
        x := x + 5
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 5
    end if
    if chars (KEY_DOWN_ARROW) then
        y := y - 5
    end if
    View.Update
    Sprite.Animate (ssprite, superman, x, y, true)
    Sprite.Animate (bsprite, boulder, d, e, true)
    delay (10)
    if x + b and y + a > d - c and e - c then
        delay (1000)
    end if
end loop



Please specify what version of Turing you are using
4.1.1a or sumthing like that

Author:  DemonWasp [ Wed Jun 24, 2009 12:05 pm ]
Post subject:  RE:Zomg Ir N00b

Well, the solution depends on what you're trying to do. Let's break up the if-statement's condition first:

code:
if x + b then

The above doesn't make any sense. Why not? Well, suppose x is 15 and b is 12. Then what you're asking is "if 27 then...", and that's just nonsense.

Similarly,
code:
if e - c then

doesn't make any sense.

You'll be happy to know that
code:
if y + a > d - c then

makes sense - because it has a comparison operation in it. Instead of asking "if 27", you're asking "if 27 is greater than 15, then...".

At a guess, you were expecting it to compare (x+b) and (y+a) to (d-c) and (e-c). In that case, you want this:
code:

if x+b > d-c and x+b > e-c and y+a > d-c and y+a > e-c then

Author:  Argus [ Wed Jun 24, 2009 5:24 pm ]
Post subject:  RE:Zomg Ir N00b

ok my sprites are centeed and i want it to be like if the top right corner is in between 2 points in the other sprite then its a hit


: