Files
thepool/source/main.cpp

194 lines
5.8 KiB
C++

#include "jgame.h"
#include "jdraw.h"
#include "jinput.h"
#include <SDL2/SDL.h>
#include "actor.h"
#include "room.h"
#include "jui.h"
draw::surface *surf;
int room_w = 2;
int room_h = 2;
int room_xp = -1;
int room_xn = -1;
int room_yp = -1;
int room_yn = -1;
int room_color = 9;
int room_floor = 0;
int room_walls = 0;
int room_doors = 0;
int room_walldoors = 0;
void restart()
{
actor::clear();
room::load(room_w, room_h, room_xp, room_xn, room_yp, room_yn, room_color, room_floor, room_walls, room_doors, room_walldoors);
/*
box = actor::create("ASCENSOR",{16,32,0}, {8,8,4}, {64,0,32,24}, {0,24});
box->flags = FLAG_MOVING;
box->movement = MOV_Z;
box->mov_push = PUSH_ZP;
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;
//actor::setDirty(box, true);
actor::reorder();
}
void game::init()
{
draw::init("The Pool", 420, 240, 3);
//room::init();
surf = draw::loadSurface("test.gif");
draw::setSource(surf);
draw::loadPalette("test.gif");
game::setUpdateTicks(64);
//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);
restart();
actor::select(actor::find("BOX"));
}
int sx=1, sy=0;
void print(int x, int y, int num)
{
int digits=0;
bool sign = num < 0;
num = SDL_abs(num);
int n = num;
while (n>0) {n=n/10;digits++;}
if (sign) digits++;
x=x+digits*4;
if (num==0) draw::draw(x+4,y,5,7,0,120);
while (num>0)
{
draw::draw(x,y,5,7,(num%10)*5,120);
num=num/10;
x=x-4;
}
if (sign) draw::draw(x,y,5,7,50,120);
}
void btn(const char* label, const int x, const int y, int &var, int min, int max)
{
char buffer[100];
int result=0;
draw::print(label, x, y+3, 15, 0);
result=ui::button(SDL_itoa(var, buffer, 10), x+50, y, 28, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE);
if (result)
{
var=SDL_max(min, SDL_min(max, var-(result-2)));
restart();
}
}
int section = 0;
void editor_move_selected()
{
actor::actor_t *selected = actor::getSelected();
if (!selected) return;
vec3_t min = room::getMin();
vec3_t max = room::getMax();
if ( input::keyDown(SDL_SCANCODE_LEFT) && selected->pos.x>min.x ) selected->pos.x--;
if ( input::keyDown(SDL_SCANCODE_RIGHT) && selected->pos.x<max.x ) selected->pos.x++;
if ( input::keyDown(SDL_SCANCODE_UP) && selected->pos.y>min.y ) selected->pos.y--;
if ( input::keyDown(SDL_SCANCODE_DOWN) && selected->pos.y<max.y ) selected->pos.y++;
if ( input::keyDown(SDL_SCANCODE_PAGEDOWN) && selected->pos.z>min.z ) selected->pos.z--;
if ( input::keyDown(SDL_SCANCODE_PAGEUP) /*&& selected->pos.z<max.z*/ ) selected->pos.z++;
}
bool game::loop()
{
if (input::keyDown(SDL_SCANCODE_ESCAPE)) return false;
// WHILE EDITING...
editor_move_selected();
//actor::update(actor::getFirst());
actor::reorder();
draw::cls(2);
room::draw();
actor::draw(actor::getFirst());
room::draw2();
//draw::draw(148+sx*2-sy*2, 67+sx+sy,24,24,24,0);
print(0,0,input::mouseX());
print(0,20,input::mouseY());
print(0,30,input::mouseBtn(1)?1:0);
print(0,40,input::mouseBtn(2)?1:0);
print(0,50,input::mouseBtn(3)?1:0);
if (section==0) {
draw::print("ROOM", 334, 13, YELLOW, LIGHT+BLACK);
if (ui::button("ACTORS", 365, 10, 30, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE)) section=1;
} else {
if (ui::button("ROOM", 330, 10, 30, 11, TEAL, LIGHT+TEAL, LIGHT+PURPLE)) section=0;
draw::print("ACTORS", 369, 13, YELLOW, BLACK);
}
switch (section) {
case 0:
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);
btn("COLOR:", 330, 140, room_color, 5, 11);
btn("FLOOR:", 330, 155, room_floor, 0, 5);
btn("WALLS:", 330, 170, room_walls, 0, 5);
btn("DOORS:", 330, 185, room_doors, 0, 4);
btn("WDOORS:", 330, 200, room_walldoors, 0, 5);
break;
case 1:
draw::color(TEAL);
draw::rect(328, 38, 67, 94);
const int mx = input::mouseX();
const int my = input::mouseY();
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
int line = 0;
actor::actor_t *act = actor::getFirst();
while (act) {
if ((act->flags&FLAG_NOEDITOR)!=FLAG_NOEDITOR) {
if (act==actor::getSelected()) {
draw::color(TEAL);
draw::fillrect(330, 40+line*9, 63, 9);
} 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);
line++;
}
act = act->next;
}
break;
}
draw::render();
return true;
}