从Scratch到Python:编程之旅进阶
1. 游戏脚本初探
在编程的世界里,我们先从一段有趣的游戏脚本开始。以下是一段脚本代码,它可以实现一些简单的游戏效果:
when
clicked
broadcast
new arrow
when I receive
new arrow
go to x:
-150
y:
-150
set size to
400
%
forever
glide
0.5
secs to x:
pick random
-150
to
150
y:
pick random
-150
to
150
when
space
key pressed
stop
other scripts in sprite
repeat
50
change size by
-10
if
touching color
?
then
start sound
cheer
say
200 points
for
2
seconds
broadcast
new arrow
这段脚本的功能流程如下:
1. 当被点击时,广播“new arrow”消息。
2. 当接收到“new arrow”消息时,角色移动到坐标(-150, -150),并将大小设置为400%。
3. 角色会永远以0.5秒的时间滑行到随机坐标(-150到150之间)。
4. 当按下空格键时,停止角色的其他脚本,并重复50次将角色大小减小10。
5. 如果角色碰到指定颜色,播放欢呼音效,显示“200 points” 2秒钟,并再次广播“new arrow”消息。
同时,我们还可以对这个
超级会员免费看
订阅专栏 解锁全文

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



