sprite/character options Help

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

48 Replies - 8596 Views - Last Post: 22 June 2011 - 05:29 AM

#1 staceyktaylor  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 08-December 10

sprite/character options Help

Posted 09 May 2011 - 11:21 AM

Hi, ive recently made a shooter game, an under the sea version which consists of a scuba man shotting bubbles at enemy sharks (please dont laugh).


I now want to try to add a simple option choice of character, therefore choose between being scuba man or scuba woman, simple sprite change. They will both do the same thing and have the same options, but just different sprite images.


How do i go about doing this? is there any tutorials? Will i need to create a player class for each?

Any help is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: sprite/character options Help

#2 DivideByZero  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 238
  • View blog
  • Posts: 551
  • Joined: 02-December 10

Re: sprite/character options Help

Posted 09 May 2011 - 04:13 PM

Get the user to choose what they want to play as, then set the sprite in your player class to the texture accordingly.

Somewhere in your game class.
Texture2D scubaManSprite;
Texture2D scubaWomanSprite;
Player player = new Player();

if (/*User chose scuba dude*/)
{
    player.Sprite = scubaManSprite;
}
else
{    
    player.Sprite = scubaWomanSprite;
}



Your player class could look like this.
Texture 2D sprite;
public Texture2D Sprite
{
    get { return sprite; }
    set { sprite = value; }
}

public Player()
{
    // Initialise some stuff you need.
}



I rushed this example, so if you're confuse just ask :)

This post has been edited by DivideByZero: 09 May 2011 - 04:20 PM

Was This Post Helpful? 1
  • +
  • -

#3 staceyktaylor  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 08-December 10

Re: sprite/character options Help

Posted 10 May 2011 - 02:18 AM

View PostDivideByZero, on 09 May 2011 - 04:13 PM, said:

Get the user to choose what they want to play as, then set the sprite in your player class to the texture accordingly.

Somewhere in your game class.
Texture2D scubaManSprite;
Texture2D scubaWomanSprite;
Player player = new Player();

if (/*User chose scuba dude*/)
{
    player.Sprite = scubaManSprite;
}
else
{    
    player.Sprite = scubaWomanSprite;
}



Your player class could look like this.
Texture 2D sprite;
public Texture2D Sprite
{
    get { return sprite; }
    set { sprite = value; }
}

public Player()
{
    // Initialise some stuff you need.
}



I rushed this example, so if you're confuse just ask :)



Thanks :) if i where to implement it like this, if i where to do that once the player had chose which sprite they want to be then had game.begin(); would that display the characters on screen before the game and start the game once the character had been chosen. (if that makes sense).
Was This Post Helpful? 0
  • +
  • -

#4 ShadowsEdge19  Icon User is offline

  • D.I.C Addict

Reputation: 142
  • View blog
  • Posts: 664
  • Joined: 16-January 10

Re: sprite/character options Help

Posted 10 May 2011 - 03:54 AM

All that would do at this stage is specify what sprite the Player would have, but there are still plenty of important things missing since it is only a rough guide.

You would need to load the player sprites in the screen's LoadContent() and then draw them in the Draw() method. Plus not to mention all the features for moving your Player once it has been drawn.
Was This Post Helpful? 0
  • +
  • -

#5 staceyktaylor  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 08-December 10

Re: sprite/character options Help

Posted 10 May 2011 - 04:14 AM

View PostShadowsEdge19, on 10 May 2011 - 03:54 AM, said:

All that would do at this stage is specify what sprite the Player would have, but there are still plenty of important things missing since it is only a rough guide.

You would need to load the player sprites in the screen's LoadContent() and then draw them in the Draw() method. Plus not to mention all the features for moving your Player once it has been drawn.



Hi, i already have my sprites drawn and loaded in the game method, the scuba sptite moves up and down and shoots bubbles.

What i want to do is allow the user to have a very simple choice to choose between being a male or female scuba sprite at the start of the game before the game itself begins (Very simple i know but im new to this so one step at a time :P )
Was This Post Helpful? 0
  • +
  • -

#6 ShadowsEdge19  Icon User is offline

  • D.I.C Addict

Reputation: 142
  • View blog
  • Posts: 664
  • Joined: 16-January 10

Re: sprite/character options Help

Posted 10 May 2011 - 09:03 AM

View Poststaceyktaylor, on 10 May 2011 - 05:14 AM, said:

Hi, i already have my sprites drawn and loaded in the game method, the scuba sptite moves up and down and shoots bubbles.

What i want to do is allow the user to have a very simple choice to choose between being a male or female scuba sprite at the start of the game before the game itself begins (Very simple i know but im new to this so one step at a time :P )


If you have a menu already perhaps have a sub menu appear before the main game starts so you can get the user to tell the game which version to load up.
Was This Post Helpful? 0
  • +
  • -

#7 staceyktaylor  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 08-December 10

Re: sprite/character options Help

Posted 10 May 2011 - 09:43 AM

View PostShadowsEdge19, on 10 May 2011 - 09:03 AM, said:

View Poststaceyktaylor, on 10 May 2011 - 05:14 AM, said:

Hi, i already have my sprites drawn and loaded in the game method, the scuba sptite moves up and down and shoots bubbles.

What i want to do is allow the user to have a very simple choice to choose between being a male or female scuba sprite at the start of the game before the game itself begins (Very simple i know but im new to this so one step at a time :P )


If you have a menu already perhaps have a sub menu appear before the main game starts so you can get the user to tell the game which version to load up.



I dont actuallh have a menu at the moment the game loads up and is the scuba sprite and begins to play automatically. Will i need to create a menu first to allow the user to select a sprite before the game begins?
Was This Post Helpful? 0
  • +
  • -

#8 ShadowsEdge19  Icon User is offline

  • D.I.C Addict

Reputation: 142
  • View blog
  • Posts: 664
  • Joined: 16-January 10

Re: sprite/character options Help

Posted 10 May 2011 - 09:53 AM

You could just have a pop-up screen that works using events that can pass back a trigger based on the user selection, the pop-up screen will be the very first thing that occurs once the game screen has loaded and once you get either the Male or Female response the game can change the sprite to either one, with a default being the Male sprite so that you already have a sprite assigned.
Was This Post Helpful? 0
  • +
  • -

#9 ShadowsEdge19  Icon User is offline

  • D.I.C Addict

Reputation: 142
  • View blog
  • Posts: 664
  • Joined: 16-January 10

Re: sprite/character options Help

Posted 10 May 2011 - 10:14 AM

Here's an example:

****Gameplay Screen Event Stuff****
using System;

public void AskGender() //Call this at start up
{
    EventArgs args = new EventArgs();

    PopUpScreen popUpScreen = new PopUpScreen();

    popUpScreen.Male += new EventHandler<EventArgs>(ConfirmMale);
    popUpScreen.Female += new EventHandler<EventArgs>(ConfirmFemale);

    //code to load popUpScreen
}                
                    
public void ConfirmMale(object sender, EventArgs e)
{
    player.Sprite = scubaManSprite;
}

public void ConfirmFemale(object sender, EventArgs e)
{
    player.Sprite = scubaWomanSprite;
}



****Pop Up Screen Event Stuff****

//declarations

using System;

public event EventHandler<EventArgs> Male;
public event EventHandler<EventArgs> Female;

...

public void HandleInput()
{
     if(//Male button/option selected)
     {
         // Raise the male event, then exit the message box.
         if (Male != null)
             Male(this, new EventArgs());

         //Exit Pop Up Screen Code
     }

     if(//Female button/option selected)
     {
          // Raise the female event, then exit the message box.
          if (Female != null)
              Female(this, new EventArgs());

          //Exit Pop Up Screen Code
         
     }
}


Was This Post Helpful? 0
  • +
  • -

#10 staceyktaylor  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 08-December 10

Re: sprite/character options Help

Posted 10 May 2011 - 02:00 PM

wow this is much harder than i thought to get my head around.here is my code so far.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace scubashooter 
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game 
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Texture2D scubaSprite;

        //Sound effect
        SoundEffect soundEffect;


        //Background image 
        Texture2D background;
        Rectangle backgroundRectangle;
       

        // shooting variables
        int playerElapsedTime = 0;
        int playerFireRate = 250;
        List<GameObject> playerBulletList = new List<GameObject>();
        Texture2D bulletSprite;

        // enemy variables
        int spawnElapsedTime = 0;
        int spawnRate = 1000;
        List<GameObject> enemyList = new List<GameObject>();
        Texture2D enemySprite;

        // variables to allow enemy to shoot
        List<GameObject> enemyBulletList = new List<GameObject>();
        Random random = new Random();

        GameObject player = new GameObject();
        
        public event EventHandler<EventArgs> Male;
	    public event EventHandler<EventArgs> Female;
        
        

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            

            // deletes bullets on screen when the game is reset
            enemyBulletList = new List<GameObject>();
        }




    public void AskGender() //Call this at start up
	{
	    EventArgs args = new EventArgs();
	 
	    PopUpScreen popUpScreen = new PopUpScreen();
	
    }
        public void HandleInput()
	{
	     if(Keyboard.GetState().IsKeyDown(Keys.M))
	     {
	         // Raise the male event, then exit the message box.
	         if (Male != null)
	             Male(this, new EventArgs());
                 
         }

         else  if(Keyboard.GetState().IsKeyDown(Keys.F))
         {
                      // Raise the female event, then exit the message box.
	          if (Female != null)
	              Female(this, new EventArgs());
	 
	          //Exit Pop Up Screen Code
	          
	     }
	}
	 
	 
	    

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            
          
            base.Initialize();
        }

    

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            //Load Background Image
            backgroundRectangle = new Rectangle(0, 0,
            graphics.GraphicsDevice.Viewport.Width,
            graphics.GraphicsDevice.Viewport.Height);

            
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Scuba man
            player.sprite = Content.Load<Texture2D>("scuba");
            player.rect = new Rectangle(42, 250, 100, 100);
            player.active = true;
            player.speed = 3;

            //background
            background = Content.Load<Texture2D>("background");

            //Bullets
            bulletSprite = Content.Load<Texture2D>("bubble");
           
            //Enemy
            enemySprite = Content.Load<Texture2D>("shark");

            //Sound effect
            soundEffect = Content.Load<SoundEffect>("Audio\\boing");


            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        // Reset game method
        private void ResetGame()
        {
            playerBulletList = new List<GameObject>();
            enemyList = new List<GameObject>();
            player.rect = new Rectangle(42, 250, 100, 100);
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Allows the scuba man/shooter to move up and down
            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                player.rect.Y -= player.speed;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                player.rect.Y += player.speed;
            }

            //Figures out how much time has passed
            playerElapsedTime += gameTime.ElapsedGameTime.Milliseconds;

            //This allows bubbles to be fired when the user presses the space bar
            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if (playerElapsedTime > playerFireRate)
                    soundEffect.Play();
                {
                    playerElapsedTime = 0;
                    GameObject tempObj = new GameObject();
                    tempObj.sprite = bulletSprite;
                    tempObj.rect = new Rectangle(player.rect.X + 64, player.rect.Y + 24, 16, 16);
                    tempObj.speed = 5;
                    tempObj.active = true;
                    playerBulletList.Add(tempObj);
                }
            }
            {

                //Bullet Update Method
                for (int b = 0; b < playerBulletList.Count; b++)
                {
                    if (playerBulletList[b].rect.X + 16 >= graphics.PreferredBackBufferWidth)
                    {
                        playerBulletList[b].active = false;
                    }
                    if (playerBulletList[b].active)
                    {
                        playerBulletList[b].rect.X += playerBulletList[b].speed;
                    }
                    else
                    {
                        playerBulletList.RemoveAt(B)/>;
                        b--;
                    }
                }

                //Update to check if there is enemy that need to be shot at
                {
                    spawnElapsedTime += gameTime.ElapsedGameTime.Milliseconds;

                    if (spawnElapsedTime >= spawnRate)
                    {
                        spawnElapsedTime = 0;
                        GameObject tempObj = new GameObject();
                        tempObj.sprite = enemySprite;
                        tempObj.rect = new Rectangle(graphics.PreferredBackBufferWidth + 64, player.rect.Y, 64, 64);
                        tempObj.speed = -3;
                        tempObj.active = true;
                        enemyList.Add(tempObj);
                    }
                    {


                        //update for enemies being shot at
                        for (int i = 0; i < enemyList.Count; i++)
                        {
                            if (enemyList[i].rect.X + 200 <= 0)
                            {
                                enemyList[i].active = false;
                            }
                            if (enemyList[i].active)
                            {
                                enemyList[i].rect.X += enemyList[i].speed;
                            }


                            // if enemy sharks hit the scuba man the game will restart
                            if (enemyList[i].rect.Intersects(player.rect))
                            {
                                ResetGame();
                                break;
                            }

                            //check for collisions 
                            for (int y = 0; y < playerBulletList.Count; y++)
                            {
                                if (playerBulletList[y].active)
                                {
                                    if (enemyList[i].rect.Intersects(playerBulletList[y].rect))
                                    {
                                        enemyList[i].active = false;
                                        playerBulletList[y].active = false;
                                    }
                                }
                            }
                        }

                        // TODO: Add your update logic here

                        base.Update(gameTime);
                    }
                }
            }
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();

            //draw background
            spriteBatch.Draw(background, backgroundRectangle, Color.White);

            //draw scuba man
            spriteBatch.Draw(player.sprite, player.rect, Color.White);

            //draw bubbles
            for (int b = 0; b < playerBulletList.Count; b++)
            {
                if (playerBulletList[b].active)
                {
                    spriteBatch.Draw(playerBulletList[b].sprite, playerBulletList[b].rect, Color.White);
                }
            }

            // draw enemies/sharks
            for (int i = 0; i < enemyList.Count; i++)
            {
                if (enemyList[i].active)
                {
                    spriteBatch.Draw(enemyList[i].sprite, enemyList[i].rect, Color.White);
                }
            }


            spriteBatch.End();

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}



This post has been edited by staceyktaylor: 10 May 2011 - 02:10 PM

Was This Post Helpful? 0
  • +
  • -

#11 bonyjoe  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: sprite/character options Help

Posted 10 May 2011 - 02:27 PM

I assume you haven't done any standard c# .net stuff before, if so the way mentioned above may not be the best for you.

Although understanding .net is a good thing perhaps your best bet at the minute is to make a simple menu class that can be used then use that, as generally .net and xna aren't used together as custom graphics look much more game like.
Was This Post Helpful? 0
  • +
  • -

#12 staceyktaylor  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 08-December 10

Re: sprite/character options Help

Posted 10 May 2011 - 02:30 PM

yeah i was a bit confused ive deleted all my new options and returned my code to

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace scubashooter 
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game 
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;


        //Sound effect
        SoundEffect soundEffect;


        //Background image 
        Texture2D background;
        Rectangle backgroundRectangle;
       

        // shooting variables
        int playerElapsedTime = 0;
        int playerFireRate = 250;
        List<GameObject> playerBulletList = new List<GameObject>();
        Texture2D bulletSprite;

        // enemy variables
        int spawnElapsedTime = 0;
        int spawnRate = 1000;
        List<GameObject> enemyList = new List<GameObject>();
        Texture2D enemySprite;

        // variables to allow enemy to shoot
        List<GameObject> enemyBulletList = new List<GameObject>();
        Random random = new Random();

        GameObject player = new GameObject();



        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";


            // deletes bullets on screen when the game is reset
            enemyBulletList = new List<GameObject>();

        }
	 
	    

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            
          
            base.Initialize();
        }

    

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            //Load Background Image
            backgroundRectangle = new Rectangle(0, 0,
            graphics.GraphicsDevice.Viewport.Width,
            graphics.GraphicsDevice.Viewport.Height);

            
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Scuba man
            player.sprite = Content.Load<Texture2D>("scuba");
            player.rect = new Rectangle(42, 250, 100, 100);
            player.active = true;
            player.speed = 3;

            //background
            background = Content.Load<Texture2D>("background");

            //Bullets
            bulletSprite = Content.Load<Texture2D>("bubble");
           
            //Enemy
            enemySprite = Content.Load<Texture2D>("shark");

            //Sound effect
            soundEffect = Content.Load<SoundEffect>("Audio\\boing");


            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        // Reset game method
        private void ResetGame()
        {
            playerBulletList = new List<GameObject>();
            enemyList = new List<GameObject>();
            player.rect = new Rectangle(42, 250, 100, 100);
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Allows the scuba man/shooter to move up and down
            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                player.rect.Y -= player.speed;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                player.rect.Y += player.speed;
            }

            //Figures out how much time has passed
            playerElapsedTime += gameTime.ElapsedGameTime.Milliseconds;

            //This allows bubbles to be fired when the user presses the space bar
            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if (playerElapsedTime > playerFireRate)
                    soundEffect.Play();
                {
                    playerElapsedTime = 0;
                    GameObject tempObj = new GameObject();
                    tempObj.sprite = bulletSprite;
                    tempObj.rect = new Rectangle(player.rect.X + 64, player.rect.Y + 24, 16, 16);
                    tempObj.speed = 5;
                    tempObj.active = true;
                    playerBulletList.Add(tempObj);
                }
            }
            {

                //Bullet Update Method
                for (int b = 0; b < playerBulletList.Count; b++)
                {
                    if (playerBulletList[b].rect.X + 16 >= graphics.PreferredBackBufferWidth)
                    {
                        playerBulletList[b].active = false;
                    }
                    if (playerBulletList[b].active)
                    {
                        playerBulletList[b].rect.X += playerBulletList[b].speed;
                    }
                    else
                    {
                        playerBulletList.RemoveAt(B)/>;
                        b--;
                    }
                }

                //Update to check if there is enemy that need to be shot at
                {
                    spawnElapsedTime += gameTime.ElapsedGameTime.Milliseconds;

                    if (spawnElapsedTime >= spawnRate)
                    {
                        spawnElapsedTime = 0;
                        GameObject tempObj = new GameObject();
                        tempObj.sprite = enemySprite;
                        tempObj.rect = new Rectangle(graphics.PreferredBackBufferWidth + 64, player.rect.Y, 64, 64);
                        tempObj.speed = -3;
                        tempObj.active = true;
                        enemyList.Add(tempObj);
                    }
                    {


                        //update for enemies being shot at
                        for (int i = 0; i < enemyList.Count; i++)
                        {
                            if (enemyList[i].rect.X + 200 <= 0)
                            {
                                enemyList[i].active = false;
                            }
                            if (enemyList[i].active)
                            {
                                enemyList[i].rect.X += enemyList[i].speed;
                            }


                            // if enemy sharks hit the scuba man the game will restart
                            if (enemyList[i].rect.Intersects(player.rect))
                            {
                                ResetGame();
                                break;
                            }

                            //check for collisions 
                            for (int y = 0; y < playerBulletList.Count; y++)
                            {
                                if (playerBulletList[y].active)
                                {
                                    if (enemyList[i].rect.Intersects(playerBulletList[y].rect))
                                    {
                                        enemyList[i].active = false;
                                        playerBulletList[y].active = false;
                                    }
                                }
                            }
                        }

                        // TODO: Add your update logic here

                        base.Update(gameTime);
                    }
                }
            }
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();

            //draw background
            spriteBatch.Draw(background, backgroundRectangle, Color.White);

            //draw scuba man
            spriteBatch.Draw(player.sprite, player.rect, Color.White);

            //draw bubbles
            for (int b = 0; b < playerBulletList.Count; b++)
            {
                if (playerBulletList[b].active)
                {
                    spriteBatch.Draw(playerBulletList[b].sprite, playerBulletList[b].rect, Color.White);
                }
            }

            // draw enemies/sharks
            for (int i = 0; i < enemyList.Count; i++)
            {
                if (enemyList[i].active)
                {
                    spriteBatch.Draw(enemyList[i].sprite, enemyList[i].rect, Color.White);
                }
            }


            spriteBatch.End();

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}




Back to square one for the options ha, ill get there eventually.
Was This Post Helpful? 0
  • +
  • -

#13 ShadowsEdge19  Icon User is offline

  • D.I.C Addict

Reputation: 142
  • View blog
  • Posts: 664
  • Joined: 16-January 10

Re: sprite/character options Help

Posted 10 May 2011 - 02:34 PM

What I posted as "Pop Up Screen Stuff" was meant to be in a separate class file that represented a 2nd screen class, so that screen has a Handle Input method that activates the Male/Female events and when the screen is turned off the event handler on the gameplay screen will either go for the ConfirmMale() or ConfirmFemale() methods.
Was This Post Helpful? 0
  • +
  • -

#14 staceyktaylor  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 08-December 10

Re: sprite/character options Help

Posted 10 May 2011 - 02:36 PM

View PostShadowsEdge19, on 10 May 2011 - 02:34 PM, said:

What I posted as "Pop Up Screen Stuff" was meant to be in a separate class file that represented a 2nd screen class, so that screen has a Handle Input method that activates the Male/Female events and when the screen is turned off the event handler on the gameplay screen will either go for the ConfirmMale() or ConfirmFemale() methods.


i realised that after i posted the code :oops: :oops:

i tried it in its own class but i couldnt quite get my head round it so ive removed all the new code to start again :)
Was This Post Helpful? 0
  • +
  • -

#15 staceyktaylor  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 08-December 10

Re: sprite/character options Help

Posted 10 May 2011 - 03:15 PM

If i use this code
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace scubashooter 
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game 
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Texture2D scubaSprite;
        Texture2D mermaidSprite;

        //Sound effect
        SoundEffect soundEffect;


        //Background image 
        Texture2D background;
        Rectangle backgroundRectangle;
       

        // shooting variables
        int playerElapsedTime = 0;
        int playerFireRate = 250;
        List<GameObject> playerBulletList = new List<GameObject>();
        Texture2D bulletSprite;

        // enemy variables
        int spawnElapsedTime = 0;
        int spawnRate = 1000;
        List<GameObject> enemyList = new List<GameObject>();
        Texture2D enemySprite;

        // variables to allow enemy to shoot
        List<GameObject> enemyBulletList = new List<GameObject>();
        Random random = new Random();

        GameObject player = new GameObject();

        public void AskGender() //Call this at start up
	{
	    EventArgs args = new EventArgs();
	 
	    PopUpScreen popUpScreen = new PopUpScreen();
	 
	    popUpScreen.Male += new EventHandler<EventArgs>(ConfirmMale);
	    popUpScreen.Female += new EventHandler<EventArgs>(ConfirmFemale);
	 
	    //code to load popUpScreen
	}               
                  
	                     
	public void ConfirmMale(object sender, EventArgs e)
	{
	    player.sprite = scubaSprite;
	}
	 
	public void ConfirmFemale(object sender, EventArgs e)
	{
	    player.sprite = mermaidSprite;
	}

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";


            // deletes bullets on screen when the game is reset
            enemyBulletList = new List<GameObject>();

        }
	 
	    

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            
          
            base.Initialize();
        }

    

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            
            //Load Background Image
            backgroundRectangle = new Rectangle(0, 0,
            graphics.GraphicsDevice.Viewport.Width,
            graphics.GraphicsDevice.Viewport.Height);

            
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Scuba man
            player.sprite = Content.Load<Texture2D>("scuba");
            player.rect = new Rectangle(42, 250, 100, 100);
            player.active = true;
            player.speed = 3;

            //background
            background = Content.Load<Texture2D>("background");

            //Bullets
            bulletSprite = Content.Load<Texture2D>("bubble");
           
            //Enemy
            enemySprite = Content.Load<Texture2D>("shark");

            //Sound effect
            soundEffect = Content.Load<SoundEffect>("Audio\\boing");

            //Mermaid
            player.sprite = Content.Load<Texture2D>("scuba");
            player.rect = new Rectangle(42, 250, 100, 100);
            player.active = true;
            player.speed = 3;


            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        // Reset game method
        private void ResetGame()
        {
            playerBulletList = new List<GameObject>();
            enemyList = new List<GameObject>();
            player.rect = new Rectangle(42, 250, 100, 100);
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Allows the scuba man/shooter to move up and down
            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                player.rect.Y -= player.speed;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                player.rect.Y += player.speed;
            }

            //Figures out how much time has passed
            playerElapsedTime += gameTime.ElapsedGameTime.Milliseconds;

            //This allows bubbles to be fired when the user presses the space bar
            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if (playerElapsedTime > playerFireRate)
                    soundEffect.Play();
                {
                    playerElapsedTime = 0;
                    GameObject tempObj = new GameObject();
                    tempObj.sprite = bulletSprite;
                    tempObj.rect = new Rectangle(player.rect.X + 64, player.rect.Y + 24, 16, 16);
                    tempObj.speed = 5;
                    tempObj.active = true;
                    playerBulletList.Add(tempObj);
                }
            }
            {

                //Bullet Update Method
                for (int b = 0; b < playerBulletList.Count; b++)
                {
                    if (playerBulletList[b].rect.X + 16 >= graphics.PreferredBackBufferWidth)
                    {
                        playerBulletList[b].active = false;
                    }
                    if (playerBulletList[b].active)
                    {
                        playerBulletList[b].rect.X += playerBulletList[b].speed;
                    }
                    else
                    {
                        playerBulletList.RemoveAt(B)/>;
                        b--;
                    }
                }

                //Update to check if there is enemy that need to be shot at
                {
                    spawnElapsedTime += gameTime.ElapsedGameTime.Milliseconds;

                    if (spawnElapsedTime >= spawnRate)
                    {
                        spawnElapsedTime = 0;
                        GameObject tempObj = new GameObject();
                        tempObj.sprite = enemySprite;
                        tempObj.rect = new Rectangle(graphics.PreferredBackBufferWidth + 64, player.rect.Y, 64, 64);
                        tempObj.speed = -3;
                        tempObj.active = true;
                        enemyList.Add(tempObj);
                    }
                    {


                        //update for enemies being shot at
                        for (int i = 0; i < enemyList.Count; i++)
                        {
                            if (enemyList[i].rect.X + 200 <= 0)
                            {
                                enemyList[i].active = false;
                            }
                            if (enemyList[i].active)
                            {
                                enemyList[i].rect.X += enemyList[i].speed;
                            }


                            // if enemy sharks hit the scuba man the game will restart
                            if (enemyList[i].rect.Intersects(player.rect))
                            {
                                ResetGame();
                                break;
                            }

                            //check for collisions 
                            for (int y = 0; y < playerBulletList.Count; y++)
                            {
                                if (playerBulletList[y].active)
                                {
                                    if (enemyList[i].rect.Intersects(playerBulletList[y].rect))
                                    {
                                        enemyList[i].active = false;
                                        playerBulletList[y].active = false;
                                    }
                                }
                            }
                        }

                        // TODO: Add your update logic here

                        base.Update(gameTime);
                    }
                }
            }
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();

            //draw background
            spriteBatch.Draw(background, backgroundRectangle, Color.White);

            //draw scuba man
            spriteBatch.Draw(player.sprite, player.rect, Color.White);

            //draw bubbles
            for (int b = 0; b < playerBulletList.Count; b++)
            {
                if (playerBulletList[b].active)
                {
                    spriteBatch.Draw(playerBulletList[b].sprite, playerBulletList[b].rect, Color.White);
                }
            }

            // draw enemies/sharks
            for (int i = 0; i < enemyList.Count; i++)
            {
                if (enemyList[i].active)
                {
                    spriteBatch.Draw(enemyList[i].sprite, enemyList[i].rect, Color.White);
                }
            }


            spriteBatch.End();

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}




would it work if i imPlemented int button guide.show message box

which offered the choice of Female or Male?
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »