游戏开发:从基础到进阶
1. 引入数学模块
在游戏开发中,数学模块是非常有用的。要引入 math 模块,只需在代码顶部添加以下行:
import math
接着,更新 set_actor_image 函数,使其如下所示:
# Show image matching new_direction and current step count
def set_actor_image (new_direction):
global player, player_step_count
step_delay = 5
player_step_count += 1
if player_step_count >= 4 * step_delay:
player_step_count = 1
player_step_position = math.floor(player_step_count / step_delay) + 1
player.image = "compassgame_person_" + new_direction + "_" + str(player_step_position)
更新后的文件为 compassgame-movement3.py 。运行更新后的代码,你会看到角色的腿部移动速度更加逼真。
超级会员免费看
订阅专栏 解锁全文
1520

被折叠的 条评论
为什么被折叠?



