Another C++ beginner question. I need to check if a certain bit is checked in an unsigned integer.
This is my array with the food-pellets in my pacman map. Each integer represents one row. Each bit is than one column.
unsigned int pellets[] = {
0x00000000, 0x7ff9ffe0, 0x42090420, 0x42090420,
0x42090420, 0x7fffffe0, 0x42402420, 0x42402420,
0x7e79e7e0, 0x20004000, 0x20004000, 0x20004000,
0x20004000, 0x20004000, 0x20004000, 0x20004000,
0x20004000, 0x20004000, 0x20004000, 0x20004000,
0x7ff9ffe0, 0x42090420, 0x42090420, 0x73f9fce0,
0x12402480, 0x12402480, 0x7e79e7e0, 0x40090020,
0x40090020, 0x7fffffe0, 0x00000000
};
This is the method to check if a pellet is at a certain map position:
boolean evalFood( const unsigned int x, const unsigned int y ) {
unsigned int row = pellets[y];
unsigned int mask = 1 << x;
return 0 != (row & mask);
}
I double-checked the values in the array and they are correct. However I get rubbish when displaying them. The pellets are shifted by 8 columns and truncated after 11 columns. Any help is appreciated.