關(guān)于我們
書(shū)單推薦
新書(shū)推薦
|
Scratch 編程樂(lè)園:輕松制作炫酷的游戲 讀者對(duì)象:兒童教育領(lǐng)域從業(yè)者。對(duì)于編程、創(chuàng)新有興趣的少年兒童。本書(shū)適合作為校園創(chuàng)客教育教材。
本書(shū)是由美國(guó)的Al Sweigart 所著,他是一名教授孩子和成人編程的軟件開(kāi)發(fā)者。本書(shū)非常適合用于指導(dǎo)8—16 歲的青少年學(xué)習(xí)Scratch 編程,也適合對(duì)Scratch 編程感興趣的成年人閱讀,而且閱讀本書(shū)并不需要具備任何編程經(jīng)驗(yàn)。本書(shū)一共分為9 章,每一章都具備大量的程序圖示來(lái)逐步引導(dǎo)你完成游戲制作,并且還會(huì)對(duì)該游戲中出現(xiàn)的Scratch 編程概念和相關(guān)的程序邏輯思維進(jìn)行梳理講解。相信你完成這些項(xiàng)目的學(xué)習(xí)后,一定會(huì)進(jìn)一步加深對(duì)Scratch 編程概念的理解,并會(huì)在編程技巧、創(chuàng)新思維方面有很大提升。另外,你還可以下載本書(shū)的隨書(shū)資源包,里面含有各章所需的素材和完整程序,這樣可節(jié)省你制作素材的時(shí)間。當(dāng)你遇到難題時(shí),也可以利用已經(jīng)完成的框架程序文件,并在此基礎(chǔ)上進(jìn)行整理學(xué)習(xí)。
Al Sweigart 是一位杰出的程序員和軟件開(kāi)發(fā)者,出版了大量關(guān)于Python和Scratch編程的圖書(shū),他也熱衷于教授小孩和成年人編程。
劉端陽(yáng)莫比嗨客公司創(chuàng)始人兼CEO,國(guó)際資深創(chuàng)客。12歲入選中國(guó)科學(xué)技術(shù)大學(xué)少年班,獲清華大學(xué)碩士學(xué)位、美國(guó)斯坦福大學(xué)博士學(xué)位。邵帥畢業(yè)于青島大學(xué)軟件工程專(zhuān)業(yè),現(xiàn)為威海市文登區(qū)信息技術(shù)教師。
目錄
原著致謝 ..................................................................................XII
前言 ........................................................................................XIII
本書(shū)為誰(shuí)創(chuàng)作 ..............................................................................XIV
關(guān)于本書(shū) ......................................................................................XIV
如何使用這本書(shū) ..........................................................................XVI
在線資源 .....................................................................................XVII
讀者服務(wù) .............................................................................. XVIII
第1 章 開(kāi)始Scratch 編程之旅 ................................................ 1
啟動(dòng)Scratch ......................................................................................2
離線編輯器 .......................................................................................3
Scratch 編輯器和角色 .....................................................................4
繪圖編輯器 .......................................................................................5
用代碼塊開(kāi)始工作 .............................................................................. 7
增加代碼塊 .......................................................................................... 7
刪除模塊 .............................................................................................. 8
運(yùn)行程序 .............................................................................................. 8
展示你的程序 ...................................................................................9
獲得幫助 .........................................................................................10
幫助窗口 ............................................................................................10
轉(zhuǎn)到設(shè)計(jì)頁(yè) ........................................................................................ 11
總結(jié) .................................................................................................12
第2 章 太空中的彩虹線 ......................................................... 13
設(shè)計(jì)游戲草圖 .................................................................................14
A 創(chuàng)建太空背景 ..........................................................................16
1.清理并設(shè)置舞臺(tái) ..........................................................................16
B 創(chuàng)建3 個(gè)會(huì)反彈的點(diǎn) ..............................................................18
2.畫(huà)點(diǎn) ..............................................................................................18
3.為“Dot1”角色添加代碼 ..........................................................20
拓展:方向和角度 ............................................................................20
4.復(fù)制“Dot1”角色 ......................................................................22
C 畫(huà)出彩虹線 ..............................................................................23
5.為“畫(huà)線點(diǎn)”角色添加代碼 ......................................................23
完整的程序 .....................................................................................25
加速模式 .........................................................................................26
2.0 版本:三角形的彩虹 ...............................................................27
3.0 版本:兩條彩虹線 ...................................................................28
4.0 版本:你來(lái)決定 .......................................................................29
總結(jié) .................................................................................................29
回顧思考 .........................................................................................30
第3 章 穿越迷宮 .................................................................... 31
設(shè)計(jì)游戲草圖 .................................................................................32
A 讓小貓動(dòng)起來(lái) ..........................................................................34
拓展:探索x 坐標(biāo)與y 坐標(biāo) ............................................................34
1.添加小貓移動(dòng)代碼 ......................................................................36
2.為小貓角色復(fù)制移動(dòng)程序模塊 ..................................................37
B 讓迷宮升級(jí) ..............................................................................39
3.下載迷宮圖形 ..............................................................................39
4.修改背景 ......................................................................................39
5.從第一個(gè)迷宮開(kāi)始 ......................................................................39
C 避免小貓穿墻而過(guò) ..................................................................40
6.偵測(cè)小貓是否碰到了墻壁 ..........................................................40
D 在迷宮的盡頭設(shè)置一個(gè)目標(biāo) ..................................................42
7.創(chuàng)建蘋(píng)果角色 ..............................................................................43
8.偵測(cè)到游戲者何時(shí)接觸到了蘋(píng)果 ..............................................43
9.給迷宮角色添加處理廣播消息代碼塊 ......................................45
完整的程序 .....................................................................................45
2.0 升級(jí)版本:雙玩家模式 ...........................................................47
復(fù)制“Apple”角色 ..........................................................................47
修改“Apple2”角色的程序 ............................................................48
復(fù)制橘色小貓角色 ............................................................................48
更改藍(lán)色小貓角色的程序 ................................................................49
返回起始位置 ....................................................................................51
3.0 版本:陷阱 ...............................................................................51
為陷阱畫(huà)一個(gè)新角色 ........................................................................52
為陷阱創(chuàng)造第二個(gè)造型 ....................................................................52
給陷阱添加克隆程序 ........................................................................53
修改橘色小貓的程序 ........................................................................55
把橘色小貓的程序復(fù)制到藍(lán)色小貓 ................................................57
“作弊”模式:穿墻而過(guò) ...............................................................58
給橘色小貓?zhí)砑哟〾Χ^(guò)的程序 ....................................................58
給藍(lán)色小貓?zhí)砑哟〾Χ^(guò)的程序 ....................................................58
總結(jié) .................................................................................................59
回顧思考 .........................................................................................60
第4 章 灌籃高手 .................................................................... 63
設(shè)計(jì)游戲草圖 .................................................................................64
A 讓小貓?zhí)鸩⒙湎?..................................................................65
1.給小貓角色添加重力代碼 ..........................................................65
拓展:“適用于所有角色”與“僅適用于當(dāng)前角色”的區(qū)別 ......66
2.添加地平線代碼 ..........................................................................69
3.給小貓?zhí)砑犹S的代碼 ..............................................................70
B 讓小貓左右移動(dòng) ......................................................................71
4.讓小貓走起來(lái) ..............................................................................71
C 懸空的籃筐 ..............................................................................72
5.創(chuàng)建籃筐角色 ..............................................................................72
6.創(chuàng)建命中對(duì)象 ..............................................................................74
D 讓小貓投籃 ..............................................................................76
7.創(chuàng)建籃球 ......................................................................................76
8.給籃球添加代碼 ..........................................................................77
9.檢測(cè)是否得分 ..............................................................................79
10.修正得分bug ............................................................................80
完整的程序 ....................................................................................82
2.0 版本:雙打模式 .......................................................................84
復(fù)制小貓和籃球角色 ........................................................................84
修改“Cat2”代碼 ...........................................................................85
修改“Basketball2”代碼 .................................................................85
作弊模式:固定籃筐 .....................................................................86
總結(jié) .................................................................................................87
回顧思考 .........................................................................................88
第5 章 破磚英雄 .................................................................... 89
設(shè)計(jì)游戲草圖 .................................................................................90
A 制作一個(gè)可以左右移動(dòng)的球拍 ..............................................91
1.創(chuàng)建球拍角色 ..............................................................................91
拓展:旋轉(zhuǎn)樣式 ................................................................................ 93
B 制作一個(gè)碰到邊緣就反彈的球 ..............................................94
2.創(chuàng)建網(wǎng)球角色 ..............................................................................94
C 讓球碰到球拍就反彈 ..............................................................94
3.給網(wǎng)球角色添加反彈代碼 ..........................................................95
拓展:克隆 ........................................................................................96
D 創(chuàng)造磚塊的克隆體 ..................................................................97
4.添加磚塊角色 ..............................................................................97
5.克隆磚塊角色 ..............................................................................98
E 讓球從磚塊上反彈 ................................................................100
6.將反彈代碼添加到磚塊角色中 ................................................100
F 制作“You win!”和“GAME OVER”字樣提示 .............101
7.修改網(wǎng)球角色的代碼 ................................................................101
8.創(chuàng)建游戲結(jié)束角色 ....................................................................101
9.創(chuàng)建“You win!”角色 .............................................................103
完整的程序 ...................................................................................104
2.0 版本:美化時(shí)間 .....................................................................105
繪制一個(gè)炫酷的背景 ......................................................................106
添加音樂(lè) ..........................................................................................107
球拍被網(wǎng)球擊中時(shí)會(huì)有閃光效果 ..................................................108
添加生動(dòng)的磚塊出場(chǎng)特效和擊中后的磚塊消失特效 ..................108
給擊中的磚塊添加退出的聲音特效 .............................................. 111
給網(wǎng)球添加聲音效果 ......................................................................112
在網(wǎng)球后面添加運(yùn)動(dòng)軌跡 ..............................................................112
為游戲結(jié)束角色添加一個(gè)出場(chǎng)特效 ..............................................113
為“You win!”角色添加進(jìn)入動(dòng)畫(huà) ...............................................115
總結(jié) ............................................................................................... 116
回顧思考 ....................................................................................... 117
第6 章 貪吃蛇 ......................................................................119
設(shè)計(jì)游戲草圖 ...............................................................................120
A 畫(huà)一個(gè)可以自由移動(dòng)的蛇頭 ................................................121
1.創(chuàng)建頭部角色 ............................................................................121
拓展:“當(dāng)按下xxx 鍵”vs“按鍵xxx 是否按下?” ..................124
B 畫(huà)一個(gè)隨機(jī)出現(xiàn)在屏幕中的蘋(píng)果 ........................................125
2.添加蘋(píng)果角色的腳本 ................................................................125
C 畫(huà)一個(gè)會(huì)不斷出現(xiàn)在蛇頭后面的身體 ................................125
3.創(chuàng)建身體角色 ............................................................................126
4.繪制身體角色的第二個(gè)造型 ....................................................126
5.添加身體角色的腳本 ................................................................127
6.檢測(cè)蛇頭是否撞到自己或舞臺(tái)邊緣 ........................................129
最終腳本 .......................................................................................131
Scratch 2.0 版本:添加水果加分項(xiàng) ............................................132
“作弊”模式:天下無(wú)敵 .............................................................133
修改頭部角色腳本 ..........................................................................134
修改身體角色腳本 ..........................................................................135
“作弊”模式:甩掉蛇的身體 .....................................................136
總結(jié) ...............................................................................................136
回顧思考 .......................................................................................137
第7 章 水果切切切 .............................................................. 139
設(shè)計(jì)游戲草圖 ...............................................................................141
A 制作開(kāi)始屏幕的背景 ............................................................142
1.繪制背景 ....................................................................................142
2.為舞臺(tái)添加代碼 ........................................................................144
B 制作切水果的軌跡 ................................................................145
3.繪制角色:“Slice” ....................................................................145
拓展:新建鏈表 ..............................................................................146
4.為“Slice”(軌跡)這個(gè)角色創(chuàng)建鏈表和變量 ......................148
5.記錄鼠標(biāo)的移動(dòng) ........................................................................150
6.制作一個(gè)自定義功能塊來(lái)繪制切水果的軌跡 ........................150
C 制作開(kāi)始按鈕 ........................................................................154
7.制作角色:“Begin Button” ......................................................154
D 讓水果和炸彈在舞臺(tái)隨機(jī)出現(xiàn) ............................................156
8.創(chuàng)建水果角色 ............................................................................157
9.制作切開(kāi)的水果造型 ................................................................158
10.給水果角色增添代碼 ..............................................................161
11.為水果角色的克隆體添加代碼 ..............................................164
E 制作角色:“health” ..............................................................166
12.創(chuàng)建角色:“health” ................................................................166
F 結(jié)束游戲 ................................................................................169
13.創(chuàng)建角色:“White Fade Out”(舞臺(tái)褪色為白色) ..............169
2.0 版本:最高分 .........................................................................171
作弊模式:恢復(fù)血量 ...................................................................173
總結(jié) ...............................................................................................174
回顧思考 .......................................................................................175
第8 章 行星終結(jié)者 .............................................................. 177
設(shè)計(jì)游戲草圖 ...............................................................................178
A 制造一艘可以控制的宇宙飛船 ............................................179
1.創(chuàng)造飛船角色 ............................................................................180
B 使宇宙飛船可以在舞臺(tái)邊緣穿梭 ........................................182
2.給飛船角色添加代碼 ................................................................182
3.給飛船角色添加隨機(jī)移動(dòng)代碼 ................................................183
C 用鼠標(biāo)瞄準(zhǔn)和用空格鍵射擊 ................................................184
4.創(chuàng)建能量炸彈角色 ....................................................................184
D 讓行星能自由地出現(xiàn)和移動(dòng) ................................................187
5.創(chuàng)建行星角色 ............................................................................187
E 行星被擊中后分裂成兩個(gè)小行星 ........................................189
6.為行星分裂添加代碼 ................................................................189
7.為能量炸彈角色添加“asteroid blasted”消息處理代碼 .......191
F 創(chuàng)建得分和計(jì)時(shí)功能 ............................................................191
8.創(chuàng)建超時(shí)角色 ............................................................................192
G 如果飛船被擊中就爆炸 ........................................................193
9.上傳爆炸角色 ............................................................................193
10.為爆炸角色添加代碼 ..............................................................194
11.為飛船角色添加爆炸代碼 ......................................................194
2.0 版本:有限的彈藥 .................................................................196
作弊模式:星爆炸彈 ...................................................................197
總結(jié) ...............................................................................................199
回顧思考 .......................................................................................200
第9 章 制作一個(gè)更高級(jí)的跳臺(tái)游戲 ..................................... 201
設(shè)計(jì)游戲草圖 ...............................................................................202
A 創(chuàng)建重力、下落和著地腳本 ................................................204
1.創(chuàng)建地面角色 ...........................................................................204
2.加上重力和著地的腳本 ............................................................205
3.讓小貓走起來(lái),并且還能在舞臺(tái)中環(huán)繞返回 .......................206
4.消除陷在地里的效果 ...............................................................208
B 處理陡坡和墻 ........................................................................209
5.為陡坡加上腳本 ........................................................................210
C 讓小貓會(huì)小跳和高跳 ............................................................212
6.加上讓小貓?zhí)S的腳本 ...........................................................213
D 加上天花板探測(cè) ....................................................................214
7.給地面角色加一個(gè)低跳臺(tái) ........................................................215
8.加上天花板探測(cè)的腳本 ............................................................215
E 給小貓角色套上一個(gè)碰撞檢測(cè)模塊 ....................................218
9.給小貓角色造型套上碰撞檢測(cè)模塊 ........................................219
10.加上碰撞檢測(cè)模塊的腳本 ......................................................220
F 加上更流暢的行走動(dòng)畫(huà) ........................................................221
11.給小貓角色加上新造型 ..........................................................222
12.做出在小貓換造型時(shí)不出錯(cuò)的模塊 ......................................223
G 做出游戲關(guān)卡 ........................................................................229
13.下載使用游戲的背景圖 ..........................................................229
14.給地面角色套上一個(gè)碰撞檢測(cè)模塊 ......................................230
15.給地面角色加上腳本 ..............................................................231
16.給小貓角色加上更多的環(huán)繞返回腳本 ..................................232
H 加上壞蛋螃蟹和蘋(píng)果 ............................................................233
17.加上蘋(píng)果角色和它的腳本 ...................................................... 234
18.做出螃蟹角色 .......................................................................... 235
19.給壞蛋加上人工智能 ..............................................................236
20.加上“Time’s up”角色 .........................................................240
總結(jié) ...............................................................................................241
回顧思考 .......................................................................................242
接下來(lái)的旅程 ......................................................................... 245
索引 ....................................................................................... 247
你還可能感興趣
我要評(píng)論
|