- Treballant, canvi de comp, ara peta
This commit is contained in:
9
data/gifs.txt
Normal file
9
data/gifs.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
abad.gif
|
||||||
|
doors.gif
|
||||||
|
floor.gif
|
||||||
|
font.gif
|
||||||
|
gat.gif
|
||||||
|
obrer.gif
|
||||||
|
roomaux.gif
|
||||||
|
test.gif
|
||||||
|
walls.gif
|
||||||
@@ -24,14 +24,14 @@ namespace actor
|
|||||||
return selected;
|
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 *create(std::string name, vec3_t p, vec3_t s, std::string 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);
|
act->name = std::string(name);
|
||||||
strcpy(act->bmp, bmp);
|
act->bmp = std::string(bmp);
|
||||||
act->pos = p;
|
act->pos = p;
|
||||||
act->size = s;
|
act->size = s;
|
||||||
act->surface = draw::loadSurface(bmp);
|
act->surface = draw::loadSurface(bmp.c_str());
|
||||||
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;
|
||||||
@@ -609,12 +609,12 @@ namespace actor
|
|||||||
if (draw_all && act->next) draw(act->next);
|
if (draw_all && act->next) draw(act->next);
|
||||||
}
|
}
|
||||||
|
|
||||||
actor_t *find(const char *name)
|
actor_t *find(std::string name)
|
||||||
{
|
{
|
||||||
actor_t *act = first;
|
actor_t *act = first;
|
||||||
while (act)
|
while (act)
|
||||||
{
|
{
|
||||||
if (SDL_strcmp(name, act->name)==0)
|
if (name == act->name)
|
||||||
{
|
{
|
||||||
return act;
|
return act;
|
||||||
}
|
}
|
||||||
@@ -624,7 +624,7 @@ namespace actor
|
|||||||
act = dirty;
|
act = dirty;
|
||||||
while (act)
|
while (act)
|
||||||
{
|
{
|
||||||
if (SDL_strcmp(name, act->name)==0)
|
if (name == act->name)
|
||||||
{
|
{
|
||||||
return act;
|
return act;
|
||||||
}
|
}
|
||||||
@@ -687,6 +687,16 @@ namespace actor
|
|||||||
(obj1->pos.z + obj1->size.z > obj2->pos.z );
|
(obj1->pos.z + obj1->size.z > obj2->pos.z );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void remove(actor_t *act)
|
||||||
|
{
|
||||||
|
if (!act) return;
|
||||||
|
if (act->prev) act->prev->next = act->next;
|
||||||
|
if (act==first) first = act->next;
|
||||||
|
if (act==dirty) dirty = act->next;
|
||||||
|
if (act->next) act->next->prev = act->prev;
|
||||||
|
free(act);
|
||||||
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
actor_t *hero = nullptr;
|
actor_t *hero = nullptr;
|
||||||
@@ -721,4 +731,5 @@ namespace actor
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#define FLAG_NONE 0
|
#define FLAG_NONE 0
|
||||||
#define FLAG_HERO 1
|
#define FLAG_HERO 1
|
||||||
#define FLAG_PUSHABLE 2
|
#define FLAG_PUSHABLE 2
|
||||||
@@ -35,9 +37,9 @@ namespace actor
|
|||||||
{
|
{
|
||||||
struct actor_t
|
struct actor_t
|
||||||
{
|
{
|
||||||
char name[16];
|
std::string name;
|
||||||
draw::surface *surface;
|
draw::surface *surface;
|
||||||
char bmp[16];
|
std::string bmp;
|
||||||
SDL_Rect bmp_rect;
|
SDL_Rect bmp_rect;
|
||||||
SDL_Point bmp_offset;
|
SDL_Point bmp_offset;
|
||||||
|
|
||||||
@@ -70,7 +72,7 @@ namespace actor
|
|||||||
|
|
||||||
actor_t *getSelected();
|
actor_t *getSelected();
|
||||||
|
|
||||||
actor_t *create(const char *name, vec3_t p, vec3_t s, const char *bmp, SDL_Rect r, SDL_Point o);
|
actor_t *create(std::string name, vec3_t p, vec3_t s, std::string 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);
|
||||||
|
|
||||||
@@ -82,7 +84,7 @@ namespace actor
|
|||||||
|
|
||||||
void draw(actor_t *act, const bool draw_all=true);
|
void draw(actor_t *act, const bool draw_all=true);
|
||||||
|
|
||||||
actor_t *find(const char *name);
|
actor_t *find(std::string name);
|
||||||
|
|
||||||
actor_t *find_at(const int x, const int y, const int z);
|
actor_t *find_at(const int x, const int y, const int z);
|
||||||
|
|
||||||
@@ -90,5 +92,7 @@ namespace actor
|
|||||||
|
|
||||||
const bool check_collision(actor_t *obj1, actor_t *obj2);
|
const bool check_collision(actor_t *obj1, actor_t *obj2);
|
||||||
|
|
||||||
|
void remove(actor_t *act);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
}
|
}
|
||||||
118
source/main.cpp
118
source/main.cpp
@@ -6,6 +6,9 @@
|
|||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "jui.h"
|
#include "jui.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
draw::surface *surf;
|
draw::surface *surf;
|
||||||
int room_w = 2;
|
int room_w = 2;
|
||||||
int room_h = 2;
|
int room_h = 2;
|
||||||
@@ -19,9 +22,16 @@ int room_walls = 0;
|
|||||||
int room_doors = 0;
|
int room_doors = 0;
|
||||||
int room_walldoors = 0;
|
int room_walldoors = 0;
|
||||||
|
|
||||||
|
std::vector<std::string> gifs;
|
||||||
|
|
||||||
void restart()
|
void restart()
|
||||||
{
|
{
|
||||||
actor::clear();
|
//actor::clear();
|
||||||
|
actor::remove(actor::find("DOOR_YP1"));
|
||||||
|
actor::remove(actor::find("DOOR_YP2"));
|
||||||
|
actor::remove(actor::find("DOOR_XP1"));
|
||||||
|
actor::remove(actor::find("DOOR_XP2"));
|
||||||
|
|
||||||
room::load(room_w, room_h, room_xp, room_xn, room_yp, room_yn, room_color, room_floor, room_walls, room_doors, room_walldoors);
|
room::load(room_w, room_h, room_xp, room_xn, room_yp, room_yn, room_color, room_floor, room_walls, room_doors, room_walldoors);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -32,11 +42,6 @@ void restart()
|
|||||||
actor::setDirty(box, true);
|
actor::setDirty(box, true);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
actor::actor_t *box = actor::create("BOX", {32,32,16}, {8,8,8}, "test.gif", {32,0,32,32}, {0,32});
|
|
||||||
box->flags = FLAG_PUSHABLE | FLAG_GRAVITY;
|
|
||||||
box->movement = MOV_CW;
|
|
||||||
box->mov_push = PUSH_XN;
|
|
||||||
actor::setDirty(box, true);
|
|
||||||
|
|
||||||
//box = actor::create("HERO", {16,32,8}, {8,8,12}, {0,32,20,32}, {-6,38});
|
//box = actor::create("HERO", {16,32,8}, {8,8,12}, {0,32,20,32}, {-6,38});
|
||||||
//box->flags = FLAG_HERO | FLAG_PUSHABLE | FLAG_GRAVITY | FLAG_ORIENTABLE | FLAG_ANIMATED;
|
//box->flags = FLAG_HERO | FLAG_PUSHABLE | FLAG_GRAVITY | FLAG_ORIENTABLE | FLAG_ANIMATED;
|
||||||
@@ -55,11 +60,25 @@ void game::init()
|
|||||||
draw::loadPalette("test.gif");
|
draw::loadPalette("test.gif");
|
||||||
game::setUpdateTicks(64);
|
game::setUpdateTicks(64);
|
||||||
|
|
||||||
|
FILE* f = fopen("data/gifs.txt", "r");
|
||||||
|
int buffer_len=255;
|
||||||
|
char buffer[buffer_len];
|
||||||
|
while(fgets(buffer, buffer_len, f)) {
|
||||||
|
gifs.push_back(std::string(buffer));
|
||||||
|
}
|
||||||
//actor::actor_t *hero = actor::create("HERO", {16,32,8}, {8,8,12}, "test.gif", {0,32,20,32}, {-6,38});
|
//actor::actor_t *hero = actor::create("HERO", {16,32,8}, {8,8,12}, "test.gif", {0,32,20,32}, {-6,38});
|
||||||
|
|
||||||
//actor::actor_t *hero = actor::create("HEROHEROHEROHER", {16,32,8}, {8,8,12}, "abad.gif", {0,0,20,35}, {-6,32});
|
//actor::actor_t *hero = actor::create("HEROHEROHEROHER", {16,32,8}, {8,8,12}, "abad.gif", {0,0,20,35}, {-6,32});
|
||||||
//hero->flags = FLAG_HERO | FLAG_PUSHABLE | FLAG_GRAVITY | FLAG_ORIENTABLE | FLAG_ANIMATED;
|
//hero->flags = FLAG_HERO | FLAG_PUSHABLE | FLAG_GRAVITY | FLAG_ORIENTABLE | FLAG_ANIMATED;
|
||||||
//actor::setDirty(hero, true);
|
//actor::setDirty(hero, true);
|
||||||
|
|
||||||
|
actor::clear();
|
||||||
|
|
||||||
|
actor::actor_t *box = actor::create("BOX", {32,32,16}, {8,8,8}, "test.gif", {32,0,32,32}, {0,32});
|
||||||
|
box->flags = FLAG_PUSHABLE | FLAG_GRAVITY;
|
||||||
|
box->movement = MOV_CW;
|
||||||
|
box->mov_push = PUSH_XN;
|
||||||
|
actor::setDirty(box, true);
|
||||||
|
|
||||||
restart();
|
restart();
|
||||||
|
|
||||||
@@ -100,7 +119,7 @@ void btn(const char* label, const int x, const int y, int &var, int min, int max
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void btn_small(const int x, const int y, int &var, int min, int max)
|
void btn_small(const int x, const int y, int &var, int min, int max, bool restrt=false)
|
||||||
{
|
{
|
||||||
char buffer[100];
|
char buffer[100];
|
||||||
int result=0;
|
int result=0;
|
||||||
@@ -108,10 +127,66 @@ void btn_small(const int x, const int y, int &var, int min, int max)
|
|||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
var=SDL_max(min, SDL_min(max, var-(result-2)));
|
var=SDL_max(min, SDL_min(max, var-(result-2)));
|
||||||
|
if (restrt) restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void btn_txt(const char* label, const int x, const int y, char *var)
|
void btn_check(const int x, const int y, const char* label, uint16_t &flags, const uint16_t value)
|
||||||
|
{
|
||||||
|
int result=0;
|
||||||
|
if (flags & value) {
|
||||||
|
result=ui::button(label, x, y, 20, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE);
|
||||||
|
} else {
|
||||||
|
result=ui::button(label, x, y, 20, 11, BLACK, WHITE, LIGHT+PURPLE);
|
||||||
|
}
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
if (flags & value) {
|
||||||
|
flags = flags & ~value;
|
||||||
|
} else {
|
||||||
|
flags = flags | value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void btn_opt(const char* label, const int x, const int y, uint8_t &var, std::vector<uint8_t> values, std::vector<std::string> labels)
|
||||||
|
{
|
||||||
|
draw::print(label, x, y+3, 15, 0);
|
||||||
|
int result = 0;
|
||||||
|
int pos = 0;
|
||||||
|
while (pos<values.size())
|
||||||
|
{
|
||||||
|
if (values[pos]==var) break;
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = ui::button(labels[pos].c_str(), x+32, y, 56, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
pos++; if (pos==values.size()) pos=0;
|
||||||
|
var = values[pos];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void btn_opt2(const char* label, const int x, const int y, std::string &var, std::vector<std::string> values)
|
||||||
|
{
|
||||||
|
draw::print(label, x, y+3, 15, 0);
|
||||||
|
int result = 0;
|
||||||
|
int pos = 0;
|
||||||
|
while (var != values[pos])
|
||||||
|
{
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = ui::button(var.c_str(), x+32, y, 56, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
pos++; if (pos==values.size()) pos=0;
|
||||||
|
var = values[pos];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void btn_txt(const char* label, const int x, const int y, const char *var)
|
||||||
{
|
{
|
||||||
draw::print(label, x, y+3, 15, 0);
|
draw::print(label, x, y+3, 15, 0);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@@ -176,10 +251,12 @@ bool game::loop()
|
|||||||
btn("ROOM WIDTH:", 330, 40, room_w, 0, 3);
|
btn("ROOM WIDTH:", 330, 40, room_w, 0, 3);
|
||||||
btn("ROOM HEIGHT:", 330, 55, room_h, 0, 3);
|
btn("ROOM HEIGHT:", 330, 55, room_h, 0, 3);
|
||||||
|
|
||||||
btn("DOOR XP:", 330, 80, room_xp, -1, 5);
|
draw::print("DOORS:", 330, 80, 15, 0);
|
||||||
btn("DOOR XN:", 330, 95, room_xn, -1, 5);
|
btn_small(352, 80, room_xn, -1, 5, true);
|
||||||
btn("DOOR YP:", 330, 110, room_yp, -1, 5);
|
btn_small(369, 80, room_yp, -1, 5, true);
|
||||||
btn("DOOR YN:", 330, 125, room_yn, -1, 5);
|
btn_small(386, 80, room_xp, -1, 5, true);
|
||||||
|
btn_small(403, 80, room_yn, -1, 5, true);
|
||||||
|
|
||||||
btn("COLOR:", 330, 140, room_color, 5, 11);
|
btn("COLOR:", 330, 140, room_color, 5, 11);
|
||||||
btn("FLOOR:", 330, 155, room_floor, 0, 5);
|
btn("FLOOR:", 330, 155, room_floor, 0, 5);
|
||||||
btn("WALLS:", 330, 170, room_walls, 0, 5);
|
btn("WALLS:", 330, 170, room_walls, 0, 5);
|
||||||
@@ -190,8 +267,8 @@ bool game::loop()
|
|||||||
act = actor::getSelected();
|
act = actor::getSelected();
|
||||||
if (act)
|
if (act)
|
||||||
{
|
{
|
||||||
btn_txt("NAME:", 330, 40, act->name);
|
btn_txt("NAME:", 330, 40, act->name.c_str());
|
||||||
btn_txt("BMP:", 330, 55, act->bmp);
|
btn_opt2("BMP:", 330, 55, act->bmp, gifs);
|
||||||
draw::print("RECT:", 330, 73, 15, 0);
|
draw::print("RECT:", 330, 73, 15, 0);
|
||||||
btn_small(352, 70, act->bmp_rect.x, 0, 512);
|
btn_small(352, 70, act->bmp_rect.x, 0, 512);
|
||||||
btn_small(369, 70, act->bmp_rect.y, 0, 512);
|
btn_small(369, 70, act->bmp_rect.y, 0, 512);
|
||||||
@@ -212,7 +289,16 @@ bool game::loop()
|
|||||||
btn_small(386, 120, act->size.y, 0, 512);
|
btn_small(386, 120, act->size.y, 0, 512);
|
||||||
btn_small(403, 120, act->size.z, 0, 512);
|
btn_small(403, 120, act->size.z, 0, 512);
|
||||||
|
|
||||||
//btn_txt("ORIENT:", 330, 135, "NONE");
|
btn_opt("ORIENT:", 330, 135, act->orient, {PUSH_NONE, PUSH_XP, PUSH_XN, PUSH_YP, PUSH_YN}, {"NONE", "XP", "XN", "YP", "YN"});
|
||||||
|
|
||||||
|
btn_check(330, 150, "HERO", act->flags, FLAG_HERO);
|
||||||
|
btn_check(352, 150, "PUSH", act->flags, FLAG_PUSHABLE);
|
||||||
|
btn_check(374, 150, "REAC", act->flags, FLAG_REACTIVE);
|
||||||
|
btn_check(396, 150, "MOVI", act->flags, FLAG_MOVING);
|
||||||
|
btn_check(330, 165, "ANIM", act->flags, FLAG_ANIMATED);
|
||||||
|
btn_check(352, 165, "ORIE", act->flags, FLAG_ORIENTABLE);
|
||||||
|
btn_check(374, 165, "DEAD", act->flags, FLAG_DEADLY);
|
||||||
|
btn_check(396, 165, "GRAV", act->flags, FLAG_GRAVITY);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -233,7 +319,7 @@ bool game::loop()
|
|||||||
} else if ((mx>=330) && (mx<394) && (my>=40+line*9) && (my<40+9+line*9) && btnDown) {
|
} else if ((mx>=330) && (mx<394) && (my>=40+line*9) && (my<40+9+line*9) && btnDown) {
|
||||||
actor::select(act);
|
actor::select(act);
|
||||||
}
|
}
|
||||||
draw::print(act->name, 332, 42+line*9, WHITE, BLACK);
|
draw::print(act->name.c_str(), 332, 42+line*9, WHITE, BLACK);
|
||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
act = act->next;
|
act = act->next;
|
||||||
|
|||||||
Reference in New Issue
Block a user