static void onNeighborAdd(void* ctxt, unsigned cube0, unsigned side0, unsigned cube1, unsigned side1) { // Update art on active cubes (not loading cubes or base) bool sfx = false; if (isActive(cube0) && cube0 == blicketDetector && blicketCubes.test(cube1)) { sfx |= showSideBar(cube1, Side(side1)); sfx |= showSideBar(cube0, Side(side0)); } if (isActive(cube1) && cube1 == blicketDetector && blicketCubes.test(cube0)) { sfx |= showSideBar(cube0, Side(side0)); sfx |= showSideBar(cube1, Side(side1)); } if (sfx) { playSfx(SfxSong); } }
static bool showSideBar(CubeID cid, CubeID nb, Side s) { // if cid is not showing a bar on side s, show it int stat1 = taskCubes[cid].status; int stat2 = taskCubes[nb].status; //To-Do: add logic for different colored bars based on the statuses of the cubes. ASSERT(activeCubes.test(cid)); if (vbuf[cid].sprites[s].isHidden()) { switch (stat1 + stat2) { case 0: vbuf[cid].sprites[s].setImage(RedBars[s]); break; //2 red -> red case 1: vbuf[cid].sprites[s].setImage(OrangeBars[s]); break; //1 red, 1 yellow -> orange case 2: if (stat1 == 0 || stat1 == 2) { //1 red, 1 blue -> purple vbuf[cid].sprites[s].setImage(PurpleBars[s]); break; } else { vbuf[cid].sprites[s].setImage(YellowBars[s]); //2 yellow -> yellow break; } case 3: vbuf[cid].sprites[s].setImage(GreenBars[s]); break; //1 yellow, 1 blue -> green case 4: vbuf[cid].sprites[s].setImage(BlueBars[s]); break; //2 blue -> blue } vbuf[cid].sprites[s].move(getRestPosition(s)); return true; } else { return false; } }
static bool hideSideBar(CubeID cid, Side s) { // if cid is showing a bar on side s, hide it ASSERT(activeCubes.test(cid)); if (!vbuf[cid].sprites[s].isHidden()) { vbuf[cid].sprites[s].hide(); return true; } else { return false; } }
static int barSpriteCount(CubeID cid) { // how many bars are showing on this cube? ASSERT(activeCubes.test(cid)); int result = 0; for(int i=0; i<4; ++i) { if (!vbuf[cid].sprites[i].isHidden()) { result++; } } return result; }
static bool hideSideBar(CubeID cid, Side s) { // If cid is showing a bar on side s, hide it and check if the // blicket detector should turn off. ASSERT(activeCubes.test(cid)); if (!vbuf[cid].sprites[s].isHidden()) { vbuf[cid].sprites[s].hide(); if (barSpriteCount(cid) == 0 && cid == 0) { vbuf[cid].bg0.image(vec(0,0), Backgrounds, 0); } else { vbuf[cid].bg0.image(vec(0,0), cond.get_condition(), cid - 1); } return true; } else { return false; } }
static bool showSideBar(CubeID cid, Side s) { // If cid is not showing a bar on side s, show it and check if the // blicket detector shold go off. ASSERT(activeCubes.test(cid)); if (vbuf[cid].sprites[s].isHidden()) { vbuf[cid].sprites[s].setImage(Bars[s]); vbuf[cid].sprites[s].move(getRestPosition(s)); if (barSpriteCount(cid) == 1 && cid == 0) { vbuf[cid].bg0.image(vec(0,0), Backgrounds, 1); } else { vbuf[cid].bg0.image(vec(0,0), cond.get_condition(), cid - 1); } return true; } else { return false; } }
static void onCubeConnect(void* ctxt, unsigned cid) { // this cube is either new or reconnected if (lostCubes.test(cid)) { // this is a reconnected cube since it was already lost this paint() lostCubes.clear(cid); reconnectedCubes.mark(cid); } else { // this is a brand-spanking new cube newCubes.mark(cid); } // begin showing some loading art (have to use BG0ROM since we don't have assets) dirtyCubes.mark(cid); auto& g = vbuf[cid]; g.attach(cid); g.initMode(BG0_ROM); g.bg0rom.fill(vec(0,0), vec(16,16), BG0ROMDrawable::SOLID_BG); g.bg0rom.text(vec(1,1), "Hold on!", BG0ROMDrawable::BLUE); g.bg0rom.text(vec(1,14), "Adding Cube...", BG0ROMDrawable::BLUE); }
static bool isActive(NeighborID nid) { // Does this nid indicate an active cube? return nid.isCube() && activeCubes.test(nid); }