public bool MoveNpcLeft(NonPlayableCharacter npc)
        {
            var npcPosition = _positionFinder.GetPosition(_gameModel.GetMap, npc);

            if (_gameModel.GetMap[npcPosition[0], npcPosition[1] - 1].BlowingElement is Flame)
            {
                npc.IsAlive = false;
                return(true);
            }

            switch (_gameModel.GetMap[npcPosition[0], npcPosition[1] - 1].MapElement)
            {
            case EmptyField _:
                _gameModel.GetMap[npcPosition[0], npcPosition[1] - 1] = new MapElementContainer(npcPosition[0], npcPosition[1] - 1, npc);
                _gameModel.GetMap[npcPosition[0], npcPosition[1]]     = new MapElementContainer(npcPosition[0], npcPosition[1], new EmptyField());
                return(true);

            case PlayerDto player:
                player.GotHit();
                npc.IsAlive = false;
                break;
            }

            _npcTurner.TurnNpc(npc);
            return(false);
        }
Exemplo n.º 2
0
    void Update()
    {
        float sideMovement     = Input.GetAxis("Horizontal");
        float verticalMovement = Input.GetAxis("Vertical");

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidBody2D.position + Vector2.up * 0.2f, lookDIrection, 1.5f, LayerMask.GetMask("NPC"));
            Debug.Log("W");
            if (hit.collider != null)
            {
                NonPlayableCharacter npc = hit.collider.GetComponent <NonPlayableCharacter>();
                Debug.Log("Waz");
                if (npc != null)
                {
                    npc.displayDialog();
                    Debug.Log("Wazzup");
                }
            }
        }


        Vector2 move     = new Vector2(sideMovement, verticalMovement);
        Vector2 position = rigidBody2D.position;

        // Checking if idle approximately
        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDIrection.Set(move.x, move.y);
            lookDIrection.Normalize();     // Normalize makes length = 1 , thus effectively storing direction
        }

        animator.SetFloat("Look X", lookDIrection.x);
        animator.SetFloat("Look Y", lookDIrection.y);
        animator.SetFloat("Speed", move.magnitude);           // Boom, vector magnitude. Speed here is the length of the move vector

        position = position + 2f * move * Time.deltaTime;
        // Here we are using rigidbody rather than transform to make the Physics system track the rigidBosy rather than the transform
        // to make charater collisions look smooth
        rigidBody2D.MovePosition(position);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        // Launch projectile
        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Move X", lookDirection.x);
        animator.SetFloat("Move Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        Vector2 position = rigidbody2d.position;

        position = position + move * speed * Time.deltaTime;

        rigidbody2d.MovePosition(position);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        else
        {
            InvincibilityEffect.Stop();
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
            this.PlaySound(throwCog);
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
    }
Exemplo n.º 4
0
        public void Setup()
        {
            _mockedGameModel = new Mock <IGameModel>();
            _testNpc         = new NonPlayableCharacter(MoveDirection.Down);

            _testMap = TestMapGenerator.GenerateMap(_testNpc);

            _mockedGameModel.Setup(x => x.GetMap).Returns(_testMap);

            _npcToDownMover = new NpcToDownMover(_mockedGameModel.Object, new PositionFinder(), new NpcTurner());
        }
        public void GivenNpcWithDirectionRight_WhenTurnNpc_ThenChangesMoveDirectionToLeft()
        {
            // Arrange
            var testNpc = new NonPlayableCharacter(MoveDirection.Right);

            // Act
            _npcTurner.TurnNpc(testNpc);

            // Assert
            Check.That(testNpc.MoveDirection).IsEqualTo(MoveDirection.Left);
        }
        public IActionResult View(int id)
        {
            if (!_sessionHandler.UserIsSignedIn())
            {
                return(Redirect("Home/Index"));
            }

            int characterId = id;

            ViewBag.Username  = _sessionHandler.GetSignedInUsername();
            ViewBag.Character = NonPlayableCharacter.GetStatsForNpcCharacter(_context, characterId);

            return(View());
        }
 public static void InitializeNPC()
 {
     foreach (GameObject enemy in Resources.LoadAll("NPC/Enemies"))
     {
         Units.Add(enemy);
     }
     foreach (TextAsset text in Resources.LoadAll <TextAsset>("NPC/UnitModels"))
     {
         UnitModel            model     = UnitModelLoader.LoadUnit(text.text);
         NonPlayableCharacter character = new NonPlayableCharacter(model.Name, model.Characteristics, Data.GetWeapon(model.WeaponName), Data.GetUnit(model.UnitName));
         //Debug.Log(character.Unit.Weapon.Name);
         NPC.Add(character);
     }
 }
    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (Input.GetKeyDown(KeyCode.C))
        {
            LaunchProjectile();
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            // position of the center of the player sprite
            Vector2      waistPosition = playerRb.position + Vector2.up * 0.2f;
            RaycastHit2D hit           = Physics2D.Raycast(waistPosition, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)   // hits NPC
            {
                NonPlayableCharacter npc = hit.collider.GetComponent <NonPlayableCharacter>();
                if (npc != null)
                {
                    npc.DisplayDialog();
                }
            }
        }
    }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        this.Animate(move);

        Vector2 position = rigidbody2d.position;

        position = position + move * Speed * Time.deltaTime;

        rigidbody2d.MovePosition(position);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
    }
Exemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        if (DialogBox.instance.isActive() || ChoiceBox.instance.isActiveAndEnabled)
        {
            horizontal = vertical = 0;
        }

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        Vector2 position = rigidbody2d.position;

        position += move * speed * Time.deltaTime;

        rigidbody2d.MovePosition(position);

        if (Input.GetButtonDown("Fire1") && !DialogBox.instance.isActive())
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 3.0f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                Debug.Log(hit.collider);
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    character.OnRaycast();
                }
            }
        }
    }
Exemplo n.º 11
0
        public void TurnNpc(NonPlayableCharacter npc)
        {
            switch (npc.MoveDirection)
            {
            case MoveDirection.Up:
                npc.MoveDirection = MoveDirection.Down;
                break;

            case MoveDirection.Down:
                npc.MoveDirection = MoveDirection.Up;
                break;

            case MoveDirection.Right:
                npc.MoveDirection = MoveDirection.Left;
                break;

            case MoveDirection.Left:
                npc.MoveDirection = MoveDirection.Right;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 12
0
    // Update is called once per frame
    void Update()
    {
        EnemyCount count = fixTracker.gameObject.GetComponent <EnemyCount>();

        if (count.fixCount == count.fixRequired && canPlay == true)
        {
            PlaySound(victory);
            canPlay = false;
        }
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        if (Input.GetKeyDown(KeyCode.X) || Input.GetButtonDown("Fire1"))
        {
            //RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.zero * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.down * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                Debug.Log("Raycast has hit the object " + hit.collider.gameObject);
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }

                else
                {
                    //ResourceCube();
                    ResourceCube cube = hit.collider.GetComponent <ResourceCube>();
                    cube.GetResources();
                    Destroy(hit.collider.gameObject);
                }
            }
        }

        //if(Input.GetKeyDown(KeyCode.C) && ammo > 0)
        //{
        //   Launch();

        //  PlaySound(throwSound);
        //}
        if (Input.GetButtonDown("Fire3") && ammo > 0)
        {
            Launch();

            PlaySound(throwSound);
        }

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        if (currentHealth <= 0)
        {
            SceneManager.LoadScene(currentScene.name);
        }
    }
Exemplo n.º 13
0
        public void MoveNpc(NonPlayableCharacter npc)
        {
            while (npc.IsAlive)
            {
                Thread.Sleep(npc.Speed);
                switch (npc.MoveDirection)
                {
                case MoveDirection.Up:
                    if (!_npcToUpMover.MoveNpcUp(npc))
                    {
                        if (_npcToLeftMover.MoveNpcLeft(npc))
                        {
                            npc.MoveDirection = MoveDirection.Left;
                        }
                        else
                        {
                            npc.MoveDirection = _npcToRightMover.MoveNpcRight(npc) ? MoveDirection.Right : MoveDirection.Down;
                        }
                    }
                    break;

                case MoveDirection.Down:
                    if (!_npcToDownMover.MoveNpcDown(npc))
                    {
                        if (_npcToRightMover.MoveNpcRight(npc))
                        {
                            npc.MoveDirection = MoveDirection.Right;
                        }
                        else
                        {
                            npc.MoveDirection = _npcToUpMover.MoveNpcUp(npc) ? MoveDirection.Up : MoveDirection.Left;
                        }
                    }
                    break;

                case MoveDirection.Right:
                    if (!_npcToRightMover.MoveNpcRight(npc))
                    {
                        if (_npcToDownMover.MoveNpcDown(npc))
                        {
                            npc.MoveDirection = MoveDirection.Down;
                        }
                        else
                        {
                            npc.MoveDirection = _npcToUpMover.MoveNpcUp(npc) ? MoveDirection.Up : MoveDirection.Left;
                        }
                    }
                    break;

                case MoveDirection.Left:
                    if (!_npcToLeftMover.MoveNpcLeft(npc))
                    {
                        if (_npcToUpMover.MoveNpcUp(npc))
                        {
                            npc.MoveDirection = MoveDirection.Up;
                        }
                        else
                        {
                            npc.MoveDirection = _npcToDownMover.MoveNpcDown(npc) ? MoveDirection.Down : MoveDirection.Right;
                        }
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                NotifyUiDrawerMoveHappened();
            }
            _npcDeleter.DeleteKilledNpc(npc);
            NotifyUiDrawerMoveHappened();
        }
Exemplo n.º 14
0
        public void DeleteKilledNpc(NonPlayableCharacter npc)
        {
            var npcPosition = _positionFinder.GetPosition(_gameModel.GetMap, npc);

            _gameModel.GetMap[npcPosition[0], npcPosition[1]] = new MapElementContainer(npcPosition[0], npcPosition[1], new EmptyField());
        }
Exemplo n.º 15
0
    private void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(this.gameObject);
        }
        else
        {
            _instance = this;

            canvasTransform = GameObject.FindGameObjectWithTag("Canvas").transform;
            boardTransform  = GameObject.FindGameObjectWithTag("Board").transform;
            mainPlayer      = new PlayableCharacter(80, "Carlos", new Energy(3), CharacterModelLibrary.KnightCharacterModel());


            // mainPlayer.AddCardToDeckById(5);
            mainPlayer.OnCharacterDead += CheckCombatEndCondition;
            mainPlayer.AddCardToDeck(CardLibrary.Charge());
            mainPlayer.AddCardToDeck(CardLibrary.ShrugItOff());
            // mainPlayer.AddCardToDeck(CardLibrary.DeadlyPoison());
            mainPlayer.AddCardToDeck(CardLibrary.GetBehind());
            mainPlayer.AddCardToDeck(CardLibrary.TwinStrike());
            mainPlayer.AddCardToDeck(CardLibrary.TwinStrike());
            mainPlayer.AddCardToDeck(CardLibrary.TwinStrike());
            mainPlayer.AddCardToDeck(CardLibrary.TwinStrike());
            mainPlayer.AddCardToDeck(CardLibrary.TwinStrike());
            mainPlayer.AddCardToDeck(CardLibrary.TwinStrike());
            mainPlayer.AddCardToDeck(CardLibrary.TwinStrike());
            mainPlayer.AddCardToDeck(CardLibrary.Strike());
            // mainPlayer.AddCardToDeck(CardLibrary.Strike());
            // mainPlayer.AddCardToDeck(CardLibrary.Strike());
            // mainPlayer.AddCardToDeck(CardLibrary.Thunder());
            // mainPlayer.AddCardToDeck(CardLibrary.Bash());
            mainPlayer.abilities.Add(AbilityLibrary.MoveLeft());
            mainPlayer.abilities.Add(AbilityLibrary.MoveRight());
            mainPlayer.abilities.Add(AbilityLibrary.Strike());

            // Character ally = new NonPlayableCharacter(80,"Roberto",new Energy(2),CharacterModelLibrary.KnightCharacterModel());
            // ally.AddCardToDeck(CardLibrary.GetBehind());
            // Character ally2 = new Character(80,"Mario",new Energy(3));
            List <Character> allyTeam = new List <Character>();
            MoveCharacterToBoardColumn(mainPlayer, 0);
            // MoveCharacterToBoardColumn(ally,1);
            // MoveCharacterToBoardColumn(mainPlayer,0);
            // MoveCharacterToBoardColumn(mainPlayer,0);
            allyTeam.Add(mainPlayer);
            // allyTeam.Add(mainPlayer);
            // allyTeam.Add(mainPlayer);
            // ally.TurnRight();
            // allyTeam.Add(ally);
            // allyTeam.Add(ally2);
            teams.Add(allyTeam);

            List <Character> NpcTeam = new List <Character>();
            teams.Add(NpcTeam);


            Character Npc = new NonPlayableCharacter(80, "bicho", new Energy(3), CharacterModelLibrary.GoblinCharacterModel());
            Npc.AddCardToDeck(CardLibrary.Thrash());
            NpcTeam.Add(Npc);
            MoveCharacterToBoardColumn(Npc, 1);
            Npc.OnCharacterDead += CheckCombatEndCondition;

            Character Npc2 = new NonPlayableCharacter(80, "bicho2", new Energy(3), CharacterModelLibrary.GoblinCharacterModel());
            Npc2.AddCardToDeck(CardLibrary.Bellow());
            NpcTeam.Add(Npc2);
            MoveCharacterToBoardColumn(Npc2, 1);
            Npc2.OnCharacterDead += CheckCombatEndCondition;



            // NpcTeam.Add(Npc2);
            // MoveCharacterToBoardColumn(Npc2,1);
            // MoveCharacterToBoardColumn(Npc2,3);
            // MoveCharacterToBoardColumn(Npc2,4);
            // MoveCharacterToBoardColumn(Npc2,5);
            // MoveCharacterToBoardColumn(Npc,3);
            // MoveCharacterToBoardColumn(Npc,4);
            // MoveCharacterToBoardColumn(Npc,4);
            // MoveCharacterToBoardColumn(Npc,4);
            // MoveCharacterToBoardColumn(Npc,1);
            InstanceCharacters();
        }
    }
        public IActionResult Create(string characterName, int gameId, int speciesId)
        {
            NonPlayableCharacter.GenerateNPC(_context, gameId, speciesId, characterName);

            return(Redirect($"../Game/View/{gameId}"));
        }
Exemplo n.º 17
0
    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        if (gameOver == true)
        {
            if (level == 2)
            {
                if (Input.GetKeyDown(KeyCode.R))
                {
                    SceneManager.LoadScene("MainScene");         // this loads the currently active scene
                }
            }

            if (level == 1)
            {
                if (Input.GetKeyDown(KeyCode.R))
                {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);         // this loads the currently active scene
                }
            }
        }



        if (Input.GetKeyDown(KeyCode.T))
        {
            tutorial = true;
            PlaySound(teleportSound);
            tutorialUI.text = "Tutorial Mode";
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            tutorial = false;
            PlaySound(teleportSound);
            tutorialUI.text = "Ready to go!";
        }



        if (tutorial == false)
        {
            if (Input.GetKeyDown(KeyCode.N))
            {
                SceneManager.LoadScene("MainScene");             // this loads the currently active scene
            }
        }

        if (tutorial == true)
        {
            if (Input.GetKeyDown(KeyCode.M))
            {
                SceneManager.LoadScene("Level 3");             // this loads the currently active scene
            }
        }



        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>();
                if (character != null)
                {
                    if (scoreValue == 5)
                    {
                        levelChange();
                    }
                    character.DisplayDialog();
                    PlaySound(jambiSound);
                }
            }
        }

        ammoUI.text = "Cogs: " + ammo.ToString();
    }