Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualÁlvaro

Posted 01 February 2013 - 08:51 PM

That looks a bit awkward. Instead of keeping an angle to indicate where the spaceship is pointing, use a vector of length 1. The code would then look something like this (ignoring the issue of the flipped x coordinate, which I think should be dealt with in the rendering code, not the scene update code):
def moveForward(self):
    self.center += self.step * self.heading
    self.rect.center = self.center.toPoint() # I don't know what this line does
What is self.rect.center? And why do you need to call `toPoint' on self.center? What is self.center if not a point?

EDIT: Oh, the tricky part with using heading as a length-one vector is how to rotate it when the user presses a key. Instead of adding something to the angle, rotate the vector by some amount (you seem to already have code for that). You may have to normalize the vector every so often (like every frame, for simplicity) so that it doesn't end up being much longer or shorter by accumulated floating-point errors.

#2Álvaro

Posted 01 February 2013 - 08:51 PM

That looks a bit awkward. Instead of keeping an angle to indicate where the spaceship is pointing, use a vector of length 1. The code would then look something like this (ignoring the issue of the flipped x coordinate, which I think should be dealt with in the rendering code, not the scene update code):
def moveForward(self):
    self.center += self.step * self.heading
    self.rect.center = self.center.toPoint() # I don't know what this line does
What is self.rect.center? And why do you need to call `toPoint' on self.center? What is self.center if not a point?

EDIT: Oh, the tricky part with using heading as a length-1 vector is how to rotate it when the user presses a key. Instead of adding something to the angle, rotate the vector by some amount (you seem to already have code for that). You may have to normalize the vector every so often (like every frame, for simplicity) so that it doesn't end up being much longer or shorter by accumulated floating-point errors.

#1Álvaro

Posted 01 February 2013 - 08:49 PM

That looks a bit awkward. Instead of keeping an angle to indicate where the spaceship is pointing, use a vector of length 1. The code would then look something like this (ignoring the issue of the flipped x coordinate, which I think should be dealt with in the rendering code, not the scene update code):
def moveForward(self):
    self.center += self.step * self.heading
    self.rect.center = self.center.toPoint() # I don't know what this line does
What is self.rect.center? And why do you need to call `toPoint' on self.center? What is self.center if not a point?

PARTNERS