hexagon.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "fxlib.h"
  2. #include "MonochromeLib.h"
  3. #include "math.h"
  4. #include "ECode.h"
  5. #include "struct.h"
  6. #include "wall.h"
  7. #include "syscall.h"
  8. #include "states.h"
  9. static const FONTCHARACTER filename[] = {'\\', '\\', 'f', 'l', 's', '0', '\\', 'S', 'H', 'C', '.', 's', 'a', 'v', 0};
  10. static const unsigned int filesize = sizeof(SaveData);
  11. void load_difficulty_names(char **str_list)
  12. {
  13. char c_1[] = "Hard";
  14. char c_2[] = "Harder";
  15. char c_3[] = "Hardest";
  16. char c_4[] = "Hardester";
  17. char c_5[] = "Hardestest";
  18. char c_6[] = "Hardestestest";
  19. int i = 0;
  20. int j = 0;
  21. for(i = 0; i < 6; i++)
  22. {
  23. str_list[i] = NULL;
  24. str_list[i] = malloc(sizeof(char) * 24);
  25. if(str_list[i] == NULL)
  26. return;
  27. for(j = 0; j < 24; str_list[i][j] = 0, j++) {
  28. }
  29. }
  30. memcpy(str_list[0], c_1, sizeof(char) * strlen(c_1));
  31. memcpy(str_list[1], c_2, sizeof(char) * strlen(c_2));
  32. memcpy(str_list[2], c_3, sizeof(char) * strlen(c_3));
  33. memcpy(str_list[3], c_4, sizeof(char) * strlen(c_4));
  34. memcpy(str_list[4], c_5, sizeof(char) * strlen(c_5));
  35. memcpy(str_list[5], c_6, sizeof(char) * strlen(c_6));
  36. }
  37. void loadDataFromSave(Game_Data* data) {
  38. int i, hasLoadedSave;
  39. SaveData dataLoaded;
  40. hasLoadedSave = 0;
  41. data->fileHandle = Bfile_OpenFile(filename, _OPENMODE_READ);
  42. if(data->fileHandle>= 0) {
  43. hasLoadedSave = 1;
  44. //(char*)data->entry_highscores
  45. if(Bfile_ReadFile(data->fileHandle, &dataLoaded, sizeof(dataLoaded), -1) < sizeof(dataLoaded))
  46. hasLoadedSave = 0;
  47. else {
  48. Bfile_CloseFile(data->fileHandle);
  49. Bfile_DeleteFile(filename);
  50. }
  51. }
  52. if(!hasLoadedSave) {
  53. for(i = 0; i < 6; i++) {
  54. data->entry_highscores[i] = 0.0f;
  55. }
  56. } else {
  57. for(i = 0; i < 6; i++) {
  58. data->entry_highscores[i] = dataLoaded.highscores[i];
  59. }
  60. }
  61. }
  62. int AddIn_main(int isAppli, unsigned short OptionNum)
  63. {
  64. SaveData dataToSave;
  65. int i;
  66. Game_Data data;
  67. // variables for fps calculation
  68. unsigned int fps = 0, frame = 0, tempsOrigine = RTC_GetTicks();
  69. // char string to display the fps
  70. unsigned char fps_text[8] = {0};
  71. // rand initialisation
  72. srand(RTC_GetTicks());
  73. // Key init
  74. data.shift_latch_value = 0;
  75. data.alpha_latch_value = 0;
  76. data.entry_highscores = NULL;
  77. data.entry_highscores = malloc(sizeof(float) * 6);
  78. if(data.entry_highscores == NULL)
  79. switch_to_state(OUT_OF_MEMORY, &data);
  80. data.entry_difficulties = NULL;
  81. data.entry_difficulties = malloc(sizeof(char*) * 6);
  82. if(data.entry_difficulties == NULL)
  83. switch_to_state(OUT_OF_MEMORY, &data);
  84. load_difficulty_names(data.entry_difficulties);
  85. loadDataFromSave(&data);
  86. switch_to_state(TITLE, &data);
  87. {
  88. char machin[] = "0";
  89. machin[0] = GetMPU() + '0';
  90. locate(1,1);
  91. Print(machin);
  92. GetKey(&i);
  93. }
  94. while(KeyUp(K_EXIT)){ // main loop
  95. // fps
  96. if(RTC_GetTicks() - tempsOrigine >= 32 )// if 1/4 seconds elapsed
  97. {
  98. fps = frame*4;
  99. frame = 0;
  100. tempsOrigine = RTC_GetTicks();
  101. }
  102. frame++;
  103. update(&data);
  104. draw(&data);
  105. // printing debug information
  106. // updating the screen
  107. ML_display_vram();
  108. ML_clear_vram();
  109. Sleep(1/0.06);
  110. }
  111. for(i = 0; i < 6; ++i)
  112. dataToSave.highscores[i] = data.entry_highscores[i];
  113. Bfile_CreateFile(filename, filesize);
  114. data.fileHandle = Bfile_OpenFile(filename, _OPENMODE_WRITE);
  115. if(data.fileHandle >= 0) {
  116. Bfile_WriteFile(data.fileHandle, &dataToSave, filesize);
  117. Bfile_CloseFile(data.fileHandle);
  118. }
  119. free(data.entry_highscores);
  120. return 1;
  121. }
  122. #pragma section _BR_Size
  123. unsigned long BR_Size;
  124. #pragma section
  125. #pragma section _TOP
  126. int InitializeSystem(int isAppli, unsigned short OptionNum)
  127. {
  128. return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
  129. }
  130. #pragma section