/// <summary>
    /// Find the player and their friend if possible and assign them a position
    /// </summary>
    /// <param name="canv"> the canvas whose corner we want to place them on </param>
    protected void FindAndPlaceHuman(GameObject canv)
    {
        // Get a reference to the player if possible.
        if (GameObject.FindWithTag("Player") != null)
        {
            Components.Player player = GameObject.FindWithTag("Player").GetComponent <Components.Player>();
            // Set position of player hardcoded, see below for how it might
            // work automatically
            Vector3 position = new Vector3(3.53f, -2.53f, 0.0f);
            PlaceAndStopHuman(position, player);
        }
        else
        {
            Debug.Log("No game object with name 'Player' found");
        }

        // Get a reference to the friend if possible.
        if (GameObject.FindWithTag("Friend") != null)
        {
            Components.Friend friend = GameObject.FindWithTag("Friend").GetComponent <Components.Friend>();
            Debug.Log("friend");
            // Set position of friend hardcoded, see below for how it might
            // work automatically
            Vector3 position = new Vector3(-2.79f, -2.53f, 0.0f);
            PlaceAndStopHuman(position, friend);
        }
        else
        {
            Debug.Log("No game object with name 'Friend' found");
        }


        // This is how we could get the corners of the panel
        // however the corners are not completely right if we use those
        //Vector3[] corners = new Vector3[4];
        //GameObject Panel = canv.transform.Find("Panel").gameObject;
        ////If the child was found.
        //if (Panel != null)
        //{
        //    Panel.GetComponent<RectTransform>().GetWorldCorners(corners);
        //    player.transform.position = new Vector3(Mathf.Abs(corners[0].x), -Mathf.Abs(corners[0].y), corners[0].z);
        //    player.transform.localScale *= 2;
        //}
        //else Debug.Log("No child with the name 'Panel' attached to the canvas");
    }
 protected override void Update()
 {
     // Check if we collected all masks and returned them to the hospital.
     // If so, pause the game and show a screen telling us to get home.
     if (!LevelSettings.GetActiveEndLevelController().levelHasFinished&& ShowCanvasAllCollectedGetHome())
     {
         // The player has collected all masks and brought them to the hospital.
         // Get a reference to the player.
         Components.Player player = GameObject.FindWithTag("Player").GetComponent <Components.Player>();
         // Set the number of masks of the player to 0,
         // since he gave his masks to the hospital.
         player.addMasks(-player.getNumMasks());
         // Pause the game
         PauseGame.Pause();
         // Show the pause message that tells him to get home.
         // This canvas has a "space-to-continue"-script attached
         CanvasAllCollectedGetHome.SetActive(true);
         // Set internal bool that the player is now on its way home
         onWayHome = true;
     }
     base.Update();
 }
예제 #3
0
파일: Enemy.cs 프로젝트: AlexRex/2DGame
        public override void Initialize(List<Texture2D> charactersTexture, GraphicsDevice graphicsDevice, ConnectionTest con, Player player, int playerChar)
        {
            character = new Character();

            character.Initialize(charactersTexture, playerChar, graphicsDevice);
            Position = new Vector2(graphicsDevice.Viewport.TitleSafeArea.X + character.Width / 2,
                graphicsDevice.Viewport.TitleSafeArea.Y + character.Height / 2
                + graphicsDevice.Viewport.TitleSafeArea.Height / 2);

            previousPosition = Position;
            Active = true;
            shootDirection = 0;
            Health = character.Health;

            //Init projectile
            projectileTexture = charactersTexture.ElementAt(0);
            projectiles = new List<Projectile>();

            this.player = player;

            oldState = Keyboard.GetState();

            base.Initialize(charactersTexture, graphicsDevice, con, player, playerChar);
        }
예제 #4
0
파일: Game1.cs 프로젝트: AlexRex/2DGame
        /// <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

            bgColor = new Color(0, 167, 254);

            //State of the game.
            GameState = STATE.InitialMenu;

            playerChar = 0;

            //Create the two players
            player = new Player();
            enemy = new Enemy();

            level = new Level();

            //Create the menu
            initMenu = new InitialMenu();
            charMenu = new CharacterSelection();
            waitingMenu = new WaitingPlayersMenu();

            //List for barriers; Helpers for spawning new barriers each .5 seconds
            barriers = new List<Barrier>();
            previousBarrierSpawnTime = TimeSpan.Zero;
            barrierSpawnTime = TimeSpan.FromSeconds(.5f);
            //Barreir position
            bPo = new Vector2(8, 8);
            //Random number for the position of the new barriers (not using now)
            random = new Random();

            //New camera object
            _camera = new Camera(GraphicsDevice.Viewport);

            //Create a connection with the server (actual: localhost)
            con = new ConnectionTest();

            base.Initialize();
        }
예제 #5
0
        public void TryAddingPlayerToChampions(string name, int points)
        {
            Player newPlayer = new Player(name, this.Points);

            if (this.champions.Count < MinesweeperGame.ChampionsListSize)
            {
                this.champions.Add(newPlayer);
            }
            else
            {
                for (int i = 0; i < this.champions.Count; i++)
                {
                    if (this.champions[i].Points < newPlayer.Points)
                    {
                        this.champions.Insert(i, newPlayer);
                        this.champions.RemoveAt(this.champions.Count - 1);
                        break;
                    }
                }
            }
        }
예제 #6
0
파일: SuperPj.cs 프로젝트: AlexRex/2DGame
 // Initialize for Enemy
 public virtual void Initialize(List<Texture2D> charactersTexture, GraphicsDevice graphicsDevice, ConnectionTest con, Player player, int playerChar)
 {
     this.graphicsDevice = graphicsDevice;
     this.con = con;
 }