Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion firmware/lib/cw-gfx-engine/EventBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions firmware/lib/cw-gfx-engine/EventBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

};
Expand Down
8 changes: 5 additions & 3 deletions firmware/lib/cw-gfx-engine/EventTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down
17 changes: 17 additions & 0 deletions firmware/lib/cw-gfx-engine/ImageUtils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <Arduino.h>
#include "Locator.h"


struct ImageUtils {
Expand Down Expand Up @@ -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);
}
}
}
}
};
7 changes: 6 additions & 1 deletion firmware/lib/cw-gfx-engine/Object.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "Locator.h"
#include "ImageUtils.h"

struct Object {
const unsigned short *_image;
Expand All @@ -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);
}
};
Loading