Advertisement
Guest User

Untitled

a guest
Jun 30th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .cpp
  2.  
  3. // Fill out your copyright notice in the Description page of Project Settings.
  4.  
  5. #include "Player_Character.h"
  6. #include "Components/SkeletalMeshComponent.h"
  7. #include "Components/CapsuleComponent.h"
  8. #include "Camera/CameraComponent.h"
  9. #include "GameFramework/SpringArmComponent.h"
  10.  
  11.  
  12.  
  13. APlayer_Character::APlayer_Character()
  14. {
  15.     SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArma"));
  16.     if (SpringArm)
  17.     {
  18.         SpringArm->SetupAttachment(GetCapsuleComponent());
  19.         SpringArm->RelativeLocation = FVector(-20.0f, 0.0f, 40.0f);
  20.         SpringArm->TargetArmLength = 0.0f;
  21.         SpringArm->bDoCollisionTest = false;
  22.         SpringArm->bUsePawnControlRotation = true;
  23.         SpringArm->bInheritPitch = false;
  24.         SpringArm->bInheritRoll = true;
  25.         SpringArm->bInheritYaw = true;
  26.     }
  27.  
  28.     Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
  29.     if (Camera)
  30.     {
  31.         Camera->FieldOfView = 90.0f;
  32.         Camera->SetupAttachment(SpringArm, USkeletalMeshComponent::SocketName);
  33.     }
  34.  
  35.     FP_Mesh = CreateDefaultSubobject <USkeletalMesh>(TEXT("FP_Mesh"));
  36.     if (FP_Mesh)
  37.     {
  38.         FP_Mesh->SetupAttachment(Camera);
  39.     }
  40.  
  41.     GunMesh = CreateDefaultSubobject <USkeletalMesh>(TEXT("GunMesh"));
  42.     if (GunMesh)
  43.     {
  44.         GunMesh->SetupAttachment(Camera);
  45.     }
  46.  
  47.     MaxHealth = 100.0f;
  48.     CurrentHealth = MaxHealth;
  49.  
  50.     bCanShoot = true;
  51.     bUnlimitedAmmo = false;
  52.     MaxAmmo = 10;
  53.     CurrentAmmo = MaxAmmo;
  54. }
  55.  
  56. void APlayer_Character::BeginPlay()
  57. {
  58.     Super::BeginPlay();
  59.  
  60.     // For when the ammo value was changed
  61.     if (CurrentAmmo != MaxAmmo)
  62.     {
  63.         CurrentAmmo = MaxAmmo;
  64.     }
  65.  
  66. }
  67.  
  68. void APlayer_Character::SetupPlayerInputComponent(UInputComponent * PlayerInputComponent)
  69. {
  70.     Super::SetupPlayerInputComponent(PlayerInputComponent);
  71.  
  72.     //Assertion Check
  73.     check(PlayerInputComponent);
  74. }
  75.  
  76. void APlayer_Character::OnDeath_Implementation()
  77. {
  78.  
  79. }
  80.  
  81.  
  82. .h
  83.  
  84.  
  85. // Fill out your copyright notice in the Description page of Project Settings.
  86.  
  87. #pragma once
  88.  
  89. #include "CoreMinimal.h"
  90. #include "Base_Character.h"
  91. #include "Components/SkeletalMeshComponent.h"
  92. #include "Camera/CameraComponent.h"
  93. #include "Player_Character.generated.h"
  94.  
  95. /**
  96.  *
  97.  */
  98. UCLASS()
  99. class CPP_PACKT_API APlayer_Character : public ABase_Character
  100. {
  101.     GENERATED_BODY()
  102.  
  103.         UPROPERTY(BlueprintReadOnly, VisibleDefaultsOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
  104.         class USpringArmComponent* SpringArm;
  105.     UPROPERTY(BlueprintReadOnly, VisibleDefaultsOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
  106.         class UCameraComponent* Camera;
  107.     // This would be for our arms mesh
  108.     UPROPERTY(BlueprintReadOnly, VisibleDefaultsOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
  109.         class USkeletalMeshComponent* FP_Mesh;
  110.     UPROPERTY(BlueprintReadOnly, VisibleDefaultsOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
  111.         class USkeletalMeshComponent* GunMesh;
  112.  
  113. public:
  114.         // Constructor
  115.         APlayer_Character();
  116.  
  117.         UFUNCTION(BlueprintPure, Category = "Character|Gun|Ammo")
  118.             int32 GetCurrentAmmo() const { return CurrentAmmo; }
  119.  
  120.         UFUNCTION(BlueprintPure, Category = "Character|Gun|Ammo")
  121.             int32 GetMaxAmmo() const { return MaxAmmo; }
  122.  
  123.         UFUNCTION(BlueprintCallable, Category = "Character|Gun|Ammo")
  124.             void SetCurrentAmmo(int NewAmmo) { CurrentAmmo = NewAmmo;  }
  125.    
  126. protected:
  127.     virtual void BeginPlay() override;
  128.     virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)override;
  129.  
  130.     virtual void OnDeath_Implementation() override;
  131.  
  132.     // Check if we have any remaining ammo
  133.     bool HasAmmo() const { return (CurrentAmmo > 0); }
  134.  
  135.     // Flag for when the player can shoot
  136.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character|Gun")
  137.         bool bCanShoot;
  138.  
  139.     // Flag for when the player can shoot unlimited amount of bullets.
  140.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Character|Gun|Ammo")
  141.         bool bUnlimitedAmmo;
  142.  
  143.     int CurrentAmmo;
  144.  
  145.     UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Character|Gun|Ammo")
  146.     int MaxAmmo;
  147. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement