天天看點

scratch源碼_scratch簡單實作彈跳小球

scratch源碼_scratch簡單實作彈跳小球

來我們看看實作效果吧:

scratch源碼_scratch簡單實作彈跳小球
1.角色分析

如圖所示,我們需要一個球、擋闆、以及最底部的矩形顔色。

scratch源碼_scratch簡單實作彈跳小球
2.開始程式設計 (1).準備:上傳角色

上傳網球、繪制擋闆、以及繪制底部矩形。

scratch源碼_scratch簡單實作彈跳小球

同樣的底部矩形:

scratch源碼_scratch簡單實作彈跳小球
(2).讓擋闆移動起來

由于擋闆是根據滑鼠的移動而移動,則可以分析出:根據滑鼠當時的x坐标位置來移動的。

scratch源碼_scratch簡單實作彈跳小球
(3).讓小球移動起來

<1>讓小球面向随機位置。<2>重複執行移動12步,并且碰到邊緣并反彈。

scratch源碼_scratch簡單實作彈跳小球
(4).讓小球碰到擋闆反彈
scratch源碼_scratch簡單實作彈跳小球
(5).讓小球碰到底部矩形結束遊戲
scratch源碼_scratch簡單實作彈跳小球
3.代碼總結: <1>小球
scratch源碼_scratch簡單實作彈跳小球
<2>擋闆
scratch源碼_scratch簡單實作彈跳小球
4.源碼分享: scratch官網:https://scratch.mit.edu/projects/326582481/ 百度網盤:

連結:https://pan.baidu.com/s/1bqAyTzFAQS0GIQ6an-VuQA 提取碼:hi9q

結語:現為scratch教師一枚。持續記錄學習成長,如有疑問請私聊。