From 507d8c4ff2424e0d877481209dfd7d64cb48c442 Mon Sep 17 00:00:00 2001 From: yucy207 <52816230+yucy207@users.noreply.github.com> Date: Tue, 15 Oct 2019 16:37:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E7=90=83=E5=90=83=E5=B0=8F=E7=90=83BU?= =?UTF-8?q?G=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 球在边界附近半径增大时(吃掉小球),可能会使球在50ms内无法运动回边界内,导致球不断的在边界上改变速度(迷之抖动233) --- Day01-15/10.图形用户界面和游戏开发.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Day01-15/10.图形用户界面和游戏开发.md b/Day01-15/10.图形用户界面和游戏开发.md index ae65624..05d4bc6 100644 --- a/Day01-15/10.图形用户界面和游戏开发.md +++ b/Day01-15/10.图形用户界面和游戏开发.md @@ -249,12 +249,14 @@ class Ball(object): """移动""" self.x += self.sx self.y += self.sy - if self.x - self.radius <= 0 or \ - self.x + self.radius >= screen.get_width(): - self.sx = -self.sx - if self.y - self.radius <= 0 or \ - self.y + self.radius >= screen.get_height(): - self.sy = -self.sy + if self.x - self.radius <= 0: + self.sx = abs(self.sx) + if self.x + self.radius >= screen.get_width(): + self.sx = -abs(self.sx) + if self.y - self.radius <= 0: + self.sy = abs(self.sy) + if self.y + self.radius >= screen.get_height(): + self.sy = -abs(self.sy) def eat(self, other): """吃其他球"""