mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-29 13:03:43 +01:00
Revert "Revert "Première compilation refactoring ExtraData""
This reverts commit 35a7a5f923
.
This commit is contained in:
parent
35a7a5f923
commit
dae4bd8a55
11 changed files with 577 additions and 520 deletions
|
@ -251,7 +251,15 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
|
||||||
#create the structure of the map
|
#create the structure of the map
|
||||||
structData = fxconv.Structure()
|
structData = fxconv.Structure()
|
||||||
|
|
||||||
nbExtraData = 0
|
nbSign = 0
|
||||||
|
nbNPC = 0
|
||||||
|
nbPortal = 0
|
||||||
|
nbDiag = 0
|
||||||
|
|
||||||
|
npcs = fxconv.Structure()
|
||||||
|
signs = fxconv.Structure()
|
||||||
|
portals = fxconv.Structure()
|
||||||
|
|
||||||
layer = data["layers"][layer_extradata]
|
layer = data["layers"][layer_extradata]
|
||||||
for i in layer["objects"]:
|
for i in layer["objects"]:
|
||||||
|
|
||||||
|
@ -260,8 +268,8 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
|
||||||
|
|
||||||
#we check if the type corresponds to a items of type Point in Tiled
|
#we check if the type corresponds to a items of type Point in Tiled
|
||||||
if tpe in ( "SGN", "NPC", "INFO"):
|
if tpe in ( "SGN", "NPC", "INFO"):
|
||||||
|
currData = fxconv.Structure()
|
||||||
|
|
||||||
nbExtraData = nbExtraData + 1
|
|
||||||
x = i["x"] + xmin
|
x = i["x"] + xmin
|
||||||
y = i["y"] + ymin
|
y = i["y"] + ymin
|
||||||
nme = i["name"]
|
nme = i["name"]
|
||||||
|
@ -278,7 +286,9 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
|
||||||
#we now fill all the properties of this item
|
#we now fill all the properties of this item
|
||||||
for j in i["properties"]:
|
for j in i["properties"]:
|
||||||
#property "dialog"
|
#property "dialog"
|
||||||
if j["name"]=="dialogID": dialogID = j[ "value" ]
|
if j["name"]=="dialogID":
|
||||||
|
dialogID = j[ "value" ]
|
||||||
|
nbDiag += 1
|
||||||
#property "isQuestion"
|
#property "isQuestion"
|
||||||
elif j["name"]=="needAction": needAction = j[ "value" ]
|
elif j["name"]=="needAction": needAction = j[ "value" ]
|
||||||
|
|
||||||
|
@ -314,7 +324,6 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if DEBUG: print( "PNJ has no Path" )
|
if DEBUG: print( "PNJ has no Path" )
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print( "UNIDENTIFIED PROPERTY : ", j["name"])
|
print( "UNIDENTIFIED PROPERTY : ", j["name"])
|
||||||
|
|
||||||
|
@ -325,35 +334,83 @@ def get_extra_map_data(input, output, params, target, xmin, ymin, xmax, ymax):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
structData += fxconv.u32( int(x) )
|
currData += fxconv.u32( int(x) )
|
||||||
structData += fxconv.u32( int(y) )
|
currData += fxconv.u32( int(y) )
|
||||||
structData += fxconv.string( nme )
|
currData += fxconv.string( nme )
|
||||||
structData += fxconv.string( tpe )
|
currData += fxconv.string( tpe )
|
||||||
structData += fxconv.string(face_type)
|
currData += fxconv.string(face_type)
|
||||||
structData += fxconv.u32( int(dialogID) )
|
currData += fxconv.u32( int(dialogID) )
|
||||||
structData += fxconv.u32( int(needAction) )
|
currData += fxconv.u32( int(needAction) )
|
||||||
|
|
||||||
if path==0:
|
if path==0:
|
||||||
structData += fxconv.u32(0)
|
currData += fxconv.u32(0)
|
||||||
structData += fxconv.u32(0)
|
currData += fxconv.u32(0)
|
||||||
structData += fxconv.u32(0)
|
currData += fxconv.u32(0)
|
||||||
structData += fxconv.u32(0)
|
currData += fxconv.u32(0)
|
||||||
else:
|
else:
|
||||||
o_xdata = fxconv.Structure()
|
o_xdata = fxconv.Structure()
|
||||||
o_xdata += xdata
|
o_xdata += xdata
|
||||||
o_ydata = fxconv.Structure()
|
o_ydata = fxconv.Structure()
|
||||||
o_ydata += ydata
|
o_ydata += ydata
|
||||||
|
|
||||||
structData += fxconv.u32(path)
|
currData += fxconv.u32(path)
|
||||||
structData += fxconv.u32(path_length)
|
currData += fxconv.u32(path_length)
|
||||||
structData += fxconv.ptr(o_xdata)
|
currData += fxconv.ptr(o_xdata)
|
||||||
structData += fxconv.ptr(o_ydata)
|
currData += fxconv.ptr(o_ydata)
|
||||||
|
|
||||||
#else we do nothing (yet)
|
if tpe == "SGN" or tpe == "INFO":
|
||||||
|
nbSign += 1
|
||||||
|
signs += currData
|
||||||
else:
|
else:
|
||||||
if DEBUG: print( "Skip this object" )
|
nbNPC += 1
|
||||||
|
signs += currData
|
||||||
|
|
||||||
return nbExtraData, structData
|
elif tpe == "PORTAL":
|
||||||
|
nbPortal+=1
|
||||||
|
currData = fxconv.Structure()
|
||||||
|
|
||||||
|
x = i["x"] + xmin
|
||||||
|
y = i["y"] + ymin
|
||||||
|
h = -1
|
||||||
|
w = -1
|
||||||
|
tp_interior = -1
|
||||||
|
tp_to = -1
|
||||||
|
|
||||||
|
for j in i["properties"]:
|
||||||
|
if j["name"] == "h":
|
||||||
|
h = j["value"]
|
||||||
|
if j["name"] == "w":
|
||||||
|
w = j["value"]
|
||||||
|
if j["name"] == "tp_interior":
|
||||||
|
tp_interior = j["value"]
|
||||||
|
if j["name"] == "tp_to":
|
||||||
|
tp_to = j["value"]
|
||||||
|
|
||||||
|
if w==-1 or h==-1 or tp_interior==-1 or tp_to==-1:
|
||||||
|
print("ERROR : Invalid portal " + i["ID"])
|
||||||
|
continue
|
||||||
|
|
||||||
|
currData += fxconv.u32(int(x))
|
||||||
|
currData += fxconv.u32(int(y))
|
||||||
|
currData += fxconv.u32(int(w))
|
||||||
|
currData += fxconv.u32(int(h))
|
||||||
|
currData += fxconv.u16(int(tp_interior))
|
||||||
|
currData += fxconv.u16(int(tp_to))
|
||||||
|
|
||||||
|
portals += currData
|
||||||
|
|
||||||
|
#else we do nothing
|
||||||
|
else:
|
||||||
|
print( "Unknown object type !" )
|
||||||
|
|
||||||
|
structData += fxconv.u32(nbNPC)
|
||||||
|
structData += fxconv.ptr(npcs)
|
||||||
|
structData += fxconv.u32(nbSign)
|
||||||
|
structData += fxconv.ptr(signs)
|
||||||
|
structData += fxconv.u32(nbPortal)
|
||||||
|
structData += fxconv.ptr(portals)
|
||||||
|
|
||||||
|
return nbDiag, structData
|
||||||
|
|
||||||
|
|
||||||
def convert_custom_image(input, output, params, target):
|
def convert_custom_image(input, output, params, target):
|
||||||
|
|
52
assets/interior1-0.tmx
Normal file
52
assets/interior1-0.tmx
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?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">
|
||||||
|
<tileset firstgid="1" source="tilesetnpp.tsx"/>
|
||||||
|
<tileset firstgid="409" source="Walkable.tsx"/>
|
||||||
|
<layer id="1" name="Background" width="12" height="8">
|
||||||
|
<data encoding="csv">
|
||||||
|
86,90,91,89,90,91,89,90,91,89,90,92,
|
||||||
|
110,114,115,113,114,115,113,114,115,113,114,116,
|
||||||
|
86,93,94,1,1,1,1,1,9,10,1,92,
|
||||||
|
110,117,118,1,1,1,1,1,33,34,1,116,
|
||||||
|
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,92,
|
||||||
|
110,1,1,1,1,2,2,1,1,1,1,116
|
||||||
|
</data>
|
||||||
|
</layer>
|
||||||
|
<layer id="2" name="Foreground" width="12" height="8">
|
||||||
|
<data encoding="csv">
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0,
|
||||||
|
0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
</data>
|
||||||
|
</layer>
|
||||||
|
<layer id="3" name="Walkable" width="12" height="8">
|
||||||
|
<data encoding="csv">
|
||||||
|
410,410,410,410,410,410,410,410,410,410,410,410,
|
||||||
|
410,410,410,410,410,410,410,410,410,410,410,410,
|
||||||
|
410,410,410,0,0,0,0,0,410,0,0,410,
|
||||||
|
410,410,410,0,0,0,0,0,410,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
|
||||||
|
</data>
|
||||||
|
</layer>
|
||||||
|
<objectgroup id="4" name="ExtraData">
|
||||||
|
<object id="1" name="Porte" type="PORTAL" x="47.862" y="63.6163">
|
||||||
|
<properties>
|
||||||
|
<property name="h" value="1"/>
|
||||||
|
<property name="tp_interior" value="0"/>
|
||||||
|
<property name="tp_to" value="0"/>
|
||||||
|
<property name="w" value="2"/>
|
||||||
|
</properties>
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
</objectgroup>
|
||||||
|
</map>
|
|
@ -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="15">
|
||||||
<editorsettings>
|
<editorsettings>
|
||||||
<export target="level0.json" format="json"/>
|
<export target="level0.json" format="json"/>
|
||||||
</editorsettings>
|
</editorsettings>
|
||||||
|
@ -117,7 +117,6 @@
|
||||||
<object id="12" name="PNJ3" type="NPC" x="267.25" y="125.75">
|
<object id="12" name="PNJ3" type="NPC" x="267.25" y="125.75">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="dialogID" type="int" value="12"/>
|
<property name="dialogID" type="int" value="12"/>
|
||||||
<property name="face" value="FEMALE"/>
|
|
||||||
<property name="hasPath" type="int" value="1"/>
|
<property name="hasPath" type="int" value="1"/>
|
||||||
<property name="needAction" type="int" value="1"/>
|
<property name="needAction" type="int" value="1"/>
|
||||||
<property name="path" type="object" value="13"/>
|
<property name="path" type="object" value="13"/>
|
||||||
|
@ -127,7 +126,6 @@
|
||||||
<object id="2" name="PNJ2" type="NPC" x="164" y="132">
|
<object id="2" name="PNJ2" type="NPC" x="164" y="132">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="dialogID" type="int" value="5"/>
|
<property name="dialogID" type="int" value="5"/>
|
||||||
<property name="face" value="MALE"/>
|
|
||||||
<property name="hasPath" type="int" value="0"/>
|
<property name="hasPath" type="int" value="0"/>
|
||||||
<property name="needAction" type="int" value="1"/>
|
<property name="needAction" type="int" value="1"/>
|
||||||
<property name="path" type="object" value="0"/>
|
<property name="path" type="object" value="0"/>
|
||||||
|
@ -137,7 +135,6 @@
|
||||||
<object id="10" name="PNJ1" type="NPC" x="252" y="164">
|
<object id="10" name="PNJ1" type="NPC" x="252" y="164">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="dialogID" type="int" value="7"/>
|
<property name="dialogID" type="int" value="7"/>
|
||||||
<property name="face" value="MILKMAN"/>
|
|
||||||
<property name="hasPath" type="int" value="1"/>
|
<property name="hasPath" type="int" value="1"/>
|
||||||
<property name="needAction" type="int" value="1"/>
|
<property name="needAction" type="int" value="1"/>
|
||||||
<property name="path" type="object" value="9"/>
|
<property name="path" type="object" value="9"/>
|
||||||
|
@ -171,5 +168,14 @@
|
||||||
<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="14" name="PorteAuberge" type="PORTAL" x="136.094" y="119.871">
|
||||||
|
<properties>
|
||||||
|
<property name="h" value="1"/>
|
||||||
|
<property name="tp_interior" value="1"/>
|
||||||
|
<property name="tp_to" value="0"/>
|
||||||
|
<property name="w" value="2"/>
|
||||||
|
</properties>
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
</map>
|
</map>
|
||||||
|
|
72
src/game.c
72
src/game.c
|
@ -16,58 +16,58 @@
|
||||||
extern bopti_image_t SignAction_img;
|
extern bopti_image_t SignAction_img;
|
||||||
|
|
||||||
extern Dialog *dialogRPG;
|
extern Dialog *dialogRPG;
|
||||||
extern NPC *npcRPG;
|
//extern NPC *npcRPG;
|
||||||
extern uint32_t nbNPC;
|
//extern uint32_t nbNPC;
|
||||||
|
|
||||||
#define MAX_INTERACTION_DISTANCE 12
|
#define MAX_INTERACTION_DISTANCE 12
|
||||||
|
|
||||||
|
void interaction_available(Game *game)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
void game_logic(Game *game) {
|
/*NPCs take priority over signs*/
|
||||||
|
|
||||||
update_npcs( game );
|
for(uint32_t i=0; i<game->map_level->nbNPC; i++){
|
||||||
|
if(!game->map_level->npcs[i].has_dialogue) continue;
|
||||||
|
|
||||||
/* we check if interactions are possible close to the player */
|
|
||||||
for( uint32_t i=0; i<game->map_level->nbextradata; i++ ){
|
|
||||||
/* simple distance check along X and Y axis */
|
/* simple distance check along X and Y axis */
|
||||||
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
||||||
if ((abs((int) game->player.wx -
|
if ((abs((int) game->player.wx -
|
||||||
(int) game->map_level->extradata[i].x*PXSIZE )
|
(int) game->map_level->npcs[i].curx*PXSIZE )
|
||||||
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
||||||
&& (abs((int) game->player.wy -
|
&& (abs((int) game->player.wy -
|
||||||
(int) game->map_level->extradata[i].y*PXSIZE )
|
(int) game->map_level->npcs[i].cury*PXSIZE )
|
||||||
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
< MAX_INTERACTION_DISTANCE*PXSIZE)){
|
||||||
&& strcmp(game->map_level->extradata[i].type, "NPC") != 0){
|
|
||||||
/* the player can do something */
|
/* the player can do something */
|
||||||
game->player.canDoSomething = true;
|
game->player.canDoSomething = true;
|
||||||
/* we mark the action for futur treatment in player_action() */
|
/* we mark the action for futur treatment in player_action() */
|
||||||
game->player.whichAction = i;
|
game->player.whichAction = i;
|
||||||
|
/* this is an interraction with a NPC */
|
||||||
|
game->player.isInteractingWithNPC = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < game->map_level->nbSign; i++){
|
||||||
|
/* simple distance check along X and Y axis */
|
||||||
|
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
||||||
|
if ((abs((int) game->player.wx -
|
||||||
|
(int) game->map_level->signs[i].x*PXSIZE )
|
||||||
|
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
||||||
|
&& (abs((int) game->player.wy -
|
||||||
|
(int) game->map_level->signs[i].y*PXSIZE )
|
||||||
|
< MAX_INTERACTION_DISTANCE*PXSIZE))
|
||||||
|
{
|
||||||
|
/* the player can do something */
|
||||||
|
game->player.canDoSomething = true;
|
||||||
|
/* we mark the action for future treatment in player_action() */
|
||||||
|
game->player.whichAction = i;
|
||||||
/* this is not an interraction with a NPC */
|
/* this is not an interraction with a NPC */
|
||||||
game->player.isInteractingWithNPC = false;
|
game->player.isInteractingWithNPC = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32_t i=0; i<nbNPC; i++){
|
|
||||||
/* simple distance check along X and Y axis */
|
|
||||||
/* Be careful to use world coordinates, not local (i.e.map) ones */
|
|
||||||
if ((abs((int) game->player.wx -
|
|
||||||
(int) npcRPG[i].curx*PXSIZE )
|
|
||||||
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
|
||||||
&& (abs((int) game->player.wy -
|
|
||||||
(int) npcRPG[i].cury*PXSIZE )
|
|
||||||
< MAX_INTERACTION_DISTANCE*PXSIZE)
|
|
||||||
&& strcmp( game->map_level->extradata[i].type, "NPC") !=0){
|
|
||||||
/* the player can do something */
|
|
||||||
game->player.canDoSomething = true;
|
|
||||||
/* we mark the action for futur treatment in player_action() */
|
|
||||||
game->player.whichAction = i;
|
|
||||||
/* this is not an interraction with a NPC */
|
|
||||||
game->player.isInteractingWithNPC = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* else nothing to be done here */
|
/* else nothing to be done here */
|
||||||
game->player.canDoSomething = false;
|
game->player.canDoSomething = false;
|
||||||
game->player.whichAction = -1;
|
game->player.whichAction = -1;
|
||||||
|
@ -75,6 +75,15 @@ void game_logic(Game *game) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void game_logic(Game *game) {
|
||||||
|
|
||||||
|
update_npcs( game );
|
||||||
|
|
||||||
|
/* we check if interactions are possible close to the player */
|
||||||
|
|
||||||
|
interaction_available(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 */
|
||||||
|
@ -93,6 +102,7 @@ void game_draw(Game *game) {
|
||||||
player_draw(game);
|
player_draw(game);
|
||||||
map_render_by_layer(game, FOREGROUND);
|
map_render_by_layer(game, FOREGROUND);
|
||||||
game_render_indicator(game);
|
game_render_indicator(game);
|
||||||
|
/*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);
|
||||||
}
|
}
|
||||||
|
|
76
src/game.h
76
src/game.h
|
@ -23,7 +23,12 @@ typedef enum {
|
||||||
P_RIGHTDOWN = 1
|
P_RIGHTDOWN = 1
|
||||||
} Checkpos;
|
} Checkpos;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t x,y;
|
||||||
|
uint32_t w,h;
|
||||||
|
|
||||||
|
} Collider;
|
||||||
|
|
||||||
/* Struct that define player parameters */
|
/* Struct that define player parameters */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -63,33 +68,68 @@ typedef struct {
|
||||||
int32_t nextOther;
|
int32_t nextOther;
|
||||||
} Dialog;
|
} Dialog;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
typedef struct {
|
{
|
||||||
/* position of the item */
|
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
uint32_t y;
|
uint32_t y;
|
||||||
/* its name */
|
/*id of it's icon*/
|
||||||
|
uint16_t icon;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
/* its class (NPC, SGN, INFO, ... )*/
|
|
||||||
char *type;
|
|
||||||
char *face;
|
|
||||||
|
|
||||||
/* the ID of the first element of the dialog */
|
/* the ID of the first element of the dialog */
|
||||||
/* (to be aligned with "dialogs.json" IDs)*/
|
/* (to be aligned with "dialogs.json" IDs)*/
|
||||||
uint32_t dialogID;
|
uint32_t dialogID;
|
||||||
/* 0 if imperative dialog (story mode) */
|
/*if the dialog is interactive or not*/
|
||||||
/* or 1 if the player need to press [SHIFT] to initiate the sequence*/
|
|
||||||
uint32_t needAction;
|
uint32_t needAction;
|
||||||
|
|
||||||
|
} Sign;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
/* current coordinates of the NPC */
|
||||||
|
float curx, cury;
|
||||||
|
|
||||||
|
/* initial coordinates of the NPC (needed to get absolute coordinates of path) */
|
||||||
|
uint32_t x;
|
||||||
|
uint32_t y;
|
||||||
|
/* id of it's face*/
|
||||||
|
uint16_t face;
|
||||||
|
|
||||||
|
bool paused;
|
||||||
|
|
||||||
|
bool has_dialogue;
|
||||||
|
/* the ID of the first element of the dialog */
|
||||||
|
/* (to be aligned with "dialogs.json" IDs)*/
|
||||||
|
uint32_t dialogID;
|
||||||
|
/*if the dialog is interactive or not*/
|
||||||
|
uint32_t needAction;
|
||||||
|
|
||||||
|
char *name;
|
||||||
|
|
||||||
/* data for NPC's trajectories */
|
/* data for NPC's trajectories */
|
||||||
uint32_t hasPath;
|
uint32_t hasPath;
|
||||||
uint32_t path_length;
|
uint32_t path_length;
|
||||||
|
uint32_t currentPoint;
|
||||||
int16_t *xpath;
|
int16_t *xpath;
|
||||||
int16_t *ypath;
|
int16_t *ypath;
|
||||||
|
|
||||||
/* ... this can be extended as per needs ... */
|
int type;
|
||||||
} ExtraData;
|
|
||||||
|
|
||||||
|
int8_t current_group;
|
||||||
|
int8_t hostile_to_group;
|
||||||
|
|
||||||
|
} NPC;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
|
||||||
|
Collider collider;
|
||||||
|
/*if the portal tps to an interior or exterior map*/
|
||||||
|
uint16_t tp_interior;
|
||||||
|
/*Id of the interior/exterior map to transport the player to*/
|
||||||
|
uint16_t tp_to;
|
||||||
|
|
||||||
|
} Portal;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* width, height and the number of layer of the map */
|
/* width, height and the number of layer of the map */
|
||||||
|
@ -112,11 +152,15 @@ typedef struct {
|
||||||
/* this is given by the layer Walkable of the map in Tiled */
|
/* this is given by the layer Walkable of the map in Tiled */
|
||||||
uint8_t *walkable;
|
uint8_t *walkable;
|
||||||
|
|
||||||
/* structure that contains all the items on the map to interract with */
|
|
||||||
/* each portion of the map has its own list to avoid scrutinizing too much */
|
uint32_t nbNPC;
|
||||||
/* data when lloking for proximity of items */
|
NPC *npcs;
|
||||||
uint32_t nbextradata;
|
|
||||||
ExtraData *extradata;
|
uint32_t nbSign;
|
||||||
|
Sign *signs;
|
||||||
|
|
||||||
|
uint32_t nbPortal;
|
||||||
|
Portal *portals;
|
||||||
|
|
||||||
/* structure that contains all the dialogs for that part of the map */
|
/* structure that contains all the dialogs for that part of the map */
|
||||||
uint32_t nbdialogsdata;
|
uint32_t nbdialogsdata;
|
||||||
|
|
|
@ -106,7 +106,7 @@ int main(void) {
|
||||||
events_bind_variable(&game.handler, (int*)&game.player.life, "life");
|
events_bind_variable(&game.handler, (int*)&game.player.life, "life");
|
||||||
events_bind_variable(&game.handler, &game.mana, "mana");
|
events_bind_variable(&game.handler, &game.mana, "mana");
|
||||||
|
|
||||||
reload_npc(&game);
|
//reload_npc(&game);
|
||||||
|
|
||||||
#if USB_FEATURE
|
#if USB_FEATURE
|
||||||
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
|
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
#include <gint/display.h>
|
#include <gint/display.h>
|
||||||
|
#include <gint/keyboard.h>
|
||||||
|
|
||||||
extern Map *worldRPG[];
|
extern Map *worldRPG[];
|
||||||
//extern ExtraData *extraRPG[];
|
//extern ExtraData *extraRPG[];
|
||||||
|
|
87
src/npc.c
87
src/npc.c
|
@ -14,8 +14,8 @@
|
||||||
extern bopti_image_t demo_PNJ_img;
|
extern bopti_image_t demo_PNJ_img;
|
||||||
|
|
||||||
|
|
||||||
NPC *npcRPG;
|
//NPC *npcRPG;
|
||||||
uint32_t nbNPC = 0;
|
//uint32_t nbNPC = 0;
|
||||||
|
|
||||||
float length( float x, float y )
|
float length( float x, float y )
|
||||||
{
|
{
|
||||||
|
@ -197,6 +197,8 @@ int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc)
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*The following functions need to be redone*/
|
||||||
|
/*
|
||||||
NPC *npc_create()
|
NPC *npc_create()
|
||||||
{
|
{
|
||||||
//Use temp pointer to avoid breaking the whole npcRPG on failure
|
//Use temp pointer to avoid breaking the whole npcRPG on failure
|
||||||
|
@ -220,14 +222,14 @@ void npc_remove(NPC *npc)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memmove(npc, &npc[1], (nbNPC-pos-1)*sizeof(NPC));
|
memmove(npc, &npc[1], (nbNPC-pos-1)*sizeof(NPC));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//Refactoring to make adding complexity cleaner
|
//Refactoring to make adding complexity cleaner
|
||||||
void update_npcs([[maybe_unused]] Game *game)
|
void update_npcs([[maybe_unused]] Game *game)
|
||||||
{
|
{
|
||||||
for( uint32_t u=0; u<nbNPC; u++ )
|
for( uint32_t u=0; u<game->map_level->nbNPC; u++ )
|
||||||
{
|
{
|
||||||
update_npc(&npcRPG[u]);
|
update_npc(&game->map_level->npcs[u]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +260,7 @@ void update_npc(NPC *npc)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void reload_npc(Game *game)
|
/*void reload_npc(Game *game)
|
||||||
{
|
{
|
||||||
if (npcRPG!=NULL)
|
if (npcRPG!=NULL)
|
||||||
{
|
{
|
||||||
|
@ -274,7 +276,7 @@ void reload_npc(Game *game)
|
||||||
{
|
{
|
||||||
ExtraData *Data = &game->map_level->extradata[u];
|
ExtraData *Data = &game->map_level->extradata[u];
|
||||||
|
|
||||||
if (strcmp(Data->type, "NPC")==0) /* the current data is a NPC */
|
if (strcmp(Data->type, "NPC")==0) //the current data is a NPC
|
||||||
{
|
{
|
||||||
nbNPC++;
|
nbNPC++;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +290,7 @@ void reload_npc(Game *game)
|
||||||
{
|
{
|
||||||
ExtraData *Data = &game->map_level->extradata[u];
|
ExtraData *Data = &game->map_level->extradata[u];
|
||||||
|
|
||||||
if (strcmp(Data->type, "NPC")==0) /* the current data is a NPC */
|
if (strcmp(Data->type, "NPC")==0) //the current data is a NPC
|
||||||
{
|
{
|
||||||
npcRPG[currentNPC].curx = (float) Data->x;
|
npcRPG[currentNPC].curx = (float) Data->x;
|
||||||
npcRPG[currentNPC].cury = (float) Data->y;
|
npcRPG[currentNPC].cury = (float) Data->y;
|
||||||
|
@ -305,19 +307,18 @@ void reload_npc(Game *game)
|
||||||
currentNPC++;
|
currentNPC++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void npc_draw(Game *game) {
|
void npc_draw(Game *game) {
|
||||||
Player *pl = &game->player;
|
Player *pl = &game->player;
|
||||||
|
|
||||||
for (uint32_t u=0; u<nbNPC; u++)
|
for (uint32_t u=0; u<game->map_level->nbNPC; u++)
|
||||||
{
|
{
|
||||||
NPC *Data = &npcRPG[u];
|
NPC *Data = &game->map_level->npcs[u];
|
||||||
|
|
||||||
/* Render the path if in debug*/
|
/* Render the path if in debug*/
|
||||||
#if DEBUGMODE
|
#if DEBUGMODE
|
||||||
if (Data->hasPath==1) /* this NPC has a trajectory */
|
if(!Data->hasPath) continue; /* this NPC has a trajectory */
|
||||||
{
|
|
||||||
int NbPoints = Data->path_length+1;
|
int NbPoints = Data->path_length+1;
|
||||||
for(int v=0; v<NbPoints; v++)
|
for(int v=0; v<NbPoints; v++)
|
||||||
{
|
{
|
||||||
|
@ -335,10 +336,8 @@ void npc_draw(Game *game) {
|
||||||
Data->ypath[(v+1) % NbPoints]) * PXSIZE)
|
Data->ypath[(v+1) % NbPoints]) * PXSIZE)
|
||||||
-(int16_t) pl->wy;
|
-(int16_t) pl->wy;
|
||||||
|
|
||||||
dline( pl->px + deltaX1, pl->py + deltaY1,
|
dline( pl->px + deltaX1, pl->py + deltaY1,pl->px + deltaX2,
|
||||||
pl->px + deltaX2, pl->py + deltaY2,
|
pl->py + deltaY2,PATH_COLOR);
|
||||||
PATH_COLOR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // DEBUGMODE
|
#endif // DEBUGMODE
|
||||||
|
|
||||||
|
@ -347,57 +346,3 @@ void npc_draw(Game *game) {
|
||||||
dimage( pl->px-P_WIDTH/2+delX, pl->py-P_HEIGHT/2+delY, &demo_PNJ_img);
|
dimage( pl->px-P_WIDTH/2+delX, pl->py-P_HEIGHT/2+delY, &demo_PNJ_img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void OLD_npc_draw(Game *game) {
|
|
||||||
Player *player = &game->player;
|
|
||||||
|
|
||||||
for (uint32_t u=0; u<game->map_level->nbextradata; u++) //uint pour enlever un warning
|
|
||||||
{
|
|
||||||
ExtraData *Data = &game->map_level->extradata[u];
|
|
||||||
|
|
||||||
|
|
||||||
if (strcmp(Data->type, "NPC")==0) /* the current data is a NPC */
|
|
||||||
{
|
|
||||||
|
|
||||||
/* TODO : This is for debugging purpose, JUste to render the path */
|
|
||||||
/* to be followed by the NPC when this will be implemented */
|
|
||||||
|
|
||||||
#if DEBUGMODE
|
|
||||||
|
|
||||||
if (Data->hasPath==1) /* this NPC has a trajectory */
|
|
||||||
{
|
|
||||||
int NbPoints = Data->path_length+1;
|
|
||||||
for(int v=0; v<NbPoints; v++)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
int16_t deltaX1=((int16_t) (Data->x + Data->xpath[v % NbPoints]) * PXSIZE)-(int16_t) player->wx;
|
|
||||||
int16_t deltaY1=((int16_t) (Data->y + Data->ypath[v % NbPoints]) * PXSIZE)-(int16_t) player->wy;
|
|
||||||
|
|
||||||
int16_t deltaX2=((int16_t) (Data->x + Data->xpath[(v+1) % NbPoints]) * PXSIZE)-(int16_t) player->wx;
|
|
||||||
int16_t deltaY2=((int16_t) (Data->y + Data->ypath[(v+1) % NbPoints]) * PXSIZE)-(int16_t) player->wy;
|
|
||||||
|
|
||||||
dline( player->px + deltaX1, player->py + deltaY1,
|
|
||||||
player->px + deltaX2, player->py + deltaY2,
|
|
||||||
PATH_COLOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // DEBUGMODE
|
|
||||||
|
|
||||||
int16_t deltaX=((int16_t) (Data->x * PXSIZE))-(int16_t) player->wx;
|
|
||||||
int16_t deltaY=((int16_t) (Data->y * PXSIZE))-(int16_t) player->wy;
|
|
||||||
dimage( player->px-P_WIDTH/2+deltaX,
|
|
||||||
player->py-P_HEIGHT/2+deltaY,
|
|
||||||
&demo_PNJ_img);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
34
src/npc.h
34
src/npc.h
|
@ -18,37 +18,6 @@ enum
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
/* current coordinates of the NPC */
|
|
||||||
float curx, cury;
|
|
||||||
|
|
||||||
/* initial coordinates of the NPC (needed to get absolute coordinates of path) */
|
|
||||||
uint32_t x;
|
|
||||||
uint32_t y;
|
|
||||||
/* the ID of the first element of the dialog */
|
|
||||||
/* (to be aligned with "dialogs.json" IDs)*/
|
|
||||||
uint32_t dialogID;
|
|
||||||
/* the number of the target point of the path */
|
|
||||||
/* Note: it must keep the value 0 if NPC has no path assigned */
|
|
||||||
uint32_t currentPoint;
|
|
||||||
/* data of the path */
|
|
||||||
uint32_t hasPath;
|
|
||||||
uint32_t path_length;
|
|
||||||
int16_t *xpath;
|
|
||||||
int16_t *ypath;
|
|
||||||
|
|
||||||
int type;
|
|
||||||
|
|
||||||
int8_t current_group;
|
|
||||||
int8_t hostile_to_group;
|
|
||||||
|
|
||||||
/* is the current NPC in pause (during dialog) */
|
|
||||||
bool paused;
|
|
||||||
|
|
||||||
char *face;
|
|
||||||
} NPC;
|
|
||||||
|
|
||||||
//Frees then malloc()s a new path to npc
|
//Frees then malloc()s a new path to npc
|
||||||
//Useful if you want to safely edit a path
|
//Useful if you want to safely edit a path
|
||||||
int npc_clear_path(NPC *npc);
|
int npc_clear_path(NPC *npc);
|
||||||
|
@ -62,12 +31,13 @@ int npc_append_path(uint16_t x, uint16_t y, NPC *npc);
|
||||||
//Returns non-zero on failure
|
//Returns non-zero on failure
|
||||||
int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc);
|
int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc);
|
||||||
|
|
||||||
|
/*
|
||||||
//realloc()s npcRPG to adequate size and returns a pointer to the new element
|
//realloc()s npcRPG to adequate size and returns a pointer to the new element
|
||||||
//Returns NULL on failure
|
//Returns NULL on failure
|
||||||
NPC *npc_create();
|
NPC *npc_create();
|
||||||
|
|
||||||
//Pops the NPC from npcRPG
|
//Pops the NPC from npcRPG
|
||||||
void npc_remove(NPC *npc);
|
void npc_remove(NPC *npc);*/
|
||||||
|
|
||||||
/* Draws the player player. This function should be called after drawing the
|
/* Draws the player player. This function should be called after drawing the
|
||||||
* map! */
|
* map! */
|
||||||
|
|
65
src/player.c
65
src/player.c
|
@ -51,8 +51,8 @@ const char damage_taken_walkable[WALKABLE_TILE_MAX] = {
|
||||||
|
|
||||||
extern bopti_image_t demo_player_img;
|
extern bopti_image_t demo_player_img;
|
||||||
|
|
||||||
extern NPC *npcRPG;
|
//extern NPC *npcRPG;
|
||||||
extern uint32_t nbNPC;
|
//extern uint32_t nbNPC;
|
||||||
|
|
||||||
|
|
||||||
void player_draw(Game *game) {
|
void player_draw(Game *game) {
|
||||||
|
@ -106,78 +106,51 @@ void player_move(Game *game, Direction direction) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void player_action(Game *game) {
|
void player_action(Game *game) {
|
||||||
register size_t i;
|
|
||||||
/* already doing something (action IS NOT with an NPC) */
|
|
||||||
if(game->player.isDoingAction) return;
|
|
||||||
|
|
||||||
if(game->player.canDoSomething && !game->player.isInteractingWithNPC){
|
/* already doing something, or can't do anything*/
|
||||||
|
if(game->player.isDoingAction || !game->player.canDoSomething) return;
|
||||||
|
|
||||||
|
if(!game->player.isInteractingWithNPC)
|
||||||
|
{
|
||||||
/* we can do something */
|
/* we can do something */
|
||||||
/* we indicate that the player is occupied */
|
/* we indicate that the player is occupied */
|
||||||
game->player.isDoingAction = true;
|
game->player.isDoingAction = true;
|
||||||
|
|
||||||
ExtraData *currentData = &game->map_level->extradata[game->player.whichAction];
|
Sign *sign = &game->map_level->signs[game->player.whichAction];
|
||||||
|
|
||||||
/* we use the correct image as per the class of the item */
|
|
||||||
|
|
||||||
bopti_image_t *face;
|
bopti_image_t *face;
|
||||||
/* we use the correct image as per the class of the item */
|
/* we use the correct image as per the type of the item */
|
||||||
|
|
||||||
|
if(sign->icon)
|
||||||
if (strcmp("INFO", currentData->type)==0){
|
|
||||||
face = &INFO_Icon_img;
|
face = &INFO_Icon_img;
|
||||||
}else if (strcmp("SGN", currentData->type)==0){
|
else
|
||||||
face = &SGN_Icon_img;
|
face = &SGN_Icon_img;
|
||||||
}else{
|
|
||||||
/* It's a NPC */
|
|
||||||
/* (Mibi88) TODO: Use string hash + strcmp if the hashes match for
|
|
||||||
* fast string comparison. */
|
|
||||||
face = NULL;
|
|
||||||
for(i=0;i<FACES;i++){
|
|
||||||
struct Face current_face = faces[i];
|
|
||||||
if(!strcmp(current_face.name, currentData->face)){
|
|
||||||
face = current_face.face;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!face) face = &npc_male;
|
|
||||||
|
|
||||||
}
|
uint32_t dialogStart = sign->dialogID;
|
||||||
|
|
||||||
uint32_t dialogStart = currentData->dialogID;
|
|
||||||
|
|
||||||
dialogs_initiate_sequence(game, face, dialogStart);
|
dialogs_initiate_sequence(game, face, dialogStart);
|
||||||
|
|
||||||
/* when done we release the occupied status of the player */
|
/* when done we release the occupied status of the player */
|
||||||
game->player.isDoingAction = false;
|
game->player.isDoingAction = false;
|
||||||
}else if(game->player.canDoSomething && game->player.isInteractingWithNPC){
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* we can do something (action IS with an NPC) */
|
/* we can do something (action IS with an NPC) */
|
||||||
/* we indicate that the player is occupied */
|
/* we indicate that the player is occupied */
|
||||||
game->player.isDoingAction = true;
|
game->player.isDoingAction = true;
|
||||||
|
|
||||||
NPC *currentNPC = &npcRPG[game->player.whichAction];
|
NPC *currentNPC = &game->map_level->npcs[game->player.whichAction];
|
||||||
|
|
||||||
/* we use the correct image as per the class of the item */
|
/* we use the correct image as per the class of the item */
|
||||||
|
/*TODO*/
|
||||||
ExtraData *currentData = &game->map_level->extradata[game->player.whichAction];
|
|
||||||
bopti_image_t *face = &npc_male;
|
bopti_image_t *face = &npc_male;
|
||||||
/* It's a NPC */
|
|
||||||
/* (Mibi88) TODO: Use string hash + strcmp if the hashes match for
|
|
||||||
* fast string comparison. */
|
|
||||||
face = NULL;
|
|
||||||
for(i=0;i<FACES;i++){
|
|
||||||
struct Face current_face = faces[i];
|
|
||||||
if(!strcmp(current_face.name, currentNPC->face)){
|
|
||||||
face = current_face.face;
|
|
||||||
}
|
|
||||||
if(!face) face = &npc_male;
|
|
||||||
}
|
|
||||||
dtext(2, 64, C_BLACK, currentData->type);
|
|
||||||
uint32_t dialogStart = currentNPC->dialogID;
|
uint32_t dialogStart = currentNPC->dialogID;
|
||||||
|
|
||||||
/* we set this NPC to paused to avoid changing its position while
|
/* we set this NPC to paused to avoid changing its position while
|
||||||
* talking (the rest of the NPCs pursue their action) */
|
* talking (the rest of the NPCs pursue their action) */
|
||||||
currentNPC->paused = true;
|
currentNPC->paused = true;
|
||||||
|
|
||||||
|
|
||||||
dialogs_initiate_sequence(game, face, dialogStart);
|
dialogs_initiate_sequence(game, face, dialogStart);
|
||||||
|
|
||||||
/* when done we release the occupied status of the player */
|
/* when done we release the occupied status of the player */
|
||||||
|
@ -256,7 +229,7 @@ bool player_collision(Game *game, Direction direction,
|
||||||
|
|
||||||
/* we update the list of NPCs in the current map */
|
/* we update the list of NPCs in the current map */
|
||||||
/* to follow the trajectories */
|
/* to follow the trajectories */
|
||||||
reload_npc(game);
|
//reload_npc(game);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
|
||||||
/* Structure 'Player' has been moved to game.h */
|
/* Structure 'Player' has been moved to game.h */
|
||||||
/* to avoid circular references between map.h, game.h and player.h */
|
/* to avoid circular references between map.h, game.h and player.h */
|
||||||
/* only methods propotypes are now in dedicated header files */
|
/* only methods propotypes are now in dedicated header files */
|
||||||
|
@ -28,7 +27,7 @@ void player_draw(Game *game);
|
||||||
*/
|
*/
|
||||||
void player_move(Game *game, Direction direction);
|
void player_move(Game *game, Direction direction);
|
||||||
|
|
||||||
/* (Mibi88) TODO: Describe this function please, I've no idea what she's for! */
|
/*Tries to do an action based on previously set flags (called if the shift key is pressed)*/
|
||||||
void player_action(Game *game);
|
void player_action(Game *game);
|
||||||
|
|
||||||
/* player_collision()
|
/* player_collision()
|
||||||
|
|
Loading…
Reference in a new issue