/** * Dessine l'entité passée en paramètre sur le plateau de jeu. * @param board Le plateau sur lequel l'entité est ajoutée * @param entity L'entité à ajouter */ void drawEntity(char board[ROWS][COLS], const Entity* entity) { board[entity->pos->x][entity->pos->y] = entity->symbol; goToXY(entity->pos->y, entity->pos->x); setColor(entity->symbolColor); putchar(convertCase(entity->symbol)); resetColor(); }
/** * Nettoie la case de l'ancienne position de l'entité. * @param board Le plateau de jeu sur lequel l'entité est retirée * @param entity L'entité à nettoyer */ void clearEntity(char board[ROWS][COLS], const Entity* entity) { goToXY(entity->pos->y, entity->pos->x); if (entity->caseBelow == THICK_CHAR) { setColor(THIN_CHAR_COLOR); board[entity->pos->x][entity->pos->y] = THIN_CHAR; putchar(convertCase(THIN_CHAR)); } else if (entity->caseBelow == SLIP_CHAR) { setColor(SLIP_CHAR_COLOR); board[entity->pos->x][entity->pos->y] = SLIP_CHAR; putchar(convertCase(SLIP_CHAR)); } else { setColor(entity->nextSymbolColor); board[entity->pos->x][entity->pos->y] = entity->nextSymbol; putchar(convertCase(entity->nextSymbol)); } resetColor(); }
/** * Dessine le plateau de jeu. * @param map Le fichier correspondant à la map * @param game L'état du jeu * @param board Le plateau à afficher */ void drawBoard(FILE* map, const GameState* game, char board[ROWS][COLS]) { unsigned short x, y; for (x = 0; x < ROWS; x++) { for (y = 0; y <= COLS; y++) { board[x][y] = fgetc(map); setColor(getCaseColor(board[x][y])); putchar(convertCase(board[x][y])); } } resetColor(); drawToolbar(game); drawPanel(); printf("\n"); closeMap(map); }
/** * Affiche la légende du jeu. */ static void drawPanel() { setColor(GRAY_COLOR); goToXY(INFOPANEL_X, 4); setColor(getCaseColor(HERO_CHAR)); printf("%c", convertCase(HERO_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Personnage"); goToXY(INFOPANEL_X, 5); setColor(getCaseColor(WALL_CHAR)); printf("%c", convertCase(WALL_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Mur"); goToXY(INFOPANEL_X, 6); setColor(getCaseColor(DOOR_CHAR)); printf("%c", convertCase(DOOR_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Porte de sortie"); goToXY(INFOPANEL_X, 7); setColor(getCaseColor(THIN_CHAR)); printf("%c", convertCase(THIN_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Glace fine"); goToXY(INFOPANEL_X, 8); setColor(getCaseColor(THICK_CHAR)); printf("%c", convertCase(THICK_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Glace epaisse"); goToXY(INFOPANEL_X, 9); setColor(getCaseColor(SLIP_CHAR)); printf("%c", convertCase(SLIP_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Glace glissante"); goToXY(INFOPANEL_X, 10); setColor(getCaseColor(MELT_CHAR)); printf("%c", convertCase(MELT_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Eau"); goToXY(INFOPANEL_X, 11); setColor(getCaseColor(LIGHTNESS_POTION_CHAR)); printf("%c", convertCase(LIGHTNESS_POTION_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Potion de legerete"); goToXY(INFOPANEL_X, 12); setColor(getCaseColor(SCORE_BONUS_CHAR)); printf("%c", convertCase(SCORE_BONUS_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Bonus de score"); goToXY(INFOPANEL_X, 13); setColor(getCaseColor(TUNNEL_CHAR)); printf("%c", convertCase(TUNNEL_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Tunnel"); goToXY(INFOPANEL_X, 14); setColor(getCaseColor(MOWER_CHAR)); printf("%c", convertCase(MOWER_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Tondeuse"); goToXY(INFOPANEL_X, 15); setColor(getCaseColor(HOLE_CHAR)); printf("%c", convertCase(HOLE_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Trou"); goToXY(INFOPANEL_X, 16); setColor(getCaseColor(ENEMY_CHAR)); printf("%c", convertCase(ENEMY_CHAR)); setColor(GRAY_COLOR); printf(" %s\n", "Ennemi"); goToXY(INFOPANEL_X, 18); printf("%s %4s\n", "(p)", "Pause"); goToXY(INFOPANEL_X, 19); printf("%s %4s\n", "(r)", "Recommencer le niveau"); goToXY(INFOPANEL_X, 20); printf("%s %2s\n", "(q)", "Quitter"); resetColor(); }
int main(int argc, char* argv[]) { FILE *file; char *buffer; unsigned long fileLen; int i; long words; int bytes; unsigned long index; const char *output_dir; if (argc < 2) { fprintf(stderr, "Usage: %s <input>.so (output_dir)\n", argv[0]); return -1; } if (argc < 3) { output_dir = ""; } else { output_dir = argv[2]; } #ifdef DEBUG printf("Opening '%s'\n", argv[1]); #endif //Open file file = fopen(argv[1], "rb"); if (!file) { fprintf(stderr, "Unable to open input file %s", argv[1]); return -1; } #ifdef DEBUG printf("Getting name..."); #endif // Get the filename char *aa_name = getName(argv[1]); if (!aa_name) { fprintf(stderr, "Memory error!"); fclose(file); return -1; } #ifdef DEBUG printf("'%s'\n", aa_name); printf("Getting length..."); #endif //Get file length fseek(file, 0, SEEK_END); fileLen=ftell(file); fseek(file, 0, SEEK_SET); #ifdef DEBUG printf("%ld\n", fileLen); #endif //Allocate memory #ifdef DEBUG printf("Creating buffer\n"); #endif buffer=(char *)malloc(fileLen+1); if (!buffer) { fprintf(stderr, "Memory error!"); free(aa_name); fclose(file); return -1; } #ifdef DEBUG printf("Reading file into buffer..."); #endif //Read file contents into buffer fread(buffer, fileLen, 1, file); #ifdef DEBUG printf("done\n"); #endif fclose(file); char output_filename[strlen(output_dir) + 1 + strlen(aa_name) + 3]; sprintf(output_filename, "%s/%s.h", output_dir, aa_name); #ifdef DEBUG printf("Opening '%s'\n", output_filename); #endif file = fopen(output_filename, "w"); if (!file) { fprintf(stderr, "Unable to create output file %s", output_filename); free(aa_name); free(buffer); return -1; } #ifdef DEBUG printf("Writing file header..."); #endif fprintf(file, "/**\n * Murac software framework\n * \n * Header file for '%s'\n * Author: Brandon Hamilton <*****@*****.**>\n */\n\n", aa_name); convertCase(aa_name); fprintf(file, "#ifndef %s_H\n#define %s_H\n\n", aa_name, aa_name); fprintf(file, "#define EXECUTE_%s int _lib_length = %d;\\\n", aa_name, fileLen); fprintf(file, " asm volatile(\"mov r1,%[value]\" : : [value]\"r\"(_lib_length) : \"r1\"); \\\n"); fprintf(file, " asm volatile(\".align 4\\n\\t\" \\\n"); fprintf(file, " \".word 0xE12FFF41\\n\\t\" \\\n"); words = fileLen / 4; bytes = fileLen % 4; index = 0; #ifdef DEBUG printf("done\nWriting data %d words, %d bytes\n", words, bytes); #endif for (i = 0; i < words; i++) { fprintf(file, " \".word 0x%x\\n\\t\" \\\n", *(unsigned int *)&buffer[index]); index += 4; } unsigned int last_word = 0; for (i = 0; i < bytes; i++) { last_word |= (buffer[index++]) << 24-(i*8); } fprintf(file, " \".word 0x%x\\n\\t\" \\\n", last_word); fprintf(file, " );"); fprintf(file, "\n#endif // %s_H\n", aa_name); #ifdef DEBUG printf("Closing file\n"); #endif fclose(file); free(aa_name); free(buffer); return 0; }