diff --git a/firmware/lib/cw-gfx-engine/EventBus.cpp b/firmware/lib/cw-gfx-engine/EventBus.cpp index d3aa0da..4781a08 100644 --- a/firmware/lib/cw-gfx-engine/EventBus.cpp +++ b/firmware/lib/cw-gfx-engine/EventBus.cpp @@ -2,8 +2,12 @@ #include "EventBus.h" void EventBus::broadcast(EventType event, Sprite* sender) { + broadcast(event, sender, 0); +} + +void EventBus::broadcast(EventType event, Sprite* sender, uint16_t value) { for (uint8_t i = 0; i < _subNum; i++) { - _subscriptions[i]->execute(event, sender); + _subscriptions[i]->execute(event, sender, value); } } diff --git a/firmware/lib/cw-gfx-engine/EventBus.h b/firmware/lib/cw-gfx-engine/EventBus.h index d6a06fb..3f54fe0 100644 --- a/firmware/lib/cw-gfx-engine/EventBus.h +++ b/firmware/lib/cw-gfx-engine/EventBus.h @@ -11,6 +11,7 @@ class EventBus { public: void broadcast(EventType event, Sprite* sender); + void broadcast(EventType event, Sprite* sender, uint16_t value); void subscribe(EventTask* task); }; diff --git a/firmware/lib/cw-gfx-engine/EventTask.h b/firmware/lib/cw-gfx-engine/EventTask.h index 49ab7b0..44e1a1b 100644 --- a/firmware/lib/cw-gfx-engine/EventTask.h +++ b/firmware/lib/cw-gfx-engine/EventTask.h @@ -4,13 +4,15 @@ #include "Sprite.h" enum EventType { - MOVE, - COLLISION + MOVE, + COLLISION, + COLLISION_JUMP, // New event type for collision-based jumps (no time update) + SKY_COLOR_CHANGED // Broadcast when sky color changes }; class EventTask { public: - virtual void execute(EventType event, Sprite* caller) = 0; + virtual void execute(EventType event, Sprite* caller, uint16_t value = 0) = 0; }; diff --git a/firmware/lib/cw-gfx-engine/ImageUtils.h b/firmware/lib/cw-gfx-engine/ImageUtils.h index e491983..ab9c850 100644 --- a/firmware/lib/cw-gfx-engine/ImageUtils.h +++ b/firmware/lib/cw-gfx-engine/ImageUtils.h @@ -1,6 +1,7 @@ #pragma once #include +#include "Locator.h" struct ImageUtils { @@ -45,4 +46,20 @@ struct ImageUtils { static void clone(uint16_t* src, uint16_t* dst, int len) { memcpy(dst, src, sizeof(src[0])*len); } + + static void drawTransparent(int x, int y, const uint16_t* bitmap, int width, int height, uint16_t maskColor) { + // Draw bitmap pixel by pixel, skipping mask pixels (TRANSPARENT) + const unsigned short TRANSPARENT = 0xFEFE; + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + uint16_t pixel = pgm_read_word(&bitmap[j * width + i]); + if (pixel != TRANSPARENT) { // Only draw non-transparent pixels + Locator::getDisplay()->drawPixel(x + i, y + j, pixel); + } else { + // Optionally, fill with maskColor if you want to erase background + // Locator::getDisplay()->drawPixel(x + i, y + j, maskColor); + } + } + } + } }; diff --git a/firmware/lib/cw-gfx-engine/Object.h b/firmware/lib/cw-gfx-engine/Object.h index 5047653..5a69cb3 100644 --- a/firmware/lib/cw-gfx-engine/Object.h +++ b/firmware/lib/cw-gfx-engine/Object.h @@ -1,5 +1,6 @@ #pragma once #include "Locator.h" +#include "ImageUtils.h" struct Object { const unsigned short *_image; @@ -13,6 +14,10 @@ struct Object { } void draw(int x, int y) { - Locator::getDisplay()->drawRGBBitmap(x, y, _image, _width, _height); + Locator::getDisplay()->drawRGBBitmap(x, y, _image, _width, _height); + } + + void drawTransparent(int x, int y, uint16_t transparentColor) { + ImageUtils::drawTransparent(x, y, _image, _width, _height, transparentColor); } };