public void AddSurfBarrel(GameTime gameTime) { timeSinceLastBarrel += (float)gameTime.ElapsedGameTime.TotalSeconds; if (timeSinceLastBarrel >= 0.5) { Body body; Animation animation; Texture2D texture = Content.Load <Texture2D>("barrel"); animation = new Animation(texture); animation.scale = 0.4f; body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(270 * animation.scale), ConvertUnits.ToSimUnits(340 * animation.scale), 20f); body.BodyType = BodyType.Dynamic; body.IsSensor = true; body.CollisionCategories = Category.All; body.IgnoreGravity = true; int y = random.Next(20, windowHeight); body.Position = ConvertUnits.ToSimUnits(new Vector2(windowWidth + 100, y)); body.OnCollision += barrelOnCollision; ArenaObject arenaObject = new ArenaObject(animation, body); surfBarrels.Add(arenaObject); timeSinceLastBarrel = 0; } }
public void CreatePillars() { pillars = new List <ArenaObject>(); Texture2D texture = Content.Load <Texture2D>("pillar"); Animation animation = new Animation(texture); animation.scale = 1f; Body body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(animation.frameWidth * animation.scale), ConvertUnits.ToSimUnits(animation.frameHeight * animation.scale), 20f); body.BodyType = BodyType.Static; body.Friction = 0.8f; body.CollisionCategories = Category.All; body.Position = ConvertUnits.ToSimUnits(new Vector2(100, windowHeight - 100)); ArenaObject arenaObject = new ArenaObject(animation, body); pillars.Add(arenaObject); texture = Content.Load <Texture2D>("pillar"); animation = new Animation(texture); animation.scale = 1f; body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(animation.frameWidth * animation.scale), ConvertUnits.ToSimUnits(animation.frameHeight * animation.scale), 20f); body.BodyType = BodyType.Static; body.Friction = 0.8f; body.CollisionCategories = Category.All; body.Position = ConvertUnits.ToSimUnits(new Vector2(windowWidth - 100, windowHeight - 100)); arenaObject = new ArenaObject(animation, body); pillars.Add(arenaObject); }
public void LoadObjects(int amount) { arenaObjects = new List <ArenaObject>(); for (int i = 0; i < amount; i++) { Body body; Animation animation; int type = random.Next(0, 2); if (type == 0) { Texture2D texture = Content.Load <Texture2D>("barrel"); animation = new Animation(texture); animation.scale = 0.4f; body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(270 * animation.scale), ConvertUnits.ToSimUnits(340 * animation.scale), 20f); } else { Texture2D texture = Content.Load <Texture2D>("crate"); animation = new Animation(texture); animation.scale = 0.25f; body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(animation.frameWidth * animation.scale), ConvertUnits.ToSimUnits(animation.frameHeight * animation.scale), 20f); } body.BodyType = BodyType.Dynamic; body.Friction = 0.8f; body.CollisionCategories = Category.All; int x = random.Next(100, windowWidth - 100); int y = random.Next(20, windowHeight); body.Position = ConvertUnits.ToSimUnits(new Vector2(x, y)); ArenaObject arenaObject = new ArenaObject(animation, body); arenaObjects.Add(arenaObject); } }