Computer Science Canada

Text collision help

Author:  Freakish [ Wed Nov 09, 2005 9:41 pm ]
Post subject:  Text collision help

I made alittle program with a bouncing star line
code:
var x, y, nx, ny : int
x := 1
y := 1
nx := 1
ny := 1
loop
    delay (100)
    locate (10,10)
    put "0000000000000000000000000000"..
    x := x + nx
    y := y + ny
    if y = 79 then
        ny := -1
    end if
    if y = 1 then
        ny := 1
    end if
    if x = 24 then
        nx := -1
    end if
    if x = 1 then
        nx := 1
    end if
    Text.Locate (x, y)
    put "*" ..
    end loop

I'm trying to figure out how to get the star to bounce off of another character like 0. so far i haven't been able to find anything on it.

i'm just don't want to do this.
code:
var x, y, nx, ny : int
x := 1
y := 1
nx := 1
ny := 1
loop
    locate (10, 50)
    put "0000000000" ..
    delay (100)
    x := x + nx
    y := y + ny
    if y = 79 then
        ny := -1
    end if
    if y = 1 then
        ny := 1
    end if
    if x = 24 then
        nx := -1
    end if
    if x = 1 then
        nx := 1
    end if
    locate (x, y)
    put "*" ..
    % Top of Walls
    if x = 9 and y = 51 then
        nx := -1
    elsif x = 9 and y = 52 then
        nx := -1
    elsif x = 9 and y = 53 then
        nx := -1
    elsif x = 9 and y = 54 then
        nx := -1
    elsif x = 9 and y = 55 then
        nx := -1
    elsif x = 9 and y = 56 then
        nx := -1
    elsif x = 9 and y = 57 then
        nx := -1
    elsif x = 9 and y = 58 then
        nx := -1
    elsif x = 9 and y = 59 then
        nx := -1
    elsif x = 9 and y = 60 then
        nx := -1
    end if
    % Bottem of Walls
        if x = 11 and y = 51 then
        nx := 1
    elsif x = 11 and y = 52 then
        nx := 1
    elsif x = 11 and y = 53 then
        nx := 1
    elsif x = 11 and y = 54 then
        nx := 1
    elsif x = 11 and y = 55 then
        nx := 1
    elsif x = 11 and y = 56 then
        nx := 1
    elsif x = 11 and y = 57 then
        nx := 1
    elsif x = 11 and y = 58 then
        nx := 1
    elsif x = 11 and y = 59 then
        nx := 1
    elsif x = 11 and y = 60 then
        nx := 1
    end if
end loop


Author:  pavol [ Thu Nov 10, 2005 10:48 am ]
Post subject: 

what you can do is use a loop instead of so many if statements
code:
var x, y, nx, ny : int
x := 1
y := 1
nx := 1
ny := 1
loop
    locate (10, 50)
    put "0000000000" ..
    delay (100)
    x := x + nx
    y := y + ny
    if y = 79 then
        ny := -1
    end if
    if y = 1 then
        ny := 1
    end if
    if x = 24 then
        nx := -1
    end if
    if x = 1 then
        nx := 1
    end if
    locate (x, y)
    put "*" ..
    % Top of Walls
    for i : 50 .. 60
        if x = 9 and y = i then
            nx := -1
        end if
    end for
    % Bottom of Walls
    for i : 50 .. 60
        if x = 11 and y = i then
            nx := 1
        end if
    end for
end loop

Author:  do_pete [ Thu Nov 10, 2005 11:48 am ]
Post subject: 

you can store all the text in an array and use that to chech for collision

Author:  Tony [ Thu Nov 10, 2005 11:49 am ]
Post subject: 

or use ranges in your if statements
Turing:

 % Bottom of Walls
        if x = 11 and y >= 50 and y <= 60 then
            nx := 1
        end if

Author:  Freakish [ Thu Nov 10, 2005 11:59 am ]
Post subject: 

Thx I think i'll try tony's idea


: