Ejemplo n.º 1
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            KeyboardState key = Keyboard.GetState();
            if (key.IsKeyDown(Keys.Space))
            {
                if (defeat)
                {
                    currentShip = null;
                    Content.Unload();
                    this.LoadContent();
                    defeat = false;
                }
            }
            else if (key.IsKeyDown(Keys.P))
            {
                if (inputDelay > 20)
                {
                    if (paused) { paused = false; }
                    else { paused = true; }
                    inputDelay = 0;
                }
            }

            if (currentShip.defeat)
            {
                //MediaPlayer.Pause();

               // death.Play();

                defeatDelay++;
                if (defeatDelay > 100)
                {
                    this.defeat = true;
                    defeatDelay = 0;
                }
            }

            if (!paused)
            {
                currentShip.Update(gameTime);

                // TODO: Add your update logic here
                base.Update(gameTime);
            }

            inputDelay++;
        }
Ejemplo n.º 2
0
        void Update()
        {
            if (tileSelectionGroup.currentlySelected != selectedTileIndex)
            {
                SelectTile(tileSelectionGroup.currentlySelected);
            }
            if (selectedTileIndex == -1 || EventSystem.current.IsPointerOverGameObject())
            {
                ghost.gameObject.SetActive(false);
            }
            else
            {
                // Need to rewrite to use input.getbuttondown
                if (!hasRotated && Mathf.Abs(Input.GetAxis("Rotate")) > 0)
                {
                    hasRotated = true;
                    rotation   = (rotation + 90 * Mathf.Sign(Input.GetAxis("Rotate"))) % 360;
                }
                else if (Input.GetAxis("Rotate") == 0)
                {
                    hasRotated = false;
                }

                ghost.gameObject.SetActive(true);
                Vector2    cursorPos     = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                bool       tileEmpty     = true;
                bool       tileSupported = false;
                Ship       attachedShip  = null;
                Tile       underCursor   = null;
                Vector2Int tilePos       = Vector2Int.zero;

                // Determine if tile is support and empty
                foreach (Ship ship in GameManager.Instance.ships)
                {
                    tilePos = ship.WorldToTilePos(cursorPos);
                    if (ship.TryGetTile(tilePos, out Tile tile))
                    {
                        attachedShip = ship;
                        underCursor  = tile;
                        tileEmpty    = false;
                        break;
                    }
                    else
                    {
                        if (ship.TileExists(tilePos - Vector2Int.left) ||
                            ship.TileExists(tilePos - Vector2Int.up) ||
                            ship.TileExists(tilePos - Vector2Int.right) ||
                            ship.TileExists(tilePos - Vector2Int.down))
                        {
                            attachedShip  = ship;
                            tileSupported = true;
                            break;
                        }
                    }
                }

                // Set position of ghost and check for partial overlap
                if (!tileSupported && underCursor == null)
                {
                    ghost.transform.position = cursorPos;
                    ghost.transform.up       = Vector2.up;
                    if (selectedTile.canRotate)
                    {
                        ghost.transform.eulerAngles += new Vector3(0, 0, rotation);
                    }
                }
                else if (underCursor != null)
                {
                    ghost.transform.position = underCursor.transform.position;
                    ghost.transform.up       = underCursor.transform.up;
                }
                else
                {
                    ghost.transform.position = attachedShip.transform.TransformPoint((Vector2)tilePos);
                    ghost.transform.up       = attachedShip.transform.up;
                    if (selectedTile.canRotate)
                    {
                        ghost.transform.eulerAngles += new Vector3(0, 0, rotation);
                    }
                    Collider2D[] overlapping = Physics2D.OverlapBoxAll(ghost.transform.position, Vector2.one * 0.95f, ghost.transform.eulerAngles.z);
                    foreach (Collider2D col in overlapping)
                    {
                        if (col.TryGetComponent <Tile>(out _) || (selectedTileIsSolid && !col.isTrigger))
                        {
                            tileEmpty = false;
                            break;
                        }
                    }
                }

                // Set color and sprite of ghost
                if (underCursor != null)
                {
                    ghost.sprite         = deleteSprite;
                    ghost.material.color = deleteColor;
                }
                else
                {
                    ghost.sprite         = selectedTileSprite;
                    ghost.material.color = (tileSupported && tileEmpty && attachedShip == selectedShip) ? ghostValidColor : ghostInvalidColor;
                }

                // Check for create/delete
                if (tileEmpty && tileSupported && attachedShip == selectedShip && Input.GetButtonDown("Fire1"))
                {
                    attachedShip.SetTileNetwork(tilePos, selectedTile.canRotate ? rotation : 0, selectedTileIndex);
                }
                else if (underCursor != null && attachedShip == selectedShip && Input.GetButtonDown("Fire2"))
                {
                    attachedShip.DestroyTileNetwork(tilePos, true);
                }
            }
        }
Ejemplo n.º 3
0
        /// <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);

            mainFont = Content.Load<SpriteFont>("mainfont");

            List<Room> rooms = new List<Room>();

            rooms.Add(Content.Load<Room>("Levels/Start"));
            rooms.Add(Content.Load<Room>("Levels/LD1"));
            rooms.Add(Content.Load<Room>("Levels/LR1"));
            rooms.Add(Content.Load<Room>("Levels/LU1"));
            rooms.Add(Content.Load<Room>("Levels/LUR1"));
            rooms.Add(Content.Load<Room>("Levels/RD1"));
            rooms.Add(Content.Load<Room>("Levels/UR1"));
            rooms.Add(Content.Load<Room>("Levels/UD1"));

            /* Added by ship gen
            rooms.Add(Content.Load<Room>("Levels/R1"));
            rooms.Add(Content.Load<Room>("Levels/L1"));
            rooms.Add(Content.Load<Room>("Levels/D1"));
            rooms.Add(Content.Load<Room>("Levels/U1"));
             * */

            deathSplash = Content.Load<Texture2D>(FileNames.deathSplash);
            pauseSplash = Content.Load<Texture2D>(FileNames.pauseSplash);

            Song track1 = Content.Load<Song>(FileNames.phase1);
            Song track2 = Content.Load<Song>(FileNames.phase2);
            Song track3 = Content.Load<Song>(FileNames.phase3);

            //death = Content.Load<SoundEffect>("Sounds/death");

            Song[] songs = new Song[] { track1, track2, track3 };

            MediaPlayer.Play(songs[1]);

            //Need to create the first ship here
            currentShip = new Ship(rooms);

            //OLD for debug below

            currentShip.Init(Content);
            // TODO: use this.Content to load your game content here
        }
Ejemplo n.º 4
0
 protected override string NegativeEvent(Ship ship)
 {
     ship.Hull -= hullLost;
     return(GetNegativeEventMessage());
 }