Jump to content
  • Advertisement
Sign in to follow this  
Kenny77

Progress So Far

This topic is 3920 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've started working on a simple game to get the hang of structuring my code (which for me is the hardest part). What are your comments on how I've started, what should I change, keep, and so on? Game
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

namespace Amazing_Cube
{
    public class Game : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;

        public enum GameState { menu, playing, winning }
        public GameState state = GameState.menu;

        private Menu menu;

        private Texture2D titleScreen;
        private Vector2 titlePos = new Vector2(0, 0);
        private SpriteBatch titleSprite;

        public Game()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);

            menu = new Menu(this);
            Components.Add(menu);
        }

        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = 640;
            graphics.PreferredBackBufferHeight = 480;
            Window.Title = "Amazing Cube";
            Window.AllowUserResizing = false;
            IsMouseVisible = true;
            graphics.ApplyChanges();

            base.Initialize();
        }

        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                titleSprite = new SpriteBatch(graphics.GraphicsDevice);
                titleScreen = content.Load<Texture2D>(@"Resources\Title Screen");
            }
        }

        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
                content.Unload();
            }
        }

        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.DarkBlue);

            switch (state)
            {
                case GameState.menu:
                    {
                        if (menu.MouseState.LeftButton == ButtonState.Released)
                        {
                            titleSprite.Begin();
                            titleSprite.Draw(titleScreen, titlePos, Color.White);
                            titleSprite.End();
                        }
                        if (menu.MouseState.LeftButton == ButtonState.Pressed)
                        {
                            state = GameState.playing;
                        }
                        break;
                    }
                case GameState.playing:
                    {
                        this.Exit();
                        break;
                    }
            }

            base.Draw(gameTime);
        }
    }
}

Menu
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Amazing_Cube
{
    public class Menu : Microsoft.Xna.Framework.GameComponent
    {
        private MouseState mouseState;

        public Menu(Game game) : base(game)
        {

        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            mouseState = Mouse.GetState();

            base.Update(gameTime);
        }

        public MouseState MouseState
        {
            get { return (mouseState); }
        }
    }
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!