[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Float precision
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Float precision
- From: OsKaR <oscartorres10@xxxxxxxxx>
- Date: Thu, 3 Jul 2008 00:22:49 +0200
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Wed, 02 Jul 2008 18:22:55 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=S1OUJqDuYp3jjVQ6SqLhUWDY35uPN+LsEq84dJmEvYo=; b=GraelgSF5rMacCAB0jWU0ebYHPk3jQutNSso8K4BAgE7xOhbmk5rPH5cEqQhK5crG9 ZmozcWFZmyhc+0y+faAu84PCZ2QV6sC0w1O43PU3WKbM+ejXrM6L/dh6+hwNA1GtxL7m llDi/Wmfn3Rv8C1PF1vzR8goZz6+0/4ChSxhA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=P1YU9io0VfJVk3MbqBGtkQSlMgyV2i6exU8mN076BaQ+D/qTUguSqli05JnGz4EmbL qFMc+DBlL3yW6k+1e2xO3P5ac25inMLF4DG4Vz2otqGqp9HjEw5DLxM1ZC7q5kmwImwj IRuN3KU5SlD5SBG6LuaDlvq0BlJ78aAQAsUKU=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Hi all, I've been trying to rotate and move forward a tank in a game I'm developing but something strange happens.
When the tank is rotating and moving it tends to move to the up-left corner and I don't know why.
Anyone knows what's happen?
Thank you all!
Here is the code:
def do_actions(self):
all_keys = pygame.key.get_pressed()
if all_keys[K_w]:
self.dir = +1
self.tank_move()
elif all_keys[K_s]:
self.dir = -1
self.tank_move()
if all_keys[K_a]:
self.rot_dir = +1
self.tank_rotate()
elif all_keys[K_d]:
self.rot_dir = -1
self.tank_rotate()
def tank_move(self):
dx = sin(self.angle * pi/180) * self.dir * self.speed
dy = cos(self.angle *pi/180) * self.dir * self.speed
add_pos = (self.dir * self.speed * dx, self.dir * self.speed * dy)
self.rect.centerx += dx
self.rect.centery += dy
def tank_rotate (self):
self.angle = self.angle + self.vel_rot * self.rot_dir
aux_center = self.rect.center
self.image = pygame.transform.rotate(self.copy, self.angle)
self.rect = self.image.get_rect()
self.rect.center = aux_center
self.rot_dir = 0