/* Handle commands from the mouse. While the mouse is being dragged, * the function attempts to move the current block towards the cursor. */ int mousecallback(int y, int x, int mstate) { static int startpos, lastpos; static int startmovecount = -1; int pos, dir, altdir; int retval, n; if (mstate == -2) return startmovecount < 0 ? 'X' : 0; else if (mstate == +2) return 0; pos = y * XSIZE + x; if (mstate == -1) { if (y < 1 || x < 1 || y >= state.game->ysize - 1 || x >= state.game->xsize - 1) return 0; n = blockid(state.map[pos]); if (!n || n == WALLID) return 0; state.currblock = n; state.ycurrpos = state.xcurrpos = 0; startpos = lastpos = pos; startmovecount = state.undo.count; return '\f'; } if (startmovecount < 0) return 0; if (y < 0 || x < 0 || y >= state.game->ysize || x >= state.game->xsize) { if (startmovecount < state.undo.count) { undomoves(state.undo.count - startmovecount); lastpos = startpos; } if (mstate == +1) startmovecount = -1; return '\f'; } retval = 0; while (pos != lastpos) { raydirections(lastpos / XSIZE, lastpos % XSIZE, y, x, &dir, &altdir); if (dir < 0 || !canmove(state.currblock, dir)) { if (altdir < 0 || !canmove(state.currblock, altdir)) dir = -1; else dir = altdir; } if (dir < 0 || !newmove(dir)) break; lastpos += dirdelta[dir]; retval = '\f'; } if (mstate == +1) startmovecount = -1; return retval; }
bool cansee(fpsent *d, vec &x, vec &y, vec &targ) { aistate &b = d->ai->getstate(); if(canmove(d) && b.type != AI_S_WAIT) return getsight(x, d->yaw, d->pitch, y, targ, d->ai->views[2], d->ai->views[0], d->ai->views[1]); return false; }
bool targetable(fpsent *d, fpsent *e, bool anyone) { if(d == e || !canmove(d)) return false; aistate &b = d->ai->getstate(); if(b.type != AI_S_WAIT) return e->state == CS_ALIVE && (!anyone || !isteam(d->team, e->team)); return false; }
void Board::move(int ipiece, int x, int y) { if (x > 0) x = 1; if (x < 0) x = -1; if (y > 0) y = 1; if (y < 0) y = -1; if (canmove(ipiece, (x * pper()) + pborder(), (y*pper())+pborder()) || mWon) piece(ipiece)->mov(x,y); }
/* Checks for any legal moves remaining */ int movesexist(void) { int i, j, peg; for (peg=1; peg<=BOARDSIZE*BOARDSIZE; peg++) { i = (peg-1)/BOARDSIZE; j = (peg-1)%BOARDSIZE; if (filled[i][j] == FULL && canmove(peg)) return 1; } return 0; }
/* Checks if a piece can move */ int canmove(Config pieces, int x, int y, int dir, Config newpieces) { int xadd, yadd; xadd = xadds[dir]; yadd = yadds[dir]; if (x + xadd < 0 || x + xadd >= WIDTH || y + yadd < 0 || y + yadd >= HEIGHT) return 0; if (pieces[y + yadd][x + xadd] == pieces[y][x]) { return canmove(pieces, x + xadd, y + yadd, dir, newpieces); } if (pieces[y + yadd][x + xadd] != 0) return 0; return canmove0(pieces, x + xadd, y + yadd, (dir + 2) % 4, newpieces); }
/* action: selects a field, which contains unique move within all the square */ int markfreesq(int sq) { int i,j,k,w=0; int istart, jstart, ipodm, jpodm; int moves[10]; /* moves which are contained in a square */ memset(moves, 0, sizeof(int) * 10); /* find boundaries of a square */ switch (sq) { case 0: istart = jstart = 0; break; case 1: istart = 0; jstart = 3; break; case 2: istart = 0; jstart = 6; break; case 3: istart = 3; jstart = 0; break; case 4: istart = jstart = 3; break; case 5: istart = 3; jstart = 6; break; case 6: istart = 6; jstart = 0; break; case 7: istart = 6; jstart = 3; break; case 8: istart = jstart = 6; break; } ipodm = istart + 3; jpodm = jstart + 3; /* count of all moves in a square */ for (i = istart; i < ipodm; i++) for (j = jstart; j < jpodm; j++) if (!sudoku[i][j].mark) for (k = 0; k < 9; k++) moves[k+1] += sudoku[i][j].moves[k]; /* finds unique moves in one square */ for (i = istart; i < ipodm; i++) for (j = jstart; j < jpodm; j++) if (!sudoku[i][j].mark) for (k = 1; k < 10; k++) if (moves[k] == 1 && canmove(j,i,k)) { sudoku[i][j].mark = k; memset(sudoku[i][j].moves, 0, sizeof(int) * 9); w = 1; break; } return w; }
bool isLegalMove(char self, char opp, char grid[8][8], int startx, int starty) { if (grid[startx][starty] != '-') return false; char str[10]; int x, y, dx, dy, ctr; for (dy = -1; dy <= 1; dy++) for (dx = -1; dx <= 1; dx++) { // keep going if both velocities are zero if (!dy && !dx) continue; str[0] = '\0'; for (ctr = 1; ctr < 8; ctr++) { x = startx + ctr*dx; y = starty + ctr*dy; if (x >= 0 && y >= 0 && x<8 && y<8) str[ctr-1] = grid[x][y]; else str[ctr-1] = 0; } if (canmove(self, opp, str)) return true; } return false; }
/* returns 1 if sudoku has been changed, 0 otherwise */ int markonlysq(int sq) { int i,j,k; int istart, jstart, ipodm, jpodm; int moves[10]; /* moves within a square */ memset(moves, 0, sizeof(int) * 10); switch (sq) { case 0: istart = jstart = 0; break; case 1: istart = 0; jstart = 3; break; case 2: istart = 0; jstart = 6; break; case 3: istart = 3; jstart = 0; break; case 4: istart = jstart = 3; break; case 5: istart = 3; jstart = 6; break; case 6: istart = 6; jstart = 0; break; case 7: istart = 6; jstart = 3; break; case 8: istart = jstart = 6; break; } ipodm = istart + 3; jpodm = jstart + 3; for (i = istart; i < ipodm; i++) for (j = jstart; j < jpodm; j++) moves[sudoku[i][j].mark]++; /* in moves[0] will be count of free fields */ if (!moves[0] || moves[0] > 1) return 0; /* find a free field */ for (i = istart; i < ipodm; i++) for (j = jstart; j < jpodm; j++) if (!sudoku[i][j].mark) goto sem; sem: for (k = 1; k < 10; k++) if (!moves[k] && canmove(j,i,k)) { sudoku[i][j].mark = k; memset(sudoku[i][j].moves, 0, sizeof(int) * 9); return 1; } return 0; }
/* Check a move for validity in the current state. If it is valid, it * is applied via domove(), otherwise return FALSE. If the move is * equivalent to an undo or a redo, then use that instead; otherwise, * the redo list is reset. */ int newmove(int dir) { action move; if (!state.currblock || !canmove(state.currblock, dir)) return FALSE; if (state.undo.count) { move = state.undo.list[state.undo.count - 1]; if (move.id == state.currblock && move.dir == backwards(dir) && !move.door) return undomove(); } if (state.redo.count) { move = state.redo.list[state.redo.count - 1]; if (move.id == state.currblock && move.dir == dir) return redomove(); } domove(makeaction(state.currblock, dir)); state.redo.count = 0; return TRUE; }
void clicked(Point coord) { Click c; Brick *b, *bc; c = findclick(coord); if (c.d == -1) return; b = &level.board[c.d][c.x][c.y]; if(isfree(c)) { if(level.c.d == -1) { level.c = c; b->clicked = 1; b->redraw = 1; } else if(eqcl(c, level.c)) { level.c = NC; b->clicked = 0; b->redraw = 1; } else { bc = &level.board[level.c.d][level.c.x][level.c.y]; if(b->type == bc->type) { clearbrick(c); bc->clicked = 0; clearbrick(level.c); level.c = NC; } else { bc->clicked = 0; bc->redraw = 1; b->clicked = 1; b->redraw = 1; level.c = c; } } updatelevel(); if(!canmove()) done(); } }
/* returns 1 if sudoku has been changed, 0 if not */ int markonlyrow(int x) { int i,k; int moves[10]; /* moves which are contained in a row */ memset(moves, 0, sizeof(int) * 10); for (i = 0; i < 9; i++) moves[sudoku[i][x].mark]++; /* in moves[0] will be count of free fields */ if (!moves[0] || moves[0] > 1) return 0; /* find free field */ for (i = 0; i < 9; i++) if (!sudoku[i][x].mark) break; for (k = 1; k < 10; k++) if (!moves[k] && canmove(x,i,k)) { sudoku[i][x].mark = k; memset(sudoku[i][x].moves, 0, sizeof(int) * 9); return 1; } return 0; }
/* returns 1 if sudoku has been changed, 0 otherwise */ int markonlycol(int y) { int j,k; int moves[10]; /* moves which are contained in a column */ memset(moves, 0, sizeof(int) * 10); for (j = 0; j < 9; j++) moves[sudoku[y][j].mark]++; /* in moves[0] will be count of free fields */ if (!moves[0] || moves[0] > 1) return 0; /* find free field */ for (j = 0; j < 9; j++) if (!sudoku[y][j].mark) break; for (k = 1; k < 10; k++) if (!moves[k] && canmove(j,y,k)) { sudoku[y][j].mark = k; memset(sudoku[y][j].moves, 0, sizeof(int) * 9); return 1; } return 0; }
/* action: selects a field, which contains an unique move within the row */ int markfreecol(int y) { int moves[9]; int j,k,w = 0; /* count of all moves in a row */ memset(moves, 0, sizeof(int) * 9); for (j = 0; j < 9; j++) if (!sudoku[y][j].mark) for (k = 0; k < 9; k++) moves[k] += sudoku[y][j].moves[k]; /* finds moves which are unique within a row */ for (j = 0; j < 9; j++) if (!sudoku[y][j].mark) for (k = 0; k < 9; k++) if (moves[k] == 1 && canmove(j,y,k+1)) { sudoku[y][j].mark = k+1; memset(sudoku[y][j].moves, 0, sizeof(int) * 9); w = 1; break; } return w; }
/* action: selects a field, which contains unique move within the column */ int markfreerow(int x) { int moves[9]; int i,k,w = 0; /* count of all moves in a column */ memset(moves, 0, sizeof(int) * 9); for (i = 0; i < 9; i++) if (!sudoku[i][x].mark) for (k = 0; k < 9; k++) moves[k] += sudoku[i][x].moves[k]; /* finds moves which are unique within a column */ for (i = 0; i < 9; i++) if (!sudoku[i][x].mark) for (k = 0; k < 9; k++) if (moves[k] == 1 && canmove(x,i,k+1)) { sudoku[i][x].mark = k+1; memset(sudoku[i][x].moves, 0, sizeof(int) * 9); w = 1; break; } return w; }
bool targetable(fpsent *d, fpsent *e) { if(d == e || !canmove(d)) return false; return e->state == CS_ALIVE && !isteam(d->team, e->team); }
void _main() { /****************************> Fix Stack <****************************/ //Load a good stack asm( "lis %r1, 0x1ab5 ;" "ori %r1, %r1, 0xd138 ;" ); /****************************> Get Handles <****************************/ //Get a handle to coreinit.rpl unsigned int coreinit_handle, vpad_handle, sysapp_handle, avm_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); OSDynLoad_Acquire("vpad.rpl", &vpad_handle); OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle); // CreeperMario: Get a handle to the audio/video manager - avm.rpl OSDynLoad_Acquire("avm.rpl", &avm_handle); // STUFF VPADData vpad_data; int(*VPADRead)(int controller, VPADData *buffer, unsigned int num, int *err); OSDynLoad_FindExport(vpad_handle, 0, "VPADRead", &VPADRead); // Sysapp stuff int(*SYSLaunchMenu)(); OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchMenu", &SYSLaunchMenu); // please dont break stuff... int(*SYSLaunchTitle) (int bit1, int bit2); OSDynLoad_FindExport(sysapp_handle, 0, "SYSLaunchTitle", &SYSLaunchTitle); int(*_Exit)(); OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &_Exit); /****************************> External Prototypes <****************************/ //OSScreen functions void(*OSScreenInit)(); unsigned int(*OSScreenGetBufferSizeEx)(unsigned int bufferNum); unsigned int(*OSScreenSetBufferEx)(unsigned int bufferNum, void * addr); //OS Memory functions void*(*memset)(void * dest, uint32_t value, uint32_t bytes); void*(*OSAllocFromSystem)(uint32_t size, int align); void(*OSFreeToSystem)(void *ptr); //IM functions int(*IM_Open)(); int(*IM_Close)(int fd); int(*IM_SetDeviceState)(int fd, void *mem, int state, int a, int b); // CreeperMario: TV Screen scaling functions bool(*AVMSetTVScale)(int width, int height); /****************************> Exports <****************************/ //OSScreen functions OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenInit", &OSScreenInit); OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx); OSDynLoad_FindExport(coreinit_handle, 0, "OSScreenSetBufferEx", &OSScreenSetBufferEx); //OS Memory functions OSDynLoad_FindExport(coreinit_handle, 0, "memset", &memset); OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem); OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem); //IM functions OSDynLoad_FindExport(coreinit_handle, 0, "IM_Open", &IM_Open); OSDynLoad_FindExport(coreinit_handle, 0, "IM_Close", &IM_Close); OSDynLoad_FindExport(coreinit_handle, 0, "IM_SetDeviceState", &IM_SetDeviceState); // CreeperMario: TV Screen scaling functions OSDynLoad_FindExport(avm_handle, 0, "AVMSetTVScale", &AVMSetTVScale); /*** CreeperMario: Set the TV screen to the proper 'scale factor'. ***/ AVMSetTVScale(854, 480); /****************************> Initial Setup <****************************/ //Restart system to get lib access int fd = IM_Open(); void *mem = OSAllocFromSystem(0x100, 64); memset(mem, 0, 0x100); //set restart flag to force quit browser IM_SetDeviceState(fd, mem, 3, 0, 0); IM_Close(fd); OSFreeToSystem(mem); //wait a bit for browser end unsigned int t1 = 0x15000000; while(t1--) ; //Call the Screen initilzation function. OSScreenInit(); //Grab the buffer size for each screen (TV and gamepad) int buf0_size = OSScreenGetBufferSizeEx(0); int buf1_size = OSScreenGetBufferSizeEx(1); //Set the buffer area. OSScreenSetBufferEx(0, (void *)0xF4000000); OSScreenSetBufferEx(1, (void *)0xF4000000 + buf0_size); //Clear both framebuffers. doclearstuff(); // Define struct for global variables! struct cGlobals caveGlobals; // Variables n stuff! caveGlobals.food = 0; caveGlobals.row = 1; caveGlobals.col = 1; caveGlobals.level = 1; caveGlobals.dogsteps = 0; caveGlobals.dogalive = 1; caveGlobals.mysteps = 0; caveGlobals.maxhealth = 10; caveGlobals.curhealth = 10; // Start at level 1 (obviously!) changelevel(&caveGlobals); // Draw Buffers and Initial Screen __os_snprintf(caveGlobals.mystat, 64, " "); doclearstuff(); drawstuff(&caveGlobals); flipBuffers(); int err; while(1) { VPADRead(0, &vpad_data, 1, &err); // Quit if (vpad_data.btn_trigger & BUTTON_HOME) { doclearstuff(); __os_snprintf(caveGlobals.endgame, 256, "Thanks for Playing!\nYour Final Level: %d \n\n\nBy: SonyUSA", caveGlobals.level); drawString(0, 0, caveGlobals.endgame); flipBuffers(); t1 = 0x50000000; while(t1--) ; //Maybe fix for exit crash? doclearstuff(); flipBuffers(); doclearstuff(); flipBuffers(); //Ape escape! SYSLaunchMenu(); _Exit(); } //Grab Stuff (A) if (vpad_data.btn_release & BUTTON_A) { //Checks for Food if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 8) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "Got it!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.food += 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 2; drawstuff(&caveGlobals); flipBuffers(); } //Check for Potions if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 11) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "*Gulp!*"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth += 5; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 2; //Make sure we don't go over health limit if (caveGlobals.curhealth > caveGlobals.maxhealth) { caveGlobals.curhealth = caveGlobals.maxhealth; } drawstuff(&caveGlobals); dog(&caveGlobals); flipBuffers(); } //Checks for Stairs if (caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] == 9) { caveGlobals.level += 1; doclearstuff(); changelevel(&caveGlobals); drawstuff(&caveGlobals); flipBuffers(); } } //Search for Hidden Traps and Doors if (vpad_data.btn_trigger & BUTTON_Y) { doclearstuff(); drawstuff(&caveGlobals); dog(&caveGlobals); //Ask the player which way to search __os_snprintf(caveGlobals.mystat, 64, "Search Which Way?"); drawString(22, 17, caveGlobals.mystat); flipBuffers(); //Lets use a while loop so players cant just hold down search while they are walking! Cheating gits! while(2) { VPADRead(0, &vpad_data, 1, &err); // Search Up if (vpad_data.btn_release & BUTTON_UP) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } // Search Down if (vpad_data.btn_release & BUTTON_DOWN) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } // Search Right if (vpad_data.btn_release & BUTTON_RIGHT) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } // Search Left if (vpad_data.btn_release & BUTTON_LEFT) { // Traps if (ishtrap(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "It's a trap!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 6; drawstuff(&caveGlobals); flipBuffers(); break; } // Doors if (ishdoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "A Secret Door!"); drawString(22, 17, caveGlobals.mystat); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 4; drawstuff(&caveGlobals); flipBuffers(); break; } // If nothing is found... doclearstuff(); drawstuff(&caveGlobals); __os_snprintf(caveGlobals.mystat, 64, "Nothing There!"); drawString(23, 17, caveGlobals.mystat); flipBuffers(); break; } } } //Open and Close Doors (X + Direction) if (vpad_data.btn_hold & BUTTON_X) { if (vpad_data.btn_trigger & BUTTON_DOWN) { if (isclosedoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col +1][caveGlobals.row] = 4; flipBuffers(); } } if (vpad_data.btn_trigger & BUTTON_UP) { if (isclosedoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col -1][caveGlobals.row] = 4; flipBuffers(); } } if (vpad_data.btn_trigger & BUTTON_LEFT) { if (isclosedoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row -1] = 4; flipBuffers(); } } if (vpad_data.btn_trigger & BUTTON_RIGHT) { if (isclosedoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 5; flipBuffers(); } else if (isopendoor(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); drawstuff(&caveGlobals); caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row +1] = 4; flipBuffers(); } } } // Movement //Down if (vpad_data.btn_trigger & BUTTON_DOWN) { if (canmove(&caveGlobals, caveGlobals.row, caveGlobals.col +1 ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.col += 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Up if (vpad_data.btn_trigger & BUTTON_UP) { if (canmove(&caveGlobals, caveGlobals.row, caveGlobals.col -1 ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.col -= 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Left if (vpad_data.btn_trigger & BUTTON_LEFT) { if (canmove(&caveGlobals, caveGlobals.row -1 , caveGlobals.col ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.row -= 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Right if (vpad_data.btn_trigger & BUTTON_RIGHT) { if (canmove(&caveGlobals, caveGlobals.row +1 , caveGlobals.col ) == true ) { doclearstuff(); dog(&caveGlobals); caveGlobals.row += 1; drawstuff(&caveGlobals); if (istrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; } if (ishtrap(&caveGlobals, caveGlobals.row, caveGlobals.col ) == true ) { __os_snprintf(caveGlobals.mystat, 64, "Ouch!"); drawString(25, 17, caveGlobals.mystat); caveGlobals.curhealth -= 1; caveGlobals.nMapArray[caveGlobals.col][caveGlobals.row] = 6; } flipBuffers(); } } //Feed the doggy if (vpad_data.btn_trigger & BUTTON_PLUS) { if (caveGlobals.dogalive == 1) { if (caveGlobals.food >= 1) { doclearstuff(); __os_snprintf(caveGlobals.mystat, 64, "*crunch* Woof!"); drawString(24, 17, caveGlobals.mystat); caveGlobals.food -= 1; caveGlobals.dogsteps -= 60; //Make sure we don't go negative in dog health if (caveGlobals.dogsteps <= 0) { caveGlobals.dogsteps = 0;} drawstuff(&caveGlobals); dog(&caveGlobals); flipBuffers(); } } } // Check if the player is dead if(caveGlobals.curhealth == 0) { doclearstuff(); __os_snprintf(caveGlobals.endgame, 256, "You're Dead!\nNow how will you get iosu? :/ \n\nThanks for Playing! \n\n\nBy: SonyUSA"); drawString(0, 0, caveGlobals.endgame); flipBuffers(); t1 = 0x80000000; while(t1--) ; SYSLaunchMenu(); _Exit(); } // Cheat and go to next level with Minus key if(vpad_data.btn_release & BUTTON_MINUS) { caveGlobals.level += 1; doclearstuff(); changelevel(&caveGlobals); drawstuff(&caveGlobals); flipBuffers(); } } }
void moveSelection(float selx, float sely) { float deltax, deltay; int dir; Config newpieces; if (!selected) return; deltax = selx - selstartx; deltay = sely - selstarty; if (fabs(deltax) > fabs(deltay)) { deltay = 0; if (deltax > 0) { if (deltax > 1) deltax = 1; dir = 2; } else { if (deltax < -1) deltax = -1; dir = 0; } } else { deltax = 0; if (deltay > 0) { if (deltay > 1) deltay = 1; dir = 3; } else { if (deltay < -1) deltay = -1; dir = 1; } } if (canmove(thePuzzle, selectx, selecty, dir, newpieces)) { move_x = deltax + selectx; move_y = deltay + selecty; if (deltax > 0.5) { memcpy(thePuzzle, newpieces, HEIGHT * WIDTH); selectx++; selstartx++; } else if (deltax < -0.5) { memcpy(thePuzzle, newpieces, HEIGHT * WIDTH); selectx--; selstartx--; } else if (deltay > 0.5) { memcpy(thePuzzle, newpieces, HEIGHT * WIDTH); selecty++; selstarty++; } else if (deltay < -0.5) { memcpy(thePuzzle, newpieces, HEIGHT * WIDTH); selecty--; selstarty--; } } else { if (deltay > 0 && thePuzzle[selecty][selectx] == 10 && selectx == 1 && selecty == 3) { /* Allow visual movement of solution piece outside of the box */ move_x = selectx; move_y = sely - selstarty + selecty; } else { move_x = selectx; move_y = selecty; } } }