public Hitbox_Gameplay(Hitbox_Gameplay _other) { HitboxType = _other.HitboxType; Position = _other.Position; Width = _other.Width; RemainingTime = _other.RemainingTime; HasStruck = _other.HasStruck; ID = ID_Counter++; AttackAttribute = _other.AttackAttribute; HurtboxAttribute = _other.HurtboxAttribute; }
private Vector3 GetInGamePosition(Hitbox_Gameplay _hbox_gameplay, bool _p1, GameState _gameState) { int position; if (_p1) { position = _gameState.P1_Position + _hbox_gameplay.Position; } else { position = _gameState.P2_Position + _hbox_gameplay.Position; } return(GameCoordsToUnityCoords(position)); }
public void ModifyHitbox(List <Hitbox_Gameplay> _hitboxes, int _length, GameplayEnums.HitboxType _hitboxType = GameplayEnums.HitboxType.Hurtbox_Limb) { Hitbox_Gameplay hbox = _hitboxes.Find(o => o.HitboxType == _hitboxType); hbox.Width = _length; if (FacingRight) { hbox.Position = GameplayConstants.CHARACTER_HURTBOX_WIDTH / 2 + _length / 2; } else { hbox.Position = GameplayConstants.CHARACTER_HURTBOX_WIDTH / -2 - _length / 2; } }
public Hitbox_Gameplay CreateHitbox(GameplayEnums.HitboxType _boxType, int _width) { Hitbox_Gameplay box = new Hitbox_Gameplay(); box.HitboxType = _boxType; box.Width = _width; if (FacingRight) { box.Position = GameplayConstants.CHARACTER_HURTBOX_WIDTH / 2 + _width / 2; } else { box.Position = GameplayConstants.CHARACTER_HURTBOX_WIDTH / -2 - _width / 2; } return(box); }
private bool DoHitboxesOverlap(Hitbox_Gameplay _p1Box, Hitbox_Gameplay _p2Box, GameState _currentState) { int p1_left = _currentState.P1_Position + _p1Box.Position - _p1Box.Width / 2; int p1_right = _currentState.P1_Position + _p1Box.Position + _p1Box.Width / 2; int p2_left = _currentState.P2_Position + _p2Box.Position - _p2Box.Width / 2; int p2_right = _currentState.P2_Position + _p2Box.Position + _p2Box.Width / 2; if (p1_right < p2_left) { return(false); } if (p2_right < p1_left) { return(false); } return(true); }
public override MatchOutcome UpdateSpecial(CharacterState _character, ref int _positionOffset) { switch (State) { case SweepState.Active: if (_character.StateFrames > ACTIVE) { m_state = SweepState.Recovery; _character.StateFrames = 0; _character.Hitboxes.RemoveAll(o => o.HitboxType == GameplayEnums.HitboxType.Hitbox_Attack); _character.ModifyHitbox(_character.Hitboxes, HURTBOX_WHIFF_EARLY); _character.DisableThrowBreak = false; } break; case SweepState.Recovery: if (_character.StateFrames > RECOVERY) { m_state = SweepState.Inactive; _character.State = GameplayEnums.CharacterState.Idle; _character.StateFrames = 0; _character.Hitboxes.RemoveAll(o => o.HitboxType == GameplayEnums.HitboxType.Hurtbox_Limb); } if (_character.StateFrames == ATTACK_RECOVERY_SHORTEN) { _character.ModifyHitbox(_character.Hitboxes, HURTBOX_WHIFF_LATE); } break; case SweepState.Startup: if (_character.StateFrames > STARTUP) { m_state = SweepState.Active; _character.StateFrames = 0; Hitbox_Gameplay hbox = _character.CreateHitbox(GameplayEnums.HitboxType.Hitbox_Attack, HITBOX_ACTIVE); hbox.AttackAttribute = GameplayEnums.AttackAttribute.Low; _character.Hitboxes.Add(hbox); _character.ModifyHitbox(_character.Hitboxes, HURTBOX_ACTIVE); } break; } return(new MatchOutcome()); }
private void ResolvePositions(GameState _currentState) { Hitbox_Gameplay p1 = _currentState.P1_Hitboxes.Find(o => o.HitboxType == GameplayEnums.HitboxType.Hurtbox_Main); Hitbox_Gameplay p2 = _currentState.P2_Hitboxes.Find(o => o.HitboxType == GameplayEnums.HitboxType.Hurtbox_Main); //1. if characters are overlapping, push each other back enough that they don't overlap if (DoHitboxesOverlap(p1, p2, _currentState)) { int overlapAmount = (_currentState.P1_Position + p1.Position + p1.Width / 2) - (_currentState.P2_Position - p2.Position - p2.Width / 2); if (overlapAmount > 0) { int pushback = overlapAmount / 2; _currentState.P1_Position -= pushback; _currentState.P2_Position += pushback; } } //2. if either character extends beyond the edge, push him out of the corner. //2.1 if this causes characters to overlap, push the other character back if (_currentState.P1_Position < GameplayConstants.ARENA_RADIUS * -1) { _currentState.P1_Position -= GameplayConstants.ARENA_RADIUS + _currentState.P1_Position; if (DoHitboxesOverlap(p1, p2, _currentState)) { int overlapAmount = (_currentState.P1_Position + p1.Position + p1.Width / 2) - (_currentState.P2_Position + p2.Position + p2.Width / 2); if (overlapAmount > 0) { _currentState.P2_Position += overlapAmount; } } } if (_currentState.P2_Position > GameplayConstants.ARENA_RADIUS) { _currentState.P2_Position -= _currentState.P2_Position - GameplayConstants.ARENA_RADIUS; if (DoHitboxesOverlap(p1, p2, _currentState)) { int overlapAmount = (_currentState.P1_Position + p1.Position + p1.Width / 2) - (_currentState.P2_Position + p2.Position + p2.Width / 2); if (overlapAmount > 0) { _currentState.P1_Position -= overlapAmount; } } } }
private bool DoesPlayerBlock(bool _p1, GameState _currentState, SinglePlayerInputs _inputs) { if (!(_inputs.JoystickDirection == 1 || _inputs.JoystickDirection == 4 || _inputs.JoystickDirection == 7)) { return(false); } GameplayEnums.CharacterState charState; Hitbox_Gameplay hitbox = _currentState.P1_CState.Hitboxes.Find(o => o.HitboxType == GameplayEnums.HitboxType.Hitbox_Attack); if (_p1) { charState = _currentState.P1_State; hitbox = _currentState.P2_CState.Hitboxes.Find(o => o.HitboxType == GameplayEnums.HitboxType.Hitbox_Attack); } else { charState = _currentState.P2_State; hitbox = _currentState.P1_CState.Hitboxes.Find(o => o.HitboxType == GameplayEnums.HitboxType.Hitbox_Attack); } if (charState == GameplayEnums.CharacterState.Crouch || charState == GameplayEnums.CharacterState.Idle || charState == GameplayEnums.CharacterState.WalkBack) { switch (hitbox.AttackAttribute) { case GameplayEnums.AttackAttribute.High: if ((_inputs.JoystickDirection == 1 || _inputs.JoystickDirection == 2 || _inputs.JoystickDirection == 3)) { return(false); } break; case GameplayEnums.AttackAttribute.Low: if (!(_inputs.JoystickDirection == 1 || _inputs.JoystickDirection == 2 || _inputs.JoystickDirection == 3)) { return(false); } break; } return(true); } return(false); }
public void RenderHitbox(Hitbox_Gameplay _hbox_gameplay, bool _p1, GameState _gameState) { //1. if an existing render hitbox exists for it, simply modify it bool found = false; foreach (Hitbox_Render renderBox in m_activeHitboxes) { if (renderBox.ReferenceBox.ID == _hbox_gameplay.ID) { ModifyHitbox(renderBox, _hbox_gameplay, _p1, _gameState); found = true; } } //2. if one does not, create a new one if (!found) { CreateNewHitbox(_hbox_gameplay, _p1, _gameState); } }
private void ModifyHitbox(Hitbox_Render _renderBox, Hitbox_Gameplay _hbox_gameplay, bool _p1, GameState _gameState) { float y = CharacterHeight; float z = 1; if (_hbox_gameplay.HitboxType == GameplayEnums.HitboxType.Hitbox_Attack) { y /= 2f; z = 2; } Vector3 pos = GetInGamePosition(_hbox_gameplay, _p1, _gameState); Vector3 scale = new Vector3(GameUnitsToUnityUnits(_hbox_gameplay.Width), y, z); _renderBox.ObjectInGame.transform.position = pos; _renderBox.ObjectInGame.transform.localScale = scale; if (_hbox_gameplay.AttackAttribute == GameplayEnums.AttackAttribute.Low) { _renderBox.ObjectInGame.transform.position = pos - new Vector3(0, y / 2f, 2f); //_renderBox.ObjectInGame.transform.localScale = new Vector3(scale.x, scale.y / 2f); } _renderBox.StillExists = true; }
private void CreateNewHitbox(Hitbox_Gameplay _hbox_gameplay, bool _p1, GameState _gameState) { Hitbox_Render _renderBox = new Hitbox_Render(); _renderBox.ReferenceBox = _hbox_gameplay; _renderBox.ObjectInGame = GameObject.CreatePrimitive(PrimitiveType.Cube); ModifyHitbox(_renderBox, _hbox_gameplay, _p1, _gameState); switch (_hbox_gameplay.HitboxType) { case GameplayEnums.HitboxType.Hitbox_Attack: case GameplayEnums.HitboxType.Hitbox_Throw: if (_p1) { _renderBox.ObjectInGame.GetComponent <Renderer>().material = P1_Active; } else { _renderBox.ObjectInGame.GetComponent <Renderer>().material = P2_Active; } break; case GameplayEnums.HitboxType.Hurtbox_Limb: case GameplayEnums.HitboxType.Hurtbox_Main: GameplayEnums.CharacterState currentCharacterState; if (_p1) { currentCharacterState = _gameState.P1_State; } else { currentCharacterState = _gameState.P2_State; } Material toSet; GameplayEnums.CharacterState cstate = currentCharacterState; if (cstate == GameplayEnums.CharacterState.Special) { if (_p1) { cstate = _gameState.P1_CState.SelectedCharacter.GetEquivalentState(); } else { cstate = _gameState.P2_CState.SelectedCharacter.GetEquivalentState(); } } switch (cstate) { case GameplayEnums.CharacterState.AttackActive: case GameplayEnums.CharacterState.AttackStartup: case GameplayEnums.CharacterState.ThrowActive: case GameplayEnums.CharacterState.ThrowStartup: if (_p1) { toSet = P1_Startup; } else { toSet = P2_Startup; } break; case GameplayEnums.CharacterState.AttackRecovery: case GameplayEnums.CharacterState.Blockstun: case GameplayEnums.CharacterState.Clash: case GameplayEnums.CharacterState.ThrowBreak: case GameplayEnums.CharacterState.ThrowRecovery: if (_p1) { toSet = P1_Recovery; } else { toSet = P2_Recovery; } break; default: if (_p1) { toSet = P1_Character; } else { toSet = P2_Character; } break; } _renderBox.ObjectInGame.GetComponent <Renderer>().material = toSet; break; } m_activeHitboxes.Add(_renderBox); }
public void SetCharacterHurtboxCrouching(List <Hitbox_Gameplay> _hitboxes) { Hitbox_Gameplay hbox = _hitboxes.Find(o => o.HitboxType == GameplayEnums.HitboxType.Hurtbox_Main); hbox.Width = GameplayConstants.CROUCHING_HURTBOX_WIDTH; }
private Hitbox_Gameplay CreateCharacterStartingHitbox() { Hitbox_Gameplay hbox = new Hitbox_Gameplay(GameplayEnums.HitboxType.Hurtbox_Main, 0, GameplayConstants.CHARACTER_HURTBOX_WIDTH); return(hbox); }