@hytopia.com/examples 1.0.25 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,129 @@
1
+ import {
2
+ startServer,
3
+ Entity,
4
+ DefaultPlayerEntity,
5
+ ParticleEmitter,
6
+ PlayerEvent,
7
+ Quaternion,
8
+ } from 'hytopia';
9
+
10
+ import worldMap from './assets/map.json';
11
+
12
+ startServer(world => {
13
+ world.loadMap(worldMap);
14
+
15
+ // Spawn a player entity when a player joins the game.
16
+ world.on(PlayerEvent.JOINED_WORLD, ({ player }) => {
17
+ const playerEntity = new DefaultPlayerEntity({
18
+ player,
19
+ name: 'Player',
20
+ });
21
+
22
+ playerEntity.spawn(world, { x: 0, y: 10, z: 0 });
23
+
24
+ attachPlayerParticles(playerEntity);
25
+ });
26
+
27
+ world.on(PlayerEvent.LEFT_WORLD, ({ player }) => {
28
+ world.entityManager.getPlayerEntitiesByPlayer(player).forEach(entity => entity.despawn());
29
+ });
30
+
31
+ // Setup particle emitters around the map
32
+
33
+ // Dirt spewing particle emitter
34
+ const dirtParticleEmitter = new ParticleEmitter({
35
+ textureUri: 'particles/dirt.png',
36
+ colorStart: { r: 194, g: 164, b: 132 },
37
+ size: 1,
38
+ sizeVariance: 1, // Variates the base size +/- this value
39
+ lifetime: 5, // How long the particles live for in seconds
40
+ lifetimeVariance: 3, // Variates the base lifetime +/- this value
41
+ position: { x: 0, y: 1, z: 0 }, // Position of the emitter
42
+ rate: 20, // How many particles to emit per second
43
+
44
+ velocity: { x: 0, y: 5, z: 0}, // Velocity of the particles
45
+ velocityVariance: { x: 4, y: 2, z: 4 }, // Variates the base velocity +/- this value
46
+ });
47
+ dirtParticleEmitter.spawn(world);
48
+
49
+ // Start/stop the emitter every 3 seconds
50
+ setInterval(() => {
51
+ if (dirtParticleEmitter.isStopped) {
52
+ dirtParticleEmitter.restart();
53
+ } else {
54
+ dirtParticleEmitter.stop();
55
+ }
56
+ }, 5000);
57
+
58
+
59
+ // Falling sparkles emitter
60
+ const fallingSparklesEmitter = new ParticleEmitter({
61
+ textureUri: 'particles/star-2.png',
62
+ colorStart: { r: 255, g: 255, b: 255 }, // White base color
63
+ colorStartVariance: { r: 255, g: 255, b: 255 }, // rgb varies +/- 255
64
+ colorEnd: { r: 255, g: 255, b: 255 }, // White base color
65
+ colorEndVariance: { r: 255, g: 255, b: 255 }, // rgb varies +/- 255
66
+ gravity: { x: 0, y: -3, z: 0 }, // Gravity of the particles, pull them down at a rate of 3 blocks per second
67
+ size: 1, // Base size of the particles
68
+ sizeVariance: 2, // Variates the base size +/- this value
69
+ lifetime: 5, // How long the particles live for in seconds
70
+ lifetimeVariance: 3, // Variates the base lifetime +/- this value
71
+ rate: 50, // How many particles to emit per second
72
+
73
+ position: { x: 17, y: 10, z: 0 }, // Position of the emitter
74
+ velocityVariance: { x: 3, y: 3, z: 3 }, // Variates the base velocity +/- this value
75
+ });
76
+ fallingSparklesEmitter.spawn(world);
77
+
78
+ // Swap the texture every 3 seconds
79
+ setInterval(() => {
80
+ if (fallingSparklesEmitter.textureUri === 'particles/star-2.png') {
81
+ fallingSparklesEmitter.setTextureUri('particles/star.png');
82
+ } else {
83
+ fallingSparklesEmitter.setTextureUri('particles/star-2.png');
84
+ }
85
+ }, 2000);
86
+
87
+ // Smoke emitter
88
+ const smokeEmitter = new ParticleEmitter({
89
+ textureUri: 'particles/smoke.png',
90
+ colorStart: { r: 220, g: 220, b: 220 }, // White-ish color
91
+ opacityStart: 0.7, // Starting opacity of the particles
92
+ opacityStartVariance: 0.5, // Variates the base opacity +/- this value
93
+ opacityEnd: 0, // Ending opacity of the particles
94
+ size: 3, // Base size of the particles
95
+ sizeVariance: 1.5, // Variates the base size +/- this value
96
+ lifetime: 10, // How long the particles live for in seconds
97
+ lifetimeVariance: 5, // Variates the base lifetime +/- this value
98
+ rate: 40, // How many particles to emit per second
99
+ position: { x: -13, y: 1, z: 12 }, // World position of the emitter
100
+ velocity: { x: 0, y: 2, z: 0 }, // Velocity of the particles
101
+ velocityVariance: { x: 0.5, y: 1, z: 0.5 }, // Variates the base velocity +/- this value
102
+ });
103
+ smokeEmitter.spawn(world);
104
+ });
105
+
106
+ function attachPlayerParticles(playerEntity: DefaultPlayerEntity) {
107
+ if (!playerEntity.world) {
108
+ return console.log('Player entity must be spawned to attach particles.');
109
+ }
110
+
111
+ // Bubble emitter effect from players
112
+ const particleEmitter = new ParticleEmitter({
113
+ attachedToEntity: playerEntity, // Attached to an entity instead of a position, in this case the player entity
114
+ textureUri: 'particles/circle-blur.png',
115
+ colorStart: { r: 128, g: 128, b: 255 }, // Blue base color
116
+ gravity: { x: 0, y: -1, z: 0 }, // Gravity of the particles, pull them down at a rate of 1 block per second
117
+ offset: { x: 0, y: 0.85, z: 0 }, // Offset of the particles from the entity
118
+ opacityStartVariance: 0.5, // Variates the base opacity +/- this value
119
+ velocity: { x: 0, y: 1, z: 0 }, // Velocity of the particles
120
+ velocityVariance: { x: 1, y: 0.5, z: 1 }, // Variates the base velocity +/- this value
121
+ size: 0.1, // Base size of the particles
122
+ sizeVariance: 0.25, // Variates the base size +/- this value
123
+ lifetime: 4, // How long the particles live for in seconds
124
+ rate: 10, // How many particles to emit per second
125
+ maxParticles: 30, // Maximum number of visible particles at any given time
126
+ });
127
+
128
+ particleEmitter.spawn(playerEntity.world);
129
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "particles",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "@hytopia.com/assets": "^0.3.2",
14
+ "hytopia": "^0.6.32"
15
+ },
16
+ "trustedDependencies": [
17
+ "mediasoup",
18
+ "sharp"
19
+ ]
20
+ }
@@ -1,42 +0,0 @@
1
- {
2
- "health": 100,
3
- "currentRegionId": "stalkhaven",
4
- "currentRegionSpawnFacingAngle": 0,
5
- "currentRegionSpawnPoint": {
6
- "x": 1,
7
- "y": 2,
8
- "z": 40
9
- },
10
- "skillExperience": [],
11
- "backpack": {
12
- "items": []
13
- },
14
- "hotbar": {
15
- "items": [
16
- {
17
- "position": 0,
18
- "itemId": "toy_sword"
19
- }
20
- ]
21
- },
22
- "questLog": {
23
- "quests": [
24
- {
25
- "questId": "exploring-stalkhaven",
26
- "state": "active",
27
- "objectiveProgress": {
28
- "talk-to-mycelis": 0,
29
- "talk-to-finn": 0,
30
- "talk-to-sporn": 0,
31
- "talk-to-mark": 0
32
- }
33
- }
34
- ]
35
- },
36
- "storage": {
37
- "items": []
38
- },
39
- "wearables": {
40
- "items": []
41
- }
42
- }
@@ -1,31 +0,0 @@
1
- {
2
- "health": 100,
3
- "currentRegionId": "stalkhaven",
4
- "currentRegionSpawnFacingAngle": 90,
5
- "currentRegionSpawnPoint": {
6
- "x": 32,
7
- "y": 2,
8
- "z": 1
9
- },
10
- "skillExperience": [],
11
- "backpack": {
12
- "items": []
13
- },
14
- "hotbar": {
15
- "items": [
16
- {
17
- "position": 0,
18
- "itemId": "toy_sword"
19
- }
20
- ]
21
- },
22
- "questLog": {
23
- "quests": []
24
- },
25
- "storage": {
26
- "items": []
27
- },
28
- "wearables": {
29
- "items": []
30
- }
31
- }
@@ -1,31 +0,0 @@
1
- {
2
- "health": 100,
3
- "currentRegionId": "stalkhaven",
4
- "currentRegionSpawnFacingAngle": 0,
5
- "currentRegionSpawnPoint": {
6
- "x": 1,
7
- "y": 2,
8
- "z": 40
9
- },
10
- "skillExperience": [],
11
- "backpack": {
12
- "items": []
13
- },
14
- "hotbar": {
15
- "items": [
16
- {
17
- "position": 0,
18
- "itemId": "toy_sword"
19
- }
20
- ]
21
- },
22
- "questLog": {
23
- "quests": []
24
- },
25
- "storage": {
26
- "items": []
27
- },
28
- "wearables": {
29
- "items": []
30
- }
31
- }