From ced5f74a880f1edcce83f5c16a40e4ede4635ac7 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 23 Jan 2019 19:23:15 +0100 Subject: [PATCH] sauvegarde avant le nettoyage --- atmega328p/eeprom.hex | 1 + atmega328p/main.c | 4 ++-- atmega328p/main.o | Bin 0 -> 3684 bytes atmega328p/usb.elf | Bin 0 -> 4940 bytes atmega328p/usb.hex | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ games/ninvaders/nInvaders | Bin 0 -> 44768 bytes games/ninvaders/nInvaders.c | 10 +++++++--- games/save | 431 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 542 insertions(+), 5 deletions(-) create mode 100644 atmega328p/eeprom.hex create mode 100644 atmega328p/main.o create mode 100755 atmega328p/usb.elf create mode 100644 atmega328p/usb.hex create mode 100755 games/ninvaders/nInvaders create mode 100644 games/save diff --git a/atmega328p/eeprom.hex b/atmega328p/eeprom.hex new file mode 100644 index 0000000..1996e8f --- /dev/null +++ b/atmega328p/eeprom.hex @@ -0,0 +1 @@ +:00000001FF diff --git a/atmega328p/main.c b/atmega328p/main.c index 7510a8e..39883c5 100755 --- a/atmega328p/main.c +++ b/atmega328p/main.c @@ -100,9 +100,9 @@ struct task{ uint8_t cpt = 0; uint8_t premier_lancement = 0; -struct task lecture_boutons = {0x300, 0, 0}; +struct task lecture_boutons = {0x300, 0}; struct task lecture_joystick = {0x0500, 0}; -struct task affiche_led = {0x0700, 0, 0}; +struct task affiche_led = {0x0700, 0}; diff --git a/atmega328p/main.o b/atmega328p/main.o new file mode 100644 index 0000000..d023e7d Binary files /dev/null and b/atmega328p/main.o differ diff --git a/atmega328p/usb.elf b/atmega328p/usb.elf new file mode 100755 index 0000000..e56cb81 Binary files /dev/null and b/atmega328p/usb.elf differ diff --git a/atmega328p/usb.hex b/atmega328p/usb.hex new file mode 100644 index 0000000..8d69c82 --- /dev/null +++ b/atmega328p/usb.hex @@ -0,0 +1,101 @@ +:100000000C9434000C9451000C9451000C94510049 +:100010000C9451000C9451000C9451000C9451001C +:100020000C9451000C9451000C9451000C94380124 +:100030000C9451000C9451000C9451000C945100FC +:100040000C9451000C9451000C9451000C945100EC +:100050000C9451000C9451000C9451000C945100DC +:100060000C9451000C94510011241FBECFEFD8E026 +:10007000DEBFCDBF11E0A0E0B1E0EEE2F6E002C0ED +:1000800005900D92AA30B107D9F721E0AAE0B1E0BE +:1000900001C01D92AC30B207E1F70E94E5020C945A +:1000A00015030C94000084B18F6184B985B18FEF82 +:1000B00085B92FEF85EA9EE0215080409040E1F71E +:1000C00000C0000085B115B80895092E000CAA0BD8 +:1000D000BB0B9C01AD0184E0220F331F441F551F51 +:1000E0008A95D1F760E074E284EF90E00E94F30219 +:1000F000215031093093C5002093C40088E18093DA +:10010000C10086E08093C200E0ECF0E080818D7F4A +:10011000808308959091C00095FFFCCF8093C60026 +:1001200008958091C00087FFFCCF8091C60008959C +:10013000EAE7F0E0808187608083ACE7B0E08C91F3 +:1001400080648C938C918F778C938C918F7D8C9322 +:10015000ABE7B0E08C91887F8C938081806880834E +:10016000808180648083089590917C00982B909387 +:100170007C0090917A00906490937A0090917A003C +:1001800096FDFCCF90917C008095892380937C0024 +:1001900080917800909179000895E1E8F0E0808105 +:1001A0008860808380818460808380818160808397 +:1001B00088E690E09093890080938800EFE6F0E075 +:1001C00080818260808308958AB18AB98BB18FEF74 +:1001D0008BB984B18F6384B9089580E0D1E0C9B14F +:1001E000C2FBCC27C0F9CD274B9BC2604C9BC4609F +:1001F0004D9BC8604E9BC061C81719F08C2F0E94A0 +:100200008A008FE39CE90197F1F700C000008C2F72 +:10021000E6CFC0E080E00E94B4008C0181E00E9443 +:10022000B400C1110BC0C80134E0969587953A958A +:10023000E1F780680E948A00C1E009C024E0969539 +:1002400087952A95E1F7806C0E948A00C0E08FE3D1 +:100250009CE90197F1F700C00000DCCF0E949100FB +:1002600085B98FE39CE90197F1F700C00000F6CF54 +:100270001F920F920FB60F9211242F933F934F931B +:100280005F936F937F938F939F93AF93BF93EF93FE +:10029000FF9380910A0181110CC081E080930A01D3 +:1002A000789480910001909101019EBF8DBF0E94C2 +:1002B0002E01813009F036C00F920FB6F8940F92DC +:1002C0001F9211242F923F924F925F926F927F92D2 +:1002D0008F929F92AF92BF92CF92DF92EF92FF9256 +:1002E0000F931F932F933F934F935F936F937F933E +:1002F0008F939F93AF93BF93CF93DF93EF93FF932E +:100300008DB79EB7909301018093000182E08093A6 +:100310000A01789480910301909104019EBF8DBFE2 +:100320000E940901823009F036C00F920FB6F8948E +:100330000F921F9211242F923F924F925F926F92D1 +:100340007F928F929F92AF92BF92CF92DF92EF9265 +:10035000FF920F931F932F933F934F935F936F934E +:100360007F938F939F93AF93BF93CF93DF93EF933D +:10037000FF938DB79EB7909304018093030183E0B0 +:1003800080930A01789480910601909107019EBFA5 +:100390008DBF0E94ED0080910B01811154C00F921E +:1003A0000FB6F8940F921F9211242F923F924F9202 +:1003B0005F926F927F928F929F92AF92BF92CF92F5 +:1003C000DF92EF92FF920F931F932F933F934F93E0 +:1003D0005F936F937F938F939F93AF93BF93CF93CD +:1003E000DF93EF93FF938DB79EB7909307018093B0 +:1003F000060180910001909101019EBF8DBFFF9188 +:10040000EF91DF91CF91BF91AF919F918F917F91AC +:100410006F915F914F913F912F911F910F91FF909D +:10042000EF90DF90CF90BF90AF909F908F907F9094 +:100430006F905F904F903F902F901F900F900FBE46 +:100440000F9081E056C0813009F056C00F920FB670 +:10045000F8940F921F9211242F923F924F925F9225 +:100460006F927F928F929F92AF92BF92CF92DF92C4 +:10047000EF92FF920F931F932F933F934F935F93AE +:100480006F937F938F939F93AF93BF93CF93DF939C +:10049000EF93FF938DB79EB7909301018093000176 +:1004A00080910301909104019EBF8DBFFF91EF9158 +:1004B000DF91CF91BF91AF919F918F917F916F917C +:1004C0005F914F913F912F911F910F91FF90EF906E +:1004D000DF90CF90BF90AF909F908F907F906F9064 +:1004E0005F904F903F902F901F900F900FBE0F90F6 +:1004F00082E080930B0157C0823009F054C00F9204 +:100500000FB6F8940F921F9211242F923F924F92A0 +:100510005F926F927F928F929F92AF92BF92CF9293 +:10052000DF92EF92FF920F931F932F933F934F937E +:100530005F936F937F938F939F93AF93BF93CF936B +:10054000DF93EF93FF938DB79EB790930401809351 +:10055000030180910601909107019EBF8DBFFF911D +:10056000EF91DF91CF91BF91AF919F918F917F914B +:100570006F915F914F913F912F911F910F91FF903C +:10058000EF90DF90CF90BF90AF909F908F907F9033 +:100590006F905F904F903F902F901F900F900FBEE5 +:1005A0000F9010920B017894FF91EF91BF91AF9152 +:1005B0009F918F917F916F915F914F913F912F917B +:1005C0000F900FBE0F901F9018950E94530080E867 +:1005D00095E20E9465000E9498000E94CD000E9452 +:1005E000E4007894FFCFA1E21A2EAA1BBB1BFD01E9 +:1005F0000DC0AA1FBB1FEE1FFF1FA217B307E40702 +:10060000F50720F0A21BB30BE40BF50B661F771F59 +:10061000881F991F1A9469F7609570958095909539 +:0E0620009B01AC01BD01CF010895F894FFCFFE +:0A062E0000070000050000030000B3 +:00000001FF diff --git a/games/ninvaders/nInvaders b/games/ninvaders/nInvaders new file mode 100755 index 0000000..8ea05fa Binary files /dev/null and b/games/ninvaders/nInvaders differ diff --git a/games/ninvaders/nInvaders.c b/games/ninvaders/nInvaders.c index 9087c4c..d02682c 100644 --- a/games/ninvaders/nInvaders.c +++ b/games/ninvaders/nInvaders.c @@ -167,8 +167,8 @@ void readInput() receiveData(2, &data, handle, endpoint_desc_list); if(data != 0){ if((data & 0x10) == 0x10) ch = KEY_LEFT; - else if((data & 0x04) == 0x04) ch = KEY_RIGHT; - else if((data & 0x08) == 0x08) ch = ' '; + else if((data & 0x02) == 0x02) ch = KEY_RIGHT; + else if((data & 0x04) == 0x04) ch = ' '; else return; } else return; @@ -192,7 +192,9 @@ void readInput() lives = 3; // restore lives sendLives(); status = GAME_NEXTLEVEL; - } else if (ch == 'q') { // quit game + } else if (ch == 'q') { // quit + lives = 0; + sendLives(0); status = GAME_EXIT; } break; @@ -230,6 +232,8 @@ void readInput() sendLives(); drawscore(); } else if (ch == 'q') { // quit game + lives = 0; + sendLives(); status = GAME_EXIT; } else { // disable turbo mode if key is not kept pressed lastmove = ' '; diff --git a/games/save b/games/save new file mode 100644 index 0000000..3b93f5d --- /dev/null +++ b/games/save @@ -0,0 +1,431 @@ +/** + * nInvaders - a space invaders clone for ncurses + * Copyright (C) 2002-2003 Dettus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * homepage: http://ninvaders.sourceforge.net + * mailto: ninvaders-devel@lists.sourceforge.net + * + */ + + +#include +#include +#include +#include "nInvaders.h" +#include "player.h" +#include "aliens.h" +#include "ufo.h" +#include "arduino.h" +#include +#include +#include +#include + +#define FPS 50 + +int lives; +long score; +int status; // status handled in timer + +#define GAME_LOOP 1 +#define GAME_NEXTLEVEL 2 +#define GAME_PAUSED 3 +#define GAME_OVER 4 +#define GAME_EXIT 5 +#define GAME_HIGHSCORE 6 + +libusb_device_handle *handle; +struct libusb_endpoint_descriptor endpoint_desc_list[ENDPOINTS_NUMBER]; +int waitUSB = 0; + +void sendLives(){ + uint8_t toSend = 0x00; + if(lives == 5) toSend = 0x1F; + else if(lives == 4) toSend = 0x0F; + else if(lives == 3) toSend = 0x07; + else if(lives == 2) toSend = 0x03; + else if(lives == 1) toSend = 0x01; + else if(lives == 0) toSend = 0x00; + if(handle != NULL && endpoint_desc_list != NULL && waitUSB == 0){ + waitUSB = 1; + usleep(100000); // wait for endpoints to be free (100 ms) + sendData(0, toSend, handle, endpoint_desc_list); + waitUSB = 0; + } +} + +/** + * initialize level: reset attributes of most units + */ +static void initLevel() +{ + playerReset(); + aliensReset(); + ufoReset(); + bunkersReset(); + render(); + drawscore(); +} + +/** + * evaluate command line parameters + */ +static void evaluateCommandLine(int argc, char **argv) +{ + + // -l : set skill level + if (argc == 3 && strcmp(argv[1], "-l") == 0) { + if (argv[2][0] >= '0' && argv[2][0] <= '9') { + skill_level = argv[2][0] - 48; + } else { + argc = 2; + } + } + + // -gpl : show GNU GPL + if (argc == 2 && strcmp(argv[1], "-gpl") == 0) { + showGpl(); + } + + // wrong command line: show usage + if (argc == 2 || (argc == 3 && strcmp(argv[1], "-l") != 0)) { + showVersion(); + showUsage(); + exit(1); + } +} + + +static void finish(int sig) +{ + endwin(); + showGplShort(); + + fprintf(stderr,"\n"); + fprintf(stderr,"\n"); + fprintf(stderr,"=========================================================================\n"); + fprintf(stderr,"\n"); + + fprintf(stderr,"Final score: %7.7ld, Final level: %2.2d\nFinal rating... ",score,level); + if (lives>0) + fprintf(stderr,"Quitter\n\n"); + else if(score<5000) + fprintf(stderr,"Alien Fodder\n\n"); + else if(score<7500) + fprintf(stderr,"Easy Target\n\n"); + else if(score<10000) + fprintf(stderr,"Barely Mediocre\n\n"); + else if(score<12500) + fprintf(stderr,"Shows Promise\n\n"); + else if(score<15000) + fprintf(stderr,"Alien Blaster\n\n"); + else if(score<20000) + fprintf(stderr,"Earth Defender\n\n"); + else if(score>19999) + fprintf(stderr,"Supreme Protector\n\n"); + + showVersion(); + exit(0); +} + + +void drawscore() +{ + statusDisplay(level, score, lives); +} + + +/** + * reads input from keyboard and do action + */ +void readInput() +{ + int ch; + static int lastmove; + + timeout(100); + ch = getch(); // get key pressed + + static uint8_t data = 0; + if(ch == -1){ // keyboard first + usleep(1000000); // slow down inputs (100 ms) + if(handle != NULL && endpoint_desc_list != NULL && waitUSB == 0) + receiveData(2, &data, handle, endpoint_desc_list); + if(data != 0){ + if((data & 0x10) == 0x10) ch = KEY_LEFT; + else if((data & 0x04) == 0x04) ch = ' '; + else if((data & 0x02) == 0x02) ch = KEY_RIGHT; + else return; + } + else return; + } + + switch (status) { + + case GAME_PAUSED: + + if (ch == 'p') { + status = GAME_LOOP; + } + break; + + case GAME_HIGHSCORE: + + if (ch == ' ') { + titleScreenClear(); + level = 0; // reset level + score = 0; // reset score + lives = 3; // restore lives + sendLives(); + status = GAME_NEXTLEVEL; + } else if (ch == 'q') { // quit game + status = GAME_EXIT; + } + break; + + case GAME_OVER: + break; // don't do anything + + default: + + if (ch == 'l' || ch == KEY_RIGHT) { // move player right + if (lastmove == 'l') { + playerTurboOn(); // enable Turbo + } else { + playerTurboOff(); // disable Turbo + } + playerMoveRight(); // move player + lastmove = 'l'; // remember last move for turbo mode + } else if (ch == 'h' || ch == KEY_LEFT) { // move player left + if (lastmove == 'h') { + playerTurboOn(); // enable Turbo + } else { + playerTurboOff(); // disable Turbo + } + playerMoveLeft(); // move player + lastmove = 'h'; // remember last move for turbo mode + } else if (ch == 'k' || ch == ' ') { // shoot missile + playerLaunchMissile(); + } else if (ch == 'p') { // pause game until 'p' pressed again + // set status to game paused + status = GAME_PAUSED; + } else if (ch == 'W') { // cheat: goto next level + status = GAME_NEXTLEVEL; + } else if (ch == 'L') { // cheat: one more live + lives++; + sendLives(); + drawscore(); + } else if (ch == 'q') { // quit game + status = GAME_EXIT; + } else { // disable turbo mode if key is not kept pressed + lastmove = ' '; + } + + } // switch + +} + + +/** + * timer + * this method is executed every 1 / FPS seconds + */ +void handleTimer() +{ + static int aliens_move_counter = 0; + static int aliens_shot_counter = 0; + static int player_shot_counter = 0; + static int ufo_move_counter = 0; + static int title_animation_counter = 0; + static int game_over_counter = 0; + + switch (status) { + + case GAME_NEXTLEVEL: // go to next level + + level++; // increase level + + initLevel(); // initialize level + + aliens_move_counter = 0; + aliens_shot_counter = 0; + player_shot_counter = 0; + ufo_move_counter = 0; + + weite = (shipnum+(skill_level*10)-(level*5)+5)/10; + + if (weite < 0) { + weite = 0; + } + + // change status and start game! + status = GAME_LOOP; + + case GAME_LOOP: // do game handling + + // move aliens + if (aliens_move_counter == 0 && aliensMove() == 1) { + // aliens reached player + lives = 0; + sendLives(); + status = GAME_OVER; + } + + // move player missile + if (player_shot_counter == 0 && playerMoveMissile() == 1) { + // no aliens left + status = GAME_NEXTLEVEL; + } + + // move aliens' missiles + if (aliens_shot_counter == 0 && aliensMissileMove() == 1) { + // player was hit + lives--; // player looses one life + sendLives(); + drawscore(); // draw score + playerExplode(); // display some explosion graphics + if (lives == 0) { // if no lives left ... + status = GAME_OVER; // ... exit game + } + } + + // move ufo + if (ufo_move_counter == 0 && ufoShowUfo() == 1) { + ufoMoveLeft(); // move it one position to the left + } + + + if (aliens_shot_counter++ >= 5) {aliens_shot_counter=0;} // speed of alien shot + if (player_shot_counter++ >= 1) {player_shot_counter=0;} // speed of player shot + if (aliens_move_counter++ >= weite) {aliens_move_counter=0;} // speed of aliend + if (ufo_move_counter++ >= 3) {ufo_move_counter=0;} // speed of ufo + + refreshScreen(); + break; + + case GAME_PAUSED: // game is paused + break; + + case GAME_OVER: // game over + if (game_over_counter == 100) { + battleFieldClear(); + status = GAME_HIGHSCORE; + game_over_counter = 0; + } else { + gameOverDisplay(); + game_over_counter++; + } + break; + + case GAME_EXIT: // exit game + finish(0); + break; + + case GAME_HIGHSCORE: // display highscore + if (title_animation_counter == 0) { + titleScreenDisplay(); + } + + if (title_animation_counter++ >= 6) {title_animation_counter = 0;} // speed of animation + break; + + } +} + + +/** + * set up timer + */ +void setUpTimer() +{ + struct itimerval myTimer; + struct sigaction myAction; + myTimer.it_value.tv_sec = 0; + myTimer.it_value.tv_usec = 1000000 / FPS; + myTimer.it_interval.tv_sec = 0; + myTimer.it_interval.tv_usec = 1000000 / FPS; + setitimer(ITIMER_REAL, &myTimer, NULL); + + myAction.sa_handler = &handleTimer; + myAction.sa_flags = SA_RESTART; + sigaction(SIGALRM, &myAction, NULL); +} + + +int go = 1; +/*void signalINT(int sig){ + if(sig == SIGINT){ + go = 0; + } +}*/ +int main(int argc, char **argv) +{ + libusb_context *context; + libusb_device **devices; + struct libusb_config_descriptor *config_desc; + + // start + start(&context, &devices, &handle, &config_desc, endpoint_desc_list); + + // singals + /*struct sigaction action; + action.sa_handler = signalINT; + sigaction(SIGINT, &action, NULL);*/ + + // nInvaders + weite = 0; + score = 0; + lives = 3; + sendLives(); + level = 0; + skill_level = 1; + + evaluateCommandLine(argc, argv); // evaluate command line parameters + graphicEngineInit(); // initialize graphic engine + + // set up timer/ game handling + setUpTimer(); + status = GAME_HIGHSCORE; + + // read keyboard input + do { + // do movements and key-checking + readInput(handle, endpoint_desc_list); + } while (go); + + // stop + stop(config_desc, handle, devices, context); + + return 0; +} + + +void doScoring(int alienType) +{ + int points[4] = {500, 200, 150, 100}; // 0: ufo, 1:red, 2:green, 3:blue + + score += points[alienType]; // every alien type does different scoring points + + // every 6000 pts player gets a new live + if (score % 6000 == 0){ + lives++; + sendLives(); + } + + drawscore(); // display score +} + -- libgit2 0.21.2