[C#] PlanetStreamer
Hejdär!
(Ja jag håller på med 2st spel samtidigt, för er som vet det.)
Jag kodar med ett spel till WindowsPhone som ska heta PlanetStreamer, det är en fin liten bakgrund och så styr man genom att dra på skeppet upp och ner och skjuter genom att klicka på skärmen.
Jag har hittils fixat bakgrunden, men till skillnad från mitt gamla projekt (som jag inte övergivit, håller på med det fortfarande) så blev det så sjuukt grötigt utan klasser och annat gott. SÅ jag ahde tänkt från början att dela upp olika saker i spelet i olika klasser.
Men eftersom vi inte gått igenom classer än i skolan så är det ett problem.
Många lämnar kritik som "Varför kan du det, men kan inte enkla saker som det?" Och det är helt enkelt för att jag googlar upp och lär mig det jag behöver veta för tillfället på internet, och lär mig riktigt långsamt i skolan. (Vi har en.. EN.. programmerings lektion i veckan, och då får man aldrig hjälp för att 30 andra elever behöver hjälp -.-'
Så jag kan lite ditt och datt om olika saker helt enkelt.
Vad jag behöver hjälp med just nu är varför mitt spel inte vill fungera:
Det är massa errors, och jag har försökt fixa dem men då kommer en annan error upp istället och så har det pågått.
Just nu har jag tre stycken klasser (.cs) filer i spelet.
Ettan är IngameTexture och är den som ändrar bakgrundsbilden när man väl är i spelet och styr planet osv.
Tvåan är MainMenu och är den som skriver Tap Screen to continue, och ändrar bakgrund bild.
Trean är IngameSpaceShip, som fixar rymdskeppet.
Alltså, vad är en klass, kan jag läsa in dem i en speciell ordning? Alltså MainMenu först, sen IngameTexture och sen IngameSpaceShip?
Och slutligen, varför kommer dessa errors upp?
IngameTexture.cs:
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.Input.Touch;
using Microsoft.Xna.Framework.Media;
namespace PlanetStreamer
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class IngameTexture : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private Texture2D Texture;
Public IngameTexture()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
// Frame rate is 30 fps by default for Windows Phone.
TargetElapsedTime = TimeSpan.FromTicks(333333);
// Extend battery life under lock.
InactiveSleepTime = TimeSpan.FromSeconds(1);
}
/// <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()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
Texture = Content.Load<Texture2D>("Space");
// 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
}
/// <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();
// 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();
spriteBatch.Draw(Texture, new Vector2(0f, 0f), Color.White);
spriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
MainMenu.cs
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 Microsoft.Xna.Framework.Input.Touch;
namespace PlanetStreamer
{
/// <summary>
/// This is a game component that implements IUpdateable.
/// </summary>
public class MainMenu : Microsoft.Xna.Framework.GameComponent
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private Texture2D MainMenuTexture;
public MainMenu(Game game)
: base(game)
{
// TODO: Construct any child components here
}
/// <summary>
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
/// </summary>
public override void Initialize()
{
// TODO: Add your initialization code here
base.Initialize();
}
/// <summary>
/// Allows the game component to update itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
///
protected void LoadContent()
{
MainMenuTexture = Content.Load<Texture2D>("Space");
}
protected void UnloadContent()
{
}
public override void Update(GameTime gameTime)
{
// TODO: Add your update code here
base.Update(gameTime);
}
protected void Draw(GameTime gameTime)
{
spriteBatch.Begin();
spriteBatch.Draw(MainMenuTexture, new Vector2(0f, 0f), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
IngameSpaceShip.cs -Inte börjat än då en SpelDesign elev gör ett rymdskepp (Han e grym!)
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 Microsoft.Xna.Framework.Input.Touch;
namespace PlanetStreamer
{
/// <summary>
/// This is a game component that implements IUpdateable.
/// </summary>
public class IngameSpaceShip : Microsoft.Xna.Framework.GameComponent
{
public IngameSpaceShip(Game game)
: base(game)
{
// TODO: Construct any child components here
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
/// </summary>
public override void Initialize()
{
// TODO: Add your initialization code here
base.Initialize();
}
/// <summary>
/// Allows the game component to update itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
// TODO: Add your update code here
base.Update(gameTime);
}
}
}
ERRORS:
Ladda hem källkod:
http://www.mediafire.com/?1ks5i6421w335mu