From 47aa1c0e783e6574a711262f794525196a656bd9 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 20 Sep 2023 18:58:41 +0200 Subject: [PATCH] - actor::find() per nom - [new] actor seleccionat - actor seleccionat es pinta de diferent color --- source/actor.cpp | 36 ++++++++++++++++++++++++++++++++++++ source/actor.h | 6 ++++++ 2 files changed, 42 insertions(+) diff --git a/source/actor.cpp b/source/actor.cpp index 5e16aae..8c7765c 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -12,12 +12,18 @@ namespace actor actor_t *first = nullptr; actor_t *dirty = nullptr; + actor_t *selected = nullptr; actor_t *getFirst() { return first; } + actor_t *getSelected() + { + return selected; + } + actor_t *create(const char *name, vec3_t p, vec3_t s, const char *bmp, SDL_Rect r, SDL_Point o) { actor_t *act = (actor_t*)malloc(sizeof(actor_t)); @@ -102,6 +108,10 @@ namespace actor } + void select(actor_t *act) { + selected = act; + } + const bool isInFront(actor_t *act1, actor_t *act2) { if (act1->pos.x >= act2->pos.x+act2->size.x) { return true; } @@ -585,7 +595,9 @@ namespace actor draw::pushSource(); draw::setSource(act->surface); + if (act==selected) draw::swapcol(1, room::getColor()==9?11:9); // Si està seleccionat, que canvie de color draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x+ao, act->bmp_rect.y+oo, flip); + draw::swapcol(1, room::getColor()); // Tornem al color per defecte draw::popSource(); //print(x+5,y,act->pos.x); //print(x+5,y+6,act->pos.y); @@ -596,6 +608,30 @@ namespace actor if (draw_all && act->next) draw(act->next); } + actor_t *find(const char *name) + { + actor_t *act = first; + while (act) + { + if (SDL_strcmp(name, act->name)==0) + { + return act; + } + act = act->next; + } + + act = dirty; + while (act) + { + if (SDL_strcmp(name, act->name)==0) + { + return act; + } + act = act->next; + } + return nullptr; + } + actor_t *find_at(const int x, const int y, const int z) { actor_t *act = first; diff --git a/source/actor.h b/source/actor.h index 2cd0703..c40b056 100644 --- a/source/actor.h +++ b/source/actor.h @@ -66,9 +66,13 @@ namespace actor actor_t *getFirst(); + actor_t *getSelected(); + actor_t *create(const char *name, vec3_t p, vec3_t s, const char *bmp, SDL_Rect r, SDL_Point o); void setDirty(actor_t *act, const bool force=false); + + void select(actor_t *act); void reorder(); @@ -76,6 +80,8 @@ namespace actor void draw(actor_t *act, const bool draw_all=true); + actor_t *find(const char *name); + actor_t *find_at(const int x, const int y, const int z); actor_t *get_collision(actor_t *act);