I downloaded visual studio 2013 and added xna to it so that I can run a game I made in vs2010. However I am having an issue in which it is not allowing me to start debugging or start without debugging. The xna I downloaded is from here https://mxa.codeplex.com/releases/view/117230 if anyone can help me I would appreciate it. I can also put the game up, it's just the begining of space invaders I made in college. I forgot to save the completed file so decided to play around with it now I have some free time.
jigglymig 12 Light Poster
Suzie999 245 Coding Hobbyist
It would be wise if you extended the information of "However I am having an issue in which it is not allowing me to start debugging or start without debugging."
jigglymig 12 Light Poster
here are my 2 main classes first is program.cs the second one is game1.cs. I have no idea why it is not letting me debug this is the message I get when I try to use the start button, "the debugger cannot continue running the process. unable to start debugging."
// this project uses XNA make sure you have it downloaded!!!
using System;
namespace SpaceInvaders
{
#if WINDOWS || XBOX
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
#endif
}
second code
// Game1 class declaration
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;
using System.Windows.Forms; // needed so that we can add normal buttons, etc.
using System.Diagnostics;
using Microsoft.Xna.Framework.Audio;
// This project doesn't do anything useful, but it illustrates the functions you'll need
// to implement your game.
namespace SpaceInvaders
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
private GraphicsDeviceManager graphics; // this represents the graphics device
private SpriteBatch spriteBatch; // all drawing takes place via this object
private Texture2D backGroundTexture; // will point to a picture to use for background
private Vector2 missilePos; // position of the missile
private Vector2 aliensPos; // position of the alien
int killedAliens; // number of dead aliens
private Rectangle viewPort; // tells us the size of the drawable area in the window
private Ship myShip; // reference to the ship controlled by the user
private Missile myMissile;
private KeyboardState oldState; // keeps previous state of keys pressed, so we can
// detect when a change in state occurs
private int livesCount; // count the lives for the ship
List<Missile> missiles; // list of existing missiles
bool GameStart = false; // starts the game
bool restartLevel = false; // restarts the current level
private AlienArmy alienArsenal; // reference to an AlienArmy
int counter = 0; // frequency on which aliens drop bomb
// define the skill levels of game
private enum skillSpeed { Beginner = 1, Intermediate = 2, Advanced = 3 };
private enum level { level1, level2 }; // define two levels of Game
level gameLevel; // stores the current level of Game
// represents choices of skill levels
private string[] cmbLabels = {"Beginner", " Intermediate", "Advanced"};
public enum cmbOptions { Beginner, Intermediate, Advanced }; // skill level options
public enum CheatOptions {NoCheat = 0, Invincible = 1}; // cheat mode options
CheatOptions currentCheat; // current cheat mode
cmbOptions currentSkillLevel; // current skill level
const int PANEL_WIDTH = 100; // width of a panel we'll add for adding buttons, etc.
// Controls we'll add to form, just for sake of illustration.
Panel gameControlPanel; // control panel
Label lblKilledAliens; // a label to show how many times we're fired
Label lblLivesCount; // a label to show the number of lives left for the ship
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
this.IsMouseVisible = true;
InitializeControlPanel();
}
/// <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()
{
aliensPos = new Vector2(0, 0);
viewPort = GraphicsDevice.Viewport.Bounds;
oldState = Keyboard.GetState();
missilePos = Vector2.Zero;
livesCount = 4;
// set default cheat mode and skill level
currentCheat = CheatOptions.NoCheat;
currentSkillLevel = cmbOptions.Beginner;
// set default level to level1
gameLevel = level.level1;
// creat an instance of Ship
myShip = new Ship(new Vector2((viewPort.Width - PANEL_WIDTH) / 2,
(viewPort.Height - 20)));
// creats an instance of Missile
missiles = new List<Missile>();
// creat two instances of AlienArmy
alienArsenal = new AlienArmy(aliensPos, (int)gameLevel, (int)skillSpeed.Beginner);
// gameOver is set to false
//alienArsenal.GameWon = false;
base.Initialize();
}
// Since this is an xna project; we can't easily drag/drop controls onto the
// main Form like we have been doing in the past. But, we can do it programatically,
// as illustrated below.
private void InitializeControlPanel()
{
// instantiate a panel and a label
gameControlPanel = new Panel();
lblKilledAliens = new Label();
lblLivesCount = new Label();
// setup the panel control. Note: this panel will overlay the viewport
// for 100 pixels; we should adjust for this (not shown in example)
this.gameControlPanel.Dock = DockStyle.Right;
this.gameControlPanel.Width = PANEL_WIDTH;
// create a button for starting the game
Button btnStart = new Button();
btnStart.Location = new System.Drawing.Point(10, 10);
btnStart.Text = "Start";
btnStart.Click += new EventHandler(btnStart_Click);
// create the button for settings
Button btnSettings = new Button();
btnSettings.Location = new System.Drawing.Point(10, btnStart.Top + btnStart.Height + 10);
btnSettings.Text = "Settings";
btnSettings.Click += new EventHandler(btnSettings_Click);
// add the buttons to the panel
this.gameControlPanel.Controls.Add(btnStart);
this.gameControlPanel.Controls.Add(btnSettings);
// setup the labels control and add the to the panel
// fireCount
// this.lblKilledAliens.Text ="Aliens: ";
this.lblKilledAliens.Location = new System.Drawing.Point(10, btnSettings.Top + btnSettings.Height + 10);
this.lblKilledAliens.AutoSize = true;
this.gameControlPanel.Controls.Add(this.lblKilledAliens);
// livesCount
this.lblLivesCount.Location = new System.Drawing.Point(10, lblKilledAliens.Top + lblKilledAliens.Height + 10);
this.lblLivesCount.AutoSize = true;
this.gameControlPanel.Controls.Add(this.lblLivesCount);
// get a reference to game window
// note that the 'as Form' is the same as a type cast
Form frm = Control.FromHandle(this.Window.Handle) as Form;
// add the panel to the game window form
frm.Controls.Add(gameControlPanel);
}
// event handler to start the game
void btnStart_Click(object sender, EventArgs e)
{
GameStart = true;
}
// event handler to display settings
void btnSettings_Click(object sender, EventArgs e)
{
// stop game
GameStart = false;
// create an instance of FormDialog
FormDialog myDialog = new FormDialog(cmbLabels, (int)currentCheat,(int)currentSkillLevel );
// check if OK is clicked
if (myDialog.ShowDialog() == DialogResult.OK)
{
// chenge Game settings
myDialog.changeSettings();
currentSkillLevel = (Game1.cmbOptions)myDialog.SkillLevel; // set skill level
currentCheat = (Game1.CheatOptions)myDialog.CheatMode; // set cheat mode
}
myDialog.Dispose();
// resume Game
GameStart = true;
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// load textures into memory once during LoadContent()
backGroundTexture = Content.Load<Texture2D>("stars");
Ship.Texture = Content.Load<Texture2D>("ship2");
Missile.Texture = Content.Load<Texture2D>("missile");
AlienArmy.alienPicture = Content.Load<Texture2D>("alienShip");
AlienArmy.bombPicture = Content.Load<Texture2D>("alienBomb");
AlienArmy.level2Alien = Content.Load<Texture2D>("alienLevel2");
}
/// <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
}
/// <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>
/// This gets called ~60 times per second
protected override void Update(GameTime gameTime)
{
if (GameStart)
{
moveShip(); // if a arrow key is held down, move the ship
fireMissle(); // create a missle if the space bar was hit
moveMissile(); // if the missle is alive, update its position
alienArsenal.move(); // move alien arsenal
if (counter == 20)
{
alienArsenal.fireBomb();
counter = 0;
}
counter++;
// check collision between bomb and ship
if (alienArsenal.isShipHit(myShip.ShipPosition,Ship.Texture))
{
// take a life and restart current level
restartLevel = true;
if (currentCheat == CheatOptions.NoCheat)
{
alienArsenal.restartLevel();
livesCount -= 1;
MediaPlayer.Play(Content.Load<Song>("collision"));
}
}
lblLivesCount.Text = "Lives: " + livesCount.ToString();
// check if the aliens are off the screen
if (alienArsenal.AliensPos.Y >= myShip.ShipPosition.Y)
{
restartLevel = true;
// reposition aliens at the top
if (restartLevel )
{
alienArsenal.restartLevel();
}
}
else
restartLevel = false;
// check collisions between missiles and aliens, and get the number of dead aliens
foreach (Missile missile in missiles)
{
killedAliens = alienArsenal.updateStatus(missile.MissilePos, (int)gameLevel);
//MediaPlayer.Play(Content.Load<Song>("collision"));
}
lblKilledAliens.Text = "Dead Aliens: " + killedAliens.ToString();
// finish game if there are no more lives
if (livesCount == 0)
{
// display a message box
MessageBox.Show(" ALIENS WON ", "GAME OVER", MessageBoxButtons.OK);
clearScreen();
GameStart = false;
}
// finish the game if humans win level2
if (alienArsenal.GameWon)
{
// display a message box
MessageBox.Show(" GAME WON ", "WON", MessageBoxButtons.OK);
clearScreen();
alienArsenal.restartLevel();
GameStart = false;
}
// change level
if (alienArsenal.CurrentLevel == (int)level.level2 && alienArsenal.StartLevel2)
{
gameLevel = level.level2;
alienArsenal = new AlienArmy(aliensPos, (int)gameLevel,(int)skillSpeed.Beginner );
}
// change skill level
if (currentSkillLevel == cmbOptions.Advanced)
{
alienArsenal.CurrentAlienSpeed = (int)skillSpeed.Advanced;
alienArsenal.BombSpeedLevel1 = 2 + ((int) skillSpeed.Advanced);
}
else if (currentSkillLevel == cmbOptions.Beginner)
{
alienArsenal.CurrentAlienSpeed = (int)skillSpeed.Beginner;
alienArsenal.BombSpeedLevel1 = 2 + ((int)skillSpeed.Beginner);
}
else if (currentSkillLevel == cmbOptions.Intermediate)
{
alienArsenal.CurrentAlienSpeed = (int)skillSpeed.Intermediate;
alienArsenal.BombSpeedLevel1 = 2 + ((int)skillSpeed.Intermediate);
}
base.Update(gameTime);
}
}
// Check to see if an arrow key is currently pressed. Take appropriate
// action to move ship (note, no boundary checking is done to ensure
// ship doesn't move off-screen; this should be fixed in your program).
private void moveShip()
{
KeyboardState state = Keyboard.GetState();
if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
{
if (myShip.ShipPosition.X > 0 )
{
myShip.move(Ship.Direction.Left);
}
}
else if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
{
if (myShip.ShipPosition.X < (viewPort.Width - PANEL_WIDTH * 6/5))
{
myShip.move(Ship.Direction.Right);
}
}
}
// Check to see if the space key is down. If so, set flag and position so
// that the Draw will Draw the missle. Note: this is a little different than
// the ship, because we only want to fire the missle on a button click
private void fireMissle()
{
KeyboardState newState = Keyboard.GetState();
// Is the SPACE key down?
if (newState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
{
// If it was not down the previous time we checked, then this is a
// new key press. If the key was down in the old state, they're just
// holding it down, so we ignore this state.
if (!oldState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
{
// create a missile
myMissile = new Missile();
// set missle launch position
myMissile.MissilePos = myShip.GunPosition;
// add myMissile to the list of missiles
missiles.Add(myMissile);
}
}
// Update saved state.
oldState = newState;
}
// If the missle is alive, move it up a few clicks until it goes off screen
public void moveMissile()
{
for (int i = missiles.Count; i > 0; i--)
{
missiles[i - 1].move();
if (missiles[i - 1].MissilePos.Y <= 0)
{
// remove missile from the list
missiles.RemoveAt(i - 1);
}
}
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
/// This is called in the main loop after Update to render the current state of the game
/// on the screen.
protected override void Draw(GameTime gameTime)
{
// spriteBatch is an object that allows us to draw everything
// on screen (it contains the Draw functions).
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
// draw the background
spriteBatch.Draw(backGroundTexture, viewPort, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
// draw the ship over background
// draw the ship
myShip.Draw(spriteBatch);
// draw the fired missiles
foreach (Missile missile in missiles)
{
missile.Draw(spriteBatch);
}
// draw aliens and bombs
alienArsenal.Draw(spriteBatch);
// This tells the graphics pipeline that we're done drawing this frame,
// and asks it to push the pixels to the graphics frame buffer.
spriteBatch.End();
base.Draw(gameTime);
}
// clear the screen
public void clearScreen()
{
if (GameStart == false)
{
foreach (Missile missile in missiles)
{
missiles.Remove(missile);
}
}
}
}
}
Suzie999 245 Coding Hobbyist
jigglymig 12 Light Poster
I got it now. Had to reinstall my software. It was having an issue with the order in the library I'm guessing. I'm guessing it is because I added xna after having the project in vs.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.