Jump to content
Posted 19 December 2012 - 08:12 PM
Posted 19 December 2012 - 10:47 PM
self.i.getkeys() self.player.vx = 0 self.player.vy = 0 if self.i.r: self.player.vx += self.player.speed if self.i.l: self.player.vx -= self.player.speed if self.i.d: self.player.vy += self.player.speed if self.i.u: self.player.vy -= self.player.speedWith this approach is that if you press left and right simultaneously, vx will add the variable speed and then subtract that same value, balancing out at 0 x-direction speed, which seems reasonable for someone trying to go both left and right at the same time.
if self.i.r: self.player.vx = self.player.speed else: if self.i.l: self.player.vx = -self.player.speed else: self.player.vx = 0It brings in the side effect that if someone were pressing right and left at the same time, the player would go right (because the first else wouldn't get hit to check for left being true).
Edited by j-locke, 19 December 2012 - 10:49 PM.
Posted 20 December 2012 - 07:20 AM