Files
thepool/source/main.cpp

97 lines
2.2 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;
actor::actor_t *box;
int room_w = 0;
void restart()
{
actor::clear();
room::load(room_w,3);
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);
box = actor::create("BOX", {32,32,16}, {8,8,8}, {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);
surf = draw::loadSurface("test.gif");
draw::setSource(surf);
draw::loadPalette("test.gif");
game::setUpdateTicks(64);
restart();
}
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);
}
bool game::loop()
{
actor::update(actor::getFirst());
actor::reorder();
draw::cls(8);
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);
char buffer[100];
draw::print("ROOM WIDTH:", 330, 13, 15, 0);
if (ui::button(SDL_itoa(room_w, buffer, 10), 380, 10, 28, 11))
{
room_w++;if(room_w>3)room_w=0;
restart();
}
draw::render();
return true;
}