Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new GameObject
 /// </summary>
 /// <param name="gameSprite">The GameSprite to use</param>
 /// <param name="startingPosition">The initial position for the GameObject</param>
 public GameObject(GameSprite gameSprite, Vector2 startingPosition)
 {
     //Sets the required GameObject values
     objectSprite = new GameSprite(gameSprite);
     Position = startingPosition;
     boundingRect = new Rectangle((int)Position.X, (int)Position.Y, (int)(objectSprite.Width * objectSprite.Scale.X), (int)(objectSprite.Height * objectSprite.Scale.Y));
     objectSprite.AnimationEnded += new AnimationEndedEventHandler(objectSprite_AnimationEnded);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new GameSprite
 /// </summary>
 /// <param name="gameSprite">The GameSprite to clone from</param>
 public GameSprite(GameSprite gameSprite)
 {
     //Sets the sprite animation
     image = gameSprite.image;
     rows = gameSprite.rows;
     columns = gameSprite.columns;
     totalFrames = rows * columns;
     Width = image.Width / columns;
     Height = image.Height / rows;
     paused = gameSprite.paused;
     AnimationSpeed = gameSprite.AnimationSpeed;
     Scale = gameSprite.Scale;
     CurrentFrame = 0;
     Looping = gameSprite.Looping;
 }
Ejemplo n.º 3
0
        // Remember to draw objects
        public List<GameObject> generateGameSet()
        {
            solutionObjectReplica = null;
            currentGameSet.Clear();
            gameObjectPosition.Clear();
            int xSpacing = 5;

            var set = Content.LoadContent<Texture2D>("Level1\\" + getRandomGameSet());

            List<string> contentName = new List<string>();
            foreach (string s in set.Keys)
                contentName.Add(s);

            List<int> contentRand = genRandomNumberList(0, contentName.Count);

            // Create solution object
            GameSprite solutionSprite = new GameSprite(set[contentName[contentRand[0]]], 1, 1, 0, 0);

            // Create selection objects
            GameSprite selectionSprite1 = new GameSprite(set[contentName[contentRand[1]]], 1, 1, 0, 0);
            GameSprite selectionSprite2 = new GameSprite(set[contentName[contentRand[2]]], 1, 1, 0, 0);
            GameSprite selectionSprite3 = new GameSprite(set[contentName[contentRand[3]]], 1, 1, 0, 0);
            // GameSprite selectionSprite4 = new GameSprite(set1["yellow_ball"]  , 1, 1, 0, 0);

            // Store positions. These are namely 2 on the left, 2 on the right
            gameObjectPosition.Add(new Vector2(0, xSpacing)); //top left
            gameObjectPosition.Add(new Vector2(0, solutionSprite.Height * 4)); // bottom left
            gameObjectPosition.Add(new Vector2(Window.ClientBounds.Width - solutionSprite.Width, 0)); // top right
            gameObjectPosition.Add(new Vector2(Window.ClientBounds.Width - solutionSprite.Width, solutionSprite.Height * 4)); //btm right

            // Generate position placement choices randomly
            List<int> randPosn = new List<int>();

            while (randPosn.Count != gameObjectPosition.Count)
            {
                int choice = rand.Next(0, gameObjectPosition.Count);
                if (!randPosn.Contains(choice))
                    randPosn.Add(choice);
            }

            // Create solution object
            GameObject solutionObj = new GameObject(solutionSprite, gameObjectPosition[randPosn[0]]);
            solutionObj.isSolutionObject = true;

            // Create a replica of the solution object for display purposes only
            solutionObjectReplica = new GameObject(solutionSprite, Window.ClientBounds.Width / 2, 0);

            // left hand side
            GameObject selectionObject1 = new GameObject(selectionSprite1, gameObjectPosition[randPosn[1]]);
            GameObject selectionObject2 = new GameObject(selectionSprite2, gameObjectPosition[randPosn[2]]);

            // right hand side
            GameObject selectionObject3 = new GameObject(selectionSprite3, gameObjectPosition[randPosn[3]]);

            // Add to current game set
            currentGameSet.Add(solutionObj); //Solution is always the first
            currentGameSet.Add(selectionObject1);
            currentGameSet.Add(selectionObject2);
            currentGameSet.Add(selectionObject3);

            return currentGameSet;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Note: use this.Content to load your game contents here

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Create needed input components
            inputManager = new InputComponent(this, true, true, false, false);

            //Loads all the sprites
            planeSprite = new GameSprite(Content.Load<Texture2D>("plane"), 1, 3, 0, 0.5);

            //Create Game objects
             planeObject = new GameObject(planeSprite, Window.ClientBounds.Width / 2 - planeSprite.Width / 2,
                 Window.ClientBounds.Height - planeSprite.Height);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new GameObjectSpawner
 /// </summary>
 /// <param name="sprite">The sprite to use for each GameObject</param>
 /// <param name="maxObjects">The maximum number of objects that can be spawned</param>
 public GameObjectSpawner(GameSprite sprite, int maxObjects)
 {
     //Sets the required components
     MaxObjects = maxObjects;
     SpawnerSprite = sprite;
     cleanTimer.TimerFinished += new TimerFinishedEventHandler(cleanTimer_TimerFinished);
     Objects = new List<GameObject>();
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new GameObjectSpawner
 /// </summary>
 /// <param name="sprite">The sprite to use for each GameObject</param>
 public GameObjectSpawner(GameSprite sprite)
 {
     SpawnerSprite = sprite;
     cleanTimer.TimerFinished += new TimerFinishedEventHandler(cleanTimer_TimerFinished);
     Objects = new List<GameObject>();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new GameObject
 /// </summary>
 /// <param name="gameSprite">The GameSprite to use</param>
 /// <param name="startingPositionX">The initial X position for the GameObject</param>
 /// <param name="startingPositionY">The initial Y position for the GameObject</param>
 /// <param name="startingVelocityX">The initial X Velocity for the GameObject</param>
 /// <param name="startingVelocityY">The initial Y Velocity for the GameObject</param>
 public GameObject(GameSprite gameSprite, int startingPositionX, int startingPositionY, int startingVelocityX, int startingVelocityY)
 {
     //Sets the required GameObject values
     objectSprite = new GameSprite(gameSprite);
     Position.X = startingPositionX;
     Position.Y = startingPositionY;
     Velocity.X = startingVelocityX;
     Velocity.Y = startingVelocityY;
     boundingRect = new Rectangle((int)Position.X, (int)Position.Y, (int)(objectSprite.Width * objectSprite.Scale.X), (int)(objectSprite.Height * objectSprite.Scale.Y));
     objectSprite.AnimationEnded += new AnimationEndedEventHandler(objectSprite_AnimationEnded);
 }