Do your actions affect the ending?

It seems like you could do a perfect good run but in the final fight just switch to mega evil? like are there specific endings that are locked based on your previous actions?