public Canyon(Game game, CanyonType type, Collidable parentCollidable, Vector3 position, float scale, float rotation = 0.0f) : base(game) { addComponent(new Spatial(game, this, Vector3.Zero)); Model m; this.type = type; switch (type) { case CanyonType.Canyon1: m = Game.Content.Load<Model>(@"Models\Canyon\Canyon1"); break; case CanyonType.Canyon2: m = Game.Content.Load<Model>(@"Models\Canyon\Canyon2"); break; case CanyonType.Canyon3: m = Game.Content.Load<Model>(@"Models\Canyon\Canyon3"); break; case CanyonType.Canyon4: m = Game.Content.Load<Model>(@"Models\Canyon\Canyon4"); break; case CanyonType.Canyon5: m = Game.Content.Load<Model>(@"Models\Canyon\Canyon5"); break; default: m = Game.Content.Load<Model>(@"Models\Canyon\Canyon5"); break; } getComponent<Spatial>().transform = Matrix.CreateRotationY(rotation) * Matrix.CreateScale(new Vector3(scale, scale * 2, scale)) ; getComponent<Spatial>().position = position; addComponent(new Drawable3D(game, this, m)); addComponent(new Collidable(game, this, CollisionType.environment, onHit, 0, 1000, parentCollidable, getComponent<Drawable3D>().modelBoundingBox)); }
public Collidable(Game game, Entity.Entity parent, CollisionType type, CollisionEvent e, int health, int damage, Collidable parentCollidable, BoundingBox boundingBox) : base(game, parent) { this.onCollision = e; this.type = type; this.health = health; this.damage = damage; children = new List<Collidable>(); parentCollidable.addChild(this); this.boundingBox = boundingBox; }
public Collidable(Game game, Entity.Entity parent, CollisionType type, CollisionEvent e, int health, int damage,Collidable parentCollidable, float range = 50.0f) : base(game, parent) { this.onCollision = e; this.type = type; this.health = health; this.damage = damage; children = new List<Collidable>(); parentCollidable.addChild(this); rangeSquared = range * range; }
public void removeCollidable(Collidable c) { if (c.type == CollisionType.environment || c.type == CollisionType.powerUp) { stationaryCollidables.Remove(c); } else { movingCollidables.Remove(c); } }
public Building(Game game, BuildingType type, Collidable parentCollidable, Vector3 position,float scale = 1.0f, bool rotate90 = false) : base(game) { addComponent(new Spatial(game, this,Vector3.Zero)); if(rotate90) getComponent<Spatial>().transform = Matrix.CreateScale(scale) * Matrix.CreateRotationY((float)Math.PI/2.0f) * Matrix.CreateTranslation(position); else getComponent<Spatial>().transform = Matrix.CreateScale(scale) * Matrix.CreateTranslation(position); Model m; switch (type) { case BuildingType.Bridge: m = Game.Content.Load<Model>(@"Models\Buildings\Bridge"); break; case BuildingType.Building_With_Tower: m = Game.Content.Load<Model>(@"Models\Buildings\Building_With_Tower"); break; case BuildingType.Building: m = Game.Content.Load<Model>(@"Models\Buildings\Building_02"); break; case BuildingType.Circular_Tower: m = Game.Content.Load<Model>(@"Models\Buildings\Circular_Tower"); break; case BuildingType.City_Building: m = Game.Content.Load<Model>(@"Models\Buildings\City_Building"); break; case BuildingType.Iffel_Tower: m = Game.Content.Load<Model>(@"Models\Buildings\Iffel_Tower"); break; case BuildingType.Pointed_Tower: m = Game.Content.Load<Model>(@"Models\Buildings\Pointed_Tower"); break; case BuildingType.Skyscraper: m = Game.Content.Load<Model>(@"Models\Buildings\Skyscraper"); break; case BuildingType.Tower: m = Game.Content.Load<Model>(@"Models\Buildings\Tower"); break; case BuildingType.Triangle_Building: m = Game.Content.Load<Model>(@"Models\Buildings\Triangle_Building"); break; case BuildingType.Warehouse: m = Game.Content.Load<Model>(@"Models\Buildings\Warehouse"); break; default: m = Game.Content.Load<Model>(@"Models\Buildings\Building"); break; } addComponent(new Drawable3D(game,this,m)); addComponent(new Collidable(game, this, CollisionType.environment, onHit, 0, 1000, parentCollidable, getComponent<Drawable3D>().modelBoundingBox)); }
public void addChild(Collidable child) { children.Add(child); }
public eCollision(Collidable collidable1, Collidable collidable2) { mainObject = collidable1; hitObject = collidable2; }
public Block(Game game, Vector3 position, Collidable parentCollidable) : base(game) { addComponent(new Spatial(game, this, position)); addComponent(new Collidable(game, this, CollisionType.environment, onHit, 0, 0, parentCollidable, new BoundingBox())); }
private float? checkAgainstChildren(Collidable c, Ray ray) { float? collided = null; for (int i = 0; i < c.children.Count && collided == null; i++) { Drawable3D dr = c.children[i].getComponent<Drawable3D>(); if (dr != null) { collided = checkAgainstMesh(dr, ray); } else { collided = checkAgainstChildren(c.children[i], ray); } } return collided; }
private void onCollision(Collidable c1, Spatial sp1, Collidable c2) { c1.health -= c2.damage; c2.health -= c1.damage; c1.onCollision(new eCollision(c1, c2)); c2.onCollision(new eCollision(c1, c2)); for (int i = 0; i < c2.children.Count; i++) { checkCollision(c1, sp1, c2.children[i], c2.children[i].getComponent<Spatial>()); } }
private void checkCollision(Collidable c1, Spatial sp1, Collidable c2, Spatial sp2) { Vector3[] points1 = new Vector3[2]; Vector3[] points2 = new Vector3[2]; points1[0] = Vector3.Transform(c1.boundingBox.Min, sp1.transform); points1[1] = Vector3.Transform(c1.boundingBox.Max, sp1.transform); points2[0] = Vector3.Transform(c2.boundingBox.Min, sp2.transform); points2[1] = Vector3.Transform(c2.boundingBox.Max, sp2.transform); BoundingBox collsionBoundingBox2 = BoundingBox.CreateFromPoints(points1); BoundingBox collsionBoundingBox1 = BoundingBox.CreateFromPoints(points2); if (collsionBoundingBox1.Intersects(collsionBoundingBox2)) { Drawable3D dw1 = c1.getComponent<Drawable3D>(); Drawable3D dw2 = c2.getComponent<Drawable3D>(); if (dw1 != null && dw2 != null) { foreach (BoundingBox bb1 in dw1.boundingBoxes) { points1[0] = Vector3.Transform(bb1.Min, sp1.transform); points1[1] = Vector3.Transform(bb1.Max, sp1.transform); collsionBoundingBox1 = BoundingBox.CreateFromPoints(points1); foreach (BoundingBox bb2 in dw2.boundingBoxes) { points2[0] = Vector3.Transform(bb2.Min, sp2.transform); points2[1] = Vector3.Transform(bb2.Max, sp2.transform); collsionBoundingBox2 = BoundingBox.CreateFromPoints(points2); if (collsionBoundingBox1.Intersects(collsionBoundingBox2)) { onCollision(c1, sp1, c2); } } } } else { onCollision(c1, sp1, c2); } } }