Jump to content
  • entries
    334
  • comments
    900
  • views
    258,107

Fractional movement


EricBall

514 views

My current challenge is rewriting the movement routine to use fractional positioning for both the player and enemies. (Well, the enemies already used fractional positioning, but now I'm giving them two speeds.) There are actually four different speeds:

falling speed - 20 pixels per second

fast player - 13.3 pixels per second

slow player / fast enemy - 10 pixels per second

slow enemy - 8 pixels per second

 

Weird numbers, but those are the integer movements which match up with the round-robin movement logic which does each enemy & player every 1/10th of a second.

 

Of course, these values don't translate into an even number of 256th pixels per frame so I'm using my super-duper fractional adder which handles the remainders: (NTSC falling)

7$	CMP	#FALLING
BNE	8$
LDA	YFPOS,X
CMP	#170
ADC	#85
STA	YFPOS,X
BVC	8$
DEC	YPOS,X
BVS	8$

Unfortunately, although I can make it work for 5 of the 8 possibilities (NTSC/PAL), 3 of them aren't 100% reversible. This is important because the player can change direction in mid-stride (the enemies don't), so if the calculations aren't symetrical in both directions, then the player could manage to get off-grid and all kinds of weird things would happen. (Because most of the movement logic is only done when the player/enemy is on grid.)

 

Fortunately, one of the 3 possibilities is slow NTSC enemy so I can ignore it. Unfortunately, that still leaves two which I need to figure out how to fix. Right now I'm trying things out in a spreadsheet to see if I can come up with some exception logic to make one direction look like the other.

 

One good thing with all of this is it will make player & enemy movement even smoother since everyone's position is updated every frame (even if it's just fractionally).

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...