void Render::calculateView(const int8_t x, const int8_t y, const Direction dir) { /* if (dir == 0) { xs[0]=+3; xs[1]=+3; xs[2]=+3; xs[3]=+2; xs[4]=+2; xs[5]=+2; xs[6]=+1; xs[7]=+1; xs[8]=+1; xs[9]=0; xs[10]=0; xs[11]=0; ys[0]=-1; ys[1]=0; ys[2]=+1; ys[3]=-1; ys[4]=0; ys[5]=+1; ys[6]=-1; ys[7]=0; ys[8]=+1; ys[9]=-1; ys[10]=0; ys[11]=+1; } if (dir == 1) { xs[0]=+1; xs[1]=0; xs[2]=0-1; xs[3]=+1; xs[4]=0; xs[5]=-1; xs[6]=+1; xs[7]=0; xs[8]=-1; xs[9]=+1; xs[10]=0; xs[11]=-1; ys[0]=+3; ys[1]=+3; ys[2]=+3; ys[3]=+2; ys[4]=+2; ys[5]=+2; ys[6]=+1; ys[7]=+1; ys[8]=+1; ys[9]=0; ys[10]=0; ys[11]=0; } if (dir == 2) { xs[0]=-3; xs[1]=-3; xs[2]=-3; xs[3]=-2; xs[4]=-2; xs[5]=-2; xs[6]=-1; xs[7]=-1; xs[8]=-1; xs[9]=0; xs[10]=0; xs[11]=0; ys[0]=+1; ys[1]=0; ys[2]=-1; ys[3]=+1; ys[4]=0; ys[5]=-1; ys[6]=+1; ys[7]=0; ys[8]=-1; ys[9]=+1; ys[10]=0; ys[11]=-1; } if (dir == 3) { xs[0]=-1; xs[1]=0; xs[2]=+1; xs[3]=-1; xs[4]=0; xs[5]=+1; xs[6]=-1; xs[7]=0; xs[8]=+1; xs[9]=-1; xs[10]=0; xs[11]=+1; ys[0]=-3; ys[1]=-3; ys[2]=-3; ys[3]=-2; ys[4]=-2; ys[5]=-2; ys[6]=-1; ys[7]=-1; ys[8]=-1; ys[9]=0; ys[10]=0; ys[11]=0; } */ static const int8_t arrA[12] = { 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0 }; static const int8_t arrB[12] = { -1, 0, +1, -1, 0, +1, -1, 0, +1, -1, 0, +1 }; int8_t xs, ys; for(uint8_t i = 0; i < 12; ++i) { switch(dir) { case Direction::East: { xs = arrA[i]; ys = arrB[i]; break; } case Direction::South: { xs = -arrB[i]; ys = arrA[i]; break; } case Direction::West: { xs = -arrA[i]; ys = -arrB[i]; break; } case Direction::North: { xs = arrB[i]; ys = -arrA[i]; break; } } wallShow[i] = wallCheck(x + xs, y + ys); itemShow[i] = false; if(wallShow[i] == false) itemShow[i] = itemCheck(x + xs, y + ys); } wallShow[10] = false; //position player is standing on if (wallShow[7]) //speed up by disabling hidden walls { wallShow[4] = false; wallShow[0] = false; wallShow[2] = false; } if (wallShow[4]) { wallShow[1] = false; } }
void Render::drawMap(void) { // Out of interest, making this value 64 instead of 63 adds 2 bytes to the code and I have no idea why. // Presumably it's a limitation of the AVR instruction set. AVR probably only affords 5 bits to immediate values. constexpr static const uint8_t offsetx = System::ScreenCentreX; // Draw map grid for(int iy = 0, jy = 0; iy < 8; ++iy, jy += 8) for(int ix = 0, jx = 0; ix < 8; ++ix, jx += 8) if (wallCheck(ix,iy)) ab->drawRect(offsetx + jx, jy, 9, 9, 1); { // Explicit scoping in the hopes the compiler will ditch these 6 variables asap // x3 and y3 refer to the point of the arrow. Only 6 coords are needed for 3 points // By adding 2 to x and y up here, 10 addition operations can be eliminated uint8_t x1 = offsetx + (player->x * 8) + 2; uint8_t y1 = (player->y * 8) + 2; uint8_t x2 = x1, y2 = y1; uint8_t x3 = x1, y3 = y1; switch(player->getDirection()) { case Direction::East: { /*x1 += 0;*/ /*y1 += 0;*/ /*x2 += 0;*/ y2 += 4; x3 += 4; y3 += 2; break; } case Direction::South: { /*x1 += 0;*/ /*y1 += 0;*/ x2 += 4; /*y2 += 0;*/ x3 += 2; y3 += 4; break; } case Direction::West: { x1 += 4; /*y1 += 0;*/ /*x2 += 0;*/ y2 += 2; x3 += 4; y3 += 4; break; } case Direction::North: { /*x1 += 0;*/ y1 += 4; x2 += 2; /*y2 += 0;*/ x3 += 4; y3 += 4; break; } } ab->drawLine(x1, y1, x3, y3, 1); ab->drawLine(x2, y2, x3, y3, 1); ab->drawLine(x1, y1, x2, y2, 1); } // Outlines the map ab->drawRect(offsetx, 0, System::ScreenWidth/2, System::ScreenHeight, 1); }
///////////////////////////////////////////////////////////FUNCTIONS////////////////////////////////////////////////////////////// int movePlayer(int playersMove, char arr[][n], int iPosition, int jPosition) { int tempi = iPosition; int tempj = jPosition; int TRUE; // printf("players move is %c\n", playersMove); if(playersMove == 8) {//printf("move up\n"); iPlayerPosition -= 1; } else if(playersMove ==2 ) {//printf("move down\n"); iPlayerPosition += 1; } else if(playersMove == 6) {//printf("move right\n"); jPlayerPosition += 1; } else if(playersMove == 4) {//printf("move left\n"); jPlayerPosition -= 1; } TRUE = moveCheck(playersMove, arr, iPlayerPosition, jPlayerPosition); if( TRUE == 1 && wallCheck(playersMove, arr, iPlayerPosition, jPlayerPosition) == 1) { //swap arrays char temp = arr[tempi][tempj]; arr[tempi][tempj] =arr[iPlayerPosition][jPlayerPosition]; arr[iPlayerPosition][jPlayerPosition] = temp; return TRUE; } else { iPlayerPosition = iPosition; jPlayerPosition = jPosition; return TRUE; } }