public static void FiresUpdate(ref List <Fire> bullets, MainPlane versus)// collision between all anemies fires and Plane { for (int x = 0; x < bullets.Count; ++x) { Fire fire = bullets[x]; if (Events.pixelCollesion(versus.texturesCollection[versus.StandardImgFrame], fire.texturesCollection[fire.StandardImgFrame], new Vector2((float)versus.cordx, (float)versus.cordy), new Vector2((float)fire.cordx, (float)fire.cordy))) { fire.Exist = false; Events.health -= 20; } if (fire.OutOfBorders(fire.width, fire.height) || !fire.Exist) // delete { bullets.Remove(fire); fire.Exist = false; x--; } else // update { fire.Update(); } } }
bool whichin = false; // to reset the velocity public void Update(Fire fire) { // Allows the game to exit // velocity_x = 0; velocity_y = 0; int radius = 200; fireeDelay--; if (fire != null) // there is no fires { if (Math.Sqrt(((cordx - fire.cordx) * (cordx - fire.cordx)) + ((cordy - fire.cordy) * (cordy - fire.cordy))) <= radius) // int the range { if (whichin == true) { velocity_x = cordx < fire.cordx ? -5 : 5; velocity_y = cordy < fire.cordy ? -5 : 5; //reset its max vel. according to plane's position } whichin = false; // rate cosidered 2 b the acceleration Avoid(new Vector2((float)fire.cordx, (float)fire.cordy), radius, true); // enemy avoids plane if (Math.Abs(velocity_x) > 5) // dont exceed max vel { velocity_x = velocity_x < 0 ? -5 : 5; } if (Math.Abs(velocity_y) > 5) { velocity_y = velocity_y < 0 ? -5 : 5; } cordx += (float)velocity_x; cordy += (float)velocity_y; // update position } } else { whichin = true; radius = 80; Avoid(new Vector2((float)Game1.Airplane.cordx, (float)Game1.Airplane.cordy - 400), radius, false); // get closer to plane's position if (Math.Abs(velocity_x) > 5) // dont exceed max vel { velocity_x = velocity_x < 0 ? -5 : 5; } if (Math.Abs(velocity_y) > 5) { velocity_y = velocity_y < 0 ? -5 : 5; } cordx += (float)velocity_x; cordy += (float)velocity_y; // update it // fire if ((int)fireeDelay <= 0 && Exist) // delay between fires { bullets.Add(new Fire("Images//2oo", new Vector2((float)cordx, (float)cordy), 0, -7)); // enemies fire image fireeDelay = rand.Next(100, 300); } Fire.FiresUpdate(ref bullets, Game1.Airplane); // update all the fires wth its collision wth the plane } /* if (OutOfBorders() == 1) * velocity_x -= 10; * else if (OutOfBorders() == -1) * velocity_x += 10; * else if (OutOfBorders() == 2) * velocity_x -= 10; * */ }
public void Update(float IncInAngle, float SpeedOfSeeking) { velocity_y = SpeedOfSeeking; velocity_x = SpeedOfSeeking; float toolmosallas = Math.Abs((float)(cordx - GotoPosition.X)); float ardmosallas = Math.Abs((float)(cordy - GotoPosition.Y)); if ((int)toolmosallas <= SpeedOfSeeking && (int)ardmosallas <= SpeedOfSeeking) // rotate when u rech ur position { DoRotation = true; } else if (toolmosallas == 0) // seek to this point (mosallasat w fithagorsat w kda) :D { cordx += velocity_x; } else if (ardmosallas == 0) { cordy += velocity_y; } else if (!(cordx == GotoPosition.X || cordy == GotoPosition.Y) && DoRotation == false) { if ((toolmosallas) < (ardmosallas)) { if (!(cordx == GotoPosition.X)) { if (cordx < GotoPosition.X) { cordx += (toolmosallas / ardmosallas) * velocity_x; } else { cordx -= (toolmosallas / ardmosallas) * velocity_x; } } if (!(cordy == GotoPosition.Y)) { if (cordy < GotoPosition.Y) { cordy += velocity_y; } else { cordy -= velocity_y; } } } else { if (!(cordx == GotoPosition.X)) { if (cordx < GotoPosition.X) { cordx += velocity_x; } else { cordx -= velocity_x; } } if (!(cordy == GotoPosition.Y)) { if (cordy < GotoPosition.Y) { cordy += (ardmosallas / toolmosallas) * velocity_y; } else { cordy -= (ardmosallas / toolmosallas) * velocity_y; } } } } if (!Exist) { StandardImgFrame = 1; // one pixel img } fireeDelay--; if ((int)fireeDelay <= 0 && Exist) // delay between fires { bullets.Add(new Fire("Images//2oo", new Vector2((float)cordx, (float)cordy), 0, -7)); // enemies fire image fireeDelay = rand.Next(100, 1000); } Fire.FiresUpdate(ref bullets, Game1.Airplane); // update all the fires wth its collision wth the plane if (bullets.Count <= 0 && Exist == false) { DeleteIt = true; } }