Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using ProjectTellchief.Data.Resource;
- /// <summary>
- /// This is the main type for your game.
- /// </summary>
- public class Game1 : Game
- {
- enum GameState
- {
- MainMenu,
- Gameplay,
- EndOfGame,
- GamePlay,
- }
- GameState _state;
- bool playerDied;
- bool pushedStartGameButton;
- bool pushedMainMenuButton;
- bool pushedRestartLevelButton;
- void ResetLevel()
- {
- throw new NotImplementedException();
- }
- /// <summary>
- /// The menu assets.
- /// </summary>
- private ResourceManager rmInstance;
- private Texture2D background;
- private Texture2D dylaninbin;
- private Texture2D btnnewgame;
- private Texture2D btnnewgameHover;
- private Texture2D title;
- private Texture2D cursor;
- private Texture2D btnMAIN;
- private Vector2 cursorPos;
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- private SoundEffect track;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- private AssetHierarchyDefinition GetAssetHierarchy()
- {
- AssetHierarchyDefinition assetDefinition = new AssetHierarchyDefinition();
- //Environment assets
- AssetFolder environment = new AssetFolder("Environment", AssetFolderContentType.TEXTURES);
- //Language assets
- AssetFolder language = new AssetFolder("Lang", AssetFolderContentType.TEXTFILES);
- //Sound assets
- AssetFolder sounds = new AssetFolder("Sounds", AssetFolderContentType.SOUNDS);
- AssetFolder sounds2 = new AssetFolder("Sound");
- AssetFolder music = new AssetFolder("Music");
- //Texture assets
- AssetFolder textures = new AssetFolder("Textures", AssetFolderContentType.TEXTURES);
- AssetFolder tiles = new AssetFolder("Tile");
- AssetFolder items = new AssetFolder("Item");
- AssetFolder entities = new AssetFolder("Entity");
- AssetFolder gui = new AssetFolder("Gui", AssetFolderContentType.TEXTURES);
- textures.AddSubFolder(tiles);
- textures.AddSubFolder(items);
- textures.AddSubFolder(entities);
- sounds.AddSubFolder(sounds2);
- sounds.AddSubFolder(music);
- //add all top level folders to the asset structure hierarchy
- assetDefinition.AddFolder(environment);
- assetDefinition.AddFolder(sounds);
- assetDefinition.AddFolder(textures);
- assetDefinition.AddFolder(gui);
- return assetDefinition;
- }
- /// <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()
- {
- IsMouseVisible = false;
- // TODO: Add your initialization logic here
- base.Initialize();
- const int defaultWidth = 1280, defaultHeight = 720;
- int currentWidth = GraphicsDevice.Viewport.Width,
- currentHeight = GraphicsDevice.Viewport.Height;
- Vector2 scale = new Vector2(currentWidth / defaultWidth,
- currentHeight / defaultHeight);
- _state = GameState.MainMenu;
- rmInstance = new ResourceManager(graphics, GetAssetHierarchy());
- rmInstance.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);
- background = Content.Load<Texture2D>("Controls/background"); // change these names to the names of your images
- dylaninbin = Content.Load<Texture2D>("Controls/dylan_in_container"); // change these names to the names of your images
- btnnewgame = Content.Load<Texture2D>("Controls/New_Game_LBlue"); // change these names to the names of your images
- btnnewgameHover = Content.Load<Texture2D>("Controls/New_Game_Yellow"); // change these names to the names of your images
- title = Content.Load<Texture2D>("Controls/title"); // change these names to the names of your images
- cursor = Content.Load<Texture2D>("Controls/cursor");
- //track = Content.Load<SoundEffect>("audio/soundtrack/sadface");
- track = (SoundEffect)rmInstance.GetResource("sounds.music.sadface");
- }
- /// <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)
- {
- // For Mobile devices, this logic will close the Game when the Back button is pressed
- // Exit() is obsolete on iOS
- #if !__IOS__ && !__TVOS__
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- {
- Exit();
- }
- #endif
- base.Update(gameTime);
- switch (_state)
- {
- case GameState.MainMenu:
- UpdateMainMenu(gameTime);
- break;
- case GameState.Gameplay:
- UpdateGameplay(gameTime);
- break;
- case GameState.EndOfGame:
- UpdateEndOfGame(gameTime);
- break;
- }
- base.Update(gameTime);
- }
- public bool isHovered { get; private set; }
- public bool isClicked { get; private set; }
- void UpdateMainMenu(GameTime deltaTime)
- {
- btnMAIN = btnnewgame;
- //if (Mouse.GetState().LeftButton == ButtonState.Pressed)
- // {
- // btnMAIN = btnnewgameHover;
- // }
- MouseState mouseState = Mouse.GetState();
- cursorPos = new Vector2(mouseState.X, mouseState.Y);
- //if (pushedStartGameButton)
- //_state = GameState.GamePlay;
- //var mousePoint = new Point(mouseState.X, mouseState.Y);
- var rectangle = new Rectangle(100, 150, btnnewgame.Width/2, btnnewgame.Height/2);
- if (rectangle.Contains(cursorPos))
- {
- btnMAIN = btnnewgameHover;
- isClicked = mouseState.LeftButton == ButtonState.Pressed;
- }
- else
- {
- btnMAIN = btnnewgame;
- isHovered = false;
- isClicked = false;
- }
- }
- void UpdateGameplay(GameTime deltaTime)
- {
- // Respond to user actions in the game.
- // Update enemies
- // Handle collisions
- if (playerDied)
- _state = GameState.EndOfGame;
- }
- void UpdateEndOfGame(GameTime deltaTime)
- {
- // Update scores
- // Do any animations, effects, etc for getting a high score
- // Respond to user input to restart level, or go back to main menu
- if (pushedMainMenuButton)
- _state = GameState.MainMenu;
- else if (pushedRestartLevelButton)
- {
- ResetLevel();
- _state = GameState.Gameplay;
- }
- }
- /// <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)
- {
- base.Draw(gameTime);
- switch (_state)
- {
- case GameState.MainMenu:
- DrawMainMenu(gameTime);
- break;
- case GameState.Gameplay:
- DrawGameplay(gameTime);
- break;
- case GameState.EndOfGame:
- DrawEndOfGame(gameTime);
- break;
- }
- }
- void DrawMainMenu(GameTime deltaTime)
- {
- spriteBatch.Begin();
- spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White);
- spriteBatch.Draw(dylaninbin, new Rectangle(0, 0, 800, 480), Color.White);
- #pragma warning disable CS0618 // Type or member is obsolete
- spriteBatch.Draw(btnMAIN, new Vector2(100, 150), scale: new Vector2((float)0.5, (float)0.5));
- #pragma warning restore CS0618 // Type or member is obsolete
- #pragma warning disable CS0618 // Type or member is obsolete
- spriteBatch.Draw(title, new Vector2(95, 25), scale: new Vector2((float)0.6, (float)0.6));
- #pragma warning restore CS0618 // Type or member is obsolete
- #pragma warning disable CS0618 // Type or member is obsolete
- spriteBatch.Draw(cursor, cursorPos, scale: new Vector2((float)0.1, (float)0.1));
- #pragma warning restore CS0618 // Type or member is obsolete
- spriteBatch.End();
- }
- void DrawGameplay(GameTime deltaTime)
- {
- // Draw the background the level
- // Draw enemies
- // Draw the player
- // Draw particle effects, etc
- }
- void DrawEndOfGame(GameTime deltaTime)
- {
- spriteBatch.Begin();
- spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.White);
- spriteBatch.End();
- // Draw text and scores
- // Draw menu for restarting level or going back to main menu
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement