Advertisement
MMBC

Untitled

Jun 21st, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.09 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include <tice.h>
  5. #include <math.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <graphx.h>
  10. #include <keypadc.h>
  11.  
  12. #define WATER_COLOR 57
  13. #define WATER_NAFF 0
  14. #define OBSTACLE_COLOR 255
  15. #define ROB_COLOR 224
  16. #define WATERMAX 10000
  17. #define WATERXGEN 2
  18. #define WATERYGEN 2
  19.  
  20. void initWater();
  21. void initEnv();
  22. void drawPixels(uint8_t color);
  23. void run();
  24. void drawRob(uint8_t col);
  25. void clean();
  26.  
  27. uint16_t coords[WATERMAX] = {0};
  28. int robx = 25;
  29. int roby = 10;
  30. int waterindex = 0;
  31.  
  32. void main(void)
  33. {
  34.     prgm_CleanUp();
  35.     gfx_Begin( gfx_8bpp );
  36.     gfx_ZeroScreen();
  37.    
  38.     initEnv();
  39.     drawRob(ROB_COLOR);
  40.     run();
  41.    
  42.     gfx_End();
  43.     prgm_CleanUp();
  44. }
  45.  
  46. void run() {
  47.     int testpixel, key;
  48.     int x, y, a, o;
  49.     int i;
  50.     bool run = 1;
  51.     while (run) {
  52.         key = kb_ScanGroup(kb_group_6);
  53.         if (key == kb_Clear) run = 0;
  54.         initEnv();
  55.         key = kb_ScanGroup(kb_group_7);
  56.         switch (key) {
  57.             case kb_Up:
  58.                 drawRob(WATER_NAFF);
  59.                 roby--;
  60.                 drawRob(ROB_COLOR);
  61.                 break;
  62.             case kb_Down:
  63.                 drawRob(WATER_NAFF);
  64.                 roby++;
  65.                 drawRob(ROB_COLOR);
  66.                 break;
  67.             case kb_Right:
  68.                 drawRob(WATER_NAFF);
  69.                 robx++;
  70.                 drawRob(ROB_COLOR);
  71.                 break;
  72.             case kb_Left:
  73.                 drawRob(WATER_NAFF);
  74.                 robx--;
  75.                 drawRob(ROB_COLOR);
  76.                 break;
  77.         }
  78.         key = kb_ScanGroup(kb_group_6);
  79.         if (key == kb_Enter) initWater();
  80.         for (i = 0; i < waterindex; i+=2) {
  81.             x = coords[i];
  82.             y = coords[i+1];
  83.             gfx_SetColor(WATER_NAFF);
  84.             gfx_SetPixel(x, y);
  85.             if (gfx_GetPixel(x, y+1) != 0) {
  86.                 a = randInt(1, 2);
  87.                 if ( a == 2 ) a = -1;
  88.                 o = x + a;
  89.                 if (gfx_GetPixel(o, y) == 0) {
  90.                     x+=a;
  91.                 } else {
  92.                     o = x - a;
  93.                     if (gfx_GetPixel(o, y) == 0) {
  94.                         x-=a;
  95.                     }
  96.                 }
  97.             } else {
  98.                 y++;
  99.             }
  100.             gfx_SetColor(WATER_COLOR);
  101.             gfx_SetPixel(x, y);
  102.             coords[i] = x;
  103.             coords[i+1] = y;
  104.         }
  105.         key = kb_ScanGroup(kb_group_1);
  106.         if (key == kb_Del) clean();
  107.     }
  108. }
  109.  
  110. void initWater() {
  111.     int i, j;
  112.     int iterator = 0;
  113.     for (i = 0; i < WATERXGEN; i++) {
  114.         for (j = 0; j < WATERYGEN; j++) {
  115.             coords[iterator+waterindex] = robx+1+i;
  116.             coords[iterator+1+waterindex] = roby+1+j;
  117.             iterator+=2;
  118.         }
  119.     }
  120.     waterindex+=WATERXGEN*WATERYGEN*2;
  121. }
  122.  
  123. void drawPixels(uint8_t color) {
  124.     int i;
  125.     gfx_SetColor(color);
  126.     for (i = 0; i < waterindex; i+=2) {
  127.         gfx_SetPixel(coords[i], coords[i+1]);
  128.     }
  129. }
  130.  
  131. void initEnv() {
  132.     gfx_SetColor(OBSTACLE_COLOR);
  133.     gfx_Line(0, 0, 0, 239);
  134.     gfx_Line(319, 0, 319, 239);
  135.     gfx_Line(0, 239, 319, 239);
  136.     gfx_Line(10, 40, 60, 90);
  137.     gfx_Line(10, 41, 60, 91);
  138.     gfx_Line(55, 120, 70, 135);
  139.     gfx_Line(55, 121, 70, 136);
  140.     gfx_Line(85, 135, 100, 120);
  141.     gfx_Line(85, 136, 100, 121);
  142.     gfx_Line(70, 135, 70, 160);
  143.     gfx_Line(69, 135, 69, 160);
  144.     gfx_Line(85, 135, 85, 160);
  145.     gfx_Line(86, 135, 86, 160);
  146.     gfx_Line(70, 161, 84, 175);
  147.     gfx_Line(69, 161, 84, 176);
  148.     gfx_Line(85, 175, 100, 175);
  149.     gfx_Line(85, 176, 100, 176);
  150.     gfx_Circle(100, 210, 9);
  151.     gfx_Circle(100, 210, 10);
  152. }
  153.  
  154. void drawRob(uint8_t col) {
  155.     gfx_SetColor(col);
  156.     gfx_Line(robx, roby, robx, roby+WATERYGEN);
  157.     gfx_Line(robx, roby, robx+WATERXGEN, roby);
  158.     gfx_Line(robx+WATERXGEN+1, roby, robx+WATERXGEN+1, roby+WATERYGEN);
  159. }
  160.  
  161. void clean() {
  162.     int i = 0;
  163.     drawPixels(WATER_NAFF);
  164.     for (i = 0; i < waterindex; i++) {
  165.         coords[i] = 0; }
  166.     waterindex = 0;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement