hexagon.c 3.5 KB

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