Help me find a way to make the lasers fire in a certain direction.
So, (as is often the case...) I was wrong about how to do the wrap around when the player gets to the edge of the screen.
self.Player.position.x %= width self.Player.position.y %= height # must be changed to... self.Player.position = (self.Player.position.x % self.size.w, self.Player.position.y % self.size.h)
This is because position is a
scene.Pointwhich is scene.Vector2 which behaves more like a tuple than a list.
Also, you can safely delete all lines containing
as is often the case
Not so True 😂
update_lasers()can be simplified...
def update_lasers(self): for laser in self.lasers: laser.direction = Vector2(-math.sin(laser.rotation), math.cos(laser.rotation))*10 laser.position += laser.direction if laser.position not in self.bounds: # laser has gone off the screen laser.remove_from_parent() self.lasers.remove(laser)
Also, it seems to me that you don't need both an Action that sets rotation and the actual assignment to rotation.. If you want to simulate acceleration, then you need to keep track of a velocity, and pressing the arrow button changes the velocity, and then the rotation is set by adding velocity.