Ok, Im completly new to C# and XNA, Ive pretty much mastered Visual Basic then moved onto this. Im doing the Going Beyond tutorials where you make the asteroids game, but Im having a problem with this line.:
Ship ship = new ship();
I dont know how to fix it, Ive read over the code tons of times and have no clue. I have also changed the code to take keyboard input rateher than a 360 controller which I got to work well. The error Im getting is this, Error 1 The type or namespace name 'Ship' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Scott\Documents\Visual Studio 2008\Projects\WindowsGame1\WindowsGame1\Game1.cs 37 9 WindowsGame1
Heres my code incase you want to check it over.
Game1.cs:
using System;
using System.Collections.Generic;
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.Net;
using Microsoft.Xna.Framework.Storage;
namespace WindowsGame1
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
KeyboardState oldState;
//Camera/View information
Vector3 cameraPosition = new Vector3(0.0f, 0.0f, -5000.0f);
float aspectRatio;
Matrix projectionMatrix;
Matrix viewMatrix;
//Audio components
AudioEngine audioEngine;
WaveBank waveBank;
SoundBank soundBank;
//Cue so we can hang onto the soun of the engine
Cue engineSound = null;
//Visual components
Ship ship = new Ship();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
aspectRatio = (float)GraphicsDeviceManager.DefaultBackBufferWidth / GraphicsDeviceManager.DefaultBackBufferHeight;
}
protected override void Initialize()
{
audioEngine = new AudioEngine("Content\\Audio\\MyGameAudio.xgs");
waveBank = new WaveBank(audioEngine, "Content\\Audio\\Wave Bank.xwb");
soundBank = new SoundBank(audioEngine, "Content\\Audio\\Sound Bank.xsb");
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);
viewMatrix = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
base.Initialize();
oldState = Keyboard.GetState();
}
private Matrix[ SetupEffectDefaults(Model myModel)
{
Matrix[ absoluteTransforms = new Matrix[myModel.Bones.Count];
myModel.CopyAbsoluteBoneTransformsTo(absoluteTransforms);
foreach (ModelMesh mesh in myModel.Meshes)
{
Effect.EnableDefaultLighting();
Effect.Projection = projectionMatrix;
Effect.View = viewMatrix;
}
return absoluteTransforms;
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
ship.Model = Content.Load<Model>("Models/p1_wedge");
ship.Transforms = SetupEffectDefaults(ship.Model);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// Get some input.
UpdateInput();
// Update audioEngine.
audioEngine.Update();
// Add velocity to the current position.
ship.Position += ship.Velocity;
// Bleed off velocity over time.
ship.Velocity *= 0.95f;
base.Update(gameTime);
}
protected void UpdateInput()
{
//Sets the keyboard as controller.
KeyboardState newState = Keyboard.GetState();
{
ship.Update(currentState);
//Rotate the model using the W key.
if (newState.IsKeyDown(Keys.A))
{
if (!oldState.IsKeyDown(Keys.A))
{
modelRotation = modelRotation + 0.10f;
}
else if (oldState.IsKeyDown(Keys.A))
{
engineSound.Pause();
}
}
if (newState.IsKeyDown(Keys.D))
{
modelRotation = modelRotation - 0.10f;
}
else if (oldState.IsKeyDown(Keys.D))
{
engineSound.Pause();
}
if (newState.IsKeyDown(Keys.W))
{
if (!oldState.IsKeyDown(Keys.W))
{
Vector3 modelVelocityAdd = Vector3.Zero;
modelVelocityAdd.X = -(float)Math.Sin(modelRotation);
modelVelocityAdd.Z = -(float)Math.Cos(modelRotation);
modelVelocity += modelVelocityAdd * 2;
}
if (engineSound == null)
{
engineSound = soundBank.GetCue("engine_2");
engineSound.Play();
}
else if (engineSound.IsPaused)
{
engineSound.Resume();
}
else
{
if (engineSound != null && engineSound.IsPlaying)
{
engineSound.Pause();
}
}
}
else if (oldState.IsKeyDown(Keys.W))
{
engineSound.Pause();
}
if (newState.IsKeyDown(Keys.S))
{
if (!oldState.IsKeyDown(Keys.S))
{
Vector3 modelVelocityAdd = Vector3.Zero;
modelVelocityAdd.X = +(float)Math.Sin(modelRotation);
modelVelocityAdd.Z = +(float)Math.Cos(modelRotation);
modelVelocity += modelVelocityAdd * 2;
}
else if (oldState.IsKeyDown(Keys.S))
{
engineSound.Pause();
}
}
if (newState.IsKeyDown(Keys.Space))
{
if (!oldState.IsKeyDown(Keys.Space))
{
modelPosition = Vector3.Zero;
modelVelocity = Vector3.Zero;
modelRotation = 0.0f;
//Make a sound when we warp.
soundBank.PlayCue("hyperspace_activate");
if (engineSound.IsPlaying)
{
engineSound.Pause();
}
}
else if (oldState.IsKeyDown(Keys.Space))
{
}
}
}}
private object currentState(Keys keys)
{
throw new NotImplementedException();
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix shipTransformMatrix = ship.RotationMatrix
* Matrix.CreateTranslation(ship.Position);
DrawModel(ship.Model, shipTransformMatrix, ship.Transforms);
base.Draw(gameTime);
}
public void DrawModel(Model model, Matrix modelTransform, Matrix[ absoluteBoneTransforms)
{
//Draw the model, a model can have multiple meshes, so loop
foreach (ModelMesh mesh in model.Meshes)
{
//This is where the mesh orientation is set
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = absoluteBoneTransforms[mesh.ParentBone.Index] * modelTransform;
}
//Draw the mesh, will use the effects set above.
mesh.Draw();
}
}
}
}
Ship.cs:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace GoingBeyond4_Tutorial
{
class Ship
{
public Model Model;
public Matrix[ Transforms;
//Position of the model in world space.
public Vector3 Position = Vector3.Zero;
//Velocity of the model, applied each frame to the model's position
public Vector3 Velocity = Vector3.Zero;
public Matrix RotationMatrix = Matrix.Identity;
private float rotation = 0.0f;
public float Rotation
{
get { return rotation; }
set
{
float newVal = value;
while (newVal >= MathHelper.TwoPi)
{
newVal -= MathHelper.TwoPi;
}
while (newVal < 0)
{
newVal += MathHelper.TwoPi;
}
if (rotation != newVal)
{
rotation = newVal;
RotationMatrix = Matrix.CreateRotationY(rotation);
}
}
}
public void Update(GamePadState controllerState)
{
//Rotate the model using the A key and scale it down.
Rotation -= controllerState.ThumbSticks.Left.X * 0.10f;
//Finally, add this vector to our velocity.
Velocity += RotationMatrix.Forward * 1.0f * controllerState.Triggers.Right;
}
}
}
Thanks for any help!