CodeWalrus

Development => Calculators => Calc Projects, Programming & Tutorials => Topic started by: Unicorn on February 24, 2016, 11:52:53 PM

Title: FloodIt [TI 84+ CE] [C] (need C help)
Post by: Unicorn on February 24, 2016, 11:52:53 PM
I'm figuring out how to use C with the CE, so I decided to port this (http://unixpapa.com/floodit/?sz=14&nc=6) game.

I've got the displaying part down, with the absence of buttons to change the color you want, but that should be easy to implement.

(https://usercontent.irccloud-cdn.com/file/Fu5tbeva/fungif.gif)

I've been trying to figure out how to check the colors of the squares adjacent and how to change their colors. Currently I have this in mind:

Select color
Change top left color
If the color of an adjacent is color of last color, change to current color
increase turns
repeat

Do you think this works? I'm going to check using getpixel, and I'm starting to believe that I'm gonna need to have each square mapped using a variable. Suggestions would be welcome on how to do this!
Title: Re: FloodIt
Post by: Dream of Omnimaga on February 25, 2016, 04:09:10 AM
Glad to see you are learning C. I hope you have fun with that language :). Also the game seems interesting. I hope you can pull it off and hopefully can get help for your problem.
Title: Re: FloodIt (need C help)
Post by: Scipi on February 25, 2016, 07:18:57 AM
I would use an array to hold all the color data, and then index into it. This article may help you: http://www.geeksforgeeks.org/flood-fill-algorithm-implement-fill-paint/
Title: Re: FloodIt (need C help)
Post by: aetios on February 25, 2016, 09:37:50 AM
I was going to suggest what @Scipi suggested. That would make it a lot easier to check color data. Are you going to use F1 .. F5 for choosing the colors?
Title: Re: FloodIt (need C help)
Post by: Unicorn on February 25, 2016, 11:38:04 PM
Quote from: aeTIos on February 25, 2016, 09:37:50 AMAre you going to use F1 .. F5 for choosing the colors?
Yes, I will also probably have a selection using the arrow keys.

Quote from: Scipi on February 25, 2016, 07:18:57 AM
I would use an array to hold all the color data, and then index into it. This article may help you: http://www.geeksforgeeks.org/flood-fill-algorithm-implement-fill-paint/
Yeah, that is what Cemetech recommended as well, I'll try to get that working, though I'm not sure how well I will be able to...

And for the curious, some code:


/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti84pce.h>

/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* CE Graphics C Library */
#include <graphc.h>
int x = 61;
int y = 4;
int color;
int r;
/* Main Function */
void main(void)
{
    /* Some variable intialization */

    gc_InitGraph();
    gc_SetColorIndex(255);
    gc_FillScrn(0);
    gc_NoClipRectangleOutline(60,2,258,195);
    while (1) {
        r = rand() % 6;
        if (r == 0)
            color = 224; //RED
        if (r == 1)
            color = 16; //BLUE
        if (r == 2)
            color = 231; //YELLOW
        if (r == 3)
            color = 5; //GREEN
        if (r == 4)
            color = 112; //PURPLE
        if (r == 5)
            color = 227; //ORANGE
           
        gc_SetColorIndex(color);   
        gc_NoClipRectangle(x,y,16,16);
        x += 16;
            if (x >= 305) {
                x = 61;
                y += 16;
            }
        if (y >= 192)
            break;
    }


    /* Print a string of stuff */
    gc_PrintStringXY("CircleStuff",1,250);
     
    /* This is a really bad function to use. Don't use it in actual things */
    _OS( GetKey() );

    /* Close the graphics canvas and return to the OS */
    gc_CloseGraph();
_OS( asm("call _DrawStatusBar"));
}
Title: Re: FloodIt (need C help)
Post by: Scipi on February 26, 2016, 03:13:06 AM
Quote from: Unicorn on February 25, 2016, 11:38:04 PM
Quote from: Scipi on February 25, 2016, 07:18:57 AM
I would use an array to hold all the color data, and then index into it. This article may help you: http://www.geeksforgeeks.org/flood-fill-algorithm-implement-fill-paint/
Yeah, that is what Cemetech recommended as well, I'll try to get that working, though I'm not sure how well I will be able to...

The code on that site looks like valid C, so you could use it more or less verbatim, provided all your color data is in a 2D array of ints.
Title: Re: FloodIt (need C help)
Post by: Unicorn on February 27, 2016, 03:13:07 AM
I'm gonna try something myself first.

So I've added boxes and for selection, but my keyboard routine is way to fast. How would I go about slowing it down? I also need help with my randomizing. Mateo told me to seed it with srand(*(unsigned long*)0xF30044); but when I put that above the rand() % 6; code, it fills the box with one color that changes each time. What am I doing wrong?
(https://usercontent.irccloud-cdn.com/file/2qf4o4V2/update.gif)

Keyboard code:

while (kb_ScanGroup(kb_group_6) != kb_Clear) {
gc_SetColorIndex(214);
gc_NoClipRectangle(selectorX,233,25,3);
key = kb_ScanGroup(kb_group_7);
if (key & kb_Left && selectorX > 65+12) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX -= 10;
}
if (key & kb_Right && selectorX < 215+62) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX += 10;
}
kb_Reset();
}


Entire Code

/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti84pce.h>

/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* CE Graphics C Library */
#include <graphc.h>
#include <keypadc.h>
int x = 61;
int y = 4;
int color;
int r;
int lastColor;
int key;
int selectorX = 65+11;
unsigned int speed;
void delay(unsigned int);
/* Main Function */
void main(void)
{
    /* Some variable intialization */

    gc_InitGraph();
    gc_SetColorIndex(255);
    gc_FillScrn(0);
gc_NoClipRectangleOutline(60,2,258,195);
gc_NoClipRectangleOutline(65+11,205,25,25);
gc_NoClipRectangleOutline(95+21,205,25,25);
gc_NoClipRectangleOutline(125+31,205,25,25);
gc_NoClipRectangleOutline(155+41,205,25,25);
gc_NoClipRectangleOutline(185+51,205,25,25);
gc_NoClipRectangleOutline(215+61,205,25,25);
gc_SetColorIndex(224);
gc_NoClipRectangle(65+12,206,23,23);
gc_SetColorIndex(16);
gc_NoClipRectangle(95+22,206,23,23);
gc_SetColorIndex(231);
gc_NoClipRectangle(125+32,206,23,23);
gc_SetColorIndex(5);
gc_NoClipRectangle(155+42,206,23,23);
gc_SetColorIndex(112);
gc_NoClipRectangle(185+52,206,23,23);
gc_SetColorIndex(227);
gc_NoClipRectangle(215+62,206,23,23);
while (1) {
r = rand() % 6;
        if (r == 0)
            color = 224; //RED
        if (r == 1)
            color = 16; //BLUE
        if (r == 2)
            color = 231; //YELLOW
        if (r == 3)
            color = 5; //GREEN
        if (r == 4)
            color = 112; //PURPLE
        if (r == 5)
            color = 227; //ORANGE
           
        gc_SetColorIndex(color);   
        gc_NoClipRectangle(x,y,16,16);
        x += 16;
            if (x >= 305) {
                x = 61;
                y += 16;
            }
        if (y >= 192)
break;
}
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
gc_SetColorIndex(214);
gc_NoClipRectangle(selectorX,233,25,3);
key = kb_ScanGroup(kb_group_7);
if (key & kb_Left && selectorX > 65+12) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX -= 10;
}
if (key & kb_Right && selectorX < 215+62) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX += 10;
}
kb_Reset();
}


    /* Print a string of stuff */
    gc_PrintStringXY("CircleStuff",1,250);
     
    /* This is a really bad function to use. Don't use it in actual things */
    _OS( GetKey() );

    /* Close the graphics canvas and return to the OS */
    gc_CloseGraph();
_OS( asm("call _DrawStatusBar"));
}

Title: Re: FloodIt (need C help)
Post by: Dream of Omnimaga on February 27, 2016, 05:43:24 AM
I can't help you with the code since I don't know C, but would using a variable as a key delay work? For example, when pressing a key, it would set the variable to 10 and then it would count down to zero every loop and when it reaches zero then you can press a key again. You would probably need to make it so that the first delay is longer, though.
Title: Re: FloodIt (need C help)
Post by: Unicorn on February 27, 2016, 05:32:07 PM
Quote from: DJ Omnimaga on February 27, 2016, 05:43:24 AM
I can't help you with the code since I don't know C, but would using a variable as a key delay work? For example, when pressing a key, it would set the variable to 10 and then it would count down to zero every loop and when it reaches zero then you can press a key again. You would probably need to make it so that the first delay is longer, though.
That is what I ended up doing, Kerm had written a description for PT_ on cemetech, and that helped me get things going. So now, I'm gonna start getting my flood-fill algorithm going, I may need some help with that at some point.
Title: Re: FloodIt (need C help)
Post by: Unicorn on February 28, 2016, 07:04:46 PM
bump.

I have fixed the above issues, I had the seed in a loop, and the key-presses were pretty easy to fix.

Anyways, I've gotten my array filled with the numbers of my colors (I hope), and I am about to move on to the flood-fill.
Check it out!

/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti84pce.h>

/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* CE Graphics C Library */
#include <graphc.h>
#include <keypadc.h>
int x = 61;
int y = 4;
int r, seed = 13;
int arrayColumn, arrayRow;
int lastColor, color;
int key, key1, key2;
int selectorX = 65+11;
unsigned int speed = 4, keyPress;
int floodArray[12][16];
/* Main Function */
void main(void)
{
    /* Some variable intialization */

    gc_InitGraph();
    gc_SetColorIndex(255);
    gc_FillScrn(0);
gc_NoClipRectangleOutline(60,2,258,195);
gc_NoClipRectangleOutline(65+11,205,25,25);
gc_NoClipRectangleOutline(95+21,205,25,25);
gc_NoClipRectangleOutline(125+31,205,25,25);
gc_NoClipRectangleOutline(155+41,205,25,25);
gc_NoClipRectangleOutline(185+51,205,25,25);
gc_NoClipRectangleOutline(215+61,205,25,25);
gc_SetColorIndex(224);
gc_NoClipRectangle(65+12,206,23,23);
gc_SetColorIndex(16);
gc_NoClipRectangle(95+22,206,23,23);
gc_SetColorIndex(231);
gc_NoClipRectangle(125+32,206,23,23);
gc_SetColorIndex(5);
gc_NoClipRectangle(155+42,206,23,23);
gc_SetColorIndex(112);
gc_NoClipRectangle(185+52,206,23,23);
gc_SetColorIndex(227);
gc_NoClipRectangle(215+62,206,23,23);
gc_SetTextColor((0<<8)|255);
gc_PrintStringXY("FloodIt",1,1);
gc_PrintStringXY("by",1,15);
gc_PrintStringXY("Unicorn",1,30);
srand(*(unsigned long*)0xF30044);
while (1) {
r = rand() % 6;
        if (r == 0)
            color = 224; //RED
        if (r == 1)
            color = 16; //BLUE
        if (r == 2)
            color = 231; //YELLOW
        if (r == 3)
            color = 5; //GREEN
        if (r == 4)
            color = 112; //PURPLE
        if (r == 5)
            color = 227; //ORANGE
           
        gc_SetColorIndex(color);   
        gc_NoClipRectangle(x,y,16,16);
x += 16;
floodArray[arrayColumn][arrayRow] = color;
if (x >= 305) {
arrayRow = 0;
            x = 61;
y += 16;
if (y >= 192)
break;
arrayColumn++;
}
arrayRow++;
}
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
if (keyPress % 45 == 0) {
if (key & kb_Left && selectorX > 65+12) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX -= 40;
}
if (key & kb_Right && selectorX < 215+58) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX += 40;
}
if (key1 & kb_2nd && selectorX == 76) {
//check algorithm - RED
lastColor = color;
color = 224;

}
if (key1 & kb_2nd && selectorX == 116) {
//check algorithm - BLUE
lastColor = color;
color = 16;
}
if (key1 & kb_2nd && selectorX == 156) {
//check algorithm - YELLOW
lastColor = color;
color = 231;
}
if (key1 & kb_2nd && selectorX == 196) {
//check algorithm - GREEN
lastColor = color;
color = 5;
}
if (key1 & kb_2nd && selectorX == 236) {
//check algorithm - PURPLE
lastColor = color;
color = 112;
}
if (key1 & kb_2nd && selectorX == 276) {
//check algorithm - ORANGE
lastColor = color;
color = 227;
}
}

gc_SetColorIndex(214);
gc_NoClipRectangle(selectorX,233,25,3);
key = kb_ScanGroup(kb_group_7);
key1 = kb_ScanGroup(kb_group_1);
gc_SetTransparentColor(30);
gc_SetTextColor(255);
gc_PrintStringXY("FloodIt",1,1);
gc_PrintStringXY("by",20,15);
gc_PrintStringXY("Unicorn",1,30);
keyPress++;
}

    /* Close the graphics canvas and return to the OS */
    gc_CloseGraph();
_OS( asm("call _DrawStatusBar"));
}


(https://usercontent.irccloud-cdn.com/file/GwuC6vMd/Randomization%2Bselection.gif)
Title: Re: FloodIt [TI 84+ CE] [C] (need C help)
Post by: Dudeman313 on February 28, 2016, 08:17:41 PM
Nice! Looks like this is running much faster than the BASIC one I just tested. Can't wait for a release! ;D
Title: Re: FloodIt (need C help)
Post by: Dream of Omnimaga on February 29, 2016, 07:04:56 AM
Good to hear, and looks nice Unicorn. By the way, does this key delay cause key detection issues? (keypresses not registering all the time) Or is it fine?
Title: Re: FloodIt (need C help)
Post by: Unicorn on February 29, 2016, 11:12:16 PM
Quote from: DJ Omnimaga on February 29, 2016, 07:04:56 AM
Good to hear, and looks nice Unicorn. By the way, does this key delay cause key detection issues? (keypresses not registering all the time) Or is it fine?
Not really, and if it becomes a problem, I can shorted the delay easily.
Title: Re: FloodIt (need C help)
Post by: Unicorn on March 01, 2016, 05:59:50 AM
So, right now, I have something of an algorithm, though it doesn't do the job correctly. (screenshot below) Any tips on how to fix it up? I'll be taking more of a look at it tomorrow, so hopefully I can get more done with a fresh mind :)

(https://usercontent.irccloud-cdn.com/file/RkB4OBu4/hum.gif)

Pseudocode of what it is supposed to do:

If 2nd pressed and Selector at RED and top left color doesn't equal red
     Set color RED
     Loop
          If last color equals the color of the squares in the row
               Set color RED
               Change color of those squares
          If last color is not the same color next square in the row
               Change columns
               Set row to first one
          Increment row
          If row is 16
               go to next column
               Set row to first one
          If column is 12
               exit loop
     Repeat loop


/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti84pce.h>

/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* CE Graphics C Library */
#include <graphc.h>
#include <keypadc.h>
int x = 61;
int y = 4;
int r, seed = 13;
int arrayColumn, arrayRow;
int lastColor, color;
int key, key1, key2;
int selectorX = 65+11;
unsigned int speed = 4, keyPress;
int floodArray[12][16], coordXArray[16], coordYArray[12];
/* Main Function */
void main(void)
{
coordYArray[0] = 4;
coordYArray[1] = 20;
coordYArray[2] = 36;
coordYArray[3] = 52;
coordYArray[4] = 68;
coordYArray[5] = 84;
coordYArray[6] = 100;
coordYArray[8] = 116;
coordYArray[9] = 132;
coordYArray[10] = 148;
coordYArray[11] = 164;
coordYArray[12] = 180;
coordXArray[0] = 61;
coordXArray[1] = 77;
coordXArray[2] = 93;
coordXArray[3] = 109;
coordXArray[4] = 125;
coordXArray[5] = 141;
coordXArray[6] = 157;
coordXArray[7] = 173;
coordXArray[8] = 189;
coordXArray[9] = 205;
coordXArray[10] = 221;
coordXArray[11] = 237;
coordXArray[12] = 253;
coordXArray[13] = 269;
coordXArray[14] = 285;
coordXArray[15] = 301;
coordXArray[16] = 317;

    gc_InitGraph();
    gc_SetColorIndex(255);
    gc_FillScrn(0);
gc_NoClipRectangleOutline(60,2,258,195);
gc_NoClipRectangleOutline(65+11,205,25,25);
gc_NoClipRectangleOutline(95+21,205,25,25);
gc_NoClipRectangleOutline(125+31,205,25,25);
gc_NoClipRectangleOutline(155+41,205,25,25);
gc_NoClipRectangleOutline(185+51,205,25,25);
gc_NoClipRectangleOutline(215+61,205,25,25);
gc_SetColorIndex(224);
gc_NoClipRectangle(65+12,206,23,23);
gc_SetColorIndex(16);
gc_NoClipRectangle(95+22,206,23,23);
gc_SetColorIndex(231);
gc_NoClipRectangle(125+32,206,23,23);
gc_SetColorIndex(5);
gc_NoClipRectangle(155+42,206,23,23);
gc_SetColorIndex(112);
gc_NoClipRectangle(185+52,206,23,23);
gc_SetColorIndex(227);
gc_NoClipRectangle(215+62,206,23,23);
gc_SetTextColor((0<<8)|255);
gc_PrintStringXY("FloodIt",1,1);
gc_PrintStringXY("by",1,15);
gc_PrintStringXY("Unicorn",1,30);
srand(*(unsigned long*)0xF30044);
while (1) {
r = rand() % 6;
        if (r == 0)
            color = 224; //RED
        if (r == 1)
            color = 16; //BLUE
        if (r == 2)
            color = 231; //YELLOW
        if (r == 3)
            color = 5; //GREEN
        if (r == 4)
            color = 112; //PURPLE
        if (r == 5)
            color = 227; //ORANGE
           
        gc_SetColorIndex(color);   
        gc_NoClipRectangle(x,y,16,16);
x += 16;
floodArray[arrayColumn][arrayRow] = color;
coordXArray[arrayRow] = x;
coordYArray[arrayColumn] = y;
if (x >= 305) {
arrayRow = 0;
            x = 61;
y += 16;
if (y >= 192)
break;
arrayColumn++;
}
arrayRow++;
}
arrayRow = 0;
arrayColumn = 0;
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
if (keyPress % 45 == 0) {
if (key & kb_Left && selectorX > 65+12) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX -= 40;
}
if (key & kb_Right && selectorX < 215+58) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX += 40;
}
lastColor = color;
if (key1 & kb_2nd && selectorX == 76 && lastColor != 224) {
//check algorithm - RED
color = 224;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 116 && lastColor != 16) {
//check algorithm - BLUE
color = 16;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 156 && lastColor != 231) {
//check algorithm - YELLOW
color = 231;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 196 && lastColor != 5) {
//check algorithm - GREEN
color = 5;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 236 && lastColor != 112) {
//check algorithm - PURPLE
color = 112;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
if (key1 & kb_2nd && selectorX == 276 && lastColor != 227) {
//check algorithm - ORANGE
color = 227;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(61,4,16,16);
while (1) {
if (lastColor == floodArray[arrayColumn][arrayRow]) { 
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);
}
arrayRow++;
if (lastColor != floodArray[arrayColumn][arrayRow]) {
arrayColumn++;
arrayRow = 0;
}
if (arrayRow == 15) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 11)
break;
}
}
}
gc_SetColorIndex(214);
gc_NoClipRectangle(selectorX,233,25,3);
key = kb_ScanGroup(kb_group_7);
key1 = kb_ScanGroup(kb_group_1);
gc_SetTransparentColor(30);
gc_SetTextColor(255);
gc_PrintStringXY("FloodIt",1,1);
gc_PrintStringXY("by",20,15);
gc_PrintStringXY("Unicorn",1,30);
keyPress++;
arrayRow = 0;
arrayColumn = 0;
}

    /* Close the graphics canvas and return to the OS */
    gc_CloseGraph();
_OS( asm("call _DrawStatusBar"));
}

EDIT: Updated code with a few fixes, but it still does pretty much the same thing.
Title: Re: FloodIt (need C help)
Post by: Dream of Omnimaga on March 07, 2016, 06:24:10 AM
@Unicorn have you gotten any luck solving this so far? It seems that not many people here are able to help or maybe you should make a separate C topic about flood filling, but have you chedked tutorials on flood filling in the meantime?
Title: Re: FloodIt (need C help)
Post by: Unicorn on March 07, 2016, 07:23:20 AM
I actually think I'm gonna be able to figure it out by this week, the people over on cemetech have been extremely helpful, so I should have an update soon :)
Title: Re: FloodIt (need C help)
Post by: aetios on March 07, 2016, 07:25:04 AM
Cool! Let us know if there is anything we can help you with.
Title: Re: FloodIt (need C help)
Post by: Dream of Omnimaga on March 07, 2016, 09:00:05 AM
Cool to read. I wish you good luck :)
Title: Re: FloodIt [TI 84+ CE] [C] (need C help)
Post by: Dudeman313 on March 07, 2016, 02:54:17 PM
Quote from: Unicorn on March 07, 2016, 07:23:20 AM
I actually think I'm gonna be able to figure it out by this week, the people over on cemetech have been extremely helpful, so I should have an update soon :)
That's great!  :D
Title: Re: FloodIt (need C help)
Post by: Unicorn on March 09, 2016, 07:17:23 PM
Any ideas why this square appears? The console in CEmu shows that all of the coords in coordXArray and coordYArray are correct...

(https://usercontent.irccloud-cdn.com/file/hEbKtwmq/somthing%20weird.gif)

Here's my code...

/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ti84pce.h>

/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <debug.h>

/* CE Graphics C Library */
#include <graphc.h>
#include <keypadc.h>
int x = 61;
int y = 4;
int r, seed = 13;
int arrayColumn, arrayRow;
int lastColor, color;
int key, key1, key2;
int selectorX = 65+11;
unsigned int speed = 4, keyPress;
int floodArray[12][16], coordXArray[16], coordYArray[12];
/* Main Function */
void main(void) {
gc_InitGraph();
gc_SetColorIndex(255);
gc_FillScrn(0);
gc_NoClipRectangleOutline(60,3,258,194);
gc_NoClipRectangleOutline(65+11,205,25,25);
gc_NoClipRectangleOutline(95+21,205,25,25);
gc_NoClipRectangleOutline(125+31,205,25,25);
gc_NoClipRectangleOutline(155+41,205,25,25);
gc_NoClipRectangleOutline(185+51,205,25,25);
gc_NoClipRectangleOutline(215+61,205,25,25);
gc_SetColorIndex(224);
gc_NoClipRectangle(65+12,206,23,23);
gc_SetColorIndex(16);
gc_NoClipRectangle(95+22,206,23,23);
gc_SetColorIndex(231);
gc_NoClipRectangle(125+32,206,23,23);
gc_SetColorIndex(5);
gc_NoClipRectangle(155+42,206,23,23);
gc_SetColorIndex(112);
gc_NoClipRectangle(185+52,206,23,23);
gc_SetColorIndex(227);
gc_NoClipRectangle(215+62,206,23,23);
gc_SetTextColor((0<<8)|255);
gc_PrintStringXY("FloodIt",3,1);
gc_PrintStringXY("by",8,15);
gc_PrintStringXY("Unicorn",2,30);
srand(*(unsigned long*)0xF30044);
while (1) {
r = rand() % 6;
        if (r == 0)
color = 224; //RED
        if (r == 1)
        color = 16; //BLUE
        if (r == 2)
            color = 231; //YELLOW
        if (r == 3)
            color = 5; //GREEN
        if (r == 4)
            color = 112; //PURPLE
        if (r == 5)
            color = 227; //ORANGE
        gc_SetColorIndex(color);
        gc_NoClipRectangle(x,y,16,16);
x += 16;
floodArray[arrayColumn][arrayRow] = color;
coordXArray[arrayRow] = x;
dbg_printf(dbgout, "Coord X Array and X\n");
dbg_printf(dbgout, "%d", coordXArray[arrayRow]);
dbg_printf(dbgout, "%d", x);
if (x >= 305) {
arrayRow = 0;
            x = 61;
y += 16;
if (y >= 192)
break;
arrayColumn++;
coordYArray[arrayColumn] = y;
dbg_printf(dbgout, "Coord Y Array and Y ");
dbg_printf(dbgout, "%d", coordYArray[arrayColumn]);
dbg_printf(dbgout, "%d", y);
}
arrayRow++;
}
arrayRow = 0;
arrayColumn = 0;
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
if (keyPress % 45 == 0) {
if (key & kb_Left && selectorX > 65+12) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX -= 40;
}
if (key & kb_Right && selectorX < 215+58) {
gc_SetColorIndex(0);
gc_NoClipRectangle(selectorX,233,25,3);
selectorX += 40;
}
if (key1 & kb_2nd && selectorX == 76) {
//check algorithm - RED
lastColor = color;
color = 224;
arrayRow = 0;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(coordXArray[0],coordYArray[0],16,16);
while (1) {
if (lastColor == color || floodArray[arrayColumn][arrayRow] != lastColor)
break;
floodArray[arrayColumn][arrayRow] = color;
if (floodArray[arrayColumn][arrayRow] == lastColor || floodArray[arrayColumn][arrayRow] == color)
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);

arrayRow++;
if (arrayRow == 16) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 12)
break;
}
}
if (key1 & kb_2nd && selectorX == 116) {
//check algorithm - BLUE
lastColor = color;
color = 16;
arrayRow = 0;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(coordXArray[0],coordYArray[0],16,16);
while (1) {
if (lastColor == color || floodArray[arrayColumn][arrayRow] != lastColor)
break;
floodArray[arrayColumn][arrayRow] = color;
if (floodArray[arrayColumn][arrayRow] == lastColor || floodArray[arrayColumn][arrayRow] == color)
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);

arrayRow++;
if (arrayRow == 16) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 12)
break;
}
}
if (key1 & kb_2nd && selectorX == 156) {
//check algorithm - YELLOW
lastColor = color;
color = 231;
arrayRow = 0;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(coordXArray[0],coordYArray[0],16,16);
while (1) {
if (lastColor == color || floodArray[arrayColumn][arrayRow] != lastColor)
break;
floodArray[arrayColumn][arrayRow] = color;
if (floodArray[arrayColumn][arrayRow] == lastColor || floodArray[arrayColumn][arrayRow] == color)
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);

arrayRow++;
if (arrayRow == 16) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 12)
break;
}
}
if (key1 & kb_2nd && selectorX == 196) {
//check algorithm - GREEN
lastColor = color;
color = 5;
arrayRow = 0;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(coordXArray[0],coordYArray[0],16,16);
while (1) {
if (lastColor == color || floodArray[arrayColumn][arrayRow] != lastColor)
break;
floodArray[arrayColumn][arrayRow] = color;
if (floodArray[arrayColumn][arrayRow] == lastColor || floodArray[arrayColumn][arrayRow] == color)
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);

arrayRow++;
if (arrayRow == 16) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 12)
break;
}
}
if (key1 & kb_2nd && selectorX == 236) {
//check algorithm - PURPLE
lastColor = color;
color = 112;
arrayRow = 0;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(coordXArray[0],coordYArray[0],16,16);
while (1) {
if (lastColor == color || floodArray[arrayColumn][arrayRow] != lastColor)
break;
floodArray[arrayColumn][arrayRow] = color;
if (floodArray[arrayColumn][arrayRow] == lastColor || floodArray[arrayColumn][arrayRow] == color)
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);

arrayRow++;
if (arrayRow == 16) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 12)
break;
}
}
if (key1 & kb_2nd && selectorX == 276) {
//check algorithm - ORANGE
lastColor = color;
color = 227;
arrayRow = 0;
arrayColumn = 0;
gc_SetColorIndex(color);
gc_NoClipRectangle(coordXArray[0],coordYArray[0],16,16);
while (1) {
if (lastColor == color || floodArray[arrayColumn][arrayRow] != lastColor)
break;
floodArray[arrayColumn][arrayRow] = color;
if (floodArray[arrayColumn][arrayRow] == lastColor || floodArray[arrayColumn][arrayRow] == color)
gc_NoClipRectangle(coordXArray[arrayRow],coordYArray[arrayColumn],16,16);

arrayRow++;
if (arrayRow == 16) {
arrayRow = 0;
arrayColumn++;
}
if (arrayColumn == 12)
break;
}
}
}
arrayRow = 0;
arrayColumn = 0;
gc_SetColorIndex(214);
gc_NoClipRectangle(selectorX,233,25,3);
key = kb_ScanGroup(kb_group_7);
key1 = kb_ScanGroup(kb_group_1);
gc_SetTransparentColor(30);
gc_SetTextColor(255);
gc_PrintStringXY("FloodIt",3,1);
gc_PrintStringXY("by",20,15);
gc_PrintStringXY("Unicorn",3,30);
keyPress++;
arrayRow = 0;
arrayColumn = 0;
}

    /* Close the graphics canvas and return to the OS */
    gc_CloseGraph();
_OS( asm("call _DrawStatusBar"));
}
Title: Re: FloodIt [TI 84+ CE] [C] (need C help)
Post by: Snektron on March 09, 2016, 07:36:35 PM
You should spread your code over mutliple files / functions (though multiple files are a cing nightmare with ZDS), that way its easier to debug too :P
Title: Re: FloodIt (need C help)
Post by: Dream of Omnimaga on March 14, 2016, 06:19:01 AM
Have you checked for possible variable conflicts?
Title: Re: FloodIt [TI 84+ CE] [C] (need C help)
Post by: Dudeman313 on April 02, 2016, 08:47:33 PM
@Unicorn , are you done w/ this by now?  :-|
Title: Re: FloodIt (need C help)
Post by: Unicorn on April 03, 2016, 06:55:01 AM
Sadly, no, as I got discouraged over that flood-fill algorithm, but hopefully if I take another stab at it in the future maybe I can finish. :)