Exemple #1
0
        public void TravelPath(byte toGridX, byte toGridY)
        {
            // Assign Travel Data
            this.willArriveX = toGridX;
            this.willArriveY = toGridY;
            this.startTime   = Systems.timer.Frame;
            this.startX      = this.posX;
            this.startY      = this.posY;
            this.endX        = toGridX * (byte)WorldmapEnum.TileWidth - 4;
            this.endY        = toGridY * (byte)WorldmapEnum.TileHeight - 20;

            // Determine the standard walk duration.
            int dist = TrigCalc.GetDistance(this.startX, this.startY, this.endX, this.endY);

            this.duration = (int)(dist * 0.4);

            // Update Face Direction
            if (this.endX > this.startX)
            {
                this.faceRight = true;
            }
            else
            {
                this.faceRight = false;
            }
        }
Exemple #2
0
        // Play a sound, but only if it's local to the character, and the distance relative to them.
        public void PlaySound(SoundEffect sound, float volume, int posX, int posY)
        {
            // If there is insufficient sound, don't play anything.
            if (Systems.settings.audio.SoundVolume <= 0)
            {
                return;
            }

            // Do not play this sound if they're not in the same room.
            if (Systems.localServer.MyCharacter.room.roomID != this.roomID)
            {
                return;
            }

            // Determine the approximate distance from the character / screen.
            int midX = Systems.camera.posX + Systems.camera.halfWidth;
            int midY = Systems.camera.posY + Systems.camera.halfHeight;

            float dist = TrigCalc.GetDistance(midX, midY, posX, posY);

            // If the sound is too far away, no sound emits:
            if (dist > 1400)
            {
                return;
            }

            float pan = 0f;

            if (midX > posX)
            {
                int diff = midX - posX;
                if (diff > 1400)
                {
                    return;
                }
                if (diff > 250)
                {
                    pan = 0 - Spectrum.GetPercentFromValue(diff, 250, 1400);
                }
            }

            else if (midX < posX)
            {
                int diff = posX - midX;
                if (diff > 1400)
                {
                    return;
                }
                if (diff > 250)
                {
                    pan = Spectrum.GetPercentFromValue(diff, 250, 1400);
                }
            }

            // Volume
            float perDist = Spectrum.GetPercentFromValue(dist, 250, 1400);

            volume = Math.Min(volume, volume * (1f - Math.Abs(perDist))) * Systems.settings.audio.SoundVolume;

            // Play the sound:
            sound.Play(volume, 0f, pan);
        }