Guest User

Untitled

a guest
Jun 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.79 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. #define UP 'z'
  6. #define DOWN 's'
  7. #define LEFT 'q'
  8. #define RIGHT 'd'
  9.  
  10. #define TRUE 1
  11. #define FALSE 0
  12.  
  13. #define DIMENSION 15
  14.  
  15. /*int randMax = DIMENSION - 1;
  16. int HEART_X1 = 1 + (int)(10.0 * rand() / (randMax+ 1.0));
  17. int HEART_Y1 = 1 + (int)(10.0 * rand() / (randMax+ 1.0));
  18. int HEART_X2 = HEART_X1 + 1;
  19. int HEART_Y2 = HEART_Y1;*/
  20. #define HEART_X1 1
  21. #define HEART_Y1 2
  22. #define HEART_X2 1
  23. #define HEART_Y2 3
  24.  
  25. int pField [DIMENSION][DIMENSION];
  26. int hLoc [2];
  27. int hDir = DOWN;
  28. int run = TRUE;
  29.  
  30. void move (char);
  31. void eventCheck (int);
  32. int collisionCheck (void);
  33. void drawGFX (void);
  34.  
  35. int main (void)
  36. {
  37.     char input = NULL;
  38.     int i = NULL;
  39.     int j = NULL;
  40.     int pEvent = NULL;
  41.  
  42.     //set every position at zero
  43.     for (i = 0; i < DIMENSION; i++)
  44.         for (j = 0; j < DIMENSION; j++)
  45.             pField[i][j] = 0;
  46.     //set hero in the middle
  47.     hLoc[1] = DIMENSION / 2;
  48.     hLoc[2] = DIMENSION / 2;
  49.     pField[DIMENSION / 2][DIMENSION / 2] = 1;
  50.     //set heart
  51.     pField[HEART_X1][HEART_Y1] = 2;
  52.     pField[HEART_X2][HEART_Y2] = 3;
  53.  
  54.     drawGFX();
  55.     while (run)
  56.     {
  57.         input = getch();
  58.         move (input);
  59.         pEvent = collisionCheck();
  60.         eventCheck (pEvent);
  61.         drawGFX();
  62.     }
  63.     drawGFX();
  64.     printf ("IK HOU VAN U LOTTE! :D  VOOR EEUWIG\n              uw Toon\n\n\n");
  65.  
  66.     return EXIT_SUCCESS;
  67. }
  68.  
  69. void move (char input)
  70. {
  71.     int x;
  72.     int y;
  73.  
  74.     pField[hLoc[2]][hLoc[1]] = 0;
  75.     if (input != hDir)
  76.     {
  77.         if (input == UP || input == DOWN || input == LEFT || input == RIGHT)
  78.         {
  79.             hDir = input;
  80.         }
  81.     }
  82.     else
  83.     {
  84.         if (input == UP && hLoc[2] > 0)
  85.             hLoc[2] --;
  86.         if (input == DOWN && hLoc[2] < DIMENSION - 1)
  87.             hLoc[2] ++;
  88.         if (input == LEFT && hLoc[1] > 0)
  89.             hLoc[1] --;
  90.         if (input == RIGHT && hLoc[1] < DIMENSION - 1)
  91.             hLoc[1] ++;
  92.     }
  93.     x = hLoc[1];
  94.     y = hLoc[2];
  95.     pField[y][x] = 1;
  96. }
  97.  
  98. int collisionCheck (void)
  99. {
  100.     if (hLoc[2] == HEART_X1 && hLoc[1] == HEART_Y1)
  101.         return 1;
  102.     if (hLoc[2] == HEART_X2 && hLoc[1] == HEART_Y2)
  103.         return 1;
  104.     return 0;
  105. }
  106.  
  107. void eventCheck (int pEvent)
  108. {
  109.     if (pEvent == 1)
  110.         run = FALSE;
  111. }
  112.  
  113. void drawGFX (void)
  114. {
  115.     int i;
  116.     int j;
  117.  
  118.     system("cls");
  119.     printf ("Vindt de weg naar mijn hart!\n\n");
  120.     for (i = 0; i < DIMENSION + 2; i++)
  121.         printf ("#");
  122.     printf ("\n");
  123.  
  124.     for (i = 0; i < DIMENSION; i++)
  125.     {
  126.         printf ("#");
  127.         for (j = 0; j < DIMENSION; j++)
  128.         {
  129.             if (pField[i][j] == 0)
  130.                 printf (" ");
  131.             if (pField[i][j] == 1)
  132.             {
  133.                 if (hDir == UP)
  134.                     printf ("^");
  135.                 if (hDir == DOWN)
  136.                     printf ("v");
  137.                 if (hDir == LEFT)
  138.                     printf ("<");
  139.                 if (hDir == RIGHT)
  140.                     printf (">");
  141.             }
  142.             if (pField[i][j] == 2)
  143.                 printf ("<");
  144.             if (pField[i][j] == 3)
  145.                 printf ("3");
  146.         }
  147.         printf ("#");
  148.         printf ("\n");
  149.     }
  150.     for (i = 0; i < DIMENSION + 2; i++)
  151.         printf ("#");
  152.     printf ("\n");
  153. }
Add Comment
Please, Sign In to add comment