Here's a simplified Medusa Head movement code in principle.
The Medusa Head doesn't move in a sine wave per se. It's more of a stretched sawtooth wave. That's one reason you shouldn't use trig functions in Game Maker to replicate Medusa Head and Bat movements. The other reason is trig is much slower to calculate out.
The problem I've had is how to hnadle the status flag in the NES processor. I obviously don't understand 8-bit programming very well because this should have been an easy conclusion for me to reach, nor is my theory perfect. It has its flaws, from what I can tell.
I still need to wrap my head around the carry bit of the status flag. It's simple enough, I know: When you add two numbers, if they exceed the current base (which is 8 bits), 1 will need to be added to the next base so you set the carry bit for the processor to remember. I get confused when dealing with subtraction. When subtracting two numbers results in a negative, you don't carry a bit over to the next base, you take one from the next base -- hence the carry bit is set when the result is greater than or equal to 0. It sounds like I understand it, but I still don't. I need to get myself into the mindset that when the carry bit is used between two bytes, those bytes are actually part of the same number. My mind is still stuck in "separate bytes" mode.
The Medusa Head's code I've been using is simple enough already, but I wanted to make it simpler and faster. I understood the underlying principle of it well enough: subtract a fraction of the difference between the current y-coordinate and the starting y-coordinate from the vertical speed. The order of operations is the tricky part and it's not a very flexible code either. It will take many tests to get a feel for how the various parts of the algorithm work.
The basic formula for 8-bit sinusoidal movement that Konami used is of the form
vspeedt+1 = vspeedt +(y0 - yt)/n
In other words, the vspeed of any given step is the previous step's vspeed plus a fraction of the difference between the starting y-coordinate and the previous y-coordinate. In other words:
vspeed -= (ystart - y)/n
The trick is getting the correlation between the initial vspeed and n figured out. A higher value of n will result in a larger wavelength. A higher initial vspeed will result in a larger amplitude. Finding the proper ratio is a matter of aesthetics.
No comments:
Post a Comment