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

Username:   Password: 
 RegisterRegister   
 Animating two objects at same time
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Vesper




PostPosted: Wed Jan 19, 2005 4:47 pm   Post subject: Animating two objects at same time

I'm trying to make a pacman game but turing won't allow me to animate more than one object at the same time (i.e pacman and the ghosts). One object gets all skippy and the other doesn't move at all. I was told that the animation code has to be in one process and under the same delay. I've been trying to get it to work for the last while but don't know what to do. If someone could tell me how to do this it would be greatly appreciated.
Sponsor
Sponsor
Sponsor
sponsor
cycro1234




PostPosted: Wed Jan 19, 2005 5:03 pm   Post subject: (No subject)

Well, you could make the animation inside a process, and have a loop inside the process. For example :

process pacman
loop
{Draw pacman}
end loop
end pacman

fork pacman

then

process ghost
loop
{Ghost animation}
end loop
end ghost

fork ghost

Does that help?
Delos




PostPosted: Wed Jan 19, 2005 5:06 pm   Post subject: (No subject)

1)
Hello.

2)
In future, post samples of the code that you've been working on. It helps us see where you are, and know that you're not leeching...not as though I'd ever suspect someone who uses Latin in their name to be a leecher.

3)
Processes are evil. Instead, what you should do have a single loop in which you will draw your two objects. At the end of the loop you will use a View.Update command. This implies that you will also use setscreen("offscreenonly") at the outset of your code.
Press F10 to read up on it.

BTW, depening on which version of OOT you're running, View.Update may not have been implemented...but that's mainly the case w/ older versions.
Vesper




PostPosted: Wed Jan 19, 2005 8:43 pm   Post subject: (No subject)

I have offscreenonly and View.Update. I've also tried to put pacman in a process but the fact that he has eight filepics depending on what key is pressed, complicates the matter (two per direction).

The animation for the ghost is set up like this
code:

process animation
    Pic.Draw (ghosto, r, c, picCopy)
    View.Update
    delay (80)
    Pic.Draw (ghosto, r, c, picXor)

end animation

and the animation for pacman is not in a process, but in the main loop..
code:

 %Using the buffer method of animation
    if chx = 8     %Animating the right file pics
            then
        Pic.Draw (paccr, x, y, picCopy)
        View.Update
        delay (80)
        Pic.Draw (paccr, x, y, picXor)
        Pic.Draw (pacor, x, y, picCopy)
        View.Update
        delay (80)
        Pic.Draw (pacor, x, y, picXor)

        for i : 17 .. 25     %For statement to block him crossing the lines
            dotC2 := whatdotcolor (x + i, y + 16)
            dotC := whatdotcolor (x + i, y)
            if dotC = col or dotC2 = col
                    then
                chx := 0
                exit
            end if
        end for
    end if

fork animation


and from the little I know about processes', the ghost should be moving around on its own without messing up pacman's animation.
cycro1234




PostPosted: Wed Jan 19, 2005 10:22 pm   Post subject: (No subject)

Well, what is it that's your problem? Is it that the pacman moves only? And not the ghosts at the same time. From what I see in ur code, it seems that since ur pacman is in the main loop and not in a process, the main loop will run first and then the ghost.
Cervantes




PostPosted: Wed Jan 19, 2005 10:28 pm   Post subject: (No subject)

Delos wrote:
Processes are evil. Instead, what you should do have a single loop in which you will draw your two objects. At the end of the loop you will use a View.Update command.

I'd just like to point out that this is the widely accepted stance on processes in Turing. Processes don't work like you think they do. No program can run perfectly if it uses processes. Find another way! Wink
cycro1234




PostPosted: Thu Jan 20, 2005 12:10 am   Post subject: (No subject)

Why is everybody so against processes?? Confused
Vesper




PostPosted: Thu Jan 20, 2005 4:19 pm   Post subject: (No subject)

Here is exactly whats not working. When I push the arrow key and pacman is moving, both he and the ghost flicker a lot and are slowed down to half of their speed. Also, when he hits a wall and comes to a stop, he disappears completely but the ghost moves perfectly normal.

Quote:
Processes are evil. Instead, what you should do have a single loop in which you will draw your two objects. At the end of the loop you will use a View.Update command. This implies that you will also use setscreen("offscreenonly") at the outset of your code.
Press F10 to read up on it.


The problem with this is that for the pacman to open and close it's mouth, it needs to have a View.Update after each of the filepics (one for open mouth and one for closed mouth).

I've tried with one View.Update at the end but it doesn't work. Btw, thanks for the help so far.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu Jan 20, 2005 4:36 pm   Post subject: (No subject)

You could use either a counter or the Time module and some thinking to make it work, without using processes. Whatever you do, only use one View.Update. They take a long time and using more than one is an unnecessary waste of processing power.
Cycro: They don't execute well. Take a look at the output from the folowing program:
Turing:

process doHi
    for i : 1 .. maxrow div 2
        put "hi"
    end for
end doHi
process doHo
    for i : 1 .. maxrow div 2
        put "ho"
    end for
end doHo
fork doHi
fork doHo

See how it produces strings of hi's and strings of ho's, and might even produce a "hiho" or "hohi", or even a blank line. That will screw your program up.
What you really want is "hi\nho\nhi\nho" etc.
Turing:

for i : 1 .. maxrow div 2
    put "hi"
    put "ho"
end for
basketball4ever




PostPosted: Fri Jan 21, 2005 7:06 pm   Post subject: (No subject)

code:

var col : int := 20
var introline : string := "HIHIHIHIHI"
var introline2 : string := "BYEBYEBYE!"
for a : 1 .. length (introline)
    colour (col)
    locate (10, a + 20)
    put introline (a)
    locate (11, a + 20)
    put introline2 (a)
    delay (400)
    col := col + 3
end for
loop
    exit when hasch
end loop

lol sorta animation : P?
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  [ 10 Posts ]
Jump to:   


Style:  
Search: