
想像一下“飞在空中的球”,以及现实生活中存在你无法打破的自然规律。比如,受地球重力作用,任何跳到半空中的物体都会再次坠落。就像今天河马哥给大家带来的这款游戏,“Magic Ball”,会向你展示了如何在游戏世界里添加重力。
现在,跟河马哥一起来通过scratch开始制作吧。
★游戏目标:
我们小球的任务是尽力击落香蕉,它可以选择朝什么方向、以何种速度跳跃。你需要让它越过大树,用尽量少的跳跃次数获得香蕉。
弹射器:
用左箭头和右箭头控制这个箭头,指向你想弹射猴子的方向。

香蕉:
小球碰到任何一串香蕉,都会把它击落。持续发射小球,直到香蕉全部被击落。

Ball :
速度是从1-20之间改变的,选择合适额速度然后按下空格键把它弹射出去。
★游戏控制:
首先,要知道玩家使用上下左右键和空格键来操控游戏。


然后开启我们的操作:
1·新建一个作品,命名为“Magic Ball”。删除默认的小猫角色,然后从角色库中把“ball”和“Arrow1”都添加进来,将“Arrow1”角色名字改为“发射器”。

2. 点击“变量”组,选择“新建变量”,添加一个变量,命名为“发射速度”。新建的这个变量会自动出现在舞台上。

3. 选择发射器角色给他添加如下三段脚本,让玩家可以通过键盘上的左右方向键来控制它的角度。箭头的方向就是猴子发射出的方向。运行脚本,试着调整箭头。

让游戏刚开始的时候发射器在舞台的左下方

当按下右移键控制发射器向右旋转1°

当按下左移键控制发射器向左旋转1°
4. 现在已经完成瞄准环节,接下来需要控制发射速度,添加如下脚本,他能让游戏机制更有趣以及让你选取你想发射的速度。

5. 现在选择小球角色,添加右边的脚本把她移动到发射器后面。

6. 在小球角色中,添加这段新脚本,当按下空格键时,发射小球。“重复执行直到......”是
一种新的循环指令,它会重复执行里面的指令直到条件成立,既然这样,小球就会一直飞行,直到它碰到舞台的边缘。

7.试着用方向键调整发射器的角度,选着合适的发射速度,然后按下空格键发射小球。他会沿着直线飞行,直到撞到舞台的边缘。但在真是情况不是这样的,当小球向前运动的时候最终他会落到地面上,稍后我们会在游戏中增加重力,让小球的运动更加逼真。

8.在这个游戏当中,小球得分的方法是击落香蕉。利用克隆指令,你就可以只添加一串香
蕉角色,却能让猴子可以瞄准很多香蕉。
添加香蕉的同时新建一个变量,命名为:“香蕉变量”,用它来记录舞台上的香蕉数量,开始的时候有5串。添加右边的脚本,他们可以克隆出香蕉。但是先不要运行他们。你还需要告诉克隆体应该干什么。

9. 添加如下脚本,让每一串香蕉克隆体随机出现在舞台右侧,同时随机改变他的外观,最后请确保它不会被隐藏。克隆体会一直等待小球来触碰它,碰到后就会自动消失,如果这是最后一串香蕉,那么它就会发出一个“游戏结束”的消息,当然需要你来创建这个新消息。




每期一案例,跟我们一起动手玩转scratch。
简单易学,快乐成长
声明:转载此文是出于传递更多信息之目的。若有来源标注错误或侵犯了您的合法权益,请作者持权属证明与本网联系,我们将及时更正、删除,谢谢。