XNA Text & Array Exercise

 

Part A

  1. Create a copy of the bouncing sprite project from the previous exercise
  2. Watch this video, describing how to display text (source code here).
  3. Modify the bouncing sprite project to display the x & y location of the sprite

Part B

  1. Modify the code in part A to allow the user to toggle the display of the bouncing sprite, using the 'Space' key
  2. The following code can be used to determine the state of the space key
  3. if(Keyboard.GetState().IsKeyDown(Keys.Space)==true){
        	//some code
        }
  4. Remember, pressing the space bar should toggle the sprite, i.e. if the sprite is visible then pressing space should make it invisible regardless of how long it is held down for and visa-versa.

Part C

  1. Modify code in part B such that, if the user clicks on the screen, the sprite should start to move towards the point clicked and the same speed. Use the Vector2 class to calculate new velocity.
  2. A click is detected if a mouse button was pressed during one frame but was not pressed in the subsequent frame. I.e the mouse was button released between frames
  3.            
    
    			if( Mouse.GetState().LeftButton == ButtonState.Pressed){
    			//some code
    			}
                   
  4. Note that you will need to give your sprite a velocity property for this to work

Part D

  1. Modify the code in part C to have 10 sprites bouncing around the screen. Create an array of positions and an array of velocities to do this.
  2.            
    
    			// this code creates an array of 10 vector2 objects
                Vector2[] positions=new Vector2[10];
                   
  3. Give all the sprites different, random starting locations.

Part E

  1. Modify the code in part D, so that clicking on (or very near) a bouncing sprite causes it to disappear.
  2. When all 10 sprites have disappeared, display the number of seconds which have elapsed (use gameTime.TotalGameTime.TotalSeconds).