Saya membuat konsol game keren dari set Meccanoid dan Erector sebagai bingkai dan saya menggunakan Sergey Royz kode (CHECK IT OUT) dan saya menambahkan hal-hal tambahan ke dalamnya dan meningkatkan kecepatan sehingga bergerak dengan lancar. Saya tidak akan menjelaskan cara membuat bingkai tetapi saya menyarankan Anda untuk membuat bingkai sendiri. Tetapi Anda membutuhkan bingkai. Bersenang-senang dengan ini melakukan apa yang Anda inginkan. SAYA HARAP ANDA MENYUKAI PROYEK INI! Beri komentar jika Anda memiliki pertanyaan dan semoga saya dapat menjawabnya sesegera mungkin dan jika Anda memiliki rekomendasi untuk proyek saya berikutnya, silakan beri komentar dan beri tahu saya. Juga fritzing saya tidak berfungsi, jadi saya hanya akan memberi tahu Anda:
Pasang pelindung ke Arduino Uno sehingga Anda memiliki lebih banyak outlet GND dan 5v tanpa menggunakan papan tempat memotong roti.
Kode
UlarC/C++
Yang harus Anda lakukan hanyalah menyalin dan menempelkan kode/** * Snake * Implementasi permainan Snake klasik * di mana ular bergerak terus-menerus dan pemain * harus menghindari persimpangan dengan dirinya sendiri dan perbatasan. * Saat ular memakan makanan, ia tumbuh dan sedikit lebih cepat. * * 23 Jun 2016 * oleh Sergey Royz dan hunter Buzzell */#include /* PIN Joystick */#define VRX A0#define VRY A1#define SW 2/* Tampilkan PIN */#define CLK 8# define CS 9#define DIN 10#define SIZE 8#define ADVANCE_DELAY 20int snake[SIZE*SIZE][2];int length;int food[2], v[2];bool is_game_over =false;long current_time;long prev_advance; int blink_count;const short messageSpeed =5;LedControl lc =LedControl(DIN, CLK, CS, 1);void init_game() { prev_advance =current_time =0; kedip_hitung =3; int setengah =UKURAN / 2; panjang =UKURAN / 3; for (int i =0; i =UKURAN) { delay(1000); showGameOverMessage(); kembali benar; } if (kepala[1] <0 || kepala[1]>=UKURAN) { delay(1000); showGameOverMessage(); kembali benar; } for (int i =0; i =0; i--) { ular[i + 1][0] =ular[i][0]; ular[i + 1][1] =ular[i][1]; } ular[0][0] +=v[0]; ular[0][1] +=v[1]; return false;}pengaturan batal() { pinMode(SW, INPUT_PULLUP); pinMode(VRX, INPUT); pinMode(VRY, INPUT); attachInterrupt(digitalPinToInterrupt(SW), mulai ulang, NAIK); lc.shutdown(0, salah); lc.setIntensity(0, 8); init_game(); render();}void loop() { if (!is_game_over) { clearScreen(); memberikan(); if (current_time - prev_advance> ADVANCE_DELAY) { is_game_over =advance(); prev_advance =waktu_saat ini; } } else { while (blink_count> 0) { clearScreen(); penundaan (300); memberikan(); penundaan (300); blink_count--; } } readControls(); current_time++;}void restart() { init_game(); is_game_over =false;}void readControls() { int dx =map(analogRead(VRX), 0, 906, 2, -2); int dy =peta(analogRead(VRY), 0, 906, -2, 2); if (dx !=0) {dx =dx / abs(dx);} if (dy !=0) {dy =dy / abs(dy);} if (dy !=0 &&v[0] !=0 ) { v[0] =0; v[1] =dy; } jika (dx !=0 &&v[1] !=0) { v[0] =dx; v[1] =0; }}const PROGMEM bool gameOverMessage[8][90] ={ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0 ,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,0,0 ,0,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0 ,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0 ,1,1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,1,1,0,0,1 ,1,0,0,1,1,0,0,1,1,0,0,1,1,1,0,1,1,1,0,0,1,1,0,0,0 ,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1 ,0,0,0,0,0,0,1,1,0,0,1,1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