Computer Science Canada multiple actions in an "if" statement? |
Author: | Weapon X [ Fri Apr 22, 2005 8:55 pm ] | ||
Post subject: | multiple actions in an "if" statement? | ||
In an code like this can the "if" statements have mulitple actions? For example: If i press Up arrow can the ball go like 5 up slowley, and then the ball automatically comes back down 5slowley (and by slwley i mean "You can see the ball go up the come back down")? |
Author: | Flikerator [ Fri Apr 22, 2005 9:10 pm ] | ||
Post subject: | |||
Here you go, if you want an explanation just ask |
Author: | Cervantes [ Sat Apr 23, 2005 8:36 am ] | ||
Post subject: | |||
That's definately not what we want, Flik. Using a for loop like that means nothing else can happen while your character is moving. Though you might be able to pass it off as an ability of your character to stop time if your user is dumb enough, but that's too risky. The user might catch on and think your program is silly! How do we fix this? Left and right movement is the easiest. If the left or right arrow keys are pressed, incriment the object's x variable appropriately. Jumping is more difficult though. Basically, we are going to give the object a certain velocity in the y plane if the up arrow is pressed. We will also use a boolean variable to keep track of whether the object is already in the air or not, just to make sure that the object can't jump off of the air (like so many crazy, unrealistic video game characters).
|
Author: | Jonny Tight Lips [ Sat Apr 23, 2005 11:24 am ] | ||
Post subject: | |||
don't know if this code will acctualy run. I didn't have turing on this computer so I couldn't actualy run it but I think I got it correct. All I juses was a counter as a flag so it keeps going up until the couter equils 5 and then goes down 5. Hope it works |
Author: | Flikerator [ Sat Apr 23, 2005 2:42 pm ] | ||
Post subject: | |||
Cervantes wrote: That's definately not what we want, Flik. Using a for loop like that means nothing else can happen while your character is moving. Though you might be able to pass it off as an ability of your character to stop time if your user is dumb enough, but that's too risky. The user might catch on and think your program is silly!
How do we fix this? Left and right movement is the easiest. If the left or right arrow keys are pressed, incriment the object's x variable appropriately. Jumping is more difficult though. Basically, we are going to give the object a certain velocity in the y plane if the up arrow is pressed. We will also use a boolean variable to keep track of whether the object is already in the air or not, just to make sure that the object can't jump off of the air (like so many crazy, unrealistic video game characters).
I didn't know thats what he wanted. |
Author: | Cervantes [ Sat Apr 23, 2005 3:54 pm ] |
Post subject: | |
Haha. Okay, maybe it's not what he wanted. But it's definately what he should want! |
Author: | Flikerator [ Sat Apr 23, 2005 4:54 pm ] |
Post subject: | |
Cervantes wrote: Haha. Okay, maybe it's not what he wanted. But it's definately what he should want!
Agreed Are const justs var's that you cannot change? |
Author: | Cervantes [ Sat Apr 23, 2005 6:05 pm ] |
Post subject: | |
Yep. You know, I should have made jumpVelocity and speedX variables, in case the player drinks some gaterade and gets an energy boost |
Author: | Flikerator [ Sat Apr 23, 2005 7:08 pm ] |
Post subject: | |
Cervantes wrote: Yep. You know, I should have made jumpVelocity and speedX variables, in case the player drinks some gaterade and gets an energy boost
Yah I was thinking about that lolz There is so much you could do with that little program. Definitly gaterade |
Author: | Weapon X [ Mon Apr 25, 2005 12:12 pm ] | ||
Post subject: | Now What? | ||
i created a program with the advice from ppl. here is wht io got but there is still a problem. can someone help me out AGAIN.
|
Author: | jamonathin [ Mon Apr 25, 2005 1:28 pm ] |
Post subject: | |
Gravity is a real variable, and it would normall be okay to add it to an integer variable, as long as the number is whole. 0.07 is not a whole number, and cannot be added to an integer variable. try making vy real, and have slimey add round (vy). |
Author: | Weapon X [ Mon Apr 25, 2005 2:47 pm ] |
Post subject: | TRU!! |
TRU, i forgot to round. thanx to everyone who helped me. |