Cov txheej txheem:

Pong hauv Kos: 16 Kauj Ruam
Pong hauv Kos: 16 Kauj Ruam

Video: Pong hauv Kos: 16 Kauj Ruam

Video: Pong hauv Kos: 16 Kauj Ruam
Video: leej twg tej ntxhai - Mang Vang [ Official MV ] 2024, Kaum ib hlis
Anonim
Pong hauv Kos
Pong hauv Kos

Txoj Haujlwm no yuav muab cov kauj ruam rau koj kom rov tsim Pong, yog ib qho ntawm thawj qhov vis dis aus ua si, hauv Txoj Haujlwm Kos.

Khoom siv

Cov Khoom Siv yog yooj yim heev, txhua yam koj xav tau yog siv internet, ib lub cuab yeej uas tuaj yeem siv internet, thiab tus as khauj rau Scratch, lub xaib siv hauv cov lus qhia no.

Kauj ruam 1: Taw qhia rau Kos

Taw qhia rau kos
Taw qhia rau kos
Taw qhia rau kos
Taw qhia rau kos

Thawj qhov koj yuav tsum tau ua yog nkag mus rau lub vev xaib pom ntawm scratch.mit.edu. ib zaug ntawm lub xaib, siv Kev Koom Tes Kos Kos los tsim tus as khauj. Thaum qhov no ua tiav, siv qhov kev xaiv tsim nyob rau sab saum toj sab laug ntawm lub qhov rais los tsim ib qhov haujlwm. Nov yog qhov pib lom zem. Raws li cov lus ceeb toom, Kos tuaj yeem yog qhov kev pab cuam zoo heev, thiab tej zaum yuav tsis teb, yog li txuag ntau.

Kauj Ruam 2: Qee Cov Ntaub Ntawv Ntxiv

Qee Cov Lus Qhia Ntxiv
Qee Cov Lus Qhia Ntxiv

Thaum tsim cov sprites tshiab, ib txwm pom qhov chaw nruab nrab rau ntawm thaj chaw tsim, cim los ntawm ib qho chaw nruab nrab. qhov no yuav yog lub hauv paus ntawm kev tsim cov txheej txheem, thiab txhua qhov X thiab Y qhov txiaj ntsig yuav xav tias tus sprite yuav tsum tsim ntawm qhov no. yog tias lub hauv paus ntsiab lus no tsis siv, lawv qhov txiaj ntsig muab yuav tsis ua haujlwm, thiab koj yuav tsum xam tawm qhov chaw raug.

Tam sim no, mus rau lub creation.

Kauj Ruam 3: Tsim Kab Hauv Kab

Tsim Kab Kab
Tsim Kab Kab

Txhawm rau tsim koj thawj sprite yuj hla tus cim miv nyob hauv qab txoj cai kaum ntawm lub vijtsam, qhov no yuav muab rau koj plaub txoj kev xaiv. Nyem "xim".

Siv cov duab plaub kos ib lub duab plaub me me dub ntsug. Qhov no yuav yog lub tsev thaiv rau kab nruab nrab.

Teem tus sprite1 tus x tus nqi rau 0 thiab y tus nqi rau 0. Tus duab plaub yuav tsum nyob rau sab saum toj nruab nrab ntawm thaj chaw ua si.

Txoj cai nyem rau ntawm "Sprite1" lub cim thiab nyem "theej tawm" Teeb tus tshiab sprite tus nqi x rau 0 thiab y rau 30 tsawg dua (-30).

Rov ua cov kauj ruam 5 thiab 6 kom txog rau thaum koj muaj kab ntawv nyob nruab nrab sib cais thaj chaw ua si rau 2 thaj chaw.

Kauj Ruam 4: Lub Hom Phiaj Tshaj Tawm

Lub Hom Phiaj Tshaj Tawm
Lub Hom Phiaj Tshaj Tawm

Hauv cov kauj ruam yooj yim no, koj yuav tsim ob lub hom phiaj kev tshaj tawm.

Tsim tus tshiab sprite ntawm lub duab plaub siab uas nthuav dav tag nrho qhov siab ntawm thaj chaw ua si. Hloov lub npe no mus rau "P1-Lub Hom Phiaj". Teeb tus nqi x rau -240 thiab y tus nqi rau 0.

Luam tawm "P1-Lub Hom Phiaj", hloov nws "P2-Lub Hom Phiaj", teeb nws tus nqi x rau 240 thiab y tus nqi rau 0.

Kauj ruam 5: Coding

Coding
Coding
Coding
Coding
Coding
Coding

Txij ntawm no mus, koj yuav tsum tau siv lub cim coding nyob rau sab saud sab laug ntawm nplooj ntawv, tsuas yog hauv qab Scratch icon. muaj tag nrho ntawm 9 hom kev cai, tab sis tsuas yog siv 7 ntawm lawv hauv txoj haujlwm no.

Kauj Ruam 6: Tsim Thawj Tus Neeg Ua Si

Tsim Thawj Tus Neeg Ua Si
Tsim Thawj Tus Neeg Ua Si

Pib cov kauj ruam no los ntawm kev luam ib qho ntawm kab hauv nruab nrab thiab teeb tsa tus nqi X rau 210, thiab Y rau 0. Hloov npe tus sprite rau Player1

Thaum qhov no ua tiav, coding pib. Ua kom ntseeg tau tias koj nyob hauv kab ntawv teev npe ntawm tus sprite nyob rau sab saum toj sab laug.

Nyem rau "Player1" sprite lub cim, nyob rau sab saud sab laug nyem rau "Code" tab

Hauv qab "Cov Txheej Txheem" rub "thaum (tus chij ntsuab) nyem" thaiv rau hauv ib puag ncig kev txhim kho ib puag ncig (IDE).

Tsis tas li nyob hauv "Cov Txheej Txheem" luag "thaum nias lub pob" thaiv rau hauv IDE. Hauv qab "Tsab ntawv tsa suab" lob tus "mus rau x: txoj haujlwm y: txoj haujlwm" thaiv thiab tua nws hauv qab "thaum (tus chij ntsuab) tau nyem" thaiv teeb tsa mus rau x txoj haujlwm rau -215 thiab y txoj haujlwm rau 0

Hauv qab "Tsab ntawv tsa suab" txuas "hloov y los" rau qhov thaum tus yuam sij nias thiab muab tus nqi 4

Hauv qab "Tsab ntawv tsa suab" "yog tias nyob ntawm ntug, thaws" txuas rau thaum nias lub pob

Hauv qab "Tsab ntawv tsa suab" "taw tes rau hauv kev taw qhia" thaiv rau "thaum nias lub pob" khawm.

Luam theej tawm "thaum nias tus yuam sij" thiab hloov "hloov y" rau -4

Teem cov keystrokes xav tau rau kev txav mus rau "thaum qhov tseem ceeb nias thaiv"

Kauj Ruam 7: Txoj Cai, thiab Tus Neeg Ua Si 2

Code, thiab Player 2
Code, thiab Player 2

Saum toj no yog qhov chaws yuav tsum zoo li cas.

Hauv qab txoj cai, qhov twg txhua tus sprites nyob, nyem rau tus neeg uas ua ntawv thiab luam nws.

Hloov nws mus rau Player2. Thaum qhov no ua tiav, nkag mus rau Player2 tus lej thiab hloov cov nyees khawm txav mus, thiab "Greenflag" txav mus rau X: -210 Y: 0

Kauj Ruam 8: Khaws Cia

Cov Quav
Cov Quav
Cov Quav
Cov Quav

Tsim tus tshiab sprite hauv qab sab laug, thiab lub npe nws "P1-Score"

Hauv cov ris tsho tab, siv lub thawv ntawv tshwj xeeb los tsim 0 hauv qhov chaw nruab nrab. Luam qhov hnav no 5 zaug.

Hloov lwm cov khaub ncaws kom lawv suav 0-5 hauv kev txiav txim.

Nyem rau ntawm "P1-Score" sprite.

Xaiv "Code" nyob rau sab saum toj sab laug

Lob tus "thaum (chij ntsuab) nyem" thaiv thiab "thaum kuv tau txais (lus)" thaiv, teeb cov lus rau "P1-Score".

Hauv qab "thaum (tus chij ntsuab) nyem" muab "hloov khaub ncaws rau (tus nqi)" thaiv, teeb tus nqi rau 0.

Hauv qab "thaum kuv tau txais (" P1-Score ")" txuas "block tom ntej" thaiv.

Luam "P1-Score" sprite thiab hloov nws mus rau "P2-score"

Hloov cov lus tau txais rau "P2-qhab nia"

Teeb tus X tus nqi ntawm "P1-Score" rau -130 thiab "P2-Score" rau 130, thiab Y rau 150 rau ob qho tib si.

Hauv kev hloov pauv, tsim 2 qhov sib txawv "P1-score" thiab "P2-score"

Hauv qab "thaum (tus chij ntsuab) nyem" thaiv rau txhua tus neeg ua si, ntxiv "teeb tsa (sib txawv) rau ()" thiab teeb tsa tus nqi rau 0.

Hauv qab "thaum Kuv Tau Txais ()" rau txhua tus, ntxiv "Hloov (hloov pauv) los ntawm ()" thiab teeb tsa tus nqi rau 1 thiab qhov sib txawv rau tus neeg sib tw ua si.

Kauj Ruam 9: Yeej Txoj Cai

Yeej Yeej
Yeej Yeej

Tsim tus sprite tshiab hu ua "WinCondition"

Siv cov cuab yeej ntawv sau "Player 1 Wins", sau lub npe "P1-Win"

Ntxiv qhov hnav thib ob

Siv cov cuab yeej ntawv sau "Player 2 Wins", sau lub npe "P2-Win"

Hauv txoj cai

Pib nrog "thaum (chij ntsuab) nyem" thaiv, thiab txuas "thaiv" thaiv (hauv qhov zoo li)

Tom ntej no lob "thaum kuv tau txais (lus)" thaiv, teeb cov lus rau "P1-Yeej", rau qhov no txuas "thaiv" thaiv

Txuas "hloov khaub ncaws rau (xaiv)" thaiv, teeb tsa qhov kev xaiv rau "P1-Win" Tam sim no txuas "nres (xaiv)" thaiv, teeb tsa kev xaiv rau txhua tus.

Txoj cai nyem rau ntawm "thaum kuv tau txais (" P1-Win ")" thaiv thiab theej tawm nws. Hloov pauv txhua yam ntsig txog tus neeg ua si 1 rau tus neeg ua si 2.

Kauj Ruam 10: Pob Ntu 1: Pib

Tsim lub voj voog ncig, thiab lub npe nws "pob".

Pib nrog "thaum (chij ntsuab) nyem" thaiv

Txog qhov ntawd txuas cov lus tsa suab "mus rau x: (txoj haujlwm) y: (txoj haujlwm)", teeb tsa ob qho txiaj ntsig rau 0

Tom ntej txuas "yog (ua haujlwm) tom qab ntawd …. lwm "block.

Hauv qhov qhib "yog" tus nqi txuas "xaiv random (tus nqi) rau (tus nqi) = (tus nqi)" thaiv thiab teeb tsa tus nqi rau 1, 0, thiab 0 feem.

Hauv qab "yog" ntu ntawm qhov thaiv txuas "tshaj tawm (xov xwm)" thaiv

Nyem rau ntawm cov ntawv qhia zaub mov nco tseg, nyem "cov lus tshiab", lub npe no "P2-Hit"

Hauv qab lwm qhov ntawm "yog (kev ua haujlwm) ces …. lwm tus "thaiv txuas" tshaj tawm (xov) "thaiv.

Tsim cov lus tshiab “P1-Hit”

Kauj Ruam 11: Pob Ntu 2: Kev txav chaw

Pib qhov thaiv tshiab ntawm cov cai nrog "thaum kuv tau txais (lus)" thaiv, teeb cov lus rau "P2-Hit"

Tom ntej txuas qhov "ib txhis" thaiv tshwj tsis yog tau hais txhua yam los ntawm no yuav nyob hauv "ib txhis" thaiv.

Txuas nrog "tos (tus nqi) vib nas this" thaiv, teeb tus nqi rau 0.01 Txuas

"Txav (tus nqi) cov kauj ruam" thaiv teeb tsa tus nqi rau 8

Txuas "yog nyob ntawm ntug, thawb" thaiv

Kauj Ruam 12: Pob Ntu 3: Cov Neeg Sib Tham

Tom ntej no lob "yog (ua haujlwm) ces" thaiv, tso "kov (sib txawv)?" thaiv hauv ntu haujlwm ntawm cov lus yog, teeb tsa qhov sib txawv rau "Player 1".

Tsis pub dhau qhov yog hais tias daim ntawv txuas "tshaj tawm (xov)", "taw tes rau hauv kev coj (tus nqi)", thiab "nres (xaiv)" thaiv.

Teem cov lus rau "P1-Hit" Muab qhov "xaiv random (tus nqi) mus rau (tus nqi)" thaiv hauv qab tus tswv thiab tso rau hauv "kev taw qhia (tus nqi)" thiab teeb tsa tus nqi sib txawv los ntawm 45 txog 135.

Teeb qhov kev xaiv hauv "nres (xaiv)" thaiv rau "tsab ntawv no".

Kauj Ruam 13: Pob Ntu 4: Qhab Nia

Pib tshiab "yog (ua haujlwm) tom qab ntawd" thaiv, ua haujlwm nrog "kov (sib txawv)?" thaiv, teeb tsa qhov sib txawv rau "P1-Lub Hom Phiaj"

Txuas "tshaj tawm (xov xwm)", teeb cov lus rau "P2-Score"

Tom ntej txuas tus "mus rau x: (txoj haujlwm) y: (txoj haujlwm)", teeb tsa ob txoj haujlwm rau 0. Txuas "taw qhia rau hauv kev taw qhia (tus nqi)", teeb tus nqi rau -90.

Txuas nrog "tos (tus nqi) vib nas this" thaiv, teeb tus nqi rau 1.

Tom ntej txuas ib qho "tshaj tawm (xov)" thaiv, teeb cov lus rau "P2-Hit".

Ncaj nraim hauv qab "tshaj tawm (xov)" txuas "yog (ua haujlwm) tom qab ntawd"

Teeb lub lag luam rau "(sib txawv) = (tus nqi)" thaiv, teeb tsa qhov sib txawv rau "P2-qhab nia" thiab tus nqi rau 5.

Hauv qhov no yog cov lus tshaj tawm txuas "tshaj tawm (lus)" thiab "nres (xaiv)" thaiv

Teem cov lus rau "P2- Yeej", thiab qhov kev xaiv nres rau "tag nrho"

Hauv qab no yog cov lus hais txuas "nres (xaiv)" thaiv, teeb qhov kev xaiv rau "tsab ntawv no"

Kauj Ruam 14: Pob Ntu 5: Luam

Txoj cai nyem rau ntawm "thaum kuv tau txais (" P2- Ntaus ")" thaiv thiab xaiv qhov theej tawm, nyem qhov twg nyob hauv IDE kom tso qhov thaiv tshiab no ntawm cov cai.

Hauv qhov thaiv tshiab ntawm cov cai hloov pauv txhua yam cuam tshuam nrog tus neeg ua si 1 rau tus neeg ua si 2 thiab hloov pauv, tseem hloov pauv ib qho "taw tes rau qhov kev coj ua" los ntawm qhov zoo mus rau qhov tsis zoo, txhua yam ntxiv tuaj yeem nyob zoo li qub.

Kauj Ruam 15: Txoj Cai Kawg rau Pob

Txoj Cai Kawg rau Pob
Txoj Cai Kawg rau Pob

Kauj Ruam 16: CONGRATULATIONS

yog tias txhua yam mus raws li tsim, koj yuav tsum muaj Pong game ua haujlwm, ua tag nrho hauv qhov khawb.

Pom zoo: