- El actors tenen la seua propia surface

This commit is contained in:
2023-09-12 19:10:56 +02:00
parent 22b22504d9
commit 21a8d70900
2 changed files with 14 additions and 5 deletions

View File

@@ -19,12 +19,13 @@ namespace actor
return first; return first;
} }
actor_t *create(const char *name, vec3_t p, vec3_t s, SDL_Rect r, SDL_Point o) 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)); actor_t *act = (actor_t*)malloc(sizeof(actor_t));
strcpy(act->name, name); strcpy(act->name, name);
act->pos = p; act->pos = p;
act->size = s; act->size = s;
act->surface = draw::loadSurface(bmp);
act->bmp_rect = r; act->bmp_rect = r;
act->bmp_offset = o; act->bmp_offset = o;
act->anim_cycle = act->orient = 0; act->anim_cycle = act->orient = 0;
@@ -566,6 +567,7 @@ namespace actor
if (!act) return; if (!act) return;
//if (act==first)order=0; //if (act==first)order=0;
//order++; //order++;
const int x = 148-act->bmp_offset.x + act->pos.x*2 - act->pos.y*2; const int x = 148-act->bmp_offset.x + act->pos.x*2 - act->pos.y*2;
const int y = 91-act->bmp_offset.y + act->pos.x + act->pos.y - act->pos.z*2; const int y = 91-act->bmp_offset.y + act->pos.x + act->pos.y - act->pos.z*2;
@@ -574,7 +576,10 @@ namespace actor
const int ao = (act->flags & FLAG_ANIMATED) ? anims[act->anim_cycle][anim_frame]*act->bmp_rect.w : 0; const int ao = (act->flags & FLAG_ANIMATED) ? anims[act->anim_cycle][anim_frame]*act->bmp_rect.w : 0;
draw::pushSource();
draw::setSource(act->surface);
draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x+ao, act->bmp_rect.y+oo, flip); draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x+ao, act->bmp_rect.y+oo, flip);
draw::popSource();
//print(x+5,y,act->pos.x); //print(x+5,y,act->pos.x);
//print(x+5,y+6,act->pos.y); //print(x+5,y+6,act->pos.y);
//print(x+5,y+12,act->pos.z); //print(x+5,y+12,act->pos.z);
@@ -648,6 +653,7 @@ namespace actor
if (act->flags & FLAG_HERO) { if (act->flags & FLAG_HERO) {
hero = act; hero = act;
} else { } else {
draw::freeSurface(act->surface);
free(act); free(act);
} }
act = tmp; act = tmp;
@@ -659,6 +665,7 @@ namespace actor
if (act->flags & FLAG_HERO) { if (act->flags & FLAG_HERO) {
hero = act; hero = act;
} else { } else {
draw::freeSurface(act->surface);
free(act); free(act);
} }
act = tmp; act = tmp;

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "misc.h" #include "misc.h"
#include "jdraw.h"
#define FLAG_NONE 0 #define FLAG_NONE 0
#define FLAG_HERO 1 #define FLAG_HERO 1
@@ -33,9 +34,10 @@ namespace actor
{ {
struct actor_t struct actor_t
{ {
char name[8]; char name[8];
SDL_Rect bmp_rect; draw::surface *surface;
SDL_Point bmp_offset; SDL_Rect bmp_rect;
SDL_Point bmp_offset;
vec3_t pos; vec3_t pos;
vec3_t size; vec3_t size;
@@ -61,7 +63,7 @@ namespace actor
actor_t *getFirst(); actor_t *getFirst();
actor_t *create(const char *name, vec3_t p, vec3_t s, SDL_Rect r, SDL_Point o); 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 setDirty(actor_t *act, const bool force=false);