Any ideas why this square appears? The console in CEmu shows that all of the coords in coordXArray and coordYArray are correct...
Here's my code...
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"));
}
I know mateo said to have only one flood-fill loop for easier debugging, but I just needed to get something going.