48 Replies - 4870 Views - Last Post: 22 June 2011 - 05:29 AM
#1
sprite/character options Help
Posted 09 May 2011 - 11:21 AM
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.
Replies To: sprite/character options Help
#2
Re: sprite/character options Help
Posted 09 May 2011 - 04:13 PM
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
#3
Re: sprite/character options Help
Posted 10 May 2011 - 02:18 AM
DivideByZero, on 09 May 2011 - 04:13 PM, said:
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
#4
Re: sprite/character options Help
Posted 10 May 2011 - 03:54 AM
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.
#5
Re: sprite/character options Help
Posted 10 May 2011 - 04:14 AM
ShadowsEdge19, on 10 May 2011 - 03:54 AM, said:
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
#6
Re: sprite/character options Help
Posted 10 May 2011 - 09:03 AM
staceyktaylor, on 10 May 2011 - 05:14 AM, said:
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
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.
#7
Re: sprite/character options Help
Posted 10 May 2011 - 09:43 AM
ShadowsEdge19, on 10 May 2011 - 09:03 AM, said:
staceyktaylor, on 10 May 2011 - 05:14 AM, said:
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
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?
#8
Re: sprite/character options Help
Posted 10 May 2011 - 09:53 AM
#9
Re: sprite/character options Help
Posted 10 May 2011 - 10:14 AM
****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
}
}
#10
Re: sprite/character options Help
Posted 10 May 2011 - 02:00 PM
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
#11
Re: sprite/character options Help
Posted 10 May 2011 - 02:27 PM
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.
#12
Re: sprite/character options Help
Posted 10 May 2011 - 02:30 PM
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.
#13
Re: sprite/character options Help
Posted 10 May 2011 - 02:34 PM
#14
Re: sprite/character options Help
Posted 10 May 2011 - 02:36 PM
ShadowsEdge19, on 10 May 2011 - 02:34 PM, said:
i realised that after i posted the code
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
#15
Re: sprite/character options Help
Posted 10 May 2011 - 03:15 PM
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?
|
|

New Topic/Question
Reply



MultiQuote





|