void GetAllRectRange() { allRanges.Clear(); //hangDis = tran1.position.x - tran2.position.x; //lieDis = tran1.position.z - tran2.position.z; hangDis = tran2.position.x- tran1.position.x; lieDis = tran2.position.z- tran1.position.z ; float oneRectangleWidth = hangDis / lieCount; float oneRectangleHeight = lieDis / hangCount; for (int hang = 0; hang < hangCount-1; hang++) { for (int lie = 0; lie < lieCount; lie++) { float ponit1_x = tran1.position.x + lie * oneRectangleWidth; float ponit1_z = tran1.position.z + hang * oneRectangleHeight; //float ponit2_x = ponit1_x + oneRectangleWidth * (lie + 1); // float ponit2_z = ponit1_z + oneRectangleWidth * (hang + 1); float ponit2_x = ponit1_x + oneRectangleWidth; float ponit2_z = ponit1_z + oneRectangleWidth ; RangeRectangle rangeRect = new RangeRectangle(); rangeRect.zuoxia = new Vector3(ponit1_x, 0, ponit1_z); rangeRect.youshang = new Vector3(ponit2_x, 0, ponit2_z); allRanges.Add(rangeRect); } } }
public override void Update(GameTime gameTime, Map map, IList <Enemy> enemies) { if (IsAttacking) { currentAnimation = attackAnimations[FaceDirection]; if (currentAnimation.IsFinished) { PerformAttack(); IsAttacking = false; currentAnimation.IsFinished = false; currentAnimation = movingAnimations[FaceDirection]; } } for (int i = 0; i < arrows.Count; i++) { arrows[i].Update(); if (arrows[i].Rectangle.X + arrows[i].Rectangle.Width / 2 > map.MapWidth || arrows[i].Rectangle.X < 0 || arrows[i].Rectangle.Y <0 || arrows[i].Rectangle.Y + arrows[i].Rectangle.Height> map.MapHeight || !RangeRectangle.Contains(arrows[i].Rectangle)) { arrows.Remove(arrows[i]); } } for (int j = 0; j < enemies.Count; j++) { for (int i = 0; i < arrows.Count; i++) { if (arrows[i].Rectangle.Intersects(enemies[j].Rectangle) && enemies[j].IsAlive) { arrows.Remove(arrows[i]); enemies[j].Health -= this.Attack; if (enemies[j].Health <= 0) { Gold += enemies[j].Gold; enemies[j].Kill(); } } } } base.Update(gameTime, map, enemies); }