Text collision help
Author |
Message |
Freakish
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
pavol
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
do_pete
![](http://i38.photobucket.com/albums/e112/do_pete/1943.gif)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
Freakish
|
Posted: Thu Nov 10, 2005 11:59 am Post subject: (No subject) |
|
|
Thx I think i'll try tony's idea |
|
|
|
|
![](images/spacer.gif) |
|
|