utils.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "utils.h"
  2. bool is_block(uint8_t tile) {
  3. return (tile > 0) && (tile != WALL_TILE);
  4. }
  5. uint8_t cap_x(uint8_t coord) {
  6. return MIN(MAX(0, coord), (SIZE_X - 1));
  7. }
  8. uint8_t cap_y(uint8_t coord) {
  9. return MIN(MAX(0, coord), (SIZE_Y - 1));
  10. }
  11. bool is_state_pause(State gameState) {
  12. return ((gameState < ABOUT) || (gameState >= PAUSED));
  13. }
  14. void copy_level(PlayGround target, PlayGround source) {
  15. memcpy(target, source, sizeof(uint8_t) * SIZE_X * SIZE_Y);
  16. }
  17. void clear_board(PlayGround* ani) {
  18. memset(ani, '\0', sizeof(uint8_t) * SIZE_X * SIZE_Y);
  19. }
  20. void randomize_bg(BackGround* bg) {
  21. memset(bg, 0, sizeof(uint8_t) * SIZE_X_BG * SIZE_Y_BG);
  22. int r;
  23. uint8_t ra, x, y;
  24. for(y = 0; y < SIZE_Y_BG; y++) {
  25. for(x = 0; x < SIZE_X_BG; x++) {
  26. do {
  27. r = rand();
  28. ra = (r % 7) + 1;
  29. if(y > 0) {
  30. if((*bg)[y - 1][x] == ra) {
  31. ra = 0;
  32. }
  33. }
  34. if(x > 0) {
  35. if((*bg)[y][x - 1] == ra) {
  36. ra = 0;
  37. }
  38. }
  39. } while(ra == 0);
  40. (*bg)[y][x] = ra;
  41. }
  42. }
  43. }
  44. const char* game_mode_label(GameMode mode) {
  45. switch(mode) {
  46. case CONTINUE:
  47. return "Continue";
  48. case CUSTOM:
  49. return "Custom";
  50. default:
  51. case NEW_GAME:
  52. return "New Game";
  53. }
  54. }