// Updates the movement compoent of the enemy. public void Move() { bool attacked = false; // Start processing. state = MoveStates.PROCESSING; // Calls attack method. Should return true if everything is cool if (_attackMethod != null) { attacked = _attackMethod(); if (attacked) { state = MoveStates.IDLE; // DO NOT MOVE IF TRUE } } // Only call movement if the enemy did not attack. if (_movMethod != null && attacked == false) { // Grab movement from the _movMethod declaredMovement = _movMethod(); // Upon exiting, it should either be IDLE or MOVING. ProcessState(); } if (state == MoveStates.MOVING) { GridSpriteTranslate gst = GetComponentInChildren <GridSpriteTranslate>(); gst.StartTranslation(); transform.position += (Vector3)declaredMovement; gst.SetPosition(); } // LABEL AS FINISHED state = MoveStates.FINISHED; }
// Update is called once per frame void Update() { Dirs dir = Dirs.NULL; // // TEST CODE // if(Input.GetKeyDown(KeyCode.D)) { // Debug.Log("Equipped dagger!"); // SetWeapon<DaggerWeapon>(); // } // if(Input.GetKeyDown(KeyCode.S)) { // Debug.Log("Equipped Longsword!"); // SetWeapon<LongswordWeapon>(); // } // if(Input.GetKeyDown(KeyCode.A)) { // Debug.Log("Equipped GUN!"); // SetWeapon<GunWeapon>(); // } // if(Input.GetKeyDown(KeyCode.D)) { // GetComponent<PlayerHealthController>().DealDamage(1); // } // if(Input.GetKeyDown(KeyCode.E)) { // pcc.AddCoins(20); // } // Rightwards Movement if (Input.GetKeyDown(KeyCode.RightArrow)) { dir = Dirs.RIGHT; } // Leftwards Movement else if (Input.GetKeyDown(KeyCode.LeftArrow)) { dir = Dirs.LEFT; } // Upwards Movement else if (Input.GetKeyDown(KeyCode.UpArrow)) { dir = Dirs.UP; } // Downwards Movement else if (Input.GetKeyDown(KeyCode.DownArrow)) { dir = Dirs.DOWN; } if (dir != Dirs.NULL) { // Reset the world timer so it doesn't prematurely fire off wt.Reset(); bool attacked = weapon.Attack(dir); // Attack in the given direction if (attacked) { eac.PlayAttack(); } // returns false is there was no enemy to attack. else { if (gm.IsStones(dir)) { gst.StartTranslation(); transform.position += (Vector3)GridMovement.DirTable[dir]; // NOTE(clark): Testing hopping here. I really like hopping. // gst.SetPosition(GridSpriteTranslate.MoveType.WALK); gst.SetPosition(GridSpriteTranslate.MoveType.WALK); anim.SetTrigger("Walk"); anim_head.SetTrigger("RESET"); } // This is an ugly block. Really brute force. OH WELL else if (gm.IsWater(dir)) { // Shoot out a ray to check for a collision with the level layer. RaycastHit2D hit = Physics2D.Raycast(transform.position + (Vector3)(GridMovement.DirTable[dir] * 2), // origin Vector3.up, // Lookup table (direction)! 0.1f, // Only 1 unit Grid LayerMask.GetMask("Stones")); // Only on this layer if (hit.collider != null) { gst.StartTranslation(); transform.position += ((Vector3)GridMovement.DirTable[dir] * 2); // Play jump noise int idx = Random.Range(0, jump_sounds.Count); AudioSource.PlayClipAtPoint(jump_sounds[idx], transform.position, jump_vol); // NOTE(clark): Testing hopping here. I really like hopping. // gst.SetPosition(GridSpriteTranslate.MoveType.WALK); gst.SetPosition(GridSpriteTranslate.MoveType.JUMP); anim.SetTrigger("Jump"); anim_head.SetTrigger("RESET"); } else { // Shoot out a ray to check for a collision with the level layer. hit = Physics2D.Raycast(transform.position + (Vector3)(GridMovement.DirTable[dir] * 2), // origin Vector3.up, // Lookup table (direction)! 0.1f, // Only 1 unit Grid LayerMask.GetMask("Water")); // Only on this layer // NO water if (hit.collider == null) { gst.StartTranslation(); transform.position += ((Vector3)GridMovement.DirTable[dir] * 2); // NOTE(clark): Testing hopping here. I really like hopping. // gst.SetPosition(GridSpriteTranslate.MoveType.WALK); gst.SetPosition(GridSpriteTranslate.MoveType.JUMP); anim.SetTrigger("Jump"); anim_head.SetTrigger("RESET"); } } } else if (gm.CanMovePlayer(dir)) { gst.StartTranslation(); transform.position += (Vector3)GridMovement.DirTable[dir]; // NOTE(clark): Testing hopping here. I really like hopping. // gst.SetPosition(GridSpriteTranslate.MoveType.WALK); gst.SetPosition(GridSpriteTranslate.MoveType.WALK); anim.SetTrigger("Walk"); anim_head.SetTrigger("RESET"); } } // NOTE(clark): Did stuff // Fire off a world update smu.UpdateWorld(); } }