private void SpawnWall() { Random random = new Random(); if (this.m_WallGrid.Count > 0) { int selectedPoint = random.Next(0, this.m_WallGrid.Count - 1); GridPoint selected = this.m_WallGrid.ElementAt(selectedPoint); //create floats in the range -1 to 1 float x = (float)(random.NextDouble() * 2 - 1); float y = (float)(random.NextDouble() * 2 - 1); Wall wall = new Wall( this, new Vector2(selected.X, selected.Y), new Vector2(x, y), Settings.wallRadius, Settings.wallThickness, true); if (!(wall.Collides(this.GetPlayer()))) { this.m_WallIndices.Add(wall.GetID()); this.AddEntity(wall); this.m_WallGrid.Remove(selected); } } }
private void DrawShadow(Wall wall, float layer) { Vector2[] corners = wall.GetPoints(); Vector2 p = GetPlayer().GetPosition(); Vector2 center = (corners[0] + corners[1] + corners[2] + corners[3]) / 4; Vector2 ray = center - p; Vector2 pos1 = corners[0]; for (int i = 1; i < 4; i++) { Vector2 ray1 = pos1 - p; Vector2 ray2 = corners[i] - p; if (SignedAngle(ray, ray2) < SignedAngle(ray, ray1)) pos1 = corners[i]; } Vector2 pos2 = corners[0]; for (int i = 1; i < 4; i++) { Vector2 ray1 = pos2 - p; Vector2 ray2 = corners[i] - p; if (SignedAngle(ray, ray2) > SignedAngle(ray, ray1)) pos2 = corners[i]; } Vector2 dir1 = pos1 - p; Vector2 dir2 = pos2 - p; float angle = SignedAngle(dir1, pos2 - p); int width = (int)Math.Min(wall.GetRadius(), wall.GetThickness()); int length = Drawer.FullScreenRectangle.Width; Rectangle rect = new Rectangle(0, 0, length, width); Vector2 offset = new Vector2(-dir1.Y, dir1.X); offset.Normalize(); float arc = angle * (length + Math.Max(dir1.Length(), dir2.Length())); //rect.Location = new Point((int)(pos1.X - width * offset.X), (int)(pos1.Y - width * offset.Y)); //Drawer.Draw(TextureStatic.Get("Shadow"), rect, null, Color.Black, (float)Math.Atan2(dir1.Y, dir1.X), Vector2.UnitY * TextureStatic.Get("Shadow").Width, SpriteEffects.None, 1f); for (float s = 0; s < arc; s += width) { float frac = s / arc; //fraction of total progress float theta = frac * angle; //float distMult = (dir2.Length() / dir1.Length()) - (1 - frac) * (dir2.Length() - dir1.Length()) / dir1.Length(); Vector2 trav = dir2 - dir1; Vector2 norm = new Vector2(trav.Y, -trav.X); norm.Normalize(); Vector2 loc = dir1 + trav * frac + norm * width * (1 - frac) * (frac) + p; rect.Location = new Point((int)(loc.X + width * offset.X * (1 - frac)), (int)(loc.Y + width * offset.Y * (1 - frac))); Drawer.Draw(TextureStatic.Get("Shadow"), rect, null, Color.Black, (float)Math.Atan2(dir1.Y, dir1.X) + theta, Vector2.UnitY * TextureStatic.Get("Shadow").Width, SpriteEffects.None, layer); } rect.Location = new Point((int)pos2.X, (int)pos2.Y); Drawer.Draw(TextureStatic.Get("Shadow"), rect, null, Color.Black, (float)Math.Atan2(dir1.Y, dir1.X) + angle, Vector2.UnitY * TextureStatic.Get("Shadow").Width, SpriteEffects.None, layer); }