public void UpdatePlayerSprite(Game1 game, PlayerObject pl, Sound1 so) { MouseState current_mouse = Mouse.GetState(); old_position = SpriteList.First().position; if (current_mouse.X > game.GraphicsDevice.Viewport.Width || current_mouse.Y > game.GraphicsDevice.Viewport.Height || current_mouse.X < 0 || current_mouse.Y < 0) { // out of bounds } else SpriteList.First().position = new Vector2(current_mouse.X * resolution_x_ratio, current_mouse.Y * resolution_y_ratio); // check for intersection with umbrella if (umbrella != null) { MovingObject umb_intersect = umbrella; umb_intersect.width = umb_width; umb_intersect.height = umb_height; if (Intersects(SpriteList.First(), umb_intersect)) { so.PlayUmbrellaPickUp(game); pl.umbrella++; umbrella=null; } } }
public void SpawnUmbrella(Game1 game, int max_X, int max_Y, Sound1 so) { if (umbrella == null) { umbrella = new MovingObject(); umbrella.width = sprite11.Width; umbrella.height = sprite11.Height; umbrella.position = new Vector2(max_X * (float)RandGen.NextDouble(), max_Y * (float)RandGen.NextDouble()); umbrella.speed = Vector2.Zero; so.PlayUmbrellaSpawn(game); } }
public bool Intersects(MovingObject a, MovingObject b) { BoundingSphere s1, s2; Vector3 acenter = new Vector3(a.position.X, a.position.Y , 0.0f); Vector3 bcenter = new Vector3(b.position.X, b.position.Y , 0.0f); // (w/2 + h/2)/3 = (w+h)/6 float aradius = ((float)(a.width+a.height)/6.0f); float bradius = ((float)(b.width+b.height)/6.0f); //s1 = new BoundingBox(new Vector3(a.position.X + 30, a.position.Y + 30, 0.0f), new Vector3(a.position.X + sprite5.Width - 30, a.position.Y + sprite5.Height - 30, 0.0f)); //s2 = new BoundingBox(new Vector3(b.position.X + 30, b.position.Y + 30, 0.0f), new Vector3(b.position.X + sprite5.Width - 30, b.position.Y + sprite5.Height - 30, 0.0f)); s1 = new BoundingSphere(acenter, aradius); s2 = new BoundingSphere(bcenter, bradius); return (s1.Intersects(s2)); }
public void SpawnFlowers(int max_X, int max_Y) { for (int i = 0; i < 100; i++) { MovingObject placeholder = new MovingObject(); placeholder.width = sprite7.Width; placeholder.height = sprite7.Height; placeholder.position = new Vector2(max_X * (float)RandGen.NextDouble(), max_Y * (float)RandGen.NextDouble()); placeholder.speed = new Vector2(10 + (50.0f * (float)Math.Sin(MathHelper.ToRadians((float)(360 * RandGen.NextDouble())))), 10 + (50.0f * (float)Math.Sin(MathHelper.ToRadians((float)(360 * RandGen.NextDouble()))))); SpriteList2.Add(placeholder); } for (int j = 0; j < 3; j++) { MovingObject placeholder = new MovingObject(); bool collided = false; placeholder.width = sprite5.Width; placeholder.height = sprite5.Height; do { collided = false; placeholder.position = new Vector2(max_X * (float)RandGen.NextDouble(), max_Y * (float)RandGen.NextDouble()); foreach (MovingObject a in SpriteList) { if (Intersects(a, placeholder)) { collided = true; break; } } } while (collided); placeholder.speed = new Vector2(100 + (float)RandGen.NextDouble() * 100.0f, 100 + (float)RandGen.NextDouble() * 100.0f); placeholder.tex = 4; SpriteList.Add(placeholder); } }
public void Initialize(Game1 game, int max_X, int max_Y) { //game.IsMouseVisible = true; int i = RandGen.Next(Constants.MAX_RAND_BEES) + Constants.MIN_BEES; // pre-calc the resolution ration for mouse movement in a resolution independant format resolution_x_ratio = (float)((float)game.TargetResolutionX / (float)game.GraphicsDevice.Viewport.Width); resolution_y_ratio = (float)((float)game.TargetResolutionY / (float)game.GraphicsDevice.Viewport.Height); SpriteList.Clear(); SpriteList2.Clear(); for (int j = 0; j < i; j++) { MovingObject placeholder = new MovingObject(); placeholder.rotation_speed = (float)RandGen.NextDouble() / 10; placeholder.speed = new Vector2(100 + (float)RandGen.NextDouble() * 100.0f, 100 + (float)RandGen.NextDouble() * 100.0f); placeholder.tex = 4;// RandGen.Next(3); placeholder.width = sprite5.Width; placeholder.height = sprite5.Height; bool collided = false; do { collided = false; placeholder.position = new Vector2(max_X * (float)RandGen.NextDouble(), max_Y * (float)RandGen.NextDouble()); foreach (MovingObject a in SpriteList) { if (Intersects(a, placeholder)) { collided = true; break; } } } while (collided); //placeholder.rotation = (float)RandGen.NextDouble()*RandGen.Next(50); if (j == 0) placeholder.first = true; else placeholder.first = false; SpriteList.Add(placeholder); } for (i = 0; i < 100; i++) { MovingObject placeholder = new MovingObject(); placeholder.width = sprite7.Width; placeholder.height = sprite7.Height; placeholder.position = new Vector2(max_X * (float)RandGen.NextDouble(), max_Y * (float)RandGen.NextDouble()); placeholder.speed = new Vector2(10 + (50.0f * (float)Math.Sin(MathHelper.ToRadians((float)(360 * RandGen.NextDouble())))), 10 + (50.0f * (float)Math.Sin(MathHelper.ToRadians((float)(360 * RandGen.NextDouble()))))); SpriteList2.Add(placeholder); } }