Cov txheej txheem:

Chaw Invaders hauv Micropython ntawm Micro: ntsis: 5 Kauj Ruam
Chaw Invaders hauv Micropython ntawm Micro: ntsis: 5 Kauj Ruam

Video: Chaw Invaders hauv Micropython ntawm Micro: ntsis: 5 Kauj Ruam

Video: Chaw Invaders hauv Micropython ntawm Micro: ntsis: 5 Kauj Ruam
Video: Tswv Yexus lub neej thaum pib txug thaum xaus 2024, Hlis ntuj nqeg
Anonim
Image
Image

Hauv peb cov ntawv yav dhau los peb tau tshawb nrhiav game ua rau GameGo, lub khoos phis tawj retro gaming tsim los ntawm TinkerGen kev kawm. Cov kev ua si uas peb tau ua yog nco txog Nintendo kev ua si qub. Hauv kab lus hnub no, peb tab tom yuav nqis rov qab, mus rau lub hnub nyoog kub ntawm kev ua si arcade. Peb yuav rov tsim Chaw Invaders game hauv Micropython ntawm Micro: me ntsis microcontroller - thiab raws li kev sib tw, peb tseem yuav siv BitPlayer Micro: qhov txuas ntxiv, uas tso cai rau peb ua si game yooj yim dua.

Txij li qhov kev qhia no yog hais txog kev ua lej game hauv Micropython, tsis yog ib txwm ib theem zuj zus ntu peb tau siv ua ntej rau kev qhia ua cov duab qhia, peb yuav mus hla txoj cai thaiv los ntawm thaiv-mus dhau cov haujlwm tseem ceeb, cov chav kawm thiab qhov tseem ceeb voj. Koj tuaj yeem rub tawm tag nrho cov cai hauv qhov haujlwm no GitHub chaw cia khoom. Rub tawm thiab cia pib!

Khoom siv

TinkerGen BitPlayer

BBC Micro: ntsis

Kauj Ruam 1: Lub Loop Loj

Joystick
Joystick

Hauv qhov kev qhia no kuv yuav siv lo lus "txheej txheem" ntau zaus. Ib txoj hauv kev nab nab yog me ntsis zoo ib yam rau kev ua haujlwm, tshwj tsis yog nws cuam tshuam nrog cov khoom/chav kawm. Yog li, txhawm rau ua kom yooj yim, koj tuaj yeem nyeem nws li "kev ua haujlwm hauv chav kawm". Koj tuaj yeem nyeem ntxiv txog cov hau kev ntawm no.

Peb nkag mus rau lub voj loj nrog

thaum tsis game_over:

mob. Sab hauv peb tau txais tus lej ntawm cov neeg tuaj txawv tebchaws, muaj feem tshwm sim thiab tus lej xav tau kom tau mus rau qib tom ntej los ntawm qib kev txhais lus. Tom ntej no peb tshawb xyuas rau sab laug-txoj cai txav nrog Listen_Dir qhov piv txwv ntawm chav kawm piv txwv JoyStick. Yog tias ib qho ntawm cov xwm txheej ntsuas raws li Tseeb, peb nce/nqis x-tus nqi ntawm peb tus yam ntxwv ua si. Peb txwv nws rau [-2, 2] nrog ob yog tias muaj xwm txheej. Tom qab ntawd peb pib ua piv txwv ntawm Chav Kawm DisplayBuffer thiab tshawb xyuas "npog" lossis "foob pob hluav taws" khawm. Peb siv txoj hauv kev DisplayBuffer.set () los teeb tsa cov khoom rau tom qab ua haujlwm. Txog kev thaiv daim ntaub thaiv peb siv DisplayBuffer.set () ncaj qha, tab sis rau cov mos txwv thiab cov neeg ntxeem tau peb ntxiv lawv rau lawv daim ntawv teev npe thiab teeb tsa () lawv ib tus los ntawm ib qho rau hauv voj nrog cov cai hauv qab no rau tom qab ua haujlwm nrog DispBuffer.render ():

rau b hauv cov mos txwv: b.render (dispBuf) rau v hauv vaders: v.render (dispBuf)

Txhua tus neeg ntxeem tau, mos txwv thiab ntaub thaiv npog tau muab tso rau ntawm cov khoom ib zaug txhua lub ntsiab lus rov ua dua nrog

dispBuf.render ()

Ua ntej qhov kawg ntawm lub voj tseem ceeb peb tshawb xyuas yog tias ib qho ntawm cov mos txwv ntawm cov neeg nkag tau mus txog qhov kawg ntawm lub vijtsam, thiab yog tias lawv yog, peb rho tawm lawv los ntawm lawv cov npe.

Kauj ruam 2: Joystick

Joystick
Joystick

BitPlayer yog ib qho yooj yim tuav thiab siv, nrog 2-axis joystick zoo li Gameboy lossis PSP cov tswj hwm, nws tseem suav nrog lwm 6 lub programmable nyees khawm uas muaj npe li L, R, A, B, C thiab D. nws tus kheej nta lub suab nrov, lub cev muaj zog kev co thiab Grove I2C chaw nres nkoj los txuas cov khoom siv ntxiv xws li OLED zaub.

Peb tsuas yog siv sab laug-sab xis rocker ntawm tus joystick rau qhov kev ua si no, piv txwv piv txwv ntawm kev siv txhua lub khawm BitPlayer koj tuaj yeem saib joystick_example.py hauv qhov haujlwm no GitHub chaw cia khoom. Ntawm kev tsim qhov piv txwv ntawm chav kawm JoyStick peb tshawb xyuas X-axis ua ntej nyeem thiab khaws tus nqi ntawd hauv tus kheej. Read_X. Tom qab ntawd hauv kev ua haujlwm Listen_Dir, peb tshawb xyuas yog tias qhov sib txawv los ntawm tus nqi tsis zoo siab dua qhov hloov pauv tau (sim kho nws tus kheej, yog tias koj xav tias JoyStick nkag siab dhau) thiab rov qab qhov tseeb ntawm qhov tsis raug raws li qhia pom.

Cia peb saib qhov piv txwv ntawm qhov no ua haujlwm li cas:

Cia peb hais peb qhov kev nyeem ntawv X-axis yog 0. Tom qab ntawd, yog tias peb txav Joystick txoj cai:

New_X = JoyStick_X.read_analog () #New_X = 200

Txoj cai = New_X - tus kheej. Read_X #Right = 200 Sab laug = self. Read_X - New_X #Left = -200

Tom qab ntawd thaum peb txheeb xyuas qhov kev taw qhia:

Precision = 150if Right> Precision: #200> 150 True Get_Rocker = DIR ['R'] elif Left> Precision: #-200> 150 False Get_Rocker = DIR ['L'] else: Get_Rocker = DIR ['NONE'] yog Dir == Get_Rocker: rov muaj tseeb ntxiv: rov dag

Kauj Ruam 3: Zaub Tsis

Zaub Tsis
Zaub Tsis

DisplayBuf chav kawm yog lub luag haujlwm tswj hwm lub vijtsam LED. Nws tau ua tiav siv ob txoj hauv kev, teeb tsa () thiab muab (). teeb () txoj kev hloov qhov txiaj ntsig sib xws rau LED npo pixel. Koj yuav nco ntsoov, cov pixels ntawm Micro: ntsis LED screen tuaj yeem hais tawm ua txoj hlua lossis cov npe - "00000: 00000: 00000: 00000: 00000: 00000" yog lub vijtsam tsis muaj dab tsi. "00000: 00000: 00000: 00000: 00100" yog lub vijtsam nrog lub teeb pom kev me me nyob hauv nruab nrab ntawm kab hauv qab.

00000:

00000

:00000

:00000:

00100"

Cov ntawv sau no yuav yooj yim dua rau txheej txheem:)

Yog li, peb ua dab tsi thaum lub ntsiab lus tseem ceeb yog hu teeb () txheej txheem ntawm DisplayBuf los teeb tsa txhua yam peb cov khoom uas xav tau los tso tawm ntawm lub vijtsam. Tom qab ntawd peb siv ua () txoj hauv kev los qhia lawv txhua tus ntawm qhov screen ib txhij.

Kauj ruam 4: Invaders, Bullets thiab Player

Invaders, Bullets thiab Player
Invaders, Bullets thiab Player

Cov mos txwv thiab Invaders koom nrog chav kawm Mover. Cov chav kawm Mover muaj lawv qhov x, y qhov chaw thiab nrawm, nrog rau qhov ci ntsa iab. Mover chav kawm muaj ob txoj hauv kev piv txwv, teeb tsa () thiab txav mus (). teeb () txoj hauv kev yooj yim hu rau DisplayBuf teeb () txoj hauv kev nrog hloov kho tshiab kom txuag tau rau tom qab ua haujlwm ntawm LED matrix. txav () txoj kev hloov kho tshiab piv txwv sib koom ua ke raws li qhov nrawm - uas tau txais txiaj ntsig tom qab, thaum peb xav tau hloov pauv kev nrawm ntawm cov neeg ntxeem tau raws li qib kev nce qib.

Class Bullet thiab Class Invader yog subclasses ntawm Mover class. Ntawm no peb siv qee yam hu ua qub txeeg qub teg. Kev ua haujlwm zoo ntawm super () tso cai rau peb hu cov txheej txheem ntawm superclass hauv subclass, tsis tas yuav rov ua cov cai.

Kauj Ruam 5: Ua Nws Li Koj Tus Kheej

Ua Koj Tus Kheej
Ua Koj Tus Kheej

Nrog koj zoo siab! Koj nyuam qhuav rov tsim qhov qub Chaw Invaders game ntawm Micro: me ntsis nrog qee qhov khoos phis tawj txias. Tau kawg, koj tuaj yeem txhim kho txoj cai game los ntawm no - piv txwv li, tam sim no, qhov kev ua si tsuas muaj ib qib - koj tuaj yeem ntxiv qhov nyuaj dua. Tsis tas li, raws li koj yuav rov nco tau, thawj qhov kev ua si muaj pob zeb ntab nyob rau hauv pem hauv ntej ntawm tus neeg uas ua ntawv, uas koj tuaj yeem ntxiv ib yam.

Yog tias koj ua qhov hloov kho ntawm qhov kev ua si, qhia nws hauv cov lus hauv qab no! Yog xav paub ntau ntxiv txog BitPlayer thiab lwm yam khoom siv kho vajtse thiab kws qhia txuj ci STEM, mus saib peb lub vev xaib, https://tinkergen.com/ thiab sau npe rau peb tsab ntawv xov xwm.

TinkerGen tsis ntev los no tau tsim Kickstarter phiaj los nqis tes rau MARK (Ua Cov Khoom Siv Neeg Hlau), cov cuab yeej neeg hlau rau kev qhia paub coding, neeg hlau, AI!

Thawj Micropython code los ntawm hexkcd/micro-vaders, tau hloov pauv los ua haujlwm nrog TinkerGen BitPlayer.

Pom zoo: