Commit 1e58fa28 authored by Zak Stephens's avatar Zak Stephens

Fix placement of Tiled objects.

parent 562c2b44
{
"playerDefaults": {
"location": {
"x": 11,
"y": 11,
"x": 2,
"y": 4,
"map": "./maps/basement.json"
}
},
"tickrate": 33,
"playerInactivityDespawnTime": 30,
"playerInactivityDespawnTime": 300,
"tileSize": 32,
......
......@@ -43,8 +43,6 @@ const util = require('util');
loadMap('./maps/basement.json', gameState);
console.log(gameState.maps['./maps/basement.json'].teleporters);
const app = express();
app.use(cors({ credentials: true, origin: true })); // Free love.
app.use('/api/v1/microtransactions', require('./routes/microtransactions'));
......
......@@ -67,7 +67,7 @@ function getObjectsOfType(tiledExport, type) {
.map(tiledObject => {
const object = {
x: tiledObject.x / tileSize,
y: tiledObject.y / tileSize,
y: (tiledObject.y-tileSize) / tileSize,
customProperties: {}
};
......@@ -90,9 +90,9 @@ function getTeleporters(tiledExport) {
getObjectsOfType(tiledExport, 'Teleporter')
.forEach(object => {
assert(object.customProperties.x);
assert(object.customProperties.y);
assert(object.customProperties.map);
assert(object.customProperties.x != null);
assert(object.customProperties.y != null);
assert(object.customProperties.map != null);
teleporters[object.y][object.x] = {
x: object.customProperties.x,
......
......@@ -68,12 +68,12 @@
{
"name":"x",
"type":"int",
"value":11
"value":0
},
{
"name":"y",
"type":"int",
"value":11
"value":0
}],
"rotation":0,
"type":"Teleporter",
......
......@@ -58,8 +58,8 @@
<object id="38" name="Basement" type="Teleporter" gid="353" x="64" y="128" width="32" height="32">
<properties>
<property name="map" value="./maps/basement.json"/>
<property name="x" type="int" value="11"/>
<property name="y" type="int" value="11"/>
<property name="x" type="int" value="0"/>
<property name="y" type="int" value="0"/>
</properties>
</object>
</objectgroup>
......
......@@ -60,6 +60,15 @@ module.exports = (gameState, playerRepository) => {
return res.sendStatus(409);
}
const teleporter = gameState.maps[map].teleporters[y][x];
if (teleporter != null) {
player.location.map = teleporter.map;
player.location.x = teleporter.x;
player.location.y = teleporter.y;
return res.sendStatus(204);
}
player.location.x = x;
player.location.y = y;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment