# Need help finding an error.

This topic is 2652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've tried tracing the program, but can't seem to find anything. Have 3 pages showing going through every line of code, and every iteration of each loop but can't seem to find the problem. Hoping someone can take a look.

Second post in 3 days :p

(The problem is that rotate doesn't rotate the block.
The important pieces of code are below.

From main:
block plyrBlock;gameMap field;plyrBlock.rotate(field);

gameMap class:
class gameMap {    private:        int map[21][12];    public:        gameMap();        bool blockExists(int x, int y);};gameMap::gameMap() { //generate the default gamemap.    int map2[21][12]={{1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,0,0,0,0,0,0,0,0,0,0,1},                     {1,1,1,1,1,1,1,1,1,1,1,1}};    for (int i = 0; i < 12 ; i++)        for (int j = 0; j < 21; j++)            map[j] = map2[j];}bool gameMap::blockExists(int x, int y) { //if a block exists in space specified return true.    if (x >= 11 || x <= 0 || y <= 0 || y >=20)        return true;    if (map[y][x] != 0) {        return true;    }    else {        return false;}}

block class:
class block {    private:        std::vector<coord> blockVert;    public:        block(); //Constructor        void rotate(gameMap map);};block::block() {/* Lets assume for the minute that the vector blockVert is initialized with*/        blockVert.push_back(coord(5,2));        blockVert.push_back(coord(5,1));	blockVert.push_back(coord(5,2));	blockVert.push_back(coord(5,3));	blockVert.push_back(coord(5,4));}void block::rotate(gameMap map) { //Rotates block 90 degrees    coord tmpVert;    std::vector<coord> tmpBlock;    bool squareQ, collides = false;    if (blockValue = 5)        squareQ = true;    else squareQ = false;    if (!squareQ) { // dont try to rotate a square. //        tmpBlock = blockVert;        //             For -90 degree turn (90 degrees to the right) we subtract rotating point by the pivot point. then multiply by rotation hen { 0 , -1 }        //which gives us that P after rotation is [ P(x0,y0) - Piv(x,y) ] = Q(a,b) then new point is (-b,a) + Piv(x,y)                            { 1 ,  0 }        for (int i = tmpBlock.size() - 1 ; i > 0 ; i--) {            tmpVert = tmpBlock - tmpBlock[0];            tmpVert = tmpVert.rotate();            tmpBlock = tmpVert + tmpBlock[0];        }        for (int i = tmpBlock.size() - 1; i>0 ; i--) {            if (map.blockExists(tmpBlock.getX(), tmpBlock.getY())) {                collides = true;                }        }        if (!collides){            blockVert = tmpBlock;}    }}

class coord: (I know there may be a "point" class built in, but when I first wrote this, I'm pretty sure I had a reason. I can't for the life of me remember what it was, but I still use it when I can, and add to it as I need more functionality. -- )
class coord {    private:        int x;        int y;    public:        coord(int a, int b); // constructor        int getY();        int getX();        coord rotate();        coord operator+(coord op2);        coord operator-(coord op2);        void operator=(coord op2);};coord::coord(int a, int b) {    x = a;    y = b;}int coord::getY() {     return y;}int coord::getX() {    return x;}coord coord::rotate() {    int tmp;    tmp = x;    x = -1 * y;    y = (tmp);    return coord(x,y);}void coord::operator=(coord op2) {    y = op2.y;    x = op2.x;}coord coord::operator+(coord op2) {    coord newCoord;    newCoord = coord();    newCoord.y = y + op2.y;    newCoord.x = x + op2.x;    return newCoord;}coord coord::operator-(coord op2) {    coord newCoord;    newCoord = coord();    newCoord.y = y - op2.y;    newCoord.x = x - op2.x;    return newCoord;}

[Edited by - Frggr on October 18, 2010 11:42:02 PM]

##### Share on other sites
Have you stepped through the rotate function to see why it doesn't rotate?

Does it rotate inside the function but not show up on the screen? Does it trigger "collide" when it shouldn't? Do the coordinates of tmpblock look correct?

You should be able to find out what is wrong by stepping through there.