Map loading fixes and improvements
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 268 B |
Binary file not shown.
Before Width: | Height: | Size: 346 B |
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="8" tileheight="8" infinite="0" nextlayerid="3" nextobjectid="5">
|
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="30" height="20" tilewidth="8" tileheight="8" infinite="0" nextlayerid="3" nextobjectid="7">
|
||||||
<tileset firstgid="1" source="tilemap.tsx"/>
|
<tileset firstgid="1" source="../tilemaps/tilemap.tsx"/>
|
||||||
<tileset firstgid="65" source="entities.tsx"/>
|
<tileset firstgid="65" source="../tilemaps/entities.tsx"/>
|
||||||
<layer id="1" name="Map" width="30" height="20" locked="1">
|
<layer id="1" name="Map" width="30" height="20" locked="1">
|
||||||
<data encoding="csv">
|
<data encoding="csv">
|
||||||
1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,2,2,2,2,
|
1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,2,2,2,2,
|
||||||
@ -28,5 +28,19 @@
|
|||||||
</layer>
|
</layer>
|
||||||
<objectgroup id="2" name="Entities">
|
<objectgroup id="2" name="Entities">
|
||||||
<object id="4" name="Player" type="player" gid="66" x="87.7275" y="119.497" width="8" height="8"/>
|
<object id="4" name="Player" type="player" gid="66" x="87.7275" y="119.497" width="8" height="8"/>
|
||||||
|
<object id="5" name="Sign" type="sign" gid="68" x="86.8498" y="55.0415" width="8" height="8">
|
||||||
|
<properties>
|
||||||
|
<property name="texts_0" value="maps.testmap.sign2.1"/>
|
||||||
|
<property name="texts_1" value="maps.testmap.sign2.2"/>
|
||||||
|
</properties>
|
||||||
|
</object>
|
||||||
|
<object id="6" name="Door" type="door" gid="69" x="111.791" y="55.7608" width="8" height="8">
|
||||||
|
<properties>
|
||||||
|
<property name="direction" type="int" value="2"/>
|
||||||
|
<property name="map" value="testmap2.map"/>
|
||||||
|
<property name="x" type="int" value="11"/>
|
||||||
|
<property name="y" type="int" value="2"/>
|
||||||
|
</properties>
|
||||||
|
</object>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
</map>
|
</map>
|
17
assets/maps/testmap2.tmx
Normal file
17
assets/maps/testmap2.tmx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="8" tileheight="8" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||||
|
<tileset firstgid="1" source="../tilemaps/tilemap.tsx"/>
|
||||||
|
<tileset firstgid="67" source="../tilemaps/entities.tsx"/>
|
||||||
|
<layer id="1" name="Tile Layer 1" width="5" height="5">
|
||||||
|
<data encoding="csv">
|
||||||
|
2,2,2,2,2,
|
||||||
|
2,2,2,3,2,
|
||||||
|
2,2,3,3,2,
|
||||||
|
2,2,3,2,2,
|
||||||
|
2,3,3,2,2
|
||||||
|
</data>
|
||||||
|
</layer>
|
||||||
|
<objectgroup id="2" name="Entities">
|
||||||
|
<object id="4" name="Player" type="player" gid="68" x="6.54983" y="15.3437" width="8" height="8"/>
|
||||||
|
</objectgroup>
|
||||||
|
</map>
|
@ -5,7 +5,9 @@
|
|||||||
},
|
},
|
||||||
"activeFile": "",
|
"activeFile": "",
|
||||||
"expandedProjectPaths": [
|
"expandedProjectPaths": [
|
||||||
|
"."
|
||||||
],
|
],
|
||||||
|
"file.lastUsedOpenFilter": "All Files (*)",
|
||||||
"fileStates": {
|
"fileStates": {
|
||||||
"": {
|
"": {
|
||||||
"scaleInDock": 1
|
"scaleInDock": 1
|
||||||
@ -14,12 +16,31 @@
|
|||||||
"scaleInDock": 1,
|
"scaleInDock": 1,
|
||||||
"scaleInEditor": 1
|
"scaleInEditor": 1
|
||||||
},
|
},
|
||||||
"testmap.tmx": {
|
"maps/testmap.tmx": {
|
||||||
"scale": 3.281458333333333,
|
"expandedObjectLayers": [
|
||||||
|
2
|
||||||
|
],
|
||||||
|
"scale": 3.404166666666667,
|
||||||
"selectedLayer": 1,
|
"selectedLayer": 1,
|
||||||
"viewCenter": {
|
"viewCenter": {
|
||||||
"x": 97.36524665100629,
|
"x": 116.328029375765,
|
||||||
"y": 58.20582820138405
|
"y": 79.90208078335371
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"maps/testmap2.tmx": {
|
||||||
|
"scale": 5.0383,
|
||||||
|
"selectedLayer": 1,
|
||||||
|
"viewCenter": {
|
||||||
|
"x": 33.940019451005305,
|
||||||
|
"y": 35.726336264216116
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"testmap.tmx": {
|
||||||
|
"scale": 3.23,
|
||||||
|
"selectedLayer": 1,
|
||||||
|
"viewCenter": {
|
||||||
|
"x": 122.60061919504646,
|
||||||
|
"y": 56.965944272445824
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"testmap2.tmx": {
|
"testmap2.tmx": {
|
||||||
@ -35,19 +56,19 @@
|
|||||||
"scaleInEditor": 4
|
"scaleInEditor": 4
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"last.externalTilesetPath": "/home/yourwishes/htdocs/Dawn/assets/map",
|
"last.externalTilesetPath": "/home/yourwishes/htdocs/Dawn/assets",
|
||||||
"last.imagePath": "/home/yourwishes/htdocs/Dawn/assets/map",
|
"last.imagePath": "/home/yourwishes/htdocs/Dawn/assets",
|
||||||
|
"map.height": 5,
|
||||||
"map.lastUsedFormat": "tmx",
|
"map.lastUsedFormat": "tmx",
|
||||||
"map.tileHeight": 8,
|
"map.tileHeight": 8,
|
||||||
"map.tileWidth": 8,
|
"map.tileWidth": 8,
|
||||||
|
"map.width": 5,
|
||||||
"openFiles": [
|
"openFiles": [
|
||||||
],
|
],
|
||||||
"project": "tiled_project.tiled-project",
|
"project": "tiled_project.tiled-project",
|
||||||
|
"property.type": "string",
|
||||||
"recentFiles": [
|
"recentFiles": [
|
||||||
"testmap.tmx",
|
"maps/testmap2.tmx"
|
||||||
"tilemap.tsx",
|
|
||||||
"entities.tsx",
|
|
||||||
"testmap2.tmx"
|
|
||||||
],
|
],
|
||||||
"tileset.lastUsedFilter": "All Files (*)",
|
"tileset.lastUsedFilter": "All Files (*)",
|
||||||
"tileset.lastUsedFormat": "tsx",
|
"tileset.lastUsedFormat": "tsx",
|
BIN
assets/tilemaps/entities.png
Normal file
BIN
assets/tilemaps/entities.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 326 B |
BIN
assets/tilemaps/tilemap.png
Normal file
BIN
assets/tilemaps/tilemap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 322 B |
@ -161,7 +161,7 @@ TILES = {
|
|||||||
"NULL": [ 0, 'N', COLORS["RED"] ],
|
"NULL": [ 0, 'N', COLORS["RED"] ],
|
||||||
"GRASS": [ 1, '#', COLORS["GREEN"] ],
|
"GRASS": [ 1, '#', COLORS["GREEN"] ],
|
||||||
"WATER": [ 2, '\\', COLORS["BLUE"] ],
|
"WATER": [ 2, '\\', COLORS["BLUE"] ],
|
||||||
"DOOR": [ 3, 'D', COLORS["BROWN"] ],
|
# "DOOR": [ 3, 'D', COLORS["BROWN"] ],
|
||||||
"BUILDING_WALL": [ 4, '-', COLORS["GRAY"] ],
|
"BUILDING_WALL": [ 4, '-', COLORS["GRAY"] ],
|
||||||
"ROOF": [ 5, '/', COLORS["BROWN"] ],
|
"ROOF": [ 5, '/', COLORS["BROWN"] ],
|
||||||
"WALKABLE_NULL": [ 6, ' ', COLORS["BLACK"] ],
|
"WALKABLE_NULL": [ 6, ' ', COLORS["BLACK"] ],
|
||||||
@ -170,6 +170,9 @@ TILES = {
|
|||||||
ENTITIES = {
|
ENTITIES = {
|
||||||
"NULL": [ 0, 'N', COLORS["RED"] ],
|
"NULL": [ 0, 'N', COLORS["RED"] ],
|
||||||
"PLAYER": [ 1, 'v', COLORS["RED"] ],
|
"PLAYER": [ 1, 'v', COLORS["RED"] ],
|
||||||
|
"NPC": [ 2, 'V', COLORS["RED"] ],
|
||||||
|
"SIGN": [ 3, '+', COLORS["YELLOW"] ],
|
||||||
|
"DOOR": [ 4, 'D', COLORS["BROWN"] ],
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create 64 x 64 RGB pixel buffer.
|
# Create 64 x 64 RGB pixel buffer.
|
||||||
|
@ -32,7 +32,8 @@ target_sources(${DAWN_TARGET_NAME}
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Assets
|
# Assets
|
||||||
tool_map(testmap map/testmap.tmx)
|
tool_map(testmap maps/testmap.tmx)
|
||||||
|
tool_map(testmap2 maps/testmap2.tmx)
|
||||||
tool_copy(en en.json)
|
tool_copy(en en.json)
|
||||||
|
|
||||||
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
add_dependencies(${DAWN_TARGET_NAME} dawnassets)
|
||||||
|
@ -93,9 +93,15 @@ void assetMapLoadEntity(
|
|||||||
door->type == ASSET_JSON_DATA_TYPE_NUMBER,
|
door->type == ASSET_JSON_DATA_TYPE_NUMBER,
|
||||||
"assetMapLoad: Door y is not a number!"
|
"assetMapLoad: Door y is not a number!"
|
||||||
);
|
);
|
||||||
entitydirection_t direction = (entitydirection_t)(
|
|
||||||
assetJsonGetObjectValue(val, "direction")->number
|
door = assetJsonGetObjectValue(val, "direction");
|
||||||
);
|
entitydirection_t direction = ENTITY_DIRECTION_SOUTH;
|
||||||
|
if(door != NULL) {
|
||||||
|
direction = (entitydirection_t)(
|
||||||
|
assetJsonGetObjectValue(val, "direction")->number
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
door = assetJsonGetObjectValue(val, "map");
|
door = assetJsonGetObjectValue(val, "map");
|
||||||
maplist_t list;
|
maplist_t list;
|
||||||
if(door == NULL) {
|
if(door == NULL) {
|
||||||
|
@ -10,8 +10,21 @@
|
|||||||
#include "game/game.h"
|
#include "game/game.h"
|
||||||
|
|
||||||
void gameStateMapChangeUpdate() {
|
void gameStateMapChangeUpdate() {
|
||||||
|
// First try and find the player object
|
||||||
|
entity_t *player = NULL;
|
||||||
|
entitydirection_t dir = ENTITY_DIRECTION_SOUTH;
|
||||||
|
if(GAME.currentMap != NULL) {
|
||||||
|
player = mapEntityGetByType(GAME.currentMap, ENTITY_TYPE_PLAYER);
|
||||||
|
dir = player->direction;
|
||||||
|
}
|
||||||
|
|
||||||
assetMapLoad(MAP_LIST_PATHS[GAME.mapNext], &MAP_MAIN);
|
assetMapLoad(MAP_LIST_PATHS[GAME.mapNext], &MAP_MAIN);
|
||||||
GAME.state = GAME_STATE_OVERWORLD;
|
GAME.state = GAME_STATE_OVERWORLD;
|
||||||
GAME.currentMap = &MAP_MAIN;
|
GAME.currentMap = &MAP_MAIN;
|
||||||
map_t *test = &MAP_MAIN;
|
|
||||||
|
// Do not reference player since its invalid, just check if it DID exist
|
||||||
|
if(GAME.currentMap != NULL && player != NULL) {
|
||||||
|
player = mapEntityGetByType(GAME.currentMap, ENTITY_TYPE_PLAYER);
|
||||||
|
player->direction = dir;
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,7 +9,8 @@
|
|||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
|
|
||||||
const char_t * MAP_LIST_PATHS[] = {
|
const char_t * MAP_LIST_PATHS[] = {
|
||||||
"testmap.map"
|
"testmap.map",
|
||||||
|
"testmap2.map"
|
||||||
};
|
};
|
||||||
|
|
||||||
const int32_t MAP_LIST_COUNT = sizeof(MAP_LIST_PATHS) / sizeof(char_t*);
|
const int32_t MAP_LIST_COUNT = sizeof(MAP_LIST_PATHS) / sizeof(char_t*);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
bool_t tileIsSolid(const tile_t tile) {
|
bool_t tileIsSolid(const tile_t tile) {
|
||||||
switch(tile) {
|
switch(tile) {
|
||||||
|
case TILE_NULL:
|
||||||
case TILE_WATER:
|
case TILE_WATER:
|
||||||
case TILE_BUILDING_WALL:
|
case TILE_BUILDING_WALL:
|
||||||
case TILE_ROOF:
|
case TILE_ROOF:
|
||||||
|
@ -63,18 +63,54 @@ for objectgroup in root.findall('objectgroup'):
|
|||||||
isEnt = objectgroup.attrib['name'].lower().find('ent') != -1
|
isEnt = objectgroup.attrib['name'].lower().find('ent') != -1
|
||||||
|
|
||||||
for tiledObject in objectgroup.findall('object'):
|
for tiledObject in objectgroup.findall('object'):
|
||||||
# /8 because tiled uses pixels for objects but we use tile indexes (8x8px)
|
floatX = float(tiledObject.attrib['x'])
|
||||||
|
floatY = float(tiledObject.attrib['y'])
|
||||||
|
|
||||||
|
# tiled uses Px and uses bottom left of sprite
|
||||||
obj = {
|
obj = {
|
||||||
"x": int(round(float(tiledObject.attrib['x']) / 8)),
|
"x": int( round(floatX / 8) ),
|
||||||
"y": int(round(float(tiledObject.attrib['y']) / 8)),
|
"y": int( round((floatY - 8) / 8) )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
propertiesElement = tiledObject.find('properties')
|
||||||
|
if propertiesElement is None:
|
||||||
|
propertyElements = []
|
||||||
|
else:
|
||||||
|
propertyElements = propertiesElement.findall('property')
|
||||||
|
|
||||||
|
properties = {}
|
||||||
|
for prop in propertyElements:
|
||||||
|
properties[prop.attrib['name']] = prop.attrib['value']
|
||||||
|
|
||||||
if isEnt:
|
if isEnt:
|
||||||
if not 'type' in tiledObject.attrib:
|
if not 'type' in tiledObject.attrib:
|
||||||
raise Exception('Entity missing type attribute')
|
raise Exception('Entity missing type attribute')
|
||||||
entType = tiledObject.attrib['type']
|
entType = tiledObject.attrib['type']
|
||||||
if entType == 'player':
|
if entType == 'player':
|
||||||
obj['type'] = 1
|
obj['type'] = 1
|
||||||
|
elif entType == 'npc':
|
||||||
|
obj['type'] = 2
|
||||||
|
elif entType == 'sign':
|
||||||
|
obj['type'] = 3
|
||||||
|
|
||||||
|
obj["texts"] = []
|
||||||
|
for key in properties:
|
||||||
|
if key.find('text') != -1:
|
||||||
|
obj["texts"].append(properties[key])
|
||||||
|
|
||||||
|
elif entType == 'door':
|
||||||
|
obj['type'] = 4
|
||||||
|
obj["door"] = {}
|
||||||
|
|
||||||
|
if 'x' in properties:
|
||||||
|
obj["door"]["x"] = int(properties['x'])
|
||||||
|
if 'y' in properties:
|
||||||
|
obj["door"]["y"] = int(properties['y'])
|
||||||
|
if 'direction' in properties:
|
||||||
|
obj["door"]["direction"] = int(properties['direction'])
|
||||||
|
if 'map' in properties:
|
||||||
|
obj["door"]["map"] = properties['map']
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception('Unknown entity type: ' + entType)
|
raise Exception('Unknown entity type: ' + entType)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user