public World(int screenWidth, int screenHeight, ContentManager content, Cam2D cam) { this.screenHeight = screenHeight; this.screenWidth = screenWidth; this.content = content; this.cam = cam; }
/// <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() { // TODO: Add your initialization logic here //Remove the exit button from the top right corner of the game Application.EnableVisualStyles(); Form gameForm = (Form)Form.FromHandle(Window.Handle); gameForm.FormBorderStyle = FormBorderStyle.None; //Set the Properties of the Graphics Model graphics.PreferMultiSampling = true; graphics.PreferredBackBufferWidth = 1080; graphics.PreferredBackBufferHeight = 640; graphics.IsFullScreen = false; graphics.ApplyChanges(); //Save the screen dimensions screenHeight = graphics.PreferredBackBufferHeight; screenWidth = graphics.PreferredBackBufferWidth; //Initialize the camera object with the viewport cam = new Cam2D(GraphicsDevice.Viewport); //Initialize the world and create the world set up all required data world = new World(screenWidth, screenHeight, Content, cam); world.Initialize("map1"); base.Initialize(); }
public static string ButtonPressedCamera(Rectangle buttonRec, Cam2D cam) { // Checks if the mouse is above the rectangle if (cam.ScreenToWorld(new Vector2(mouse.X, mouse.Y)).X > buttonRec.X && cam.ScreenToWorld(new Vector2(mouse.X, mouse.Y)).X < (buttonRec.X + buttonRec.Width)) { if (cam.ScreenToWorld(new Vector2(mouse.X, mouse.Y)).Y > buttonRec.Y && cam.ScreenToWorld(new Vector2(mouse.X, mouse.Y)).Y < (buttonRec.Y + buttonRec.Height)) { // If the mouse is pressed if (mouse.LeftButton == ButtonState.Pressed) { // If the mouse is being held down if (mousePre.LeftButton != ButtonState.Pressed /* && !fade.Active*/) { //buttonClick.Play(); return("PRESSED"); } else { return("HOLD"); } } else { return("HOVER"); } } } return("NOTHING"); }
void Awake() { _use = this; cam = GetComponent <Camera>(); cam.orthographic = true; FindPlayer(); CalculateBounds(); }
/// <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); //Sets the texture data for all the tiles (static method) Tile.SetTextureData(Content); //Sets the texture data for all the weapons EnemyRifle.SetTextureData(Content); Handgun.SetTextureData(Content); PlayerRifle.SetTextureData(Content); Shotgun.SetTextureData(Content); ThrowingKnife.SetTextureData(Content); //Sets the texture data for the projectiles Projectile.SetTextureData(Content); camera = new Cam2D(GraphicsDevice.Viewport, fullScreenSize, 1, 1, 0, new Rectangle(0, 0, 0, 0)); profileHelper = new ProfileHelper(onlineHelper); buttonFont = this.Content.Load <SpriteFont>("Fonts\\ButtonFont"); enlargedButtonFont = this.Content.Load <SpriteFont>("Fonts\\EnlargedButtonFont"); titleFont = this.Content.Load <SpriteFont>("Fonts\\TitleFont"); backgroundTexture = new Texture2D(GraphicsDevice, 1, 1); backgroundTexture.SetData(new Color[] { Color.White }); CreateTextBoxs(); CreateLabels(); CreateButtons(); SetKeys(); // TODO: use this.Content to load your game content here }
/// <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); whiteSquare = Content.Load <Texture2D>("WhiteSquare"); basicFont = Content.Load <SpriteFont>("BasicFont"); playerTex[0] = Content.Load <Texture2D>("Assets/Player/Player2"); stonetextures[0] = Content.Load <Texture2D>("Assets/Stones/Rock_texture_6"); stonetextures[1] = Content.Load <Texture2D>("Assets/Stones/Rock_texture_8"); stonetextures[2] = Content.Load <Texture2D>("Assets/Stones/Rock_texture_9"); stonetextures[3] = Content.Load <Texture2D>("Assets/Stones/Rock_texture_10"); stonetextures[4] = Content.Load <Texture2D>("Assets/Stones/Rock_texture1"); stonetextures[5] = Content.Load <Texture2D>("Assets/Stones/Rock_texture2"); stonetextures[6] = Content.Load <Texture2D>("Assets/Stones/Rock_texture3"); stonetextures[7] = Content.Load <Texture2D>("Assets/Stones/Rock_texture4"); stoneBackgroundtextures[0] = Content.Load <Texture2D>("Assets/Backgrounds/Background1"); stoneBackgroundtextures[1] = Content.Load <Texture2D>("Assets/Backgrounds/Background2"); stoneBackgroundtextures[2] = Content.Load <Texture2D>("Assets/Backgrounds/Background3"); stoneBackgroundtextures[3] = Content.Load <Texture2D>("Assets/Backgrounds/Background4"); stoneBackgroundtextures[4] = Content.Load <Texture2D>("Assets/Backgrounds/Background5"); stoneBackgroundtextures[5] = Content.Load <Texture2D>("Assets/Backgrounds/Background6"); stoneBackgroundtextures[6] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundFinal"); stoneBackgroundtextures[10] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundFinal"); stoneBackgroundtextures[11] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundFinal"); stoneBackgroundtextures[12] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundFinal"); stoneBackgroundtextures[13] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundFinal"); stoneBackgroundtextures[7] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundBlood1"); stoneBackgroundtextures[14] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundBlood1"); stoneBackgroundtextures[15] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundBlood1"); stoneBackgroundtextures[8] = Content.Load <Texture2D>("Assets/Backgrounds/Poop"); stoneBackgroundtextures[16] = Content.Load <Texture2D>("Assets/Backgrounds/Poop"); stoneBackgroundtextures[17] = Content.Load <Texture2D>("Assets/Backgrounds/Poop"); stoneBackgroundtextures[9] = Content.Load <Texture2D>("Assets/Backgrounds/poop3"); stoneBackgroundtextures[18] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundFinal"); stoneBackgroundtextures[19] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundFinal"); stoneBackgroundtextures[20] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundFinal"); stoneBackgroundtextures[21] = Content.Load <Texture2D>("Assets/Backgrounds/BackgroundFinal"); backgroundAnimationsTex[0] = Content.Load <Texture2D>("Assets/Backgrounds/EyesFinal"); backgroundAnimationsTex[1] = Content.Load <Texture2D>("Assets/Backgrounds/EyesSmall"); objectsAnimationTex[0] = Content.Load <Texture2D>("Assets/Objects/chest_idle"); objectsAnimationTex[1] = Content.Load <Texture2D>("Assets/Objects/chest_open"); objectsAnimationTex[2] = Content.Load <Texture2D>("Assets/Objects/Trapped_chest"); objectsAnimationTex[3] = Content.Load <Texture2D>("Assets/Objects/Drone"); oreTexture[0] = Content.Load <Texture2D>("Assets/Ore/ore1"); enemyAnimationTex[0] = Content.Load <Texture2D>("Assets/Enemies/Rat_run"); topLayerTexture[0] = Content.Load <Texture2D>("Assets/TopLayers/Sand"); playerCam = new Cam2D(GraphicsDevice.Viewport, new Rectangle(-20000, -5000, 42500, 100000), 1, 5, 0, Player.rec); // TODO: use this.Content to load your game content here }
//Pre: The list of keys that need to be checked, the array of gametiles, the current gamestate, and the camera //Post: The new gamestate is returned //Desc: A method for updating the creator controls public GameState UpdateCreatorControls(List <Keys> keysToCheck, Tile[,] gameTiles, GameState gameState, Cam2D camera) { //Updates the current keyboard state keyboardState = Keyboard.GetState(); //Updates the mouse state mouse = Mouse.GetState(); //If the mouse button is released if (mouse.LeftButton == ButtonState.Released) { //Set it to not being held anymore mouseButtonHeld = false; } //Updates the keys which are pressed pressedKeys = keyboardState.GetPressedKeys(); //Loop for every key that was pressed for (int i = 0; i < pressedKeys.Length; i++) { //If the current key is the up key if (pressedKeys[i] == Keys.Up || pressedKeys[i] == Keys.W) { //Move the camera up mapCreatorPos.Y -= (Human.HUMAN_SPEED * 5); } //If the current key is the down key else if (pressedKeys[i] == Keys.Down || pressedKeys[i] == Keys.S) { //Move the camera down mapCreatorPos.Y += (Human.HUMAN_SPEED * 5); } //If the current key is the left key else if (pressedKeys[i] == Keys.Left || pressedKeys[i] == Keys.A) { //Move the camera to the left mapCreatorPos.X -= (Human.HUMAN_SPEED * 5); } //If the current key is the right key else if (pressedKeys[i] == Keys.Right || pressedKeys[i] == Keys.D) { //Move the camera to the right mapCreatorPos.X += (Human.HUMAN_SPEED * 5); } //If the X position is less then 0 if (mapCreatorPos.X < 0) { //Set the position equal to 0 mapCreatorPos.X = 0; } //If the X position is greater then the screen size if (mapCreatorPos.X > ((Rectangle)camera.GetLimits()).Width) { //Sets the position to the screen size mapCreatorPos.X = ((Rectangle)camera.GetLimits()).Width; } //If the Y position is less then 0 if (mapCreatorPos.Y < 0) { //Set the position equal to 0 mapCreatorPos.Y = 0; } //If the Y position is greater then the screen size if (mapCreatorPos.Y > ((Rectangle)camera.GetLimits()).Height) { //Sets the position to the screen size mapCreatorPos.Y = ((Rectangle)camera.GetLimits()).Height; } //Looks at the position camera.LookAt(mapCreatorPos); //If the key is something that can be used if (CheckOldKeys(i, keysToCheck)) { //If the current key is the one key if (pressedKeys[i] == Keys.NumPad1 || pressedKeys[i] == Keys.D1) { //Sets the tile that is currently used CurrentTileType = TileType.Blank; PlacingEnemy = false; } //If the current key is the two key else if (pressedKeys[i] == Keys.NumPad2 || pressedKeys[i] == Keys.D2) { //Sets the tile that is currently used CurrentTileType = TileType.Save; PlacingEnemy = false; } //If the current key is the three key else if (pressedKeys[i] == Keys.NumPad3 || pressedKeys[i] == Keys.D3) { //Sets the tile that is currently used CurrentTileType = TileType.Spawn; PlacingEnemy = false; } //If the current key is the four key else if (pressedKeys[i] == Keys.NumPad4 || pressedKeys[i] == Keys.D4) { //Sets the tile that is currently used CurrentTileType = TileType.Wall; PlacingEnemy = false; } //If the current key is the 5 key else if (pressedKeys[i] == Keys.NumPad5 || pressedKeys[i] == Keys.D5) { //Sets the enemy to be placing PlacingEnemy = true; } //If the current key is the escape key else if (pressedKeys[i] == Keys.Escape) { //Sets the game state gameState = GameState.SaveCreatorMap; } //If the current key is the H key else if (pressedKeys[i] == Keys.H) { //Sets the game state gameState = GameState.MapCreatorHelp; } } } //Set the previously pressed keys to the currently pressed keys prevPressedKeys = pressedKeys; //Returns the current game state return(gameState); }
//Pre: The List of buttons, the gamestate, the camera object, the screen height and the camera displacement //Post: The scrolling buttons are updated with whether they were clicked or not and the new gamestate is returned //Desc: A method for updating the scrolling buttons and whether they were clicked or not public GameState UpdateScrollingButtons(List <Button> buttons, GameState gameState, Cam2D camera, int screenHeight, int cameraDisplacement) { //Sets the mouses' state mouse = Mouse.GetState(); //If the mouse button is released if (mouse.LeftButton == ButtonState.Released) { //Set it to not being held anymore mouseButtonHeld = false; } //Loop for every button for (int i = 0; i < buttons.Count; i++) { //Creates a rectangle that is used to store the location of the current button Rectangle tempRect; //If the current button is not the first button, the rectangle for it is set if (i != 0) { tempRect = new Rectangle(buttons[i].GetCurrentRectangle().X, (buttons[i].GetCurrentRectangle().Y - (int)((camera.GetPosition().Y + cameraDisplacement) - (int)(screenHeight / 2))), buttons[i].GetCurrentRectangle().Width, buttons[i].GetCurrentRectangle().Height); } //If the current button is the first button, the rectangle for it is set else { tempRect = buttons[i].GetCurrentRectangle(); } //If the current button is visible on the screen if (camera.IntersectsScreen(buttons[i].GetCurrentRectangle()) || buttons[i].GetText() == "Go Back") { //The current button is checked for hovering if (CheckButtonHovering(tempRect)) { //The current button is checked if it was pressed if (CheckButtonPressed(tempRect)) { //Changes the states depending on the state stored in the button class and sets the button to clicked gameState = buttons[i].GetGameState(); buttons[i].isClicked = true; } //If the current button was not pressed but is hovering, the current button is set to hovering else { buttons[i].SetHovering(true); } } //if the current button is hovering, the button is set to hovering else { buttons[i].SetHovering(false); } } } //Returns the game state return(gameState); }