This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

direction flag vs negative velocity

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