Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Text collision help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Freakish




PostPosted: 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

Sponsor
Sponsor
Sponsor
sponsor
pavol




PostPosted: Thu Nov 10, 2005 10:48 am   Post subject: (No 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
do_pete




PostPosted: Thu Nov 10, 2005 11:48 am   Post subject: (No subject)

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




PostPosted: Thu Nov 10, 2005 11:49 am   Post subject: (No 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
Freakish




PostPosted: Thu Nov 10, 2005 11:59 am   Post subject: (No subject)

Thx I think i'll try tony's idea
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: