// 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(); } }