예제 #1
0
 public SoundEmitter(Location l, float _SoundPower)
 {
     location   = l;
     radius     = 0.3f;
     soundPower = _SoundPower;
     circleLine = DrawerStructure.CreateCircle(TerrainBoard.transformGridToPosition(l.x, l.y), radius, new Color(0, 1, 1));
 }
예제 #2
0
    public Queue <Vector2> Search(Vector2 a, Vector2 b)
    {
        Location start = TerrainBoard.transformPositionToGrid(a);

        Location goal = TerrainBoard.transformPositionToGrid(b);

        SearchAlgorithm.Search(start, goal);

        Queue <Vector2> targets = new Queue <Vector2>();

        foreach (Location l in SearchAlgorithm.GetResult())
        {
            targets.Enqueue(TerrainBoard.transformGridToPosition(l.x, l.y));
        }
        return(targets);

        //TerrainBoard.ResetColor();
        //foreach (Location i in TerrainBoard.AStar.GetExploredList())
        //{
        //  TerrainBoard.SetColor(i.x,i.y,Color.red);
        //}
    }
예제 #3
0
    //Location l, float radius, float intensity,float power)
    private void UpdateSoundParticle(SoundEmitter e)
    {
        int             Rangex = e.location.x + (int)e.radius;
        int             Rangey = e.location.y + (int)e.radius;
        List <Location> walls  = new List <Location>();

        //Find wall
        for (int x = e.location.x - (int)e.radius - 1; x < Rangex; x++)
        {
            for (int y = e.location.y - (int)e.radius; y < Rangey; y++)
            {
                if (TerrainBoard.map.IsWall(x, y))
                {
                    walls.Add(new Location(x, y));
                }
            }
        }

        for (int x = 0; x < Rangex; x++)
        {
            if (x < 0 || x >= TerrainBoard.map.width)
            {
                continue;
            }
            for (int y = 0; y < Rangey; y++)
            {
                if (y < 0 || y >= TerrainBoard.map.height)
                {
                    continue;
                }

                Vector2 dir = new Vector2(x - e.location.x, y - e.location.y);

                //Check if collided with wall
                bool intersected = false;

                foreach (Location i in walls)
                {
                    int wallNeighbourCount = 0;
                    if (TerrainBoard.map.IsWall(i + new Location(-1, -1)))
                    {
                        wallNeighbourCount++;
                    }
                    if (TerrainBoard.map.IsWall(i + new Location(0, -1)))
                    {
                        wallNeighbourCount++;
                    }
                    if (TerrainBoard.map.IsWall(i + new Location(1, -1)))
                    {
                        wallNeighbourCount++;
                    }
                    if (TerrainBoard.map.IsWall(i + new Location(-1, 0)))
                    {
                        wallNeighbourCount++;
                    }
                    if (TerrainBoard.map.IsWall(i + new Location(1, 0)))
                    {
                        wallNeighbourCount++;
                    }
                    if (TerrainBoard.map.IsWall(i + new Location(-1, 1)))
                    {
                        wallNeighbourCount++;
                    }
                    if (TerrainBoard.map.IsWall(i + new Location(0, 1)))
                    {
                        wallNeighbourCount++;
                    }
                    if (TerrainBoard.map.IsWall(i + new Location(1, 1)))
                    {
                        wallNeighbourCount++;
                    }


                    if (i.x == e.location.x && i.y == e.location.y)
                    {
                        continue;
                    }
                    Vector2 rayStart = new Vector2(x, y);
                    Vector2 rayEnd   = new Vector2(e.location.x, e.location.y);
                    if (LineAABBIntersect(new Vector2(i.x, i.y), rayStart, rayEnd))
                    {
                        intersected = true;
                        if (e.ChildCount < 3 && !e.isChild)
                        {
                            if (!toBeCreatedLocation.Contains(e.location) && wallNeighbourCount < 2)
                            {
                                ++e.ChildCount;
                                CreateEmitter(TerrainBoard.transformGridToPosition(i.x, i.y), e.soundPower / 3, true);
                            }
                        }
                    }
                }

                if (intersected)
                {
                    continue;
                }

                if (dir.magnitude < e.radius)
                {
                    float currentIntensity = IntensityGrid[x, y] + e.intensity;
                    if (currentIntensity > 1)
                    {
                        currentIntensity = 1;
                    }
                    IntensityGrid[x, y] = currentIntensity;
                }
            }
        }
    }