Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- namespace Stake_it_Out
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- //Environment Vars
- int numberRegions, treeDensity, regionX, regionY, regionStartX, regionStartY;
- Vector2 regionStartCoords;
- //Universal Tools and Input
- Random RandomClass = new Random();
- KeyboardState curKeyboardState, oldKeyboardState;
- public MouseState mouseStateCurrent, mouseStatePrevious;
- //States
- Boolean menuState, ingameState, deathState;
- Boolean gameSetup;
- //PlayerVars
- Vector2 playerPosition, playerGridPosition;
- int innerTileOffset;
- Player playerObject;
- //Tile Vars
- Vector2 newTilePosition, oldTilePosition;
- public int gridWidth, gridHeight, tileWidth, tileHeight;
- int tileNumberX,tileNumberY, gridScope;
- public Tile[,] tileArray;
- List<Tile> tileList;
- List<TreeRegion> treeRegionList;
- //Internews
- Interface interfaceObject;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- //Initialize
- protected override void Initialize()
- {
- //States
- ingameState = true;
- gameSetup = false;
- //Tile and Grid Properties
- tileWidth = 30; tileHeight = 30;
- gridWidth = 100; gridHeight = 100;
- gridScope = gridWidth * gridHeight;
- treeDensity = 200;
- tileNumberX= 0;
- tileNumberY = 0;
- tileArray = new Tile[gridScope, gridScope];
- tileList = new List<Tile>();
- Vector2 emptyVector = Vector2.Zero;
- Vector2 newTilePosition = new Vector2(emptyVector.X-tileWidth, emptyVector.Y);
- oldTilePosition = newTilePosition;
- innerTileOffset = 3;
- playerPosition = new Vector2(270 + innerTileOffset, 180 + innerTileOffset);
- playerObject = new Player(playerPosition, GraphicsDevice.Viewport);
- //Tree Region Properties
- treeRegionList = new List<TreeRegion>();
- //Init Methods
- createTiles();
- createInterface();
- loadGraphicContent();
- createTrees();
- IsMouseVisible = true;
- base.Initialize();
- }
- //Loading Graphics
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- }
- //Update
- protected override void Update(GameTime gameTime)
- {
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- updatePlayer(gameTime);
- //Make Consistent Trees
- for (int a=0; a < tileList.Count; a++)
- {
- tileList[a].maintainTreeLocation();
- }
- base.Update(gameTime);
- }
- //Draw
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.Black);
- spriteBatch.Begin();
- //Draw the for loop
- for (int d = 0; d < tileList.Count; d++)
- {
- tileList[d].Draw(this.spriteBatch);
- }
- playerObject.Draw(this.spriteBatch);
- interfaceObject.Draw(this.spriteBatch);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- //Player and Input
- private void updatePlayer(GameTime gameTime)
- {
- //Keyboard Input
- curKeyboardState = Keyboard.GetState();
- if (curKeyboardState.IsKeyDown(Keys.A))
- {
- if (oldKeyboardState.IsKeyUp(Keys.A))
- { for (int m = 0; m < tileList.Count; m++)
- {
- tileList[m].position.X += tileWidth;
- }
- }
- }
- if (curKeyboardState.IsKeyDown(Keys.D))
- {
- if (oldKeyboardState.IsKeyUp(Keys.D))
- {
- for (int m = 0; m < tileList.Count; m++)
- {
- tileList[m].position.X -= tileWidth;
- }
- }
- }
- if (curKeyboardState.IsKeyDown(Keys.W))
- {
- if (oldKeyboardState.IsKeyUp(Keys.W))
- {
- for (int m = 0; m < tileList.Count; m++)
- {
- tileList[m].position.Y += tileHeight;
- }
- }
- }
- if (curKeyboardState.IsKeyDown(Keys.S))
- {
- if (oldKeyboardState.IsKeyUp(Keys.S))
- {
- for (int m = 0; m < tileList.Count; m++)
- {
- tileList[m].position.Y -= tileWidth;
- }
- }
- }
- if (curKeyboardState.IsKeyDown(Keys.Space))
- {
- if (oldKeyboardState.IsKeyUp(Keys.Space))
- { }
- }
- oldKeyboardState = curKeyboardState;
- //MouseInput
- mouseStateCurrent = Mouse.GetState();
- if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
- {
- if (mouseStatePrevious.LeftButton != ButtonState.Pressed)
- {
- }
- }
- mouseStatePrevious = mouseStateCurrent;
- }
- //Create Tiles
- public void createTiles()
- {
- for (int a = 0; a < gridHeight; a++)
- {
- for (int b = 0; b < gridWidth; b++)
- {
- //Row Tiles
- newTilePosition = new Vector2(oldTilePosition.X + tileWidth, oldTilePosition.Y);
- tileNumberX+=1;
- int grassRand = RandomClass.Next(0, 9);
- Tile tileObject = new Tile(newTilePosition, grassRand, GraphicsDevice.Viewport);
- int xInt = (int)newTilePosition.X;
- int yInt = (int)newTilePosition.Y;
- //Arrayshit
- tileArray[xInt, yInt] = tileObject;
- tileList.Add(tileObject);
- oldTilePosition = newTilePosition;
- }
- //New Column
- oldTilePosition = new Vector2(oldTilePosition.X - (gridWidth * tileWidth), oldTilePosition.Y + tileHeight);
- }
- }
- //Create Trees
- public void createTrees()
- {
- numberRegions = (gridHeight * gridWidth) / treeDensity;
- for (int i = 0; i < numberRegions; i++)
- {
- //Starting Pos
- int regionStartX = RandomClass.Next(0, 10);
- regionStartX = regionStartX * 30;
- int regionStartY = RandomClass.Next(0, 10);
- regionStartY = regionStartY * 30;
- regionStartCoords = new Vector2(regionStartX, regionStartY);
- //Length and Width
- int regionX = RandomClass.Next(1, 10);
- regionX = regionStartX * 30;
- int regionY = RandomClass.Next(1, 10);
- regionY = regionStartX * 30;
- TreeRegion treeRegionObject = new TreeRegion(regionStartCoords, regionX, regionY, GraphicsDevice.Viewport);
- treeRegionList.Add(treeRegionObject);
- }
- for (int p = 0; p < treeRegionList.Count; p++)
- {
- treeRegionList[p].createTreess();
- treeRegionList[p].sendResults();
- }
- }
- //Create Interface
- public void createInterface()
- {
- interfaceObject = new Interface(GraphicsDevice.Viewport);
- }
- //Load Graphics
- public void loadGraphicContent()
- {
- //Tiles
- for (int a = 0; a < tileList.Count; a++)
- {
- tileList[a].LoadContent(this.Content, "graphic0", "graphic1", "graphic2", "graphic3", "graphic4", "graphic5", "graphic6", "graphic7", "graphic8", "graphic9","treeGraphic");
- }
- //Player
- playerObject.LoadContent(this.Content, "playerGraphic");
- //Interface
- interfaceObject.LoadContent(this.Content, "interfaceGraphic", "interfaceGraphic2","largeIcon0","largeIcon1", "smallIcon");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement