Skip to content

Commit

Permalink
Fix: pergerakan realtime multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikhsanheriyawan2404 committed Jul 12, 2023
1 parent 5d0fd0c commit aab18e5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
4 changes: 3 additions & 1 deletion dist/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class HelperManager {
}

moveMap(direction) {
const player = Player.getPlayer(localStorage.getItem('player_id'));
// console.log(player)
var step = 0.005; // Adjust the step size as needed
var currentCenter = this.Leaflet.map.getCenter();

Expand All @@ -78,7 +80,7 @@ class HelperManager {
}
colyClient.room.send('move', {
player_id: colyClient.options.id,
id: localStorage.getItem('player_id'),
id: player.id,
position: {
lat: this.Leaflet.map.getCenter().lat,
long: this.Leaflet.map.getCenter().lng
Expand Down
3 changes: 1 addition & 2 deletions dist/MapLeaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MapLeaflet {

this.allObjectMap = [];

// this.optionMaps = {}
this.optionMaps = {}

// this.center = null;
this.zoom = 17;
Expand Down Expand Up @@ -64,7 +64,6 @@ class MapLeaflet {
} else if (object.type == "wall" || object.type == "weather") {
switch (properties.type) {
case "polyline":
console.log(properties.poly)
objectMap = L.polyline(properties.poly, {
color: 'red',
weight: 3,
Expand Down
2 changes: 0 additions & 2 deletions dist/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class EntityPlayer {

const newPlayer = new PlayerDetail(player);
this.#players.push(newPlayer);

return player;
}

getPlayer(id) {
Expand Down
2 changes: 0 additions & 2 deletions dist/PlayerDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ class PlayerDetail {
// }

moveIcon = (lat, long) => {
// push to maps
const center = [
lat,
long,
];
// Leaflet.map.s
this.marker.setLatLng(center).addTo(Leaflet.map);
}

Expand Down
23 changes: 17 additions & 6 deletions dist/multiplayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ColyClient {
colyClient.room = room;
localStorage.setItem("player_id", room.sessionId)
this.addListeners();
console.log("JOIN SUCCESS", room);
}).catch(e => {
console.log("JOIN ERROR", e);
});
Expand All @@ -58,17 +59,13 @@ class ColyClient {

this.room.onStateChange.once((state) => {
state.Message.$items.forEach((messages, key) => {
console.log(messages)
Helper.displayMessage(messages);
});


state.ObjectMap.$items.forEach((object, key) => {
Leaflet.plotObject(object);
});
});

this.room.onStateChange((state) => {

state.Player.$items.forEach((player, key) => {
let dataPlayer = player;
Expand All @@ -77,6 +74,22 @@ class ColyClient {
Player.addPlayer(dataPlayer);
});

state.Player.onAdd((player, key) => {
console.log("onadd")
let dataPlayer = player;
const center = [dataPlayer.position.lat, dataPlayer.position.long];
dataPlayer.marker = L.marker(center, {icon: Leaflet.avatarIcon});
Player.addPlayer(dataPlayer);
})

});

this.room.onStateChange((state) => {

// state.Player.$items.forEach((player, key) => {
// console.log("perubahan")
// });

})


Expand All @@ -97,8 +110,6 @@ class ColyClient {


this.room.onMessage("move", (message) => {
console.log(message.player_id, "bergerak")
console.log(message.position.lat, message.position.long)
let player = Player.getPlayer(message.id)
player.moveIcon(message.position.lat, message.position.long);
});
Expand Down

0 comments on commit aab18e5

Please sign in to comment.