Ejemplo n.º 1
0
        public DeadlyObject(Level currentLevel, Rectangle initialBoundingBox, Vector2 initialVelocity, MovingObjectObserver myObserver)
            : base(currentLevel, initialBoundingBox, initialVelocity, myObserver)
        {
            beginFade = false;
            fadeDuration = TimeSpan.FromSeconds(1);

            // create an array of possible sprites
            sprites.Add("Weapons/anvil");
            //sprites.Add("mooglegrin");

            spriteMasses["Weapons/anvil"] = 400;

            string spriteName = (string)sprites[rand.Next(sprites.Count)];

            // choose a random sprite and set your bounding box accordingly
            sprite = currentLevel.Content.Load<Texture2D>(spriteName);

            // set the mass
            if (spriteMasses.ContainsKey(spriteName))
            {
                mass = spriteMasses[spriteName];
            }

            boundingRectangle.Height = sprite.Height;
            boundingRectangle.Width = sprite.Width;

            hitSFX = level.Content.Load<SoundEffect>("Audio/cannon");
        }
Ejemplo n.º 2
0
 public MovingObject(Level currentLevel, Rectangle initialBoundingRectangle, Vector2 initialVelocity, MovingObjectObserver myObserver)
 {
     level = currentLevel;
     velocity = initialVelocity;
     observer = myObserver;
     boundingRectangle = initialBoundingRectangle;
 }
Ejemplo n.º 3
0
 public Cloud(Vector2 initialPosition, float initialVelocity, Texture2D sprite, Color tint, float scale, CloudFactory myObserver, Level currentLevel)
 {
     level = currentLevel;
     boundingRectangle = new Rectangle((int)initialPosition.X, (int)initialPosition.Y,
                                      (int)((float)sprite.Width * scale), (int)((float)sprite.Height * scale));
     this.scale = scale;
     velocityX = initialVelocity;
     cloudSprite = sprite;
     cloudTint = tint;
     observer = myObserver;
 }
Ejemplo n.º 4
0
        public Cannon(Level currentLevel)
        {
            level = currentLevel;
            lastFiring = new TimeSpan();
            lastSpeedIncrease = new TimeSpan();

            cannonSprite = currentLevel.Content.Load<Texture2D>("Cannon/cannongun");
            cannonBase = currentLevel.Content.Load<Texture2D>("Cannon/cannonbase");

            cannonSFX = level.Content.Load<SoundEffect>("Audio/cannon");
        }
Ejemplo n.º 5
0
        public Sheep(Level currentLevel, Rectangle initialBoundingRectangle, Vector2 initialVelocity, MovingObjectObserver myObserver)
            : base(currentLevel, initialBoundingRectangle, initialVelocity, myObserver)
        {
            beginFade = false;
            sheepSprite = currentLevel.Content.Load<Texture2D>("Sheep/sheep");
            boundingRectangle.Width  = sheepSprite.Width;
            boundingRectangle.Height = sheepSprite.Height / 2;
            boundingRectangle.X -= boundingRectangle.Width;
            boundingRectangle.Y -= boundingRectangle.Height;
            mass = 900;

            sheepSFX = level.Content.Load<SoundEffect>("Audio/sheep");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructs a new Farmer.
        /// </summary>
        public Farmer(Level currentLevel, Vector2 position)
        {
            level = currentLevel;
            lastInvuln = new TimeSpan();
            isAlive = true;

            LoadContent();

            location = new Rectangle((int)position.X, (int)position.Y, idleAnimation.FrameWidth, 0);
            boundingBox = location;
            boundingBox.X -= (idleAnimation.FrameWidth - 100) / 2;
            boundingBox.Y -= idleAnimation.FrameHeight - 22;
            boundingBox.Width -= 105;
            boundingBox.Height += idleAnimation.FrameHeight / 3;

            basket = new Rectangle(location.X - (idleAnimation.FrameWidth - 80) / 2, location.Y - idleAnimation.FrameHeight / 2, location.Width - 85, 50);

            Velocity = Vector2.Zero;
        }
Ejemplo n.º 7
0
        public CloudFactory(Color tint, float scale, int numberOfClouds, Level currentLevel)
        {
            cloudTint = tint;
            objectList = new List<Cloud>();
            cloudSprites = new List<Texture2D>();
            level = currentLevel;

            //Load all cloud textures
            cloudSprites.Add(currentLevel.Content.Load<Texture2D>("Clouds/cloud_1"));
            cloudSprites.Add(currentLevel.Content.Load<Texture2D>("Clouds/cloud_2"));
            cloudSprites.Add(currentLevel.Content.Load<Texture2D>("Clouds/cloud_3"));
            cloudSprites.Add(currentLevel.Content.Load<Texture2D>("Clouds/cloud_4"));
            cloudSprites.Add(currentLevel.Content.Load<Texture2D>("Clouds/cloud_5"));
            cloudSprites.Add(currentLevel.Content.Load<Texture2D>("Clouds/cloud_6"));
            cloudSprites.Add(currentLevel.Content.Load<Texture2D>("Clouds/cloud_7"));

            //Populate clouds
            for(int i=0; i < numberOfClouds; i++)
                objectList.Add(new Cloud(new Vector2((1280 * i / numberOfClouds) + (scale * random.Next(-20,+20)),randomY()),0f,
                               cloudSprites[random.Next(cloudSprites.Count)],tint,scale,
                               this,level));
        }
 public DeadlyObjectFactory(Level level)
 {
     this.level = level;
 }
Ejemplo n.º 9
0
        public void MoveObject(GameTime gameTime, Farmer farmer, Level level)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.Ticks / 10000000;

            velocity.Y += elapsedTime * gravity;
            if (mass != 0) velocity.X += elapsedTime * (level.Wind.X / mass);

            Vector2 velocityVector = velocity * elapsedTime;
            boundingRectangle.Location = new Point(
                (int)Math.Round(velocityVector.X) + boundingRectangle.Location.X,
                (int)Math.Round(velocityVector.Y) + boundingRectangle.Location.Y
            );

            if (boundingRectangle.Intersects(level.Ground))
            {
                boundingRectangle.Location = new Point(boundingRectangle.Left, level.Ground.Y - boundingRectangle.Height);
                velocity.X = 0f;
                velocity.Y = 0f;
                hitBottom(farmer, gameTime);
            }

            if (CollidesWithFarmer(farmer))
                hitFarmer(farmer, gameTime);
        }
 public MovingObjectObserver(Level currentLevel)
 {
     objectList = new List<MovingObject>();
     level = currentLevel;
 }