[gameprogrammer] Re: Flash Games

  • From: Scott Harper <lareon@xxxxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Sat, 21 Oct 2006 11:52:53 -0600

Something (which may or may not be good) that I've resorted to doing is, because of consistent-speed versus inconsistent framerate, I have -- assuming only left/right up/down movement, and that they are opposed in those pairs -- two signed integer variables that I use for movement. This setup is for a top-down four-directional-scroller style, but could be adapted to other styles. Anyway, when the user presses left, I subtract 1 from the forwardMovement variable, righ I add 1. Up I add one to the upwardMovement variable, and down I subtract 1. Then you do the reverse when each key is released.

This gives me two nice equations for moving the character:

player.x += ( fMovementSpeedPerSecond * fTimePassedInSecondsSinceLastFrame * forwardMovement );
player.y += ( fMovementSpeedPerSecond * fTimePassedInSecondsSinceLastFrame * upwardMovement );


In this way I avoid extra conditionals every frame. Opposing movements negate each other as they should. The only thing to be careful of in this case is key-repeats, because you have to ONLY make the change on the INITIAL press, ignoring key-repeats. Many APIs will have either different methods for key-presses versus key- repeats, or ways you can turn off/ignore repeating keys, however.

This is only what I do, and I don't know how much is helps or not. I'm sure the two conditionals you have to make won't slow you down by enough to worry about if you do it the other way... But this way makes a lot of sense to me and feels more streamlined. Probably just new-programmer-misconception-of-speed, though, which happens often.

--Scott

On Oct 17, 2006, at 12:25 PM, Stephen Smith wrote:

Here's a slight tweak to that: instead of creating a new var for each key, what I do is create a boolean array, and then on a KeyDown event (I use Java so whatever the C equivalent is) just set the cell of the ascii code to true (and false when the key is released).

Steve


Alan Wolfe wrote:
Oh here's another concept which greatly helps in game programming...
Instead of checking for keyboard events (such as making the player move when the player presses an arrow key), what you want to do is store the STATES of keys - whether they are pressed down or not.
for example, when the user presses the right arrow key, instead of moving the player, just set RightArrowKeyPressed=1, and when they let go of the key, set RightArrowKeyPressed=0.
Then, in your UpdateWorld function, all you do is...
if(RightArrowKeyPressed==1)
//move player right
if(LeftArrowKeyPressed==1)
//move player left
if(SpaceBarPressed==1)
//shoot a bullet
when you do it this way, it makes for much smoother controls, and lets you do things like move diagonally and shoot at the same time - as well as holding in the fire button to do rapid fire.
On 10/16/06, *David Cornell* <kaosboy192000@xxxxxxxxx <mailto:kaosboy192000@xxxxxxxxx>> wrote:


I want to create a Flash MX game in the side-scrolling beat-em-up
fashion, hopefully 3/4 perspective, but I have NO IDEA how to
start aside from sketching character models, scanning them in, and
editing variations with a good art editor. Beyond that, I could
use a technical starting point for this project.








--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html




---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: