Initializes the explosion system, loading needed bitmaps, etc
| 679 | |
| 680 | // Initializes the explosion system, loading needed bitmaps, etc |
| 681 | void InitFireballs() { |
| 682 | int i, num_fireballs = NUM_FIREBALLS; |
| 683 | for (i = 0; i < num_fireballs; i++) { |
| 684 | if (!(stricmp(Fireballs[i].name, "NOIMAGE"))) |
| 685 | continue; |
| 686 | int bm_handle = LoadTextureImage(IGNORE_TABLE(Fireballs[i].name), NULL, Fireballs[i].tex_size, 0); |
| 687 | if (bm_handle < 0) { |
| 688 | Error("Couldn't load fireball %s in InitFireballs.", Fireballs[i].name); |
| 689 | return; |
| 690 | } |
| 691 | ASSERT(bm_handle >= 0); |
| 692 | Fireballs[i].bm_handle = bm_handle; |
| 693 | } |
| 694 | |
| 695 | // convert the grey spark into grayscale |
| 696 | uint16_t *data; |
| 697 | int size; |
| 698 | float recip32 = 1.0f / 32.0f; |
| 699 | data = bm_data(Fireballs[GRAY_SPARK_INDEX].bm_handle, 0); |
| 700 | size = bm_w(Fireballs[GRAY_SPARK_INDEX].bm_handle, 0) * bm_h(Fireballs[GRAY_SPARK_INDEX].bm_handle, 0); |
| 701 | for (i = 0; i < size; i++) { |
| 702 | uint16_t col565 = data[i]; |
| 703 | if (col565 == 0x07e0) { |
| 704 | data[i] = NEW_TRANSPARENT_COLOR; |
| 705 | } else { |
| 706 | uint8_t r = (uint8_t)((col565 & 0xf800) >> 11); |
| 707 | uint8_t g = (uint8_t)((col565 & 0x07c0) >> 6); |
| 708 | uint8_t b = (uint8_t)(col565 & 0x001f); |
| 709 | float brightness = ((r * 0.30f) + (g * 0.59f) + (b * 0.11f)) * recip32; |
| 710 | uint8_t elem = (uint8_t)(255.0f * brightness); |
| 711 | if (brightness > 1.0f) |
| 712 | elem = 255; |
| 713 | data[i] = GR_RGB16(elem, elem, elem) | OPAQUE_FLAG; |
| 714 | } |
| 715 | } |
| 716 | GameBitmaps[Fireballs[GRAY_SPARK_INDEX].bm_handle].flags |= BF_CHANGED; |
| 717 | } |
| 718 | |
| 719 | // Given an object, renders the representation of this fireball |
| 720 | void DrawFireballObject(object *obj) { |
no test coverage detected