public virtual void Set(String a, Vector2 p, NPC n, Vector2 v, int d, bool iE, bool collide, float dT, ManagerHelper mH) { asset = a; position = p; velocity = v; damage = d; // set damage existenceTime = 4; // Default 10 seconds drawTime = dT; //set up draw time affiliation = n.GetAffiliation(); //Sets up hurting creator = n; isExplosive = iE; shouldCollide = collide; //Get x and y values from angle and set up direction rotation = DWMath.Atan2(velocity.Y, velocity.X); //No friction drag = 0; LoadContent(mH.GetTextureManager()); if (!(this is Tossable)) { setModeIndex();//set mode index } }
public static void Initialize() { for (int i = 0; i < NUM_DIRECTIONS; i++) { ROTATIONS[i] = MathHelper.TwoPi * i / NUM_DIRECTIONS; DIRECTIONS[i] = new Vector2(DWMath.Cos(ROTATIONS[i]), DWMath.Sin(ROTATIONS[i])); } }
public static Vector2 CollideRandom(Vector2 v1, Vector2 v2) { var rand = new Random(); //Skew the angle slightly to nudge the collider out of the way gradulaly var angle = PathHelper.Direction(v1, v2) + (((rand.Next(2) == 0) ? -1 : 1) * MathHelper.Pi * 4 / 5); //Exctract the x and y values from the skewed angle return(new Vector2(DWMath.Cos(angle), DWMath.Sin(angle))); }
public Bomber(Vector2 p, AffliationTypes a, NPC t, ManagerHelper mH) : base("", p) { hasBombed = false; drawTarget = true; targetPosition = t.GetOriginPosition(); health = 100; movementSpeed = 1000; affiliation = a; //Set up rotation rotation = PathHelper.Direction(GetOriginPosition(), targetPosition); //Set up direction float dir = PathHelper.Direction(GetOriginPosition(), t.GetOriginPosition()); velocity = new Vector2(DWMath.Cos(dir), DWMath.Sin(dir)) * movementSpeed; //Set up path path = new Path(); path.Add(targetPosition, mH); string targeAsset = ""; //Set up affiliation switch (a) { case AffliationTypes.red: targeAsset = "Dots/Red/targetRed"; asset = "Dots/Red/bomber_red"; break; case AffliationTypes.blue: targeAsset = "Dots/Blue/targetBlue"; asset = "Dots/Blue/bomber_blue"; break; case AffliationTypes.green: targeAsset = "Dots/Green/targetGreen"; asset = "Dots/Green/bomber_green"; break; case AffliationTypes.yellow: targeAsset = "Dots/Yellow/targetYellow"; asset = "Dots/Yellow/bomber_yellow"; break; } targetSprite = new Sprite(targeAsset, targetPosition); mH.GetAudioManager().Play(AudioManager.PLANE, AudioManager.RandomVolume(mH), AudioManager.RandomPitch(mH), 0, false); }
public static float Direction(Vector2 pA, Vector2 pB) { //Slope float cX = pB.X - pA.X, cY = pB.Y - pA.Y; float angle = DWMath.Atan2(cY, cX); if (angle < 0) { angle += MathHelper.TwoPi; } else if (angle >= MathHelper.TwoPi) { angle -= (MathHelper.TwoPi); } return(angle); }
public override void Update(ManagerHelper mH) { foreach (Sprite section in poolSections) { section.Turn(10000.0f / (section.GetFrame().Width *section.GetFrame().Width) * mH.GetDeltaSeconds()); } foreach (NPC a in mH.GetNPCManager().GetNPCs()) { if (!(a is Bomber)) { float tempDistance = PathHelper.DistanceSquared(GetOriginPosition(), a.GetOriginPosition()); if (tempDistance < 15 * 15) { //TODO: Modify a.position = mH.GetLevelSize() * new Vector2(mH.GetRandom().Next(2), mH.GetRandom().Next(2)); } else if (tempDistance < frame.Width / 2 * frame.Width / 2) { float tempRot = PathHelper.Direction(a.GetOriginPosition(), GetOriginPosition()) - MathHelper.Pi / 9; a.AddAcceleration(new Vector2(DWMath.Cos(tempRot), DWMath.Sin(tempRot)) * 4); } } } foreach (Particle e in mH.GetParticleManager().GetParticles()) { float tempDistance = PathHelper.DistanceSquared(GetOriginPosition(), e.GetOriginPosition()); if (tempDistance < 15 * 15) { e.SetDrawTime(0); } else if (tempDistance < (frame.Width / 2) * (frame.Width / 2)) { float tempRot = PathHelper.Direction(e.GetOriginPosition(), GetOriginPosition()) + MathHelper.Pi / 9; e.AddAcceleration(new Vector2((float)DWMath.Cos(tempRot), (float)DWMath.Sin(tempRot)) * 100); } } base.Update(mH); }
public bool IsVectorObstructed(Vector2 pA, Vector2 pB) { var slope = new Vector2(pB.X - pA.X, pB.Y - pA.Y); float theta = DWMath.Atan2(slope.Y, slope.X); slope = new Vector2(DWMath.Cos(theta) * 32, DWMath.Sin(theta) * 32); pB /= new Vector2(32); pB.X = (int)pB.X; pB.Y = (int)pB.Y; var t = new Vector2((int)(pA.X / 32), (int)(pA.Y / 32)); if (t == pB) { return(false); } return(RecursiveVectorObstructed(pA, pB, slope)); }
public static Vector2 Direction(float r) { return(new Vector2(DWMath.Cos(r), DWMath.Sin(r))); }
public static float Direction(Vector2 r) { return(DWMath.Atan2(r.Y, r.X)); }