Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
地图对象
  • Loading branch information
gaowanlu committed Jan 21, 2024
1 parent af09454 commit e864048
Show file tree
Hide file tree
Showing 9 changed files with 3,141 additions and 1,548 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# production
/build
/nwjs

# misc
.DS_Store
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
```bash
npm install
npm run build
cd nwjs
./nwjs/nw.exe ./build --ignore-certificate-errors

{
"name": "nw-demo",
"version": "0.0.1",
"main": "index.html"
}
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "thub",
"version": "0.1.0",
"private": true,
"main": "index.html",
"dependencies": {
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
Expand Down
993 changes: 864 additions & 129 deletions public/assets/map.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/地图.tiled-project
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"automappingRulesFile": "",
"commands": [
],
"compatibilityVersion": 1100,
"compatibilityVersion": 1080,
"extensionsPath": "extensions",
"folders": [
"."
Expand Down
37 changes: 31 additions & 6 deletions public/assets/地图.tiled-session
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
"height": 4300,
"width": 2
},
"activeFile": "地图.json",
"activeFile": "地图.tmx",
"expandedProjectPaths": [
"."
],
"file.lastUsedOpenFilter": "全部文件 (*)",
"fileStates": {
"": {
"scaleInDock": 1
"scaleInDock": 0.33
},
"terrain_atlas.tsx": {
"scaleInDock": 0.125,
"scaleInDock": 0.75,
"scaleInEditor": 1
},
"地图.json": {
Expand All @@ -25,20 +26,44 @@
},
"地图.json#terrain_atlas": {
"scaleInDock": 0.33
},
"地图.tmj": {
"scale": 1,
"selectedLayer": 1,
"viewCenter": {
"x": 879.5,
"y": 391.5
}
},
"地图.tmj#terrain_atlas": {
"scaleInDock": 1.5
},
"地图.tmx": {
"scale": 0.33,
"selectedLayer": 3,
"viewCenter": {
"x": 292.4242424242424,
"y": 331.81818181818187
}
},
"地图.tmx#terrain_atlas": {
"scaleInDock": 0.33
}
},
"last.exportedFilePath": "C:/Users/gaowanlu/Desktop/MyProject/thub/public/assets",
"last.imagePath": "C:/Users/gaowanlu/Desktop/MyProject/thub/public/assets/Atlas",
"map.lastUsedExportFilter": "JSON map files (*.tmj *.json)",
"map.lastUsedFormat": "json",
"map.lastUsedFormat": "tmx",
"openFiles": [
"地图.json",
"terrain_atlas.tsx"
"地图.tmx"
],
"project": "地图.tiled-project",
"recentFiles": [
"地图.tmx",
"terrain_atlas.tsx",
"地图.tmj",
"地图.json"
],
"tileset.embedInMap": true,
"tileset.lastUsedFormat": "tsx"
}
988 changes: 860 additions & 128 deletions public/assets/地图.tmj

Large diffs are not rendered by default.

2,628 changes: 1,344 additions & 1,284 deletions public/assets/地图.tmx

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/pages/GamePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const WIDTH = 1320;
const HEIGHT = 680;
let miniMap;

let Objects = [];

WS.connect();

// function collectStar(player, star) {
Expand Down Expand Up @@ -120,6 +122,7 @@ function GamePage() {
this.load.tilemapTiledJSON({ key: 'map', url: 'assets/map.json' });
// 加载地图使用的图块集
this.load.image('tiles', 'assets/Atlas/terrain_atlas.png');
this.load.spritesheet('tilesetSprite', 'assets/Atlas/terrain_atlas.png', { frameWidth: 32, frameHeight: 32 });
}

// 创建场景
Expand All @@ -136,6 +139,7 @@ function GamePage() {
layer1.setCollisionByExclusion([-1]);
let layer2 = map.createLayer("scene_layer2", tiles, 0, 0);
layer2.setCollisionByExclusion([-1]);

this.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
this.cameras.main.setSize(WIDTH, HEIGHT);

Expand Down Expand Up @@ -232,6 +236,28 @@ function GamePage() {
this.physics.add.collider(player, beds2);
this.physics.add.collider(player, beds3);



// Load object layer
let objectLayer = map.getObjectLayer('object_layer1');

if (objectLayer) {
// Iterate through objects in the object layer
objectLayer.objects.forEach(object => {
// Example: create a sprite at each object's position
let sprite = this.physics.add.sprite(object.x, object.y - 32, 'tilesetSprite', object.gid - 1);
sprite.setOrigin(0, 0);
this.physics.world.enable(sprite);
Objects.push(sprite);
});
}


Objects.forEach((v, i, arr) => {
this.physics.add.collider(player, v);
});


// 键盘
cursors = this.input.keyboard.createCursorKeys();
cursors.w = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.W);
Expand Down Expand Up @@ -282,6 +308,11 @@ function GamePage() {
this.physics.add.collider(newPlayer, beds1);
this.physics.add.collider(newPlayer, beds2);
this.physics.add.collider(newPlayer, beds3);

Objects.forEach((v, i, arr) => {
this.physics.add.collider(newPlayer, v);
});

}
// 将消息装入对应玩家的message
for (let j = 0; j < data.Data.length; j++) {
Expand Down

0 comments on commit e864048

Please sign in to comment.