super-super alpha (near-disgustingly garbage level)
right now, it only plays the foward animation sprite
to be quite honest, i'm not all too sure... i just picked up the program yesterday! :s
i can drop the lines of code that used here though, if you'd like?
I had similar problem while working on my pong game and I have gone into detail how I solved it over here.
When you travel diagonally on both X and Y axis at the same time, you actually travel further then if only on X or Y. This is because the diagonals in any square/rectangle are greater than any of the lengths (Diagonal "d" = √(Xsquared + Ysquared) ). So if you travel 3 pixels each tick on X and Y, diagonally you actually travel (√(33 + 33))= roughly 4.24 pixels. That's almost 125% increase!
To solve that you would need to make sure, that no matter what buttons are pressed the travel distance is the same. One way to do this is to use pythagorean theorem. You keep your distance in a variable (speed). When a single button is pressed, sprite's X or Y (depending on button) = speed (or -speed, again depending on button pressed). This is very similar to what you have right now.
When two buttons are held at the same time (one for X axis, other for Y), instead of travelling at X and Y = speed. You want X and Y equal √(speed)/2. You can implement that either with IF functions for pressing two buttons at once, or by limiting the speed variable two 3.
Hope that helps a bit. There is probably a much easier way to do it, but I am a beginner programmer myself ;)
You can solve diagonal movement by changing the player's velocity by a percentage if both arrow keys are held down. This allows you to scale it according to what you think feels right as you play around with it. I find that 71.5% works pretty well.
Something along the lines of
if (left and up, left and down, right and up, right and down) speedModifier = 0.715 else speedModifier = 1 end player.vel = speed * speedModifier |
[Please log in to post a comment]