View Single Post
  #2 (permalink)  
Old 09-14-2007, 07:34 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
In case if you're curious, here's the entire code:

PHP Code:
#region File Description
//-----------------------------------------------------------------------------
// GameplayScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#endregion

namespace GameStateManagement
{
    
/// <summary>
    /// This screen implements the actual game logic. It is just a
    /// placeholder to get the idea across: you'll probably want to
    /// put some more interesting gameplay in here!
    /// </summary>
    
class GameplayScreen GameScreen
    
{
        
#region Fields

        
ContentManager content;
        
SpriteFont gameFont;

        
Vector2 playerPosition = new Vector2(100100);
        
Vector2 enemyPosition = new Vector2(100100);

        
Random random = new Random();

        
#region Variables

        
Model shipModel;
        
Vector3 cameraPosition = new Vector3(0.0f5000.0f0.0f);
        
Vector3 shipPosition Vector3.Zero;

        
#endregion

        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        
public GameplayScreen()
        {
            
TransitionOnTime TimeSpan.FromSeconds(1.5);
            
TransitionOffTime TimeSpan.FromSeconds(0.5);
        }


        
/// <summary>
        /// Load graphics content for the game.
        /// </summary>
        
public override void LoadGraphicsContent(bool loadAllContent)
        {
            if (
loadAllContent)
            {
                if (
content == null)
                    
content = new ContentManager(ScreenManager.Game.Services);

                
gameFont content.Load<SpriteFont>("Content/gamefont");
                
shipModel content.Load<Model>("Models/p1_wedge");

                
// A real game would probably have more content than this sample, so
                // it would take longer to load. We simulate that by delaying for a
                // while, giving you a chance to admire the beautiful loading screen.
                
Thread.Sleep(1000);
            }
        }


        
/// <summary>
        /// Unload graphics content used by the game.
        /// </summary>
        
public override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (
unloadAllContent)
                
content.Unload();
        }


        
#endregion

        #region Update and Draw


        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        
public override void Update(GameTime gameTimebool otherScreenHasFocusbool coveredByOtherScreen)
        {
            
base.Update(gameTimeotherScreenHasFocuscoveredByOtherScreen);

            if (
IsActive)
            {
                
// Apply some random jitter to make the enemy move around.
                
const float randomization 10;

                
enemyPosition.+= (float)(random.NextDouble() - 0.5) * randomization;
                
enemyPosition.+= (float)(random.NextDouble() - 0.5) * randomization;

                
// Apply a stabilizing force to stop the enemy moving off the screen.
                
Vector2 targetPosition = new Vector2(200200);

                
enemyPosition Vector2.Lerp(enemyPositiontargetPosition0.05f);

                
// TODO: this game isn't very fun! You could probably improve
                // it by inserting something more interesting in this space :-)
            
}
        }


        
/// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        
public override void HandleInput(InputState input)
        {
            if (
input == null)
                
throw new ArgumentNullException("input");

            if (
input.PauseGame)
            {
                
// If they pressed pause, bring up the pause menu screen.
                
ScreenManager.AddScreen(new PauseMenuScreen());
            }
            else
            {
                
// Otherwise move the player position.
                
const float movementSpeed 2;

                if (
input.CurrentKeyboardState.IsKeyDown(Keys.Left))
                    
playerPosition.-= movementSpeed;

                if (
input.CurrentKeyboardState.IsKeyDown(Keys.Right))
                    
playerPosition.+= movementSpeed;

                if (
input.CurrentKeyboardState.IsKeyDown(Keys.Up))
                    
playerPosition.-= movementSpeed;

                if (
input.CurrentKeyboardState.IsKeyDown(Keys.Down))
                    
playerPosition.+= movementSpeed;

                
Vector2 thumbstick input.CurrentGamePadState.ThumbSticks.Left;

                
playerPosition.+= thumbstick.movementSpeed;
                
playerPosition.-= thumbstick.movementSpeed;
            }
        }


        
/// <summary>
        /// Draws the gameplay screen.
        /// </summary>
        
public override void Draw(GameTime gameTime)
        {
            
// This game has a blue background. Why? Because!
            
ScreenManager.GraphicsDevice.Clear(ClearOptions.TargetColor.CornflowerBlue00);

            
Matrix[] transforms = new Matrix[shipModel.Bones.Count];
            
shipModel.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (
ModelMesh mesh in shipModel.Meshes)
            {
                foreach (
BasicEffect effect in mesh.Effects)
                {
                    
effect.EnableDefaultLighting();
                    
effect.World transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(shipPosition);
                    
effect.View Matrix.CreateLookAt(cameraPositionVector3.ZeroVector3.Up);
                    
Matrix projection Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f), (800.0f 600.0f), 10.0f10000.0f);
                }
                
mesh.Draw();
            }

            
// If the game is transitioning on or off, fade it out to black.
            
if (TransitionPosition 0)
                
ScreenManager.FadeBackBufferToBlack(255 TransitionAlpha);
        }


        
#endregion
    
}

I really need help on this for some reason it doesn't show anything!!! sigh... I think there's something wrong with the aspect ratio...?

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote