Compare commits
2 Commits
0a24e2b3fe
...
b0dd34b5df
| Author | SHA1 | Date | |
|---|---|---|---|
| b0dd34b5df | |||
| 8725532586 |
@@ -8,6 +8,7 @@ font2.gif
|
||||
gat.gif
|
||||
gat2.gif
|
||||
jailgames.gif
|
||||
mapa.gif
|
||||
objectes.gif
|
||||
obrer.gif
|
||||
roomaux.gif
|
||||
|
||||
BIN
data/mapa.gif
Normal file
BIN
data/mapa.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 614 B |
@@ -8,6 +8,7 @@ floor-texture: 0
|
||||
wall-texture: 2
|
||||
door-texture: 0
|
||||
under-door-texture: 0
|
||||
exit-xp: 2
|
||||
exit-xn: 0
|
||||
|
||||
actor{
|
||||
|
||||
11
data/rooms/02.txt
Normal file
11
data/rooms/02.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
width: 3
|
||||
height: 2
|
||||
door-height-xn: 0
|
||||
door-height-yn: 0
|
||||
color: GREEN
|
||||
floor-texture: 0
|
||||
wall-texture: 0
|
||||
door-texture: 0
|
||||
under-door-texture: 0
|
||||
exit-xn: 1
|
||||
exit-yn: 3
|
||||
11
data/rooms/03.txt
Normal file
11
data/rooms/03.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
width: 2
|
||||
height: 3
|
||||
door-height-xn: 0
|
||||
door-height-yp: 0
|
||||
color: CYAN
|
||||
floor-texture: 0
|
||||
wall-texture: 0
|
||||
door-texture: 0
|
||||
under-door-texture: 0
|
||||
exit-xn: 4
|
||||
exit-yp: 2
|
||||
11
data/rooms/04.txt
Normal file
11
data/rooms/04.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
width: 2
|
||||
height: 2
|
||||
door-height-xp: 0
|
||||
door-height-xn: 0
|
||||
color: CYAN
|
||||
floor-texture: 0
|
||||
wall-texture: 0
|
||||
door-texture: 0
|
||||
under-door-texture: 0
|
||||
exit-xp: 3
|
||||
exit-xn: 5
|
||||
9
data/rooms/05.txt
Normal file
9
data/rooms/05.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
width: 2
|
||||
height: 2
|
||||
door-height-xp: 0
|
||||
color: CYAN
|
||||
floor-texture: 0
|
||||
wall-texture: 0
|
||||
door-texture: 0
|
||||
under-door-texture: 0
|
||||
exit-xp: 4
|
||||
@@ -568,23 +568,29 @@ namespace draw
|
||||
for (int i=0;i<len;++i)
|
||||
{
|
||||
char chr = text[i]-32;
|
||||
draw((x+i)*8, y*8, 8, 8, (chr&15)*8, (chr>>4)*8, DRAW_FLIP_NONE,zoom&FONT_ZOOM_HORIZONTAL?16:8, zoom&FONT_ZOOM_VERTICAL?16:8);
|
||||
draw((x+(i*(zoom&FONT_ZOOM_HORIZONTAL?2:1)))*8, y*8, 8, 8, (chr&15)*8, (chr>>4)*8, DRAW_FLIP_NONE,zoom&FONT_ZOOM_HORIZONTAL?16:8, zoom&FONT_ZOOM_VERTICAL?16:8);
|
||||
}
|
||||
source = tmp;
|
||||
}
|
||||
|
||||
void print2(const int num, const int positions, const int x, const int y, const uint8_t color, const int zoom)
|
||||
{
|
||||
char buffer[positions+1];
|
||||
int digit = positions-1;
|
||||
int value = num;
|
||||
const char empty = positions < 0 ? '0' : ' ';
|
||||
const int pos = positions < 0 ? -positions : positions;
|
||||
char buffer[pos+1];
|
||||
int digit = pos-1;
|
||||
int value = num<0 ? -num : num;
|
||||
while (digit>=0)
|
||||
{
|
||||
buffer[digit] = (value%10)==0 && digit<positions-1 ? 32 : (value%10)+48;
|
||||
value = value/10;
|
||||
if (digit==0 && num<0) {
|
||||
buffer[digit] = '-';
|
||||
} else {
|
||||
buffer[digit] = (value%10)==0 && digit<pos-1 ? empty : (value%10)+48;
|
||||
value = value/10;
|
||||
}
|
||||
digit--;
|
||||
}
|
||||
buffer[positions]=0;
|
||||
buffer[pos]=0;
|
||||
print2(buffer, x, y, color, zoom);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
|
||||
game::params = argv;
|
||||
|
||||
game::init();
|
||||
input::init(draw::getZoom());
|
||||
input::init();
|
||||
|
||||
static unsigned int current_ticks = SDL_GetTicks();
|
||||
|
||||
|
||||
@@ -9,12 +9,10 @@ namespace input
|
||||
static uint8_t keydown = 0;
|
||||
static uint8_t btnClicked = 0;
|
||||
static int wheel = 0;
|
||||
static int screen_zoom = 1;
|
||||
|
||||
void init(const int zoom)
|
||||
void init()
|
||||
{
|
||||
keys = SDL_GetKeyboardState(NULL);
|
||||
screen_zoom = zoom;
|
||||
}
|
||||
|
||||
// Determina si la tecla especificada està sent polsada ara mateix
|
||||
@@ -76,7 +74,7 @@ namespace input
|
||||
{
|
||||
int x;
|
||||
SDL_GetMouseState(&x, NULL);
|
||||
return x/screen_zoom;
|
||||
return x/draw::getZoom();
|
||||
}
|
||||
|
||||
// Torna la posició Y actual del ratolí
|
||||
@@ -84,7 +82,7 @@ namespace input
|
||||
{
|
||||
int y;
|
||||
SDL_GetMouseState(NULL, &y);
|
||||
return y/screen_zoom;
|
||||
return y/draw::getZoom();
|
||||
}
|
||||
|
||||
// Determina si el botó del ratolí especificat està sent polsada ara mateix
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
namespace input
|
||||
{
|
||||
/// @brief Inicialitza els sistemes de teclat, ratolí i gamepad
|
||||
void init(const int zoom);
|
||||
void init();
|
||||
|
||||
/// @brief Determina si la tecla especificada està sent polsada ara mateix
|
||||
/// @param key tecla a consultar
|
||||
|
||||
109
source/m_editor_map.cpp
Normal file
109
source/m_editor_map.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "m_editor_map.h"
|
||||
#include "jdraw.h"
|
||||
#include "jinput.h"
|
||||
#include "misc.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "room.h"
|
||||
|
||||
namespace modules
|
||||
{
|
||||
namespace editor_map
|
||||
{
|
||||
draw::surface *surf;
|
||||
vec2_t scroll {0,0};
|
||||
bool drawn[64];
|
||||
int current_room;
|
||||
|
||||
struct miniroom_t
|
||||
{
|
||||
uint8_t w;
|
||||
uint8_t h;
|
||||
uint8_t color;
|
||||
uint8_t exits[6];
|
||||
};
|
||||
miniroom_t minirooms[64];
|
||||
|
||||
void loadMiniRoom()
|
||||
{
|
||||
const int room = room::getCurrent();
|
||||
if (drawn[room]) return;
|
||||
drawn[room] = true;
|
||||
|
||||
minirooms[room].color = room::getColor(0);
|
||||
minirooms[room].w = (room::getSize().x >> 1)-1;
|
||||
minirooms[room].h = (room::getSize().y >> 1)-1;
|
||||
for (int i=0; i<ZN; ++i) minirooms[room].exits[i] = room::getExit(i);
|
||||
|
||||
for (int i=0; i<ZN; ++i) {
|
||||
const int next_room = minirooms[room].exits[i];
|
||||
if ( (next_room >= 0) && (next_room <= 64) && (!drawn[next_room]) ) {
|
||||
room::load(next_room);
|
||||
loadMiniRoom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
surf = draw::getSurface("mapa.gif");
|
||||
scroll = {260,120};
|
||||
draw::resetViewport();
|
||||
for (int i=0;i<64;++i) drawn[i]=false;
|
||||
|
||||
current_room = room::getCurrent();
|
||||
loadMiniRoom();
|
||||
room::load(current_room);
|
||||
}
|
||||
|
||||
void drawRoom(const int room, const int x, const int y)
|
||||
{
|
||||
if (drawn[room]) return;
|
||||
drawn[room] = true;
|
||||
if ( (x>=-32) && (x<520) && (y>=-16) && (y<240) )
|
||||
{
|
||||
draw::stencil::set(room);
|
||||
draw::swapcol(1, minirooms[room].color);
|
||||
draw::draw(x-16, y-8, 32, 16, minirooms[room].w*32, minirooms[room].h*16);
|
||||
|
||||
draw::swapcol(1, RED);
|
||||
if (minirooms[room].exits[XN] != 255) draw::draw(x-4-(minirooms[room].w*2), y-5-(minirooms[room].w),4,5,0,64);
|
||||
if (minirooms[room].exits[YN] != 255) draw::draw(x+(minirooms[room].h*2), y-5-(minirooms[room].h),4,5,3,64);
|
||||
if (minirooms[room].exits[XP] != 255) draw::draw(x+(minirooms[room].w*2), y-3+(minirooms[room].w),4,5,0,64);
|
||||
if (minirooms[room].exits[YP] != 255) draw::draw(x-4-(minirooms[room].h*2), y-3+(minirooms[room].h),4,5,3,64);
|
||||
|
||||
char num[] = "00"; num[0] = 48+(room/10); num[1] = 48+(room%10);
|
||||
draw::print(num, x-4, y-3, LIGHT+(room==current_room?YELLOW:WHITE), BLACK);
|
||||
}
|
||||
if (minirooms[room].exits[XN] != 255) drawRoom(minirooms[room].exits[XN], x-24, y-12);
|
||||
if (minirooms[room].exits[XP] != 255) drawRoom(minirooms[room].exits[XP], x+24, y+12);
|
||||
if (minirooms[room].exits[YN] != 255) drawRoom(minirooms[room].exits[YN], x+24, y-12);
|
||||
if (minirooms[room].exits[YP] != 255) drawRoom(minirooms[room].exits[YP], x-24, y+12);
|
||||
}
|
||||
|
||||
bool loop()
|
||||
{
|
||||
for (int i=0;i<64;++i) drawn[i]=false;
|
||||
|
||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE) || input::keyPressed(SDL_SCANCODE_TAB)) return false;
|
||||
|
||||
draw::cls(2);
|
||||
draw::setSource(surf);
|
||||
|
||||
draw::stencil::enable();
|
||||
draw::stencil::clear(255);
|
||||
|
||||
drawRoom(room::getCurrent(), scroll.x, scroll.y);
|
||||
draw::render();
|
||||
|
||||
if (input::mouseClk(1)) {
|
||||
const int clicked = draw::stencil::query(input::mouseX(), input::mouseY());
|
||||
if (clicked!=255) {
|
||||
room::load(clicked);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
source/m_editor_map.h
Normal file
10
source/m_editor_map.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace modules
|
||||
{
|
||||
namespace editor_map
|
||||
{
|
||||
void init();
|
||||
bool loop();
|
||||
}
|
||||
}
|
||||
@@ -265,16 +265,19 @@ namespace modules
|
||||
else
|
||||
return GAME_MENU;
|
||||
}
|
||||
if (input::keyPressed(SDL_SCANCODE_TAB) || input::keyPressed(SDL_SCANCODE_GRAVE) ) console::toggle();
|
||||
|
||||
// WHILE EDITING...
|
||||
if (editor::isEditing())
|
||||
{
|
||||
if (input::keyPressed(SDL_SCANCODE_TAB)) return GAME_EDITOR_MAP;
|
||||
|
||||
editor_move_selected();
|
||||
actor::updateEditor(actor::getFirst());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input::keyPressed(SDL_SCANCODE_TAB) || input::keyPressed(SDL_SCANCODE_GRAVE) ) console::toggle();
|
||||
|
||||
if (!console::update())
|
||||
{
|
||||
actor::update(actor::getFirst());
|
||||
@@ -375,7 +378,45 @@ namespace modules
|
||||
}
|
||||
|
||||
|
||||
draw::print2(room::getExit(XN), -2, 1, 1, TEAL, FONT_ZOOM_NONE);
|
||||
draw::print2(room::getExit(YN), -2, 38, 1, TEAL, FONT_ZOOM_NONE);
|
||||
draw::print2(room::getExit(XP), -2, 38, 28, TEAL, FONT_ZOOM_NONE);
|
||||
draw::print2(room::getExit(YP), -2, 1, 28, TEAL, FONT_ZOOM_NONE);
|
||||
draw::print2(room::getExit(ZP), -2, 19, 1, TEAL, FONT_ZOOM_NONE);
|
||||
draw::print2(room::getExit(ZN), -2, 19, 28, TEAL, FONT_ZOOM_NONE);
|
||||
|
||||
draw::print2(room::getCurrent(), -2, 4, 3, WHITE, FONT_ZOOM_BOTH);
|
||||
|
||||
if (input::mouseClk(1)) {
|
||||
const int mx = draw::getLocalX(input::mouseX());
|
||||
const int my = draw::getLocalY(input::mouseY());
|
||||
if (mx>=0 && my>=0 && mx<320 && my<240) {
|
||||
if (mx<32 && my<24) {
|
||||
int room = room::editor::refExit(XN);
|
||||
if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, XP);
|
||||
}
|
||||
if (mx>288 && my<24) {
|
||||
int room = room::editor::refExit(YN);
|
||||
if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, YP);
|
||||
}
|
||||
if (mx>288 && my>216) {
|
||||
int room = room::editor::refExit(XP);
|
||||
if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, XN);
|
||||
}
|
||||
if (mx<32 && my>216) {
|
||||
int room = room::editor::refExit(YP);
|
||||
if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, YN);
|
||||
}
|
||||
if (mx>144 && mx<176 && my<24) {
|
||||
int room = room::editor::refExit(ZP);
|
||||
if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, ZN);
|
||||
}
|
||||
if (mx>144 && mx<176 && my>216) {
|
||||
int room = room::editor::refExit(ZN);
|
||||
if (room>=0 || input::keyPressed(SDL_SCANCODE_LCTRL)) room::load(room, ZP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui::start();
|
||||
|
||||
@@ -412,6 +453,7 @@ namespace modules
|
||||
const int mx = draw::getLocalX(input::mouseX());
|
||||
const int my = draw::getLocalY(input::mouseY());
|
||||
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
|
||||
const bool btnClk = input::mouseClk(1) || input::mouseClk(3);
|
||||
|
||||
if (mx>=0 && mx <=100 && my>=0 && my<=221)
|
||||
{
|
||||
@@ -449,7 +491,7 @@ namespace modules
|
||||
draw::color(LIGHT+BLUE);
|
||||
draw::fillrect(4, 2+line*9, 92, 9);
|
||||
}
|
||||
if ((mx>=2) && (mx<98) && (my>=2+line*9) && (my<2+9+line*9) && btnDown) {
|
||||
if ((mx>=2) && (mx<98) && (my>=2+line*9) && (my<2+9+line*9) && btnClk) {
|
||||
if (i == room::editor::getCurrentRoom()) {
|
||||
section = SECTION_ACTOR;
|
||||
} else {
|
||||
@@ -464,7 +506,7 @@ namespace modules
|
||||
}
|
||||
} else if (section==SECTION_ACTOR)
|
||||
{
|
||||
if ((mx>=2) && (mx<98) && (my>=2+line*9) && (my<2+9+line*9) && btnDown) {
|
||||
if ((mx>=2) && (mx<98) && (my>=2+line*9) && (my<2+9+line*9) && btnClk) {
|
||||
section = SECTION_ROOM;
|
||||
}
|
||||
|
||||
@@ -482,7 +524,7 @@ namespace modules
|
||||
draw::color(LIGHT+BLUE);
|
||||
draw::fillrect(4, 2+line*9, 92, 9);
|
||||
}
|
||||
if ((mx>=2) && (mx<98) && (my>=2+line*9) && (my<2+9+line*9) && btnDown) {
|
||||
if ((mx>=2) && (mx<98) && (my>=2+line*9) && (my<2+9+line*9) && btnClk) {
|
||||
actor::select(act);
|
||||
section = SECTION_ACTOR;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace modules
|
||||
#define GAME_NONE -1
|
||||
#define GAME_MENU 0
|
||||
#define GAME_DEAD 1
|
||||
#define GAME_EDITOR_MAP 2
|
||||
|
||||
void init();
|
||||
int loop();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "m_catslife.h"
|
||||
#include "m_menu_tecles.h"
|
||||
#include "m_menu_audio.h"
|
||||
#include "m_editor_map.h"
|
||||
|
||||
#define M_LOGO 0
|
||||
#define M_MENU 1
|
||||
@@ -28,6 +29,8 @@
|
||||
#define M_CATSLIFE 5
|
||||
#define M_MENU_TECLES 6
|
||||
#define M_MENU_AUDIO 7
|
||||
#define M_EDITOR_MAP 8
|
||||
#define M_EDITOR_TEMPLATES 9
|
||||
|
||||
int current_module = M_LOGO;
|
||||
int zoom = 3;
|
||||
@@ -134,9 +137,16 @@ bool game::loop()
|
||||
} else {
|
||||
modules::gameover::init(); current_module = M_GAMEOVER;
|
||||
}
|
||||
} else if (option==GAME_EDITOR_MAP) {
|
||||
modules::editor_map::init(); current_module = M_EDITOR_MAP;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case M_EDITOR_MAP:
|
||||
if (!modules::editor_map::loop()) {
|
||||
current_module = M_GAME;
|
||||
}
|
||||
break;
|
||||
case M_INGAME:
|
||||
option = modules::ingame::loop();
|
||||
if (option != INGAME_NONE) {
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace room
|
||||
if (room > MAX_ROOMS || room < 0) {
|
||||
room = find_next_room();
|
||||
exits[inverse_door(door)] = room;
|
||||
if (door<4 && door_height[door]==-1) door_height[door]=0;
|
||||
if (door<4 && door_height[inverse_door(door)]==-1) door_height[inverse_door(door)]=0;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
@@ -446,6 +446,11 @@ namespace room
|
||||
num_color_cycles = times;
|
||||
}
|
||||
|
||||
int getCurrent()
|
||||
{
|
||||
return current_room;
|
||||
}
|
||||
|
||||
vec3_t getSize()
|
||||
{
|
||||
return size;
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace room
|
||||
void draw2();
|
||||
void cycleColor(int times);
|
||||
|
||||
int getCurrent();
|
||||
vec3_t getSize();
|
||||
vec3_t getMin();
|
||||
vec3_t getMax();
|
||||
|
||||
Reference in New Issue
Block a user