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

Username:   Password: 
 RegisterRegister   
 getting an object to go toward center of window
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Skizzarz




PostPosted: Tue Jan 20, 2004 7:32 pm   Post subject: getting an object to go toward center of window

How would i go about making an object (a cirlce for example) go toward the center of the screen but with some 'randmality', kind of like a brownian program but going to the center instead of totally random directions, thx allot
Sponsor
Sponsor
Sponsor
sponsor
shorthair




PostPosted: Tue Jan 20, 2004 7:40 pm   Post subject: (No subject)

You can make the randint have maxx and min values , just make it randomize on a certain area , the randomize is defined by the user
Skizzarz




PostPosted: Tue Jan 20, 2004 7:54 pm   Post subject: (No subject)

but how would make it randomized like using "proc" or whatever
AsianSensation




PostPosted: Tue Jan 20, 2004 8:37 pm   Post subject: (No subject)

code:

-------------------------------------
|                                            |
|                                            |
|                                            |
|                                            |
|                     *                     |
|                                            |
|         O                                 |
|                                            |
|                                            |
-------------------------------------


calculate the difference in y position, and the difference in x position. Then use Rand.Int or something, and randomly choose to go up one or right one (in the example above)

if you want it to look very very random, then every five loop or so, randomly move to any direction.
Skizzarz




PostPosted: Tue Jan 20, 2004 8:48 pm   Post subject: (No subject)

where can i find a brownian like program in turing (with source code), cuz my ball wont go towards the center:

code:
setscreen ("nocursor")
var x : int := 1
var y : int := 1
var newx : int
loop
x := x + 3
y := y + 3
randint ( x, 0, 5)
randint ( y, 0, 5)
drawfilloval (x, y, 10, 10, 5)
cls
end loop


if i could get a look at some brownian source then i could fix it
Andy




PostPosted: Tue Jan 20, 2004 8:53 pm   Post subject: (No subject)

just increase ur x and y in ratios of xdis/ydis of u and the center
Skizzarz




PostPosted: Tue Jan 20, 2004 8:55 pm   Post subject: (No subject)

im not tryin to be a code whore but could u gimme a little example plz?
AsianSensation




PostPosted: Tue Jan 20, 2004 8:57 pm   Post subject: (No subject)

code:
var posx, posy, dx, dy, randnum : int := 0
posx := Rand.Int (0, maxx)
posy := Rand.Int (0, maxy)
loop
    dx := maxx div 2 - posx
    dy := maxy div 2 - posy

    randint (randnum, -1, 1)

    if randnum = -1 then
        posx += Rand.Int (-1, 1)
        posy += Rand.Int (-1, 1)
    elsif randnum = 0 then
        posx += 1 * sign (dx)
    elsif randnum = 1 then
        posy += 1 * sign (dy)
    end if

    drawfilloval (posx, posy, 10, 10, 5)
    delay (10)
    cls
end loop


did you even try at all? I am seriously wondering....
Skizzarz




PostPosted: Tue Jan 20, 2004 9:18 pm   Post subject: (No subject)

i really did try, sorry but im kind of stupid, well ive been takeing turing since the start of the schoool year and i havnt really progressed allot. i have a really important question, how would u get that to run while other things are happening, because its a loop, just like a crosshair over a mouse, its a loop , so how would i get other things to happen while its looping?
the_short1




PostPosted: Tue Jan 20, 2004 9:57 pm   Post subject: (No subject)

fork a proceedure... then it will do it at same time as loop.. if you want it to do it again and again... make a loop inside of process... see example:

process musik
loop
if mus := "yes"
Music.PlayFile ("wav/backroundbeat.mp3")
end if
end loop
end musik
fork musik (once not in your loop)
then it will keep repeating my backround msuik... hope that helps...
i use Music.PlayFileStop and then i make mus := no to end my musik...
this can be used for counters on games for time and such....kinda slows down with movement of arrow keys tho....
make a pixel brownian program and randomize the x and the y value to either do nothing or plus 1 to center... i think that might work,,, or try previous post's example..AsianSensation<<<he pro>>
AsianSensation




PostPosted: Tue Jan 20, 2004 10:34 pm   Post subject: (No subject)

the_short1 wrote:
fork a proceedure... then it will do it at same time as loop.. if you want it to do it again and again... make a loop inside of process...


arg, arg, arg. Don't use turing's process unless you really really really have to. It's way to inaccurate and out of sync with the rest of your program. Instead, just do everything in the loop. I only did calculations in there, the only part that really affects the output is the drawoval part. So basicly, I would suggest this, do all your calculation somewhere in the loop, and near the end of the loop, output everything to screen. That should let you have multiple things going on without process.
Skizzarz




PostPosted: Wed Jan 21, 2004 8:06 pm   Post subject: (No subject)

um asian, i totally dont get wut u mean, but i kind of understand the 'fork' thing, is there a tutorial i could find on 'forking'? thanks
scryed




PostPosted: Wed Jan 21, 2004 8:44 pm   Post subject: (No subject)

Ahhh...parents were a little too shy to explain the ins and outs of 'forking' eh? Embarassed

Seriously listen to AS, you only NEED to fork when you want to play beautiful music (for the most part)
Skizzarz




PostPosted: Wed Jan 21, 2004 9:30 pm   Post subject: (No subject)

but if u have a loop within a loop then it will never get out of the loop inside, because its endless, so forking makes sense to me...
AsianSensation




PostPosted: Wed Jan 21, 2004 10:40 pm   Post subject: (No subject)

Skizzarz wrote:
but if u have a loop within a loop then it will never get out of the loop inside, because its endless, so forking makes sense to me...


I never said loop within a loop, I meant something like this:

code:
loop
    calculate enemy movement
    calculate self movement

    draw enemy
    draw self
    View.Update
end loop


so you are constantly changing the position of self and enemy, and then you draw them, so it seem like both of them are moving. No forking needed.

btw, if you have a loop in a loop, you can either use return to instantly terminates the program, or set flags of boolean value, and exit the loop when the flag is true.
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  [ 15 Posts ]
Jump to:   


Style:  
Search: