Computer Science Canada Controlling a Character and Having an Object Move at the Same Time |
Author: | Greyscale [ Sun Dec 14, 2014 10:31 pm ] | ||
Post subject: | Controlling a Character and Having an Object Move at the Same Time | ||
What is it you are trying to achieve? I'm making a dungeon crawler game, where the player controls a character and there is an enemy moving, guarding an object. The player has to get past the enemy to get to the object. What is the problem you are having? I can't get the player to be able to control the character and have the enemy move automatically at the same time. ie. I can't get two different parts to run at the same time. Describe what you have tried to solve this problem I've tried making processes of the enemy movement part, and forking it. Found out that forking should really only be used with music or audio. I tried to call the two parts in as subprograms at the same time, got an error. And of course, I looked online to see if anyone had a similar problem to mine. I didn't find any. If I have indeed missed a post that deals with this same issue, please link me to it. Thanks! Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using Open Turing |
Author: | Insectoid [ Sun Dec 14, 2014 10:50 pm ] | ||
Post subject: | RE:Controlling a Character and Having an Object Move at the Same Time | ||
You need to learn about the idea of a game loop. Right now, you use a separate loop for everything that moves. The player gets a loop, the enemies get a loop, projectiles get their own loop, etc. To get everything to move together, you need to put everything into the same loop instead. Every time that loop completes an iteration, every animation will have advanced by one frame. It will check keyboard/mouse input once, calculate and update all sprite positions for the current frame once, do one frame's worth of other game logic and draw everything once. It should look something like this:
Obviously that code won't run but it should give you an idea of what your code should look like. |
Author: | Greyscale [ Mon Dec 15, 2014 4:38 pm ] |
Post subject: | Re: Controlling a Character and Having an Object Move at the Same Time |
Hey, thanks for the answer. It was really helpful! The program runs fine, now all I have to do is clean it up a bit. |