I have been making games off and on for the past year or two and i am just getting into game states. I have looked on the XNA site and they have but one example which is way to complicated for me at this point in time. I need to make a simple game with a start menu, inGame, and end screen. Ive got the idea down; get an enum list called Gamestates, change the states in the update methode and draw a different background to the screen depending on the game state, and do logic when the state is InGame. Ive got that down and working(except the logic), my problem is implementing the game logic and uploading my sprites.
What i want to do is when my GameState is InGame, i want to call a class(lets call it level1) and then upload the sprites i need, perform logic, and draw to the screen. I get problems with trying to load sprites in the level1 class and having the game perform logic and output.
Ive been researching this for a while and trying to implement for even longer. Am I on the right track? Is there a trick i am missing? What should i do to make my level1 class to load, do logic, and draw? Can anyone show me or point me in the right direction im about to go ape shit.
Game1.cs file is below to show what I have going.
Thanks very much for your time and appreciate anything you can do to help me figure this out
-UofMCreed
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.Net;
using Microsoft.Xna.Framework.Storage;
namespace GameWithAliensInIt
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
//Rectangles
Rectangle mainFrame;
Rectangle groundRectangle;
//Keyboard States
KeyboardState cK;
KeyboardState pK = Keyboard.GetState();
//Backgrounds for the different states
Texture2D titlescreen;
Texture2D endscreen;
Texture2D gamescreen;
Texture2D ground;
Texture2D playerTexture;
enum GameState { Start, InGame, GameOver };
GameState currentGameState = GameState.Start;
//Game state level
private Level level = new Level();
int counter = 0;
public int Counter
{
get { return counter; }
set
{
counter = value;
if (counter == 0)
{
currentGameState = GameState.GameOver;
}
}
}
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
//Loading the background textures
gamescreen = Content.Load<Texture2D>(@"Images/50x50 Pixel Grid");
titlescreen = Content.Load<Texture2D>(@"Images/mainScreen");
endscreen = Content.Load<Texture2D>(@"Images/endScreen");
//Rectangle that fits the entire game window, all action happens within this rectangle
mainFrame = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
//Loading the ground texture
ground = Content.Load<Texture2D>(@"Images/Ground");
//Rectangle for the ground, to help collision detection
groundRectangle = new Rectangle(0, 550, ground.Width, ground.Height);
playerTexture = Content.Load<Texture2D>(@"Images/player");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit using the keyboard
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
this.Exit();
#region GameStates
cK = Keyboard.GetState();
switch (currentGameState)
{
//If the state of the game 'GameState' is set to start, it will draw titlescreen
case GameState.Start:
if (cK.IsKeyDown(Keys.Space) && pK.IsKeyUp(Keys.Space))
{
currentGameState = GameState.InGame;
counter = 0;
}
break;
//If the state of the game is set to ingame, it will draw gamescreen
case GameState.InGame:
if (cK.IsKeyDown(Keys.Space) && pK.IsKeyUp(Keys.Space))
{
currentGameState = GameState.GameOver;
}
//LEVEL1 CALLS SHOULD GO HERE I WOULD THINK
break;
//If the state of the game is set to gameover, it will draw the endscreen
case GameState.GameOver:
if (cK.IsKeyDown(Keys.Space) && pK.IsKeyUp(Keys.Space))
{
//Exiting the Game
this.Exit();
}
break;
}
pK = cK;
#endregion
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
//GraphicsDevice.Clear(Color.CornflowerBlue);
//Drawing the different backgrounds to the screen depending on the GameState
switch (currentGameState)
{
//If the state of the game 'GameState' is set to start, it will draw titlescreen
case GameState.Start:
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin();
spriteBatch.Draw(titlescreen, new Rectangle(0, 0, window.ClientBounds.Width,
window.ClientBounds.Height), null, Color.White, 0,Vector2.Zero, SpriteEffects.None, 0);
spriteBatch.End();
break;
//If the state of the game is set to ingame, it will draw gamescreen
case GameState.InGame:
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin();
spriteBatch.Draw(gamescreen, new Rectangle(0, 0, window.ClientBounds.Width,
window.ClientBounds.Height), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
spriteBatch.Draw(ground, groundRectangle, Color.White);
spriteBatch.End();
break;
//If the state of the game is set to gameover, it will draw the endscreen
case GameState.GameOver:
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin();
spriteBatch.Draw(endscreen, new Rectangle(0, 0, window.ClientBounds.Width,
window.ClientBounds.Height), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
spriteBatch.End();
break;
}
base.Draw(gameTime);
}
}
}

New Topic/Question
Reply


MultiQuote








|