#pragma once #include "CoreMinimal.h" #include "GameFramework/Pawn.h" #include "InputActionValue.h" #include "Blueprint/UserWidget.h" #include "SpaceshipPawn.generated.h" // Movement mode enum to allow switching between different control schemes UENUM(BlueprintType) enum class EShipMovementMode : uint8 { Arcade, // Direct control, minimal inertia Assisted, // Some inertia with auto-stabilization Realistic // Full physics with momentum (original) }; UCLASS() class MYPROJECT3_API ASpaceshipPawn : public APawn { GENERATED_BODY() public: ASpaceshipPawn(); virtual void Tick(float DeltaTime) override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; // Override TakeDamage to handle player damage virtual float TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, AActor* DamageCauser) override; // Get current health percentage UFUNCTION(BlueprintCallable, Category = "Combat") float GetHealthPercentage() const { return CurrentHealth / MaxHealth; } // Get current shield percentage UFUNCTION(BlueprintCallable, Category = "Combat") float GetShieldPercentage() const { return CurrentShield / MaxShield; } UFUNCTION(BlueprintCallable, Category = "Stats") float GetCurrentHealth() const { return CurrentHealth; } UFUNCTION(BlueprintCallable, Category = "Stats") float GetMaxHealth() const { return MaxHealth; } UFUNCTION(BlueprintCallable, Category = "Stats") float GetCurrentShield() const { return CurrentShield; } UFUNCTION(BlueprintCallable, Category = "Stats") float GetMaxShield() const { return MaxShield; } protected: virtual void BeginPlay() override; // Components UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components") class UStaticMeshComponent* ShipMesh; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components") class USpringArmComponent* CameraSpringArm; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components") class UCameraComponent* Camera; // Enhanced Input Components UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputMappingContext* DefaultMappingContext; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputAction* ThrottleAction; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputAction* MouseLookAction; // Add a strafe input to allow lateral movement UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputAction* StrafeAction; // Input action for shooting UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputAction* ShootAction; // Movement Parameters UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") EShipMovementMode MovementMode = EShipMovementMode::Arcade; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") float MaxSpeed = 3000.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") float Acceleration = 2000.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") float Deceleration = 1500.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") float RotationSpeed = 5.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") float MouseSensitivity = 2.0f; // Auto-stabilization for assisted mode UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (ClampMin = "0.0", ClampMax = "10.0")) float StabilizationSpeed = 3.0f; // How much momentum to preserve when changing direction (0 = none, 1 = full) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (ClampMin = "0.0", ClampMax = "1.0")) float DirectionalInertia = 0.1f; // How quickly the ship aligns with its movement direction UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement", meta = (ClampMin = "0.0", ClampMax = "10.0")) float VelocityAlignmentSpeed = 4.0f; // Auto-braking when not thrusting in Arcade mode UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") bool bAutoBrakeEnabled = true; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") float AutoBrakeStrength = 3.0f; // Shooting properties UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat") TSubclassOf ProjectileClass; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat") float FireRate = 0.2f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat") USceneComponent* ProjectileSpawnPoint; UPROPERTY(EditDefaultsOnly, Category = "UI") TSubclassOf CrosshairWidgetClass; UPROPERTY() UUserWidget* CrosshairWidget; // Input functions void HandleThrottleInput(const FInputActionValue& Value); void HandleStrafeInput(const FInputActionValue& Value); void HandleMouseLook(const FInputActionValue& Value); // Health properties UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat|Stats") float MaxHealth = 100.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat|Stats") float CurrentHealth = 100.0f; // Shield properties UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat|Stats") float MaxShield = 100.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat|Stats") float CurrentShield = 100.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat") float ShieldRechargeRate = 5.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat") float ShieldRechargeDelay = 3.0f; // Impact effects UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effects") UParticleSystem* ImpactEffect; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effects") class USoundBase* ImpactSound; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effects") class UCameraShakeBase* DamageShake; // Damage flash effect for the ship UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effects") float DamageFlashDuration = 0.2f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Effects") FLinearColor DamageFlashColor = FLinearColor(1.0f, 0.0f, 0.0f, 0.5f); private: // Movement state float CurrentThrottleInput; float CurrentStrafeInput; bool bThrottlePressed; FVector CurrentVelocity; FRotator TargetRotation; float CurrentPitch; float CurrentYaw; APlayerController* PlayerControllerRef; FVector2D MouseDeltaSmoothed; FVector2D LastMouseDelta; float MouseSmoothingSpeed = 10.0f; FTimerHandle FireTimerHandle; bool bCanFire = true; void HandleShoot(const FInputActionValue& Value); void Fire(); void ResetFire(); // Movement helper functions void UpdateArcadeMovement(float DeltaTime); void UpdateAssistedMovement(float DeltaTime); void UpdateRealisticMovement(float DeltaTime); void UpdateShipRotation(float DeltaTime); // Damage handling void ApplyDamageFlash(); void ResetDamageFlash(); FTimerHandle ShieldRechargeTimerHandle; FTimerHandle DamageFlashTimerHandle; float LastDamageTime; void StartShieldRecharge(); void RechargeShield(); bool IsDead() const { return CurrentHealth <= 0.0f; } void Die(); };