Join us on Discord!
You can help CodeWalrus stay online by donating here.

FloodIt [TI 84+ CE] [C] (need C help)

Started by Unicorn, February 24, 2016, 11:52:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Unicorn

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 :)
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

aetios

Cool! Let us know if there is anything we can help you with.
ceci n'est pas une signature

Dream of Omnimaga

Cool to read. I wish you good luck :)
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Dudeman313

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
  • Calculators owned: TI-84 PCE
  • Consoles, mobile devices and vintage computers owned: Android O Phone
Does this qualify as a signature? 
The answer is "Sure."


Unicorn

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...

/* 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"));
}
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Snektron

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
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Dream of Omnimaga

Have you checked for possible variable conflicts?
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Dudeman313

  • Calculators owned: TI-84 PCE
  • Consoles, mobile devices and vintage computers owned: Android O Phone
Does this qualify as a signature? 
The answer is "Sure."


Unicorn

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. :)
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Powered by EzPortal