mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-29 13:03:43 +01:00
Merge pull request 'Add portal support' (#61) from portals into dev
Reviewed-on: https://git.planet-casio.com/Slyvtt/Collab_RPG/pulls/61
This commit is contained in:
commit
40bfea66aa
9 changed files with 120 additions and 27 deletions
|
@ -47,6 +47,8 @@ set(ASSETS
|
||||||
assets/level2.tmx
|
assets/level2.tmx
|
||||||
assets/level3.tmx
|
assets/level3.tmx
|
||||||
assets/level4.tmx
|
assets/level4.tmx
|
||||||
|
assets/interior1_0_dialogs.json
|
||||||
|
assets/interior1_0.tmx
|
||||||
# ...
|
# ...
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,9 @@ def convert_map(input: str, output: str, params: dict, target):
|
||||||
npc_paths = {}
|
npc_paths = {}
|
||||||
npcs = {}
|
npcs = {}
|
||||||
signs = {}
|
signs = {}
|
||||||
|
portals = {}
|
||||||
|
|
||||||
|
name = os.path.splitext(os.path.basename(input))[0]
|
||||||
|
|
||||||
map_struct = fxconv.Structure()
|
map_struct = fxconv.Structure()
|
||||||
|
|
||||||
|
@ -226,6 +229,17 @@ def convert_map(input: str, output: str, params: dict, target):
|
||||||
"icon": SIGN_TYPES.index(object.type)
|
"icon": SIGN_TYPES.index(object.type)
|
||||||
}
|
}
|
||||||
signs[object.id] = data
|
signs[object.id] = data
|
||||||
|
# Get the portals
|
||||||
|
for object in ed_objgroup.objects:
|
||||||
|
if (object.get_data_type() == "rectangle"
|
||||||
|
and object.type == "PORTAL"):
|
||||||
|
data = {
|
||||||
|
"rect": object.get_data(),
|
||||||
|
"name": object.name,
|
||||||
|
"dest": object.get_property("dest"),
|
||||||
|
"destPortal": object.get_property("destPortal")
|
||||||
|
}
|
||||||
|
portals[object.id] = data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Show a simple error message on failure.
|
# Show a simple error message on failure.
|
||||||
sys.stderr.write(f"ERROR: Failed to get the extra data.\n"
|
sys.stderr.write(f"ERROR: Failed to get the extra data.\n"
|
||||||
|
@ -297,8 +311,24 @@ def convert_map(input: str, output: str, params: dict, target):
|
||||||
sign_struct += fxconv.u32(i["needAction"])
|
sign_struct += fxconv.u32(i["needAction"])
|
||||||
map_struct += fxconv.ptr(sign_struct)
|
map_struct += fxconv.ptr(sign_struct)
|
||||||
# Load portals
|
# Load portals
|
||||||
map_struct += fxconv.u32(0) # TODO: Portal support in-game
|
map_struct += fxconv.u32(len(portals))
|
||||||
map_struct += fxconv.ptr(bytes())
|
portal_struct = fxconv.Structure()
|
||||||
|
for i in portals.values():
|
||||||
|
dest_file_name = os.path.splitext(os.path.basename(i["dest"]))[0]
|
||||||
|
dest_portal = i["destPortal"]
|
||||||
|
portal_name = i["name"]
|
||||||
|
if VERBOSE: print(f"INFO: Storing portal {name}_{portal_name}")
|
||||||
|
portal_struct += fxconv.sym(f"{name}_{portal_name}")
|
||||||
|
# Add the collider
|
||||||
|
rect = i["rect"]
|
||||||
|
portal_struct += fxconv.u32(rect[0])
|
||||||
|
portal_struct += fxconv.u32(rect[1])
|
||||||
|
portal_struct += fxconv.u32(rect[2])
|
||||||
|
portal_struct += fxconv.u32(rect[3])
|
||||||
|
# Add a reference to the destination portal
|
||||||
|
portal_struct += fxconv.ref(f"{dest_file_name}_{dest_portal}")
|
||||||
|
portal_struct += fxconv.ref(f"{dest_file_name}")
|
||||||
|
map_struct += fxconv.ptr(portal_struct)
|
||||||
map_struct += fxconv.u32(dialog_num)
|
map_struct += fxconv.u32(dialog_num)
|
||||||
|
|
||||||
# Get the name of the dialog file and create a reference to it: it is built
|
# Get the name of the dialog file and create a reference to it: it is built
|
||||||
|
@ -319,7 +349,6 @@ def convert_map(input: str, output: str, params: dict, target):
|
||||||
map_struct += fxconv.ptr(foreground_data)
|
map_struct += fxconv.ptr(foreground_data)
|
||||||
|
|
||||||
# Create the fxconv object
|
# Create the fxconv object
|
||||||
name = os.path.splitext(os.path.basename(input))[0]
|
|
||||||
fxconv.elf(map_struct, output, f"_{name}", **target)
|
fxconv.elf(map_struct, output, f"_{name}", **target)
|
||||||
|
|
||||||
def convert_dialog(input: str, output: str, params: dict, target):
|
def convert_dialog(input: str, output: str, params: dict, target):
|
||||||
|
|
|
@ -37,3 +37,11 @@ level3_dialogs.json:
|
||||||
level4_dialogs.json:
|
level4_dialogs.json:
|
||||||
custom-type: dialog
|
custom-type: dialog
|
||||||
name: level4_dialogs
|
name: level4_dialogs
|
||||||
|
|
||||||
|
interior1_0.tmx:
|
||||||
|
custom-type: tmx
|
||||||
|
name: level0
|
||||||
|
|
||||||
|
interior1_0_dialogs.json:
|
||||||
|
custom-type: dialog
|
||||||
|
name: interior1_0_dialogs
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<map version="1.8" tiledversion="1.8.2" orientation="orthogonal" renderorder="right-down" width="12" height="8" tilewidth="8" tileheight="8" infinite="0" nextlayerid="5" nextobjectid="2">
|
<map version="1.8" tiledversion="1.8.2" orientation="orthogonal" renderorder="right-down" width="12" height="8" tilewidth="8" tileheight="8" infinite="0" nextlayerid="5" nextobjectid="3">
|
||||||
|
<properties>
|
||||||
|
<property name="dialogFile" type="file" value="interior1_0_dialogs.json"/>
|
||||||
|
<property name="mapX" type="int" value="65536"/>
|
||||||
|
<property name="mapY" type="int" value="65536"/>
|
||||||
|
</properties>
|
||||||
<tileset firstgid="1" source="tilesetnpp.tsx"/>
|
<tileset firstgid="1" source="tilesetnpp.tsx"/>
|
||||||
<tileset firstgid="409" source="Walkable.tsx"/>
|
<tileset firstgid="409" source="Walkable.tsx"/>
|
||||||
<layer id="1" name="Background" width="12" height="8">
|
<layer id="1" name="Background" width="12" height="8">
|
||||||
|
@ -9,9 +14,9 @@
|
||||||
86,93,94,1,1,1,1,1,9,10,1,92,
|
86,93,94,1,1,1,1,1,9,10,1,92,
|
||||||
110,117,118,1,1,1,1,1,33,34,1,116,
|
110,117,118,1,1,1,1,1,33,34,1,116,
|
||||||
86,1,1,1,1,1,1,1,1,1,1,92,
|
86,1,1,1,1,1,1,1,1,1,1,92,
|
||||||
110,1,1,1,1,1,1,1,1,1,1,116,
|
110,1,1,1,1,133,2,1,1,1,1,116,
|
||||||
110,1,1,1,1,133,2,1,1,1,1,92,
|
110,1,1,1,1,2,2,1,1,1,1,92,
|
||||||
110,1,1,1,1,2,2,1,1,1,1,116
|
110,114,114,114,114,114,114,114,114,114,114,116
|
||||||
</data>
|
</data>
|
||||||
</layer>
|
</layer>
|
||||||
<layer id="2" name="Foreground" width="12" height="8">
|
<layer id="2" name="Foreground" width="12" height="8">
|
||||||
|
@ -35,18 +40,15 @@
|
||||||
410,0,0,0,0,0,0,0,0,0,0,410,
|
410,0,0,0,0,0,0,0,0,0,0,410,
|
||||||
410,0,0,0,0,0,0,0,0,0,0,410,
|
410,0,0,0,0,0,0,0,0,0,0,410,
|
||||||
410,0,0,0,0,0,0,0,0,0,0,410,
|
410,0,0,0,0,0,0,0,0,0,0,410,
|
||||||
410,0,0,0,0,0,0,0,0,0,0,410
|
410,410,410,410,410,410,410,410,410,410,410,410
|
||||||
</data>
|
</data>
|
||||||
</layer>
|
</layer>
|
||||||
<objectgroup id="4" name="ExtraData">
|
<objectgroup id="4" name="ExtraData">
|
||||||
<object id="1" name="Porte" type="PORTAL" x="47.862" y="63.6163">
|
<object id="2" name="porte" type="PORTAL" x="39.6736" y="40.0979" width="15.8058" height="15.9119">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="h" value="1"/>
|
<property name="dest" type="file" value="level0.tmx"/>
|
||||||
<property name="tp_interior" value="0"/>
|
<property name="destPortal" value="taverne"/>
|
||||||
<property name="tp_to" value="0"/>
|
|
||||||
<property name="w" value="2"/>
|
|
||||||
</properties>
|
</properties>
|
||||||
<point/>
|
|
||||||
</object>
|
</object>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
</map>
|
</map>
|
13
assets/interior1_0_dialogs.json
Normal file
13
assets/interior1_0_dialogs.json
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{ "dialogs":[
|
||||||
|
{ "ID":0,
|
||||||
|
"dialog":"_",
|
||||||
|
"isQuestion":0,
|
||||||
|
"choice":"_",
|
||||||
|
"conclusion1":"_",
|
||||||
|
"next1":-1,
|
||||||
|
"conclusion2":"_",
|
||||||
|
"next2":-1,
|
||||||
|
"nextOther":1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<map version="1.8" tiledversion="1.8.2" orientation="orthogonal" renderorder="right-down" width="48" height="24" tilewidth="8" tileheight="8" infinite="0" nextlayerid="8" nextobjectid="14">
|
<map version="1.8" tiledversion="1.8.2" orientation="orthogonal" renderorder="right-down" width="48" height="24" tilewidth="8" tileheight="8" infinite="0" nextlayerid="8" nextobjectid="17">
|
||||||
<editorsettings>
|
<editorsettings>
|
||||||
<export target="level0.json" format="json"/>
|
<export target="level0.json" format="json"/>
|
||||||
</editorsettings>
|
</editorsettings>
|
||||||
|
@ -173,5 +173,11 @@
|
||||||
<object id="13" name="Chemin 100pas Client Auberge" type="TRJ" x="267.25" y="126.25">
|
<object id="13" name="Chemin 100pas Client Auberge" type="TRJ" x="267.25" y="126.25">
|
||||||
<polyline points="0,0 -30.5,16.75 -182.5,15.75 -195.25,-26 -183.25,16.5 -29.25,18.5"/>
|
<polyline points="0,0 -30.5,16.75 -182.5,15.75 -195.25,-26 -183.25,16.5 -29.25,18.5"/>
|
||||||
</object>
|
</object>
|
||||||
|
<object id="16" name="taverne" type="PORTAL" x="128.974" y="111.676" width="14.7688" height="7.99134">
|
||||||
|
<properties>
|
||||||
|
<property name="dest" type="file" value="interior1_0.tmx"/>
|
||||||
|
<property name="destPortal" value="porte"/>
|
||||||
|
</properties>
|
||||||
|
</object>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
</map>
|
</map>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit f426664f4444d4c8a6054bc7b69fb676ed43bcaa
|
Subproject commit b084ecda91a2352a72a5d1a61b37e0009228ee40
|
41
src/game.c
41
src/game.c
|
@ -82,11 +82,20 @@ void game_logic(Game *game) {
|
||||||
|
|
||||||
void game_render_indicator(Game *game) {
|
void game_render_indicator(Game *game) {
|
||||||
/* nothing to do for the player so we quit */
|
/* nothing to do for the player so we quit */
|
||||||
if(game->player.canDoSomething == false)
|
if(game->player.canDoSomething)
|
||||||
return;
|
|
||||||
|
|
||||||
/* else we draw a small indicator on the screen */
|
|
||||||
dimage(5, 5, &SignAction_img);
|
dimage(5, 5, &SignAction_img);
|
||||||
|
int i;
|
||||||
|
Player *player = &game->player;
|
||||||
|
for(i=0;i<game->map_level->nbPortal;i++){
|
||||||
|
Portal *portal = &game->map_level->portals[i];
|
||||||
|
if(player->x >= portal->collider.x1*PXSIZE &&
|
||||||
|
player->x < portal->collider.x2*PXSIZE &&
|
||||||
|
player->y >= portal->collider.y1*PXSIZE &&
|
||||||
|
player->y < portal->collider.y2*PXSIZE){
|
||||||
|
dimage(5, 5, &SignAction_img);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_draw(Game *game) {
|
void game_draw(Game *game) {
|
||||||
|
@ -100,6 +109,7 @@ void game_draw(Game *game) {
|
||||||
/*DEBUG*/
|
/*DEBUG*/
|
||||||
dprint(8, 8, C_BLACK, "Lifes: %d", game->player.life);
|
dprint(8, 8, C_BLACK, "Lifes: %d", game->player.life);
|
||||||
dprint(8, 16, C_BLACK, "Mana: %d", game->mana);
|
dprint(8, 16, C_BLACK, "Mana: %d", game->mana);
|
||||||
|
dprint(8, 24, C_BLACK, "X: %d Y: %d", game->player.x, game->player.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Key management */
|
/* Key management */
|
||||||
|
@ -133,6 +143,29 @@ void game_get_inputs(Game *game) {
|
||||||
sleep();
|
sleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Player *player = &game->player;
|
||||||
|
if(keydown(KEY_SHIFT)){
|
||||||
|
int i;
|
||||||
|
for(i=0;i<game->map_level->nbPortal;i++){
|
||||||
|
Portal *portal = &game->map_level->portals[i];
|
||||||
|
if(player->x >= portal->collider.x1*PXSIZE &&
|
||||||
|
player->x < portal->collider.x2*PXSIZE &&
|
||||||
|
player->y >= portal->collider.y1*PXSIZE &&
|
||||||
|
player->y < portal->collider.y2*PXSIZE){
|
||||||
|
Portal *dest_portal = (Portal*)portal->portal;
|
||||||
|
Collider dest_collider = dest_portal->collider;
|
||||||
|
Map *dest_map = (Map*)portal->map;
|
||||||
|
player->x = (dest_collider.x1+dest_collider.x2)/2*PXSIZE;
|
||||||
|
player->y = (dest_collider.y1+dest_collider.y2)/2*PXSIZE;
|
||||||
|
game->map_level = dest_map;
|
||||||
|
/* TODO: Make something cleaner */
|
||||||
|
while(keydown(KEY_SHIFT)) {
|
||||||
|
clearevents();
|
||||||
|
sleep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Display Debug Information on screen */
|
/* Display Debug Information on screen */
|
||||||
#if DEBUGMODE
|
#if DEBUGMODE
|
||||||
|
|
12
src/game.h
12
src/game.h
|
@ -12,8 +12,8 @@ typedef enum { D_UP, D_DOWN, D_LEFT, D_RIGHT } Direction;
|
||||||
typedef enum { P_LEFTUP = -1, P_CENTER = 0, P_RIGHTDOWN = 1 } Checkpos;
|
typedef enum { P_LEFTUP = -1, P_CENTER = 0, P_RIGHTDOWN = 1 } Checkpos;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t x, y;
|
uint32_t x1, y1;
|
||||||
uint32_t w, h;
|
uint32_t x2, y2;
|
||||||
|
|
||||||
} Collider;
|
} Collider;
|
||||||
|
|
||||||
|
@ -109,10 +109,10 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Collider collider;
|
Collider collider;
|
||||||
/*if the portal tps to an interior or exterior map*/
|
/* The destination portal */
|
||||||
uint16_t tp_interior;
|
void *portal;
|
||||||
/*Id of the interior/exterior map to transport the player to*/
|
/* The destination map */
|
||||||
uint16_t tp_to;
|
void *map;
|
||||||
} Portal;
|
} Portal;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in a new issue