numpy入个门

numpy入个门


自己也不总结了,上课看了一篇博客,下面贴出 博客入口基础入门入口:


未表明转发,如有侵权,请联系删除!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
下面是一个使用Ursina和NumPy库编写的足球点球大战游戏示例代码,其中包含守员和射者,玩家可以控制射力度: ```python from ursina import * import numpy as np app = Ursina() # 创建球 goal = Entity(model='cube', scale=(8, 3, 0.5), color=color.white, position=(0, 2, -10)) goal_left = Entity(model='cube', scale=(1, 3, 0.5), color=color.red, position=(-4.5, 2, -10)) goal_right = Entity(model='cube', scale=(1, 3, 0.5), color=color.red, position=(4.5, 2, -10)) # 创建足球 ball = Entity(model='sphere', color=color.white, scale=0.2, position=(0, 1, 0)) ball.collider = 'sphere' ball.add_script(SmoothFollow(target=ball, offset=(0, 5, -10), speed=4)) # 创建射者 shooter = Entity(model='cube', scale=(0.5, 1, 0.5), color=color.red, position=(0, 1, -14)) # 创建守员 goalkeeper = Entity(model='cube', scale=(1, 1.5, 0.5), color=color.blue, position=(0, 2.5, -7)) # 创建游戏界面文本 score_text = Text(text='Score: 0', position=(-0.85, 0.45), scale=2) # 初始化分数和射状态 score = 0 is_shooting = False power = 0 def input(key): global is_shooting, power # 按空格键开始射 if key == 'space' and not is_shooting: power = 0 is_shooting = True # 控制射力度 if key == 'up' and is_shooting: power += 1 if power > 10: power = 10 if key == 'down' and is_shooting: power -= 1 if power < 0: power = 0 def update(): global score, is_shooting, power # 射状态下,球碰撞到球或球边界时,判断射结果 if is_shooting and ball.intersects(goal) or ball.intersects(goal_left) or ball.intersects(goal_right): if ball.x >= goal_left.x and ball.x <= goal_right.x: score += 1 else: score -= 1 score_text.text = f'Score: {score}' is_shooting = False power = 0 # 控制射动作 if is_shooting: shooter.animate_position(shooter.position + (0, 0, -power), duration=0.2, curve=curve.out_cubic, loop=False) # 守员随机移动 goalkeeper.x += np.random.normal(scale=0.01) goalkeeper.y += np.random.normal(scale=0.01) goalkeeper.z += np.random.normal(scale=0.01) # 球碰撞到守员时,判断射结果 if ball.intersects(goalkeeper): if ball.x >= goal_left.x and ball.x <= goal_right.x: score -= 1 else: score += 1 score_text.text = f'Score: {score}' is_shooting = False power = 0 # 重置射者位置 if not is_shooting and shooter.y != 1: shooter.y = 1 app.run() ``` 这个示例游戏中,玩家使用空格键控制射动作,通过按上下方向键控制射力度。射时,射者会向前移动并踢出足球,玩家需要选择合适的力度将足球射内得分。如果足球在球范围内,得1分;如果足球在球范围外,扣1分。同时,守员会随机移动,玩家需要避免将球射员的范围内。分数将会在游戏界面上显示出来。玩家可以不断尝试提高自己的得分。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值