python浮点数可以不带小数吗_python中不能存储小数吗

python中不能存储小数吗那这样绕了一圈最后self.rect.centerx不是还只能取self.center的整数值吗?有什么意义?importpygameclassShip():def__init__(self,ai_settings,screen):"""In...

python中不能存储小数吗那这样绕了一圈最后self.rect.centerx不是还只能取self.center的整数值吗?有什么意义?

import pygameclass Ship(): def __init__(self, ai_settings, screen): """Initialize the spaceship image and set its original position.""" self.screen = screen self.ai_settings = ai_settings # Load the image and obtain its bounding rectangle. self.image = pygame.image.load( r'D:\python_work\alien_invasion\images\ship.bmp') self.rect = self.image.get_rect() self.screen_rect = screen.get_rect() # Place the spaceship in the center of the bottom of the screen. self.rect.centerx = self.screen_rect.centerx self.rect.bottom = self.screen_rect.bottom # Store the decimals in the property center. self.center = float(self.rect.centerx) # The moving sign self.moving_right = False self.moving_left = False def update(self): """Adjust the position of the ship based on the sign.""" # Update the center of the ship instead of the rect. if self.moving_right and self.rect.right < self.screen_rect.right: self.center += self.ai_settings.ship_speed_factor if self.moving_left and self.rect.left > 0: self.center -= self.ai_settings.ship_speed_factor # Update rect based on self.center self.rect.centerx = self.center def blitme(self): """Place the spaceship in the designated position.""" self.screen.blit(self.image, self.rect)

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值