public void TryLaserShot() { float LaserLen = 10f; if (LasersCharges.x > 0) { LasersCharges.x--; AsteroidsGame.current.UpdateLaserCounter(); var up = logicobj.up; foreach (var item in Engine.FindObjectsOfType <FastPhysics>()) { if (!FastPhysics.CrossArray(item.logicobj.tags, tagsblacklist)) { //Расстояние до лазера от объекта это длина его перпендикуляра если корабль смотрит в сторону объекта var ip = item.position; if (Vector2.Distance(up + position, ip) < Vector2.Distance(position, ip))//Если корабль смотрит в сторону объекта { Vector2 cross = PerpPoint(ip - position, up); if (cross.magnitude < item.Radius && Vector2.Distance(ip - cross, position) < LaserLen)//Длина перепендикуляра { AsteroidsGenerator.Crush(item.logicobj, true); } } } } var laser = LogicalObject.Create() .AddPart(new PolyRenderer(new Vector2[] { new Vector2(0, 0.5f), new Vector2(0, LaserLen) }, Color.red)); laser.position = position; laser.angle = angle; Destroy(laser, 0.1f); } }
public static LogicalObject Meteor() { return(LogicalObject.Create(Vector2.zero, new Vector2(0.8f, 0.8f), tag: "Meteor") .AddPart <PolyRenderer>() .AddPart(new SpriteDrawer(Chache.Resources.loaded["Asteroid" + UnityEngine.Random.Range(0, 3)])) .AddPart <MeteorsLogic>() .AddPart(new FastPhysics(0, 0.4f))); }
public static LogicalObject Asteroid() { return(LogicalObject.Create(tag: "Asteroid") .AddPart <PolyRenderer>() .AddPart(new SpriteDrawer(Chache.Resources.loaded["Asteroid" + UnityEngine.Random.Range(0, 3)])) .AddPart <AsteroidsLogic>() .AddPart(new FastPhysics(0, 0.5f))); }
public static LogicalObject Ship() { return(LogicalObject.Create(tag: "Ship") .AddPart(new PolyRenderer(new Vector2[] { new Vector2(-0.5f, -0.5f), new Vector2(0.5f, -0.5f), new Vector2(0, 0.5f), })) .AddPart(new SpriteDrawer(source: Chache.Resources.loaded["ship"])) .AddPart <ShipLogic>() .AddPart <ShipControll>() .AddPart(new FastPhysics(drag: 3, radius: 0.5f))); }
public static LogicalObject Bullet() { return(LogicalObject.Create(Vector2.zero, new Vector2(0.2f, 0.2f), tag: "Untagged") .AddPart(new PolyRenderer(new Vector2[] { new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) })) .AddPart(new SpriteDrawer(Chache.Resources.loaded["bullet"])) .AddPart(new BulletLogic()) .AddPart(new FastPhysics(drag: 0, radius: 0.05f))); }
public static LogicalObject UFO() { return(LogicalObject.Create(tag: "UFO") .AddPart(new PolyRenderer(new Vector2[] { new Vector2(-0.5f, -0.1f), new Vector2(-0.3f, -0.3f), new Vector2(0.3f, -0.3f), new Vector2(0.5f, -0.1f), new Vector2(0.3f, 0.1f), new Vector2(-0.3f, 0.1f), new Vector2(-0.5f, -0.1f), new Vector2(0.5f, -0.1f), new Vector2(0.3f, 0.1f), new Vector2(0.3f, 0.1f), new Vector2(0.2f, 0.1f), new Vector2(0.1f, 0.3f), new Vector2(-0.1f, 0.3f), new Vector2(-0.2f, 0.1f), new Vector2(-0.3f, 0.1f), })) .AddPart(new SpriteDrawer(Chache.Resources.loaded["UFO"])) .AddPart <UFOLogic>() .AddPart(new FastPhysics(0, 0.5f))); }