Merge pull request #453 from pewpew-game/stage

Fix display orientation for _stage module
This commit is contained in:
Dan Halbert 2017-11-21 17:19:02 -05:00 committed by GitHub
commit 26862f8a52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 19 deletions

View File

@ -47,8 +47,8 @@ uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, uint16_t y) {
uint8_t tx = x >> 4; uint8_t tx = x >> 4;
uint8_t ty = y >> 4; uint8_t ty = y >> 4;
frame = layer->map[(tx * layer->width + ty) >> 1]; frame = layer->map[(ty * layer->width + tx) >> 1];
if (ty & 0x01) { if (tx & 0x01) {
frame &= 0x0f; frame &= 0x0f;
} else { } else {
frame >>= 4; frame >>= 4;
@ -60,41 +60,41 @@ uint16_t get_layer_pixel(layer_obj_t *layer, int16_t x, uint16_t y) {
y &= 0x0f; y &= 0x0f;
// Rotate the image. // Rotate the image.
uint8_t tx = x; // Temporary variable for swapping. uint8_t ty = y; // Temporary variable for swapping.
switch (layer->rotation) { switch (layer->rotation) {
case 1: // 90 degrees clockwise case 1: // 90 degrees clockwise
x = 15 - y; y = 15 - x;
y = tx; x = ty;
break; break;
case 2: // 180 degrees case 2: // 180 degrees
x = 15 - tx; y = 15 - ty;
y = 15 - y; x = 15 - x;
break; break;
case 3: // 90 degrees counter-clockwise case 3: // 90 degrees counter-clockwise
x = y; y = x;
y = 15 - tx; x = 15 - ty;
break; break;
case 4: // 0 degrees, mirrored case 4: // 0 degrees, mirrored
y = 15 - y; x = 15 - x;
break; break;
case 5: // 90 degrees clockwise, mirrored case 5: // 90 degrees clockwise, mirrored
x = y; y = x;
y = tx; x = ty;
break; break;
case 6: // 180 degrees, mirrored case 6: // 180 degrees, mirrored
x = 15 - tx; y = 15 - ty;
break; break;
case 7: // 90 degrees counter-clockwise, mirrored case 7: // 90 degrees counter-clockwise, mirrored
x = 15 - y; y = 15 - x;
y = 15 - tx; x = 15 - ty;
break; break;
default: // 0 degrees default: // 0 degrees
break; break;
} }
// Get the value of the pixel. // Get the value of the pixel.
uint8_t pixel = layer->graphic[(frame << 7) + (x << 3) + (y >> 1)]; uint8_t pixel = layer->graphic[(frame << 7) + (y << 3) + (x >> 1)];
if (y & 0x01) { if (x & 0x01) {
pixel &= 0x0f; pixel &= 0x0f;
} else { } else {
pixel >>= 4; pixel >>= 4;

View File

@ -59,8 +59,8 @@ uint16_t get_text_pixel(text_obj_t *text, int16_t x, uint16_t y) {
y &= 0x07; y &= 0x07;
// Get the value of the pixel. // Get the value of the pixel.
uint8_t pixel = text->font[(c << 4) + (x << 1) + (y >> 2)]; uint8_t pixel = text->font[(c << 4) + (y << 1) + (x >> 2)];
pixel = ((pixel >> ((y & 0x03) << 1)) & 0x03) + color_offset; pixel = ((pixel >> ((x & 0x03) << 1)) & 0x03) + color_offset;
// Convert to 16-bit color using the palette. // Convert to 16-bit color using the palette.
return text->palette[pixel << 1] | text->palette[(pixel << 1) + 1] << 8; return text->palette[pixel << 1] | text->palette[(pixel << 1) + 1] << 8;