- Treballant, canvi de comp, ara peta
This commit is contained in:
118
source/main.cpp
118
source/main.cpp
@@ -6,6 +6,9 @@
|
||||
#include "room.h"
|
||||
#include "jui.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
draw::surface *surf;
|
||||
int room_w = 2;
|
||||
int room_h = 2;
|
||||
@@ -19,9 +22,16 @@ int room_walls = 0;
|
||||
int room_doors = 0;
|
||||
int room_walldoors = 0;
|
||||
|
||||
std::vector<std::string> gifs;
|
||||
|
||||
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);
|
||||
|
||||
/*
|
||||
@@ -32,11 +42,6 @@ void restart()
|
||||
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->flags = FLAG_HERO | FLAG_PUSHABLE | FLAG_GRAVITY | FLAG_ORIENTABLE | FLAG_ANIMATED;
|
||||
@@ -55,11 +60,25 @@ void game::init()
|
||||
draw::loadPalette("test.gif");
|
||||
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("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;
|
||||
//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();
|
||||
|
||||
@@ -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];
|
||||
int result=0;
|
||||
@@ -108,10 +127,66 @@ void btn_small(const int x, const int y, int &var, int min, int max)
|
||||
if (result)
|
||||
{
|
||||
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);
|
||||
int result = 0;
|
||||
@@ -176,10 +251,12 @@ bool game::loop()
|
||||
btn("ROOM WIDTH:", 330, 40, room_w, 0, 3);
|
||||
btn("ROOM HEIGHT:", 330, 55, room_h, 0, 3);
|
||||
|
||||
btn("DOOR XP:", 330, 80, room_xp, -1, 5);
|
||||
btn("DOOR XN:", 330, 95, room_xn, -1, 5);
|
||||
btn("DOOR YP:", 330, 110, room_yp, -1, 5);
|
||||
btn("DOOR YN:", 330, 125, room_yn, -1, 5);
|
||||
draw::print("DOORS:", 330, 80, 15, 0);
|
||||
btn_small(352, 80, room_xn, -1, 5, true);
|
||||
btn_small(369, 80, room_yp, -1, 5, true);
|
||||
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("FLOOR:", 330, 155, room_floor, 0, 5);
|
||||
btn("WALLS:", 330, 170, room_walls, 0, 5);
|
||||
@@ -190,8 +267,8 @@ bool game::loop()
|
||||
act = actor::getSelected();
|
||||
if (act)
|
||||
{
|
||||
btn_txt("NAME:", 330, 40, act->name);
|
||||
btn_txt("BMP:", 330, 55, act->bmp);
|
||||
btn_txt("NAME:", 330, 40, act->name.c_str());
|
||||
btn_opt2("BMP:", 330, 55, act->bmp, gifs);
|
||||
draw::print("RECT:", 330, 73, 15, 0);
|
||||
btn_small(352, 70, act->bmp_rect.x, 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(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;
|
||||
}
|
||||
@@ -233,7 +319,7 @@ bool game::loop()
|
||||
} else if ((mx>=330) && (mx<394) && (my>=40+line*9) && (my<40+9+line*9) && btnDown) {
|
||||
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++;
|
||||
}
|
||||
act = act->next;
|
||||
|
||||
Reference in New Issue
Block a user