direction flag vs negative velocity

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
direction flag vs negative velocity
by on (#136916)
I have a problem. I need to be able to perform character actions in both directions (left and right) so I'm using a direction flag to decide either to add or subtract velocity to an object position. The problem I have is when the player kicks a boss, in order to fall in the correct direction, it has to EOR direction flags and negate velocity if they're facing opposite directions. Anybody know of a way to fix this problem?
Re: direction flag vs negative velocity
by on (#136917)
Could you be a bit more specific about what you're asking?

You need a direction flag to store which direction a player is facing even if standing still.

If you have to "EOR direction flags and negate velocity", then "EOR direction flags and negate velocity". You'll probably need to special case whether the player and enemy are facing same or opposite directions anyway so that you can animate the enemy properly whether kicked from the front or the back.

Negating a number can be done inline:
Code:
  eor #$FF
  sec
  adc #$00

This is in fact a special case of reverse subtraction:
Code:
; A := amount - A
  eor #$FF
  sec
  adc amount