public override void AddComponents() { Texture2D texture = ContentLoader.Load <Texture2D>("Mobs/Squid/circle"); SpriteRenderer spriteRenderer = new SpriteRenderer(new Sprite(texture)); spriteRenderer.Color = Color.HotPink; AddComponent(spriteRenderer); RectangleF targetRectangle = spriteRenderer.TargetRectangle; _outerCircleCollider = new CircleCollider( new Vector2(targetRectangle.Left, targetRectangle.Top), new Vector2(targetRectangle.Right, targetRectangle.Top), new Vector2(targetRectangle.Right, targetRectangle.Bottom), new Vector2(targetRectangle.Left, targetRectangle.Bottom) ); AddComponent(_outerCircleCollider); float localCircleBorderRadius = 6; _innerCircleCollider = new CircleCollider( new Vector2(targetRectangle.Left + localCircleBorderRadius, targetRectangle.Top + localCircleBorderRadius), new Vector2(targetRectangle.Right - localCircleBorderRadius, targetRectangle.Top + localCircleBorderRadius), new Vector2(targetRectangle.Right - localCircleBorderRadius, targetRectangle.Bottom - localCircleBorderRadius), new Vector2(targetRectangle.Left + localCircleBorderRadius, targetRectangle.Bottom - localCircleBorderRadius) ); AddComponent(_innerCircleCollider); _transform = AddComponent <Transform>(); _transform.Position = _headPosition; _transform.Origin = spriteRenderer.TargetRectangle.Size * 0.5f; _transform.Scale = 0.01f; }
void AddObjects() { CircleCollider cc = new CircleCollider(new Vector2(), objectSize); // Set the visuals for each object up ObjectVisuals earthVis = new ObjectVisuals(Brushes.Blue, objectSize); ObjectVisuals venusVis = new ObjectVisuals(Brushes.Beige, objectSize); ObjectVisuals mercuryVis = new ObjectVisuals(Brushes.Gray, objectSize); ObjectVisuals marsVis = new ObjectVisuals(Brushes.Red, objectSize); ObjectVisuals saturnVis = new ObjectVisuals(Brushes.Yellow, objectSize); ObjectVisuals jupiterVis = new ObjectVisuals(Brushes.LightGray, objectSize); ObjectVisuals uranusVis = new ObjectVisuals(Brushes.LightBlue, objectSize); ObjectVisuals neptuneVis = new ObjectVisuals(Brushes.DarkBlue, objectSize); ObjectVisuals sunVis = new ObjectVisuals(Brushes.Yellow, 9); // Create the objects needed for the solar system Star sun = new Star("Sun", 1.989E+30, new Vector2(0, 0), new Vector2(2 * Constants.AstronomicalUnit, 1 * Constants.AstronomicalUnit), cc, sunVis); CelestialObject mercury = new CelestialObject("Mercury", 0.3829 * 6E24, new Vector2(45E+3, 0), new Vector2(2 * Constants.AstronomicalUnit, 1.466 * Constants.AstronomicalUnit), cc, mercuryVis); CelestialObject venus = new CelestialObject("Venus", 6E24 * 0.815, new Vector2(35E+3, 0), new Vector2(2 * Constants.AstronomicalUnit, 1.72 * Constants.AstronomicalUnit), cc, venusVis); CelestialObject earth = new CelestialObject("Earth", 6E24, new Vector2(30E+3, 0), new Vector2(2 * Constants.AstronomicalUnit, 2 * Constants.AstronomicalUnit), cc, earthVis); CelestialObject mars = new CelestialObject("Mars", 0.107 * 6E24, new Vector2(24E+3, 0), new Vector2(2 * Constants.AstronomicalUnit, 2.666 * Constants.AstronomicalUnit), cc, marsVis); CelestialObject jupiter = new CelestialObject("Jupiter", 317.8 * 6E24, new Vector2(13E+3, 0), new Vector2(2 * Constants.AstronomicalUnit, 7 * Constants.AstronomicalUnit), cc, jupiterVis); CelestialObject saturn = new CelestialObject("Saturn", 8.55 * 6E24, new Vector2(9.68E+3, 0), new Vector2(2 * Constants.AstronomicalUnit, 11 * Constants.AstronomicalUnit), cc, saturnVis); CelestialObject urnanus = new CelestialObject("Uranus", 14.5 * 6E24, new Vector2(0, -6.8E+3), new Vector2(21 * Constants.AstronomicalUnit, 2 * Constants.AstronomicalUnit), cc, uranusVis); CelestialObject neptune = new CelestialObject("Neptune", 17.147 * 6E24, new Vector2(0, 5.43E+3), new Vector2(32 * Constants.AstronomicalUnit, 2 * Constants.AstronomicalUnit), cc, neptuneVis); }
public static bool Intersection(CircleCollider circle, float2 pos) { float2 dir = circle.Center - pos; float dist = math.length(dir); return(false); }
public static void CreateContacts(List <Body> bodies, out List <Contact> contacts) { contacts = new List <Contact>(); for (int i = 0; i < bodies.Count - 1; i++) { for (int j = i + 1; j < bodies.Count; j++) { Body bodyA = bodies[i]; Body bodyB = bodies[j]; if (bodyA.type == Body.eType.Static && bodyB.type == Body.eType.Static) { continue; } CircleCollider circleA = new CircleCollider(bodyA.position, ((Circle)bodyA.shape).radius); CircleCollider circleB = new CircleCollider(bodyB.position, ((Circle)bodyB.shape).radius); if (circleA.Contains(circleB)) { Contact contact = new Contact() { bodyA = bodyA, bodyB = bodyB }; float distance = (circleA.center - circleB.center).magnitude; contact.depth = (circleA.radius + circleB.radius) - distance; contact.normal = (circleA.center - circleB.center).normalized; contacts.Add(contact); } } } }
public static bool DoCollide(CircleCollider c1, CircleCollider c2) { float dist = MathUtils.GetDistance(c1.GetCenter(), c2.GetCenter()); float radsum = c1.GetRadius() + c2.GetRadius(); return(dist <= radsum); }
public SpriteShip(Sprite sprite) : base(sprite, false) { _boundary = new Rectangle { X = 10, Y = 50, Height = (int)World.Instance.WorldSize.Y - 80, Width = (int)World.Instance.WorldSize.X - 10 }; Scale.X = Scale.Y = 0.15f; PlayerStats = new PlayerStatistics(); Controller = new NullController(); // Create collider for ship CircleCollider cldr = new CircleCollider() { Radius = (int)230 * Scale.X, Position = Position }; cldr.Center.X = (Width / 2) - 9; cldr.Center.Y = (Height / 2) - 9; Collider = cldr; _weapon = new SingleBlaster(Width); Sprite.Frames.Add(new Rectangle { X = 0, Y = 0, Width = 405, Height = 488 }); Sprite.CenterPoint = new Vector2D { X = 405f / 2f, Y = 488f / 2f }; }
public Kuratko(Scene defaultScene) { entity = defaultScene.createEntity("entity", new Vector2(50, 50)); _inputHandler = entity.addComponent(new KuratkoInputHandler()); _mover = entity.addComponent(new Mover()); _collider = entity.colliders.add(new CircleCollider()); // ANIMACE var texture = defaultScene.contentManager.Load <Texture2D>("sprites/zviratka"); var subtextures = Subtexture.subtexturesFromAtlas(texture, 32, 32); _animation = entity.addComponent(new Sprite <Animations>(subtextures[8])); _animation.addAnimation(Animations.Default, new SpriteAnimation(new List <Subtexture>() { subtextures[8], })); _animation.addAnimation(Animations.Walk, new SpriteAnimation(new List <Subtexture>() { subtextures[9], subtextures[8], subtextures[16], })); }
public static Vector2 PushSpeedVector(CircleCollider main, CircleCollider second) { Vector2 pushV = second.GetCenter() - main.GetCenter(); pushV.Normalize(); return(pushV * pushOutSpeed); }
public Body(Layer layer, Vector2 position) : base(layer) { ICollider collider; if (_r.Next(2) == 0) { collider = new RectangleCollider( position, new Vector2(_r.Next(32, 64), _r.Next(32, 64)) / 2f ); } else { collider = new CircleCollider( position, _r.Next(16, 48) / 2f ); } AddComponent(new CPosition(position)); var phy = new CPhysics(1); phy.Collider = collider; AddComponent(phy); }
public static bool CheckCollision(CircleCollider h1, CircleCollider h2) { var h1Position = h1.GetPosition(); var h2Position = h2.GetPosition(); return(Math.Pow((h1Position.X - h2Position.X), 2) + Math.Pow((h1Position.Y - h2Position.Y), 2) < Math.Pow((h1.Radius + h2.Radius), 2)); }
private void GenerateCircleCollider() { float2 center = (Bounds.Min + Bounds.Max) * 0.5f; float r = math.distance(Bounds.Min, center); BoundsCircle = new CircleCollider(center, r); }
public static bool CheckCollision(BoxCollider h1, CircleCollider h2) { var deltaX = h2.Position.X - Math.Max(h1.Box.X, Math.Min(h2.Position.X, h1.Box.Right)); var deltaY = h2.Position.Y - Math.Max(h1.Box.Y, Math.Min(h2.Position.Y, h1.Box.Bottom)); return((deltaX * deltaX + deltaY * deltaY) < (h2.Radius * h2.Radius)); }
protected override void OnAdded() { var rectCollider = new RectangleCollider(); rectCollider.Area = new RectF(0, 0, 100, 100); rectCollider.IsVisible = true; rectCollider.Tag = "A"; AddCollider(rectCollider); var lineCollider = new LineCollider(); lineCollider.StartingPosition = new Vector2DF(110, 110); lineCollider.EndingPosition = new Vector2DF(200, 200); lineCollider.Thickness = 10; lineCollider.Tag = "B"; lineCollider.IsVisible = true; AddCollider(lineCollider); var circleCollider = new CircleCollider(); circleCollider.Center = new Vector2DF(300, 300); circleCollider.Radius = 90; circleCollider.Tag = "C"; circleCollider.IsVisible = true; AddCollider(circleCollider); Scale = new Vector2DF(0.5f, 0.5f); velocity = new Vector2DF(4, 0); }
public override void onAddedToEntity() { _circleCollider = entity.getComponent <CircleCollider>(); _mover = entity.getComponent <Mover>(); _physicsHandler = entity.getComponent <PhysicsHandler>(); _mapComponent = entity.scene.findEntity("tiled-map").getComponent <TiledMapComponent>(); }
public void CircleCollider() { var tc = new TestCore(); tc.Init(); var collider1 = new CircleCollider(); collider1.Position = new Vector2F(30f, 30f); collider1.Rotation = MathHelper.DegreeToRadian(10.0f); collider1.Radius = 30.0f; const string path = "Serialization/CircleCollider.bin"; Serialize(path, collider1); var collider2 = Deserialize <CircleCollider>(path); Assert.NotNull(collider2); Assert.AreEqual(collider1.Position, collider2.Position); Assert.AreEqual(collider1.Rotation, collider2.Rotation); Assert.AreEqual(collider1.Radius, collider2.Radius); tc.End(); }
public override void OnSpawn() { //_sprite = entity.addComponent(new Sprite(AssetLoader.GetTexture("particles/blood"))); _sprite = addComponent(new Sprite(_bloodTexture)); _sprite.renderLayer = _drawAbovePlayer ? Layers.PlayerFrontest : Layers.MapObstacles; _sprite.material = new Material(); _mover = addComponent(new Mover()); _bloodHitbox = addComponent(new CircleCollider(0.1f)); Flags.setFlagExclusive(ref _bloodHitbox.collidesWithLayers, Layers.MapObstacles); _bloodHitbox.physicsLayer = 0; //Scale //float random_scale = ((float)rng.range(-20, 20) / 100); float random_scale = ((float)rng.range(-20, 20) / 100); scale = new Vector2(1f + random_scale, 1f + random_scale); //Rotation _sprite.transform.rotation = rng.nextAngle(); if (_drawAbovePlayer) { Core.schedule(0.5f, _ => UpdateRenderLayerDepth()); } }
/// <summary> /// A train that drives along a given path. /// Does not react to traffic lights. /// </summary> private Train(List <Vector2> Path) : base(Path[0]) { AddComponent(new Path(Path)); AddComponent(new Graphic(Assets.Train.GetRandom(), true)); Collider = AddComponent(new CircleCollider(new Vector2(60, 0), 10, CollisionTag.Vehicle)) as CircleCollider; }
public SpriteAsteroid CreateAsteroid(float x, float y, float rotation) { if (_spriteAsteroid == null) { _spriteAsteroid = GraphicsManager.Instance.LoadSpriteFromImagePath(String.Format("{0}\\Spritesheets\\asteroid_01.png", AssetPath)); _spriteAsteroid.Frames.Add(new System.Drawing.Rectangle { X = 0, Y = 0, Width = 120, Height = 120 }); } SpriteAsteroid sprite = new SpriteAsteroid(_spriteAsteroid); sprite.Position.X = x; sprite.Position.Y = y; sprite.Velocity.X = 0f; sprite.Velocity.Y = 0f; CircleCollider collider = (CircleCollider)PhysicsFactory.CreateCircleCollider(sprite.Position, 40); collider.Center.X = 125f / 2f; collider.Center.Y = 125f / 2f; sprite.Collider = collider; sprite.Life = (float)(RandomManager.Instance.Next(100, 1200) / 100f); return(sprite); }
private bool collisionWithCircle(CircleCollider circle) { bool inside1 = circleCollisionWithPoint(circle, startPos); bool inside2 = circleCollisionWithPoint(circle, endPos); if (inside1 || inside2) { return(true); } float lineLength = (endPos - startPos).magnitude; // Dot product of line and circle float dot = (((circle.transform.position.x - startPos.x) * (endPos.x - startPos.x)) + ((circle.transform.position.y - startPos.y) * (endPos.y - startPos.y))) / Mathf.Pow(lineLength, 2); float closestX = startPos.x + (dot * (endPos.x - startPos.x)); float closestY = startPos.y + (dot * (endPos.y - startPos.y)); Vector3 closest = new Vector3(closestX, closestY); if (!collisionWithPoint(closest)) { return(false); } float dist = (closest - circle.transform.position).magnitude; return(dist <= circle.radius); }
/// <summary> /// A circular field. /// </summary> public SystemicField(string affects, float amountPerFrame, float lifetime, float radius) : this(affects, amountPerFrame, lifetime) { Collider circle = new CircleCollider((int)radius, (int)CollisionTags.SystemicAreaOfEffect); circle.CenterOrigin(); AddCollider(circle); }
private void InitCircleColliders() { ColliderCategory colliderCategory = ColliderCategory.Bullet; ColliderCategory collidesWith = ColliderCategory.Terrain | ColliderCategory.Actor | ColliderCategory.Bullet; CircleCollider fragNade = new CircleCollider(null, "FragNade", 3 / 32f, 0.3f, colliderCategory, collidesWith); CircleColliders.Add("FragNade", fragNade); }
private void setOffset(ref CircleCollider collider, Vector2 offset) { var o = Util.Rotate(offset, sprite.Angle); collider.CenterOrigin(); collider.OriginX += o.X; collider.OriginY += o.Y; }
public override void onAddedToEntity() { collider = new CircleCollider(); collider.isTrigger = true; this.entity.addComponent(collider); //this.entity.addComponent(new Text(Graphics.instance.bitmapFont, "TESTTEST", new Vector2(0, 0), Color.White)) // .setRenderLayer(99); }
public bool Contains(CircleCollider circle) { Vector2 direction = center - circle.center; float sqrDistance = direction.sqrMagnitude; float sqrRadius = (radius + circle.radius) * (radius + circle.radius); return(sqrDistance <= sqrRadius); }
public Projectile(float x, float y, Vector2 direction, float speed, int radius, float lifespan, int damage, params int[] tags) : base(x, y) { direction.Normalize(); this.velocity = direction * speed; this.lifespan = lifespan; Collider = new CircleCollider(radius, tags); Collider.CenterOrigin(); this.damage = damage; }
public PickupItem(float x = 0, float y = 0, Graphic graphic = null, Collider collider = null, string name = "") : base(x, y, graphic, collider, name) { Graphic = graphic ?? Image.CreateCircle(ItemRadius, Color.Green); Collider = new CircleCollider(ItemRadius, Tag.PickupItem); Graphic.CenterOrigin(); Collider.CenterOrigin(); }
public override void OnCollision(CircleCollider other, Vector2 normal) { // On collision with another CircleCollider, run Physics Simulation physicsBody.CollisionResolution(other, normal); // and play a bounce sound. if (soundInstance.State == SoundState.Stopped && Vector2.Distance(physicsBody.velocity, Vector2.Zero) > 5) { soundInstance.Play(); } }
/// <summary> /// Returns a list of entities that collide with the given Collider and posess the Tag. /// </summary> public IEnumerable <Entity> Collide(CircleCollider Collider, CollisionTag Tag) { foreach (var possibleCollider in Colliders) { if (possibleCollider.Tag == Tag && possibleCollider.Entity != Collider.Entity && possibleCollider.CollidesWith(Collider)) { yield return(possibleCollider.Entity); } } }
public override void OnCollision(CircleCollider other, Vector2 normal) { // On collision with another CircleCollider, run Physics Simulation physicsBody.CollisionResolution(other, normal); // If the player collides with a patient, heal them. if (other.entity.tag == "Player") { health = 100f; } }
public override void onAddedToScene() { switcherTexture = scene.content.Load <Texture2D>("ColorEntities/color_switcher"); switcherSprite = new Sprite(switcherTexture); addComponent(switcherSprite); var collider = new CircleCollider(switcherTexture.Height / 2); addComponent(collider); }
private static bool CollideRectCirc(RectangleCollider a, CircleCollider b) { if (a.IntersectsPoint(b.GetCenter())) return true; //Check the circle against the four edges of the rectangle Vector2 pA = a.GetTopLeft(); Vector2 pB = a.GetTopRight(); Vector2 pC = a.GetBottomRight(); Vector2 pD = a.GetBottomLeft(); if (b.IntersectsLine(pA, pB, 0) || b.IntersectsLine(pB, pC, 0) || b.IntersectsLine(pC, pD, 0) || b.IntersectsLine(pD, pA, 0)) return true; return false; }
private static bool CollideCircCirc(CircleCollider a, CircleCollider b) { Vector2 diff = b.GetCenter() - a.GetCenter(); return (diff.X * diff.X + diff.Y * diff.Y < Math.Pow(XP.Distance(b.GetCenter(), a.GetCenter()),2)); }
private void SetUpWorldObjects() { // get user input object Input = new InputManager(); Input.AddBinding(PAUSE, Keys.Escape); Input.AddBinding(TOGGLE_OFFSET, Keys.T); Add(Input); // create the center marker CenterMarker = new Sprite(ContentLoader.Content.Load<Texture2D>("ItemGlimer")); CenterMarker.Center(); CenterMarker.Scale = new Vector2(0.1f, 0.1f); CenterMarker.Position = new Vector2(1920 / 2, 1080 / 2); CenterMarker.Color = Color.Red; Add(CenterMarker); // create the center colliders centerCircleCollider = new CircleCollider(100); centerCircleCollider.WireFrame = WireFrames.CircleWireFrame(centerCircleCollider.Bounds); centerCircleCollider.Position = new Vector2(1920 / 2, 1080 / 2); Add(centerCircleCollider); centerBoxCollider = new BoxCollider(new Point(200, 200)); centerBoxCollider.WireFrame = WireFrames.BoxWireFrame(centerBoxCollider.Bounds); centerBoxCollider.Position = new Vector2(1920 / 2, 1080 / 2); centerBoxCollider.Center(); //Add(centerBoxCollider); // create the screen size marker ScreenSizeMarker = new Sprite(ContentLoader.Content.Load<Texture2D>("ItemGlimer")); ScreenSizeMarker.Center(); ScreenSizeMarker.Scale = new Vector2(0.1f, 0.1f); ScreenSizeMarker.Position = new Vector2(1920, 1080); ScreenSizeMarker.Color = Color.Red; Add(ScreenSizeMarker); // create smiley smiley = new SmileyWalkDude(); smiley.Position = new Vector2(1920 / 4, 1080 / 4); Add(smiley); // create the instruction text instructions = new InstructionText("Move the Character off of the screen to continue."); instructions.Position = new Vector2(200, 50); instructions.DrawOrder = 1; Add(instructions); // create the outerBounds Point size = new Point(1920 - 10, 1080 - 10); outerBounds = new Corral(size, smiley); outerBounds.Position = new Vector2(5, 5); Add(outerBounds); }