bool LoadMap(const string& filename) { // TODO: assert that int is 32 bit int numPlanes; bool sexSwap = false; fstream f(filename.c_str(),ios::in|ios::binary); { char magicTest[sizeof(fileMagic)]; int sexTest[2]; f.read(magicTest,magicLen); f.read((char*)sexTest,sizeof(int)*2); if (strncmp(magicTest,fileMagic,magicLen)) { // Check file magic OGLCONSOLE_Print("Unrecognized file format in map file \"%s\"\n", filename.c_str()); return false; } if (sexTest[0] != byteSex[0] || sexTest[1] != byteSex[1]) { if (sexTest[0] == byteXes[0] && sexTest[1] == byteXes[1]) { OGLCONSOLE_Print("This map file is written in the opposite bytesex!\n"); sexSwap = true; } else { OGLCONSOLE_Print("0x%x%x\n0x%x%x\nBroken bytesex magic! May not be a map file?\n", byteSex[0], byteSex[1], sexTest[0], sexTest[1]); return false; } } } f.read((char*)&numPlanes, sizeof(int)); if (sexSwap) fagswap(numPlanes,1); for (IPlane i=Planes.begin(); i!=Planes.end(); i++) delete *i; Planes.clear(); for (; numPlanes; numPlanes--) Planes.push_back(new TilePlane(f, sexSwap)); f.close(); return true;//TODO:check for failure, lol }
bool SDLEvent(SDL_Event *e) { switch (e->type) { case SDL_KEYDOWN: if (e->key.state) switch (e->key.keysym.sym) { default: return false; case ' ': RStep(); return true; case SDLK_RETURN: pause = ! pause; return true; case 'n': /* TODO: clear all grids */ return true; case 'm': if (e->key.keysym.mod & KMOD_CTRL) { if (machineGrid) machineGrid->Clear(); return true; } return false; case 'l': if (e->key.keysym.mod & KMOD_CTRL) { if (lifeGrid) lifeGrid->Clear(); return true; } //case 'l': RUN THROUGH is deliberate here case SDLK_RIGHT: if (e->key.keysym.mod & KMOD_SHIFT) mX++; else { mX=++mx; mY=my; } return true; case 'j': case SDLK_DOWN: if (e->key.keysym.mod & KMOD_SHIFT) mY++; else { mY=++my; mX=mx; } return true; case 'k': case SDLK_UP: if (e->key.keysym.mod & KMOD_SHIFT) mY--; else { mY=--my; mX=mx; } return true; case 'h': case SDLK_LEFT: if (e->key.keysym.mod & KMOD_SHIFT) mX--; else { mX=--mx; mY=my; } return true; case SDLK_BACKSPACE: if (machineGrid) machineGrid->DestroyAllSparks(); break; case 'y': //yank if (machineGrid) { if (mclip) delete[] mclip; mclipw = mX-mx+1; mcliph = mY-my+1; OGLCONSOLE_Print("Yanked %ix%i\n", mclipw, mcliph); mclip = new char[mclipw*mcliph]; for (int x=0; x<mclipw; x++) for (int y=0; y<mcliph; y++) mclip[x+y*mclipw] = *machineGrid->Gell(x+mx,y+my); } return true; case 'p': //paste if (machineGrid) { if (mclip) { for (int x=0; x<mclipw; x++) for (int y=0; y<mcliph; y++) *machineGrid->Gell(x+mx,y+my) = mclip[x+y*mclipw]; } } return true; case 's': if (machineGrid) { char *c = machineGrid->Gell(mx, my); switch (*c) { case MachineGrid::MachineWire: *c = MachineGrid::MachineSpark; break; case MachineGrid::MachineSpark: *c = MachineGrid::MachineHotWire; break; case MachineGrid::MachineHotWire: *c = MachineGrid::MachineWire; break; case MachineGrid::MachineSWire: *c = MachineGrid::MachineSSpark; break; case MachineGrid::MachineSSpark: *c = MachineGrid::MachineHotSWire; break; case MachineGrid::MachineHotSWire: *c = MachineGrid::MachineSWire; break; case MachineGrid::MachineOWire: *c = MachineGrid::MachineOSpark; break; case MachineGrid::MachineOSpark: *c = MachineGrid::MachineHotOWire; break; case MachineGrid::MachineHotOWire: *c = MachineGrid::MachineOWire; break; case MachineGrid::MachineKiller: *c = MachineGrid::KillerSpark; break; case MachineGrid::KillerSpark: *c = MachineGrid::MachineKiller; break; } return true; } case 'a': if (machineGrid) { char *c = machineGrid->Gell(mx, my); switch (*c) { case MachineGrid::MachineWire: case MachineGrid::MachineHotWire: *c = MachineGrid::MachineSWire; break; case MachineGrid::MachineSWire: case MachineGrid::MachineHotSWire: *c = MachineGrid::MachineOWire; break; case MachineGrid::MachineOWire: case MachineGrid::MachineHotOWire: *c = MachineGrid::MachineLifer; break; case MachineGrid::MachineLifer: *c = MachineGrid::MachineKiller; break; case MachineGrid::MachineKiller: case MachineGrid::KillerSpark: *c = MachineGrid::MachineClocker; break; default: case MachineGrid::MachineClocker: *c = MachineGrid::MachineWire; break; } OGLCONSOLE_Print("Incrementing %i,%i to %i\n", mx, my, *c); } return true; case 'x': if (machineGrid) { char *c = machineGrid->Gell(mx, my); switch (*c) { case MachineGrid::MachineWire: case MachineGrid::MachineHotWire: *c = MachineGrid::MachineClocker; break; case MachineGrid::MachineOWire: case MachineGrid::MachineHotOWire: *c = MachineGrid::MachineSWire; break; case MachineGrid::MachineLifer: *c = MachineGrid::MachineOWire; break; case MachineGrid::MachineKiller: case MachineGrid::KillerSpark: *c = MachineGrid::MachineLifer; break; default: case MachineGrid::MachineClocker: *c = MachineGrid::MachineKiller; break; case MachineGrid::MachineSWire: case MachineGrid::MachineHotSWire: *c = MachineGrid::MachineWire; break; } OGLCONSOLE_Print("Incrementing %i,%i to %i\n", mx, my, *c); } return true; case 'g': OGLCONSOLE_Print("Cursor position: %i,%i", mx, my); if (lifeGrid) OGLCONSOLE_Print(" Life:%i", *lifeGrid->Gell(mx, my)); if (machineGrid) OGLCONSOLE_Print(" Machine:%i\n", *machineGrid->Gell(mx,my)); else OGLCONSOLE_Print("\n"); return true; } } return false; }
bool Key(int key, bool down) { switch(key) { case SDLK_p: if (down) paused = ! paused; break; case SDLK_c: if (down) rsb=!rsb; break; case SDLK_t: if (down){ PBACK->small=!PBACK->small; PBACK->h=PBACK->ducking||PBACK->small?12:20;} break; case SDLK_e: PBACK->Key(SPINJUMP,down); break; case SDLK_s: PBACK->Key(CROUCH,down); break; case SDLK_a: PBACK->Key(LEFT,down); break; case SDLK_d: PBACK->Key(RIGHT,down); break; case SDLK_w: PBACK->Key(JUMP,down); break; case SDLK_f: PBACK->Key(RUN,down); break; case ']': if (down) { SuperScroll = ! SuperScroll; OGLCONSOLE_Print("The ']' key turned SuperScroll %s\n", SuperScroll?"on":"off"); } break; case SDLK_UP: if(down)SuperScrollY=-10; else SuperScrollY=0; break; case SDLK_DOWN: if(down)SuperScrollY=10; else SuperScrollY=0; break; case SDLK_LEFT: if(down)SuperScrollX=-10; else SuperScrollX=0; break; case SDLK_RIGHT: if(down)SuperScrollX=10; else SuperScrollX=0; break; default: return true; } return false; }