Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdint.h>
- #include <tice.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <graphx.h>
- #include <keypadc.h>
- #define WATER_COLOR 57
- #define WATER_NAFF 0
- #define OBSTACLE_COLOR 255
- #define ROB_COLOR 224
- #define WATERMAX 10000
- #define WATERXGEN 2
- #define WATERYGEN 2
- void initWater();
- void initEnv();
- void drawPixels(uint8_t color);
- void run();
- void drawRob(uint8_t col);
- void clean();
- uint16_t coords[WATERMAX] = {0};
- int robx = 25;
- int roby = 10;
- int waterindex = 0;
- void main(void)
- {
- prgm_CleanUp();
- gfx_Begin( gfx_8bpp );
- gfx_ZeroScreen();
- initEnv();
- drawRob(ROB_COLOR);
- run();
- gfx_End();
- prgm_CleanUp();
- }
- void run() {
- int testpixel, key;
- int x, y, a, o;
- int i;
- bool run = 1;
- while (run) {
- key = kb_ScanGroup(kb_group_6);
- if (key == kb_Clear) run = 0;
- initEnv();
- key = kb_ScanGroup(kb_group_7);
- switch (key) {
- case kb_Up:
- drawRob(WATER_NAFF);
- roby--;
- drawRob(ROB_COLOR);
- break;
- case kb_Down:
- drawRob(WATER_NAFF);
- roby++;
- drawRob(ROB_COLOR);
- break;
- case kb_Right:
- drawRob(WATER_NAFF);
- robx++;
- drawRob(ROB_COLOR);
- break;
- case kb_Left:
- drawRob(WATER_NAFF);
- robx--;
- drawRob(ROB_COLOR);
- break;
- }
- key = kb_ScanGroup(kb_group_6);
- if (key == kb_Enter) initWater();
- for (i = 0; i < waterindex; i+=2) {
- x = coords[i];
- y = coords[i+1];
- gfx_SetColor(WATER_NAFF);
- gfx_SetPixel(x, y);
- if (gfx_GetPixel(x, y+1) != 0) {
- a = randInt(1, 2);
- if ( a == 2 ) a = -1;
- o = x + a;
- if (gfx_GetPixel(o, y) == 0) {
- x+=a;
- } else {
- o = x - a;
- if (gfx_GetPixel(o, y) == 0) {
- x-=a;
- }
- }
- } else {
- y++;
- }
- gfx_SetColor(WATER_COLOR);
- gfx_SetPixel(x, y);
- coords[i] = x;
- coords[i+1] = y;
- }
- key = kb_ScanGroup(kb_group_1);
- if (key == kb_Del) clean();
- }
- }
- void initWater() {
- int i, j;
- int iterator = 0;
- for (i = 0; i < WATERXGEN; i++) {
- for (j = 0; j < WATERYGEN; j++) {
- coords[iterator+waterindex] = robx+1+i;
- coords[iterator+1+waterindex] = roby+1+j;
- iterator+=2;
- }
- }
- waterindex+=WATERXGEN*WATERYGEN*2;
- }
- void drawPixels(uint8_t color) {
- int i;
- gfx_SetColor(color);
- for (i = 0; i < waterindex; i+=2) {
- gfx_SetPixel(coords[i], coords[i+1]);
- }
- }
- void initEnv() {
- gfx_SetColor(OBSTACLE_COLOR);
- gfx_Line(0, 0, 0, 239);
- gfx_Line(319, 0, 319, 239);
- gfx_Line(0, 239, 319, 239);
- gfx_Line(10, 40, 60, 90);
- gfx_Line(10, 41, 60, 91);
- gfx_Line(55, 120, 70, 135);
- gfx_Line(55, 121, 70, 136);
- gfx_Line(85, 135, 100, 120);
- gfx_Line(85, 136, 100, 121);
- gfx_Line(70, 135, 70, 160);
- gfx_Line(69, 135, 69, 160);
- gfx_Line(85, 135, 85, 160);
- gfx_Line(86, 135, 86, 160);
- gfx_Line(70, 161, 84, 175);
- gfx_Line(69, 161, 84, 176);
- gfx_Line(85, 175, 100, 175);
- gfx_Line(85, 176, 100, 176);
- gfx_Circle(100, 210, 9);
- gfx_Circle(100, 210, 10);
- }
- void drawRob(uint8_t col) {
- gfx_SetColor(col);
- gfx_Line(robx, roby, robx, roby+WATERYGEN);
- gfx_Line(robx, roby, robx+WATERXGEN, roby);
- gfx_Line(robx+WATERXGEN+1, roby, robx+WATERXGEN+1, roby+WATERYGEN);
- }
- void clean() {
- int i = 0;
- drawPixels(WATER_NAFF);
- for (i = 0; i < waterindex; i++) {
- coords[i] = 0; }
- waterindex = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement