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

Username:   Password: 
 RegisterRegister   
 Moving Asterisks
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
dymd3z




PostPosted: Wed Jun 20, 2007 6:40 pm   Post subject: Moving Asterisks

How would I make one asterrisk from the left side of the screen and the right side move towards the middle, bounce off each other and back to the right and left side of the screen? Of course, it's easy to make it shift one way, but to appear as though they bounce off each other, just boggles tyhe mind.
Sponsor
Sponsor
Sponsor
sponsor
Albrecd




PostPosted: Thu Jun 28, 2007 9:14 pm   Post subject: Re: Moving Asterisks

Well, start by using variables to hold the number of spaces before the first asterisx and between the two.
then use for loops to draw the situation.
put the whole thing in a loop that will modify the numbers of spaces.

code:

for i : 1 .. numSpaces
    put " "..
end for
Nick




PostPosted: Wed Aug 15, 2007 5:43 am   Post subject: Re: Moving Asterisks

Quote:
var ast : array 1 .. 2 of int
var changeAst : array 1 .. 2 of int
ast (1) := 1
ast (2) := 80
changeAst (1) := 1
changeAst (2) := -1
loop
cls
locate (10, ast (1))
put "*" ..
locate (10, ast (2))
put "*" ..
ast (1) += changeAst (1)
ast (2) += changeAst (2)
if ast (1) >= ast (2) then
changeAst (1) := -1
changeAst (2) := 1
end if
if ast (1) <= 1 then
changeAst (1) := 1
end if
if ast (2) >= maxcol then
changeAst (2) := -1
end if
delay (10)
end loop




well thats pretty much it...
also to make it look like they're actually bouncing and not just travelling through each other you could give each a dif color with colourback(color) right before the put
Aziz




PostPosted: Wed Aug 15, 2007 8:16 am   Post subject: RE:Moving Asterisks

Three things, momop:

1) You can use [ code ] tags instead of quotes.
2) Glad to see you helping out
3) Don't do it for him Smile Give him hints, tips, pseudo-code, string him along. Believe me, you won't want to after the 50th time doing it <_<
Nick




PostPosted: Wed Aug 15, 2007 8:22 am   Post subject: RE:Moving Asterisks

lmao thanks
1) i didnt see it... can i just replace the [quote/] with [code/]?
2) no problem glad to help
3) lol ill keep that in mind the next time so it wont reach the 50th Razz
Aziz




PostPosted: Wed Aug 15, 2007 8:40 am   Post subject: RE:Moving Asterisks

Yeaup, the code tags are what you use:

code:
This is inside [ code ] and [ /code ] (take out the spaces) tags


or even syntax tags:

Turing:
%This is inside [ syntax="turing" ] and [ /syntax ] tags

var name : string

loop
    get name*
    put "Hello, ", name, "!"
end loop
Nick




PostPosted: Wed Aug 15, 2007 8:43 am   Post subject: Re: Moving Asterisks

code:
i think i got it :P
thanks
Turing:
see?
Aziz




PostPosted: Wed Aug 15, 2007 9:28 am   Post subject: Re: Moving Asterisks

Okay, now actually helping:

I think the best idea is for you to have two variables, each one holding the x position of one asterisk. Then, draw each asterisk at it's respective x value. Next iteration of the loop, increase the x value by a number. I would use a variable to store this number. When you notice that this move will bring it close to the opposite asterisk, negate that move value.

Something like this:

Turing:
%Positions of asterisks
var x1, x2 : int

%Movement of each asterisk
var move1, move2 : int

%First column
x1 := 1

%Last column
x2 := 10 %set to maxcol or something

move1 := 1
move2 := -1

loop
    % locate(row, column) i think
    locate(5, x1)
    color(red)
    put "*"..

    locate(5, x2)
    color(blue)
    put "*"..

    if x1 + move1 > x2 + move2 then
        move1 := -move1
        move2 := -move2
    end if

    if x1 + move1 < 0 then
        move1 := -move1
    end if

    if x2 + move2 > maxcol then
        move2 := -move2
    end if

   
    x1 += move1
    x2 += move2
end loop


Someone check that out and tell me if you can get it to work.
Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Wed Aug 15, 2007 9:33 am   Post subject: Re: Moving Asterisks

there were 1 or 2 problrems but i fixed and also the code u wrote makes the asterisks bounce of the wall and dymd3z says
Quote:
How would I make one asterrisk[sin] from the left side of the screen and the right side move towards the middle, bounce off each other and back to the right and left side of the screen? Of course, it's easy to make it shift one way, but to appear as though they bounce off each other, just boggles tyhe[sin] mind.


Turing:
%Positions of asterisks
var x1, x2 : int

%Movement of each asterisk
var move1, move2 : int

%First column
x1 := 1

%Last column
x2 := 10 %set to maxcol or something

move1 := 1
move2 := -1

loop
    cls
    % locate(row, column) i think
    locate (5, x1)
    color (red)
    put "*" ..

    locate (5, x2)
    color (blue)
    put "*" ..

    if x1 + move1 > x2 + move2 then
        move1 := -move1
        move2 := -move2
    end if

    if x1 + move1 < 1 then
        move1 := -move1
    end if

    if x2 + move2 > maxcol then
        move2 := -move2
    end if

    delay (10)

    x1 += move1
    x2 += move2
end loop
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  [ 9 Posts ]
Jump to:   


Style:  
Search: