public void Draw(GameTimerEventArgs gameTime, Rectangle square, Rectangle screen, SpriteBatch sb, Map map) { Point p; Point off; double factX = ((this.egg.getBounds().Width * 0.45) * (square.Width / 155.0)); double factY = ((this.egg.getBounds().Height * 0.45) * (square.Height / 58.0)); off.X = (this.pos.X + 1) * (square.Width / 2); off.Y = (this.pos.X) * (square.Height / 2); p.X = -this.pos.Y * (square.Width / 2) + off.X + square.X + ((int)map.getSize().Y - 1) * (square.Width / 2); p.Y = this.pos.Y * (square.Height / 2) + off.Y + square.Y - ((int)map.getSize().Y - 1) * (square.Height / 2); Rectangle tar = new Rectangle((int)(p.X + (int)(117 * (square.Width / 155.0))), (int)(p.Y + (int)(38 * (square.Height / 58.0))), (int)factX, (int)factY); if (screen.Intersects(tar)) this.egg.Draw(sb, tar); }
public void Draw(GameTimerEventArgs gameTime, Rectangle square, Rectangle screen, SpriteBatch sb, Map map) { Point p; Point off; if (this.st == States.DEAD && this.dead == false) { this.deadTimer = gameTime.TotalTime + TimeSpan.FromSeconds(5); this.dead = true; } if (this.st == States.DEAD || this.st == States.FINISHED) { if (this.deadTimer >= gameTime.TotalTime) { double factX = (this.sdead.getBounds().Width * (square.Width / 155.0)); double factY = (this.sdead.getBounds().Height * (square.Height / 58.0)); off.X = (this.pos.X + 1) * (square.Width / 2); off.Y = (this.pos.X) * (square.Height / 2); p.X = -this.pos.Y * (square.Width / 2) + off.X + square.X + ((int)map.getSize().Y - 1) * (square.Width / 2); p.Y = this.pos.Y * (square.Height / 2) + off.Y + square.Y - ((int)map.getSize().Y - 1) * (square.Height / 2); Rectangle tar = new Rectangle((int)(p.X + (int)(42 * (square.Width / 155.0))), (int)(p.Y - (int)(19 * (square.Height / 58.0))), (int)factX, (int)factY); if (screen.Intersects(tar)) this.sdead.Draw(sb, tar); } else this.st = States.FINISHED; } else { Rectangle tar = Rectangle.Empty; double factX = 0.0; double factY = 0.0; if (this.st == States.TAKE || this.st == States.DROP) { factX = (this.stake[(int)this.dir].getBounds().Width * (square.Width / 155.0)); factY = (this.stake[(int)this.dir].getBounds().Height * (square.Height / 58.0)); off.X = (this.pos.X + 1) * (square.Width / 2); off.Y = (this.pos.X) * (square.Height / 2); p.X = -this.pos.Y * (square.Width / 2) + off.X + square.X + ((int)map.getSize().Y - 1) * (square.Width / 2); p.Y = this.pos.Y * (square.Height / 2) + off.Y + square.Y - ((int)map.getSize().Y - 1) * (square.Height / 2); tar = new Rectangle((int)(p.X + (int)(42 * (square.Width / 155.0))), (int)(p.Y - (int)(19 * (square.Height / 58.0))), (int)factX, (int)factY); if (screen.Intersects(tar)) this.stake[(int)this.dir].Draw(sb, tar); } else if (this.st == States.INCANT) { factX = (this.sincant.getBounds().Width * (square.Width / 155.0)); factY = (this.sincant.getBounds().Height * (square.Height / 58.0)); off.X = (this.pos.X + 1) * (square.Width / 2); off.Y = (this.pos.X) * (square.Height / 2); p.X = -this.pos.Y * (square.Width / 2) + off.X + square.X + ((int)map.getSize().Y - 1) * (square.Width / 2); p.Y = this.pos.Y * (square.Height / 2) + off.Y + square.Y - ((int)map.getSize().Y - 1) * (square.Height / 2); tar = new Rectangle((int)(p.X + (int)(42 * (square.Width / 155.0))), (int)(p.Y - (int)(19 * (square.Height / 58.0))), (int)factX, (int)factY); if (screen.Intersects(tar)) this.sincant.Draw(sb, tar); } else if (this.st == States.FORK) { factX = (this.sfork[(int)this.dir].getBounds().Width * (square.Width / 155.0)); factY = (this.sfork[(int)this.dir].getBounds().Height * (square.Height / 58.0)); off.X = (this.pos.X + 1) * (square.Width / 2); off.Y = (this.pos.X) * (square.Height / 2); p.X = -this.pos.Y * (square.Width / 2) + off.X + square.X + ((int)map.getSize().Y - 1) * (square.Width / 2); p.Y = this.pos.Y * (square.Height / 2) + off.Y + square.Y - ((int)map.getSize().Y - 1) * (square.Height / 2); tar = new Rectangle((int)(p.X + (int)(42 * (square.Width / 155.0))), (int)(p.Y - (int)(19 * (square.Height / 58.0))), (int)factX, (int)factY); if (screen.Intersects(tar)) this.sfork[(int)this.dir].Draw(sb, tar); } else if (this.st == States.INCANT) { factX = (this.sincant.getBounds().Width * (square.Width / 155.0)); factY = (this.sincant.getBounds().Height * (square.Height / 58.0)); off.X = (this.pos.X + 1) * (square.Width / 2); off.Y = (this.pos.X) * (square.Height / 2); p.X = this.pos.Y * (square.Width / 2) + off.X + square.X; p.Y = -this.pos.Y * (square.Height / 2) + off.Y + square.Y; tar = new Rectangle((int)(p.X + (int)(42 * (square.Width / 155.0))), (int)(p.Y - (int)(19 * (square.Height / 58.0))), (int)factX, (int)factY); if (screen.Intersects(tar)) this.sincant.Draw(sb, tar); } else { factX = (this.player[(int)this.dir].getBounds().Width * (square.Width / 155.0)); factY = (this.player[(int)this.dir].getBounds().Height * (square.Height / 58.0)); off.X = (this.pos.X + 1) * (square.Width / 2); off.Y = (this.pos.X) * (square.Height / 2); p.X = -this.pos.Y * (square.Width / 2) + off.X + square.X + ((int)map.getSize().Y - 1)* (square.Width / 2); p.Y = this.pos.Y * (square.Height / 2) + off.Y + square.Y - ((int)map.getSize().Y - 1) * (square.Height / 2); tar = new Rectangle((int)(p.X + (int)(42 * (square.Width / 155.0))), (int)(p.Y - (int)(19 * (square.Height / 58.0))), (int)factX, (int)factY); if (screen.Intersects(tar)) this.player[(int)this.dir].Draw(sb, tar); } if (screen.Intersects(tar)) { factX = (this.slvl[this.lvl - 1].getBounds().Width * (square.Width / 155.0)); factY = (this.slvl[this.lvl - 1].getBounds().Height * (square.Height / 58.0)); if (this.dir == Direction.NORTH || dir == Direction.WEST) this.slvl[this.lvl - 1].Draw(sb, new Rectangle((int)(p.X + (int)(35 * (square.Width / 155.0))), (int)(p.Y - (int)(30 * (square.Height / 58.0))), (int)factX, (int)factY)); else this.slvl[this.lvl - 1].Draw(sb, new Rectangle((int)(p.X + (int)(48 * (square.Width / 155.0))), (int)(p.Y - (int)(30 * (square.Height / 58.0))), (int)factX, (int)factY)); if (this.broadcast != null) { this.broacastTimer = gameTime.TotalTime + TimeSpan.FromSeconds(2); this.broadcast = null; } if (this.broacastTimer >= gameTime.TotalTime) { factX = (this.sbroadcast[0].getBounds().Width * (square.Width / 155.0)); factY = (this.sbroadcast[0].getBounds().Height * (square.Height / 58.0)); if (this.dir == Direction.NORTH || dir == Direction.WEST) this.sbroadcast[0].Draw(sb, new Rectangle((int)(p.X + (int)(78 * (square.Width / 155.0))), (int)(p.Y - (int)(25 * (square.Height / 58.0))), (int)factX, (int)factY)); else this.sbroadcast[1].Draw(sb, new Rectangle((int)(p.X + (int)(35 * (square.Width / 155.0))), (int)(p.Y - (int)(25 * (square.Height / 58.0))), (int)factX, (int)factY)); } } } }
public bool isInPolygon(Vector2 p, Rectangle square, Map map) { Vector2 pos = new Vector2(-(this.p.Y + 1) * (square.Width / 2) + square.X + ((this.p.X + 1) * (square.Width / 2)) + (map.getSize().Y) * (square.Width / 2), (this.p.Y + 1) * (square.Height / 2) + square.Y + ((this.p.X + 1) * (square.Height / 2)) - (map.getSize().Y) * (square.Height / 2)); Polygon target = new Polygon(new Vector2[] { new Vector2((pos.X) + square.Width / 2, (pos.Y)), new Vector2((pos.X) + square.Width, (pos.Y) + square.Height / 2), new Vector2((pos.X) + square.Width / 2, (pos.Y) + square.Height), new Vector2((pos.X), (pos.Y) + square.Height / 2) }); return target.Contains(p); }