public void Draw(RenderTarget window, Location offset) { rect.Rotation = -Rotation - 90; rect.Position = Location.Vec2f + offset.Vec2f; rect.Texture = texture; window.Draw(rect); }
public LinearEntity(Location start, float rad, float speed) : base(new Texture("bullet.png")) { Location = start; rad += (float)Math.PI * 0.5f; x = (float)Math.Sin(rad) * speed; y = (float)Math.Cos(rad) * speed; rect.Size = new SFML.Window.Vector2f(6, 6); rect.TextureRect = new IntRect(0, 0, 12, 12); rect.Origin = new SFML.Window.Vector2f(3, 3); radius = 3; }
public void Draw(RenderTarget t, Location offset) { List<Particle> toRemove = new List<Particle>(); for(int i = 0; i < particles.Count; i++) { particles[i].time -= 0.01f; if(particles[i].time <= 0) toRemove.Add(particles[i]); else { particle.Position = particles[i].location.Vec2f + offset.Vec2f; particle.Color = new Color(255, 255, 255, (byte)(particles[i].time * 255)); t.Draw(particle); } } for(int i = 0; i < toRemove.Count; i++) particles.Remove(toRemove[i]); toRemove.Clear(); }
public bool Shoot(Location l, float rot) { return false; }
public void Lighten(Location l, float rad, float strength = 1) { if (highQuality) { Color color = Color.White; float opacity; for (int i = 10; i >= 0; i -= 1) { opacity = 1 / (float)Math.Max(1, i * 2); float radi = rad * 0.1f * i; lightCircle.Radius = radi; lightCircle.Origin = new Vector2f(radi, radi); lightCircle.Position = l.Vec2f; lightCircle.FillColor = new Color(color.R, color.G, color.B, (byte)(opacity * 255 * strength)); light.Draw(lightCircle); } } else { Color color = Color.White; color.A = (byte)(strength * color.A); lightCircle.Radius = rad * 0.6f; lightCircle.Origin = new Vector2f(rad * 0.6f, rad * 0.6f); lightCircle.Position = l.Vec2f; lightCircle.FillColor = color; light.Draw(lightCircle); } }
public float DistSquared(Location b) { return (b.X - X) * (b.X - X) + (b.Y - Y) * (b.Y - Y); }
public void AddEntity(Location l) { Entity e = new Entity(new Texture("Content/enemy.png")); e.Location = l * 32 + 16; Entities.Add(e); }
public void ShakeScreen(float amount, int shakes = 10) { if (!shaking) { shaking = true; new Thread(() => { orginalOffset = offset; for (int i = 0; i < shakes; i++) { offset += new Location() { X = amount * 10, Y = 0 }; Thread.Sleep(100); offset += new Location() { X = 0, Y = amount * 7 }; Thread.Sleep(100); offset -= new Location() { X = amount * 10, Y = 0 }; Thread.Sleep(100); offset -= new Location() { X = 0, Y = amount * 7 }; Thread.Sleep(100); } shaking = false; }).Start(); } }
public void Mutate(Location l) { try { Block b = Blocks[(int)l.X, (int)l.Y]; if (b == Block.Wood) Blocks[(int)l.X, (int)l.Y] = Block.WetWood; if (b == Block.Bricks) Blocks[(int)l.X, (int)l.Y] = Block.MossBricks; } catch { } }
public int Move(Location l, float size = 32) { int tx = (int)(l.X / 32.0f); int ty = (int)(l.Y / 32.0f); try { if (tx < 0 || tx >= Width || ty < 0 || ty >= Height) return 0; Block b = Blocks[tx, ty]; return b.CollideFlag; } catch { Console.Error.WriteLine("How?"); return 0; } }
public void Load(string file) { Office = false; Entities.Clear(); Lights = new List<Location>(); using (StreamReader r = new StreamReader(file)) { string level = ""; int lineN = 0; string line; while ((line = r.ReadLine()) != null) { if (lineN == 0) { if (!uint.TryParse(line, out Width)) { Width = 16; Console.Error.WriteLine("Can't Read Level Width"); } } else if (lineN == 1) { if (!uint.TryParse(line, out Height)) { Height = 16; Console.Error.WriteLine("Can't Read Level Height"); } } else if (lineN == 2) { char b = line[0]; switch (b) { case 'b': OutterBlock = Block.Bricks; break; case ' ': OutterBlock = Block.Wood; break; case 'd': OutterBlock = Block.DestroyedBricks; break; default: Console.Error.WriteLine("Can't Read Outter Level Block"); OutterBlock = Block.Bricks; break; } } else { level += line; } lineN++; } Blocks = new Block[Width, Height]; for (int i = 0; i < level.Length; i++) { char b = level[i]; switch (b) { case 'b': Blocks[i % Width, i / Width] = Block.Bricks; break; case ' ': Blocks[i % Width, i / Width] = Block.Wood; break; case 'd': Blocks[i % Width, i / Width] = Block.DestroyedBricks; break; case 'S': Blocks[i % Width, i / Width] = Block.Wood; Start = new Location() { X = i % Width, Y = i / Width }; break; case 'F': Blocks[i % Width, i / Width] = Block.Finish; break; case 'E': Blocks[i % Width, i / Width] = Block.Wood; AddEntity(new Location() { X = i % Width, Y = i / Width }); break; case 'D': Blocks[i % Width, i / Width] = Block.EntityDestroyer; break; case 'L': Blocks[i % Width, i / Width] = Block.Wood; Lights.Add(new Location() { X = i % Width, Y = i / Width }); break; case 'G': Blocks[i % Width, i / Width] = Block.NyanGun; break; case 'M': Blocks[i % Width, i / Width] = Block.Monolog; break; case 'T': Blocks[i % Width, i / Width] = Block.OfficeEnter; break; case '0': Blocks[i % Width, i / Width] = Block.B0; break; case '1': Blocks[i % Width, i / Width] = Block.B1; break; case '2': Blocks[i % Width, i / Width] = Block.B2; break; case '3': Blocks[i % Width, i / Width] = Block.B3; break; case '4': Blocks[i % Width, i / Width] = Block.B4; break; case '5': Blocks[i % Width, i / Width] = Block.B5; break; case '6': Blocks[i % Width, i / Width] = Block.B6; break; case '7': Blocks[i % Width, i / Width] = Block.B7; break; case '8': Blocks[i % Width, i / Width] = Block.B8; break; default: Console.Error.WriteLine("Can't Read Block: " + b); break; } } } DestroySome(); int ww = (int)Width * 32; int hh = (int)Height * 32; int ox = ((int)Game.Width - ww) / 2; int oy = ((int)Game.Height - hh) / 2; offset = new Location() { X = ox, Y = oy }; }
public bool Intersect(Entity entity, Location l, float radius) { if (entity.Location.DistSquared(l) <= radius * radius + entity.radius * entity.radius) { return true; } return false; }
public void Emit(Location l) { particles.Add(new Particle() { location = l + new Location() { X = (float)random.NextDouble() * 10 - 5, Y = (float)random.NextDouble() * 10 - 5 }, time = 1 }); }