diff --git a/Config/DefaultEditor.ini b/Config/DefaultEditor.ini index e69de29..d3f5a12 100755 --- a/Config/DefaultEditor.ini +++ b/Config/DefaultEditor.ini @@ -0,0 +1 @@ + diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index fa3870b..32094fe 100755 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -49,6 +49,7 @@ bUseSplitscreen=False +Profiles=(Name="Ragdoll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Simulating Skeletal Mesh Component. All other channels will be set to default.") +Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.") +Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility"),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") ++Profiles=(Name="Pickup",CollisionEnabled=QueryAndPhysics,bCanModify=True,ObjectTypeName="WorldStatic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap),(Channel="Character",Response=ECR_Overlap)),HelpMessage="Item to pickup") +DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Block,bTraceType=False,bStaticObject=False,Name="Character") -ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall") -ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn") diff --git a/Content/AmmoPickup.uasset b/Content/AmmoPickup.uasset new file mode 100755 index 0000000..1694fa1 Binary files /dev/null and b/Content/AmmoPickup.uasset differ diff --git a/Content/BasePawn_BP.uasset b/Content/BasePawn_BP.uasset deleted file mode 100755 index 23b920c..0000000 Binary files a/Content/BasePawn_BP.uasset and /dev/null differ diff --git a/Content/EnemyPawn_BP.uasset b/Content/EnemyPawn_BP.uasset new file mode 100755 index 0000000..e6228f7 Binary files /dev/null and b/Content/EnemyPawn_BP.uasset differ diff --git a/Content/EnemySpawner_BP.uasset b/Content/EnemySpawner_BP.uasset index 0b5527c..cbaf24d 100755 Binary files a/Content/EnemySpawner_BP.uasset and b/Content/EnemySpawner_BP.uasset differ diff --git a/Content/PlayerPawn_BP.uasset b/Content/PlayerPawn_BP.uasset index 6861cf2..f292b6e 100755 Binary files a/Content/PlayerPawn_BP.uasset and b/Content/PlayerPawn_BP.uasset differ diff --git a/Content/PresidentPawn.uasset b/Content/PresidentPawn.uasset index 6836922..df81884 100755 Binary files a/Content/PresidentPawn.uasset and b/Content/PresidentPawn.uasset differ diff --git a/Content/TempBullet.uasset b/Content/TempBullet.uasset index 5394f29..bbff9b2 100755 Binary files a/Content/TempBullet.uasset and b/Content/TempBullet.uasset differ diff --git a/Content/TestMap.umap b/Content/TestMap.umap index e04c8e1..864be60 100755 Binary files a/Content/TestMap.umap and b/Content/TestMap.umap differ diff --git a/Content/TestMap_BuiltData.uasset b/Content/TestMap_BuiltData.uasset index ecbcb72..fbbf49a 100755 Binary files a/Content/TestMap_BuiltData.uasset and b/Content/TestMap_BuiltData.uasset differ diff --git a/PresidentsBrigade.sln b/PresidentsBrigade.sln index 954887a..d17e23b 100755 --- a/PresidentsBrigade.sln +++ b/PresidentsBrigade.sln @@ -7,9 +7,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Engine", "Engine", "{94A6C6 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Games", "Games", "{8E2F6A87-1826-34F4-940C-CC23A48F9FE4}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PresidentsBrigade", "Intermediate\ProjectFiles\PresidentsBrigade.vcxproj", "{96B177F0-8EDF-4729-A78F-BAD24CB85C00}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PresidentsBrigade", "Intermediate\ProjectFiles\PresidentsBrigade.vcxproj", "{F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UE4", "Intermediate\ProjectFiles\UE4.vcxproj", "{79A8FA76-49BB-457C-B380-F831AAAAD3DE}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UE4", "Intermediate\ProjectFiles\UE4.vcxproj", "{1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Visualizers", "Visualizers", "{1CCEC849-CC72-4C59-8C36-2F7C38706D4C}" ProjectSection(SolutionItems) = preProject @@ -35,53 +35,53 @@ Global Shipping|Win64 = Shipping|Win64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame Editor|Android.ActiveCfg = Invalid|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame Editor|Win32.ActiveCfg = Invalid|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame Editor|Win64.ActiveCfg = DebugGame_Editor|x64 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame Editor|Win64.Build.0 = DebugGame_Editor|x64 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame|Android.ActiveCfg = Android_DebugGame|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame|Android.Build.0 = Android_DebugGame|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame|Win32.ActiveCfg = DebugGame|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame|Win32.Build.0 = DebugGame|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame|Win64.ActiveCfg = DebugGame|x64 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.DebugGame|Win64.Build.0 = DebugGame|x64 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development Editor|Android.ActiveCfg = Invalid|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development Editor|Win32.ActiveCfg = Invalid|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development Editor|Win64.ActiveCfg = Development_Editor|x64 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development Editor|Win64.Build.0 = Development_Editor|x64 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development|Android.ActiveCfg = Android_Development|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development|Android.Build.0 = Android_Development|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development|Win32.ActiveCfg = Development|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development|Win32.Build.0 = Development|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development|Win64.ActiveCfg = Development|x64 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Development|Win64.Build.0 = Development|x64 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Shipping|Android.ActiveCfg = Android_Shipping|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Shipping|Android.Build.0 = Android_Shipping|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Shipping|Win32.ActiveCfg = Shipping|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Shipping|Win32.Build.0 = Shipping|Win32 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Shipping|Win64.ActiveCfg = Shipping|x64 - {96B177F0-8EDF-4729-A78F-BAD24CB85C00}.Shipping|Win64.Build.0 = Shipping|x64 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.DebugGame Editor|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.DebugGame Editor|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.DebugGame Editor|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.DebugGame|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.DebugGame|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.DebugGame|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.Development Editor|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.Development Editor|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.Development Editor|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.Development|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.Development|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.Development|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.Shipping|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.Shipping|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 - {79A8FA76-49BB-457C-B380-F831AAAAD3DE}.Shipping|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame Editor|Android.ActiveCfg = Invalid|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame Editor|Win32.ActiveCfg = Invalid|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame Editor|Win64.ActiveCfg = DebugGame_Editor|x64 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame Editor|Win64.Build.0 = DebugGame_Editor|x64 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame|Android.ActiveCfg = Android_DebugGame|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame|Android.Build.0 = Android_DebugGame|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame|Win32.ActiveCfg = DebugGame|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame|Win32.Build.0 = DebugGame|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame|Win64.ActiveCfg = DebugGame|x64 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.DebugGame|Win64.Build.0 = DebugGame|x64 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development Editor|Android.ActiveCfg = Invalid|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development Editor|Win32.ActiveCfg = Invalid|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development Editor|Win64.ActiveCfg = Development_Editor|x64 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development Editor|Win64.Build.0 = Development_Editor|x64 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development|Android.ActiveCfg = Android_Development|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development|Android.Build.0 = Android_Development|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development|Win32.ActiveCfg = Development|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development|Win32.Build.0 = Development|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development|Win64.ActiveCfg = Development|x64 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Development|Win64.Build.0 = Development|x64 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Shipping|Android.ActiveCfg = Android_Shipping|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Shipping|Android.Build.0 = Android_Shipping|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Shipping|Win32.ActiveCfg = Shipping|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Shipping|Win32.Build.0 = Shipping|Win32 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Shipping|Win64.ActiveCfg = Shipping|x64 + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444}.Shipping|Win64.Build.0 = Shipping|x64 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.DebugGame Editor|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.DebugGame Editor|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.DebugGame Editor|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.DebugGame|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.DebugGame|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.DebugGame|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.Development Editor|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.Development Editor|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.Development Editor|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.Development|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.Development|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.Development|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.Shipping|Android.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.Shipping|Win32.ActiveCfg = BuiltWithUnrealBuildTool|Win32 + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D}.Shipping|Win64.ActiveCfg = BuiltWithUnrealBuildTool|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {79A8FA76-49BB-457C-B380-F831AAAAD3DE} = {94A6C6F3-99B3-346E-9557-ABF9D4064DBD} - {96B177F0-8EDF-4729-A78F-BAD24CB85C00} = {8E2F6A87-1826-34F4-940C-CC23A48F9FE4} + {1FED94F2-9FEC-4D92-9CAE-368909B2BF8D} = {94A6C6F3-99B3-346E-9557-ABF9D4064DBD} + {F7E08F87-96C6-4EFA-AB4B-FFF8D73E1444} = {8E2F6A87-1826-34F4-940C-CC23A48F9FE4} EndGlobalSection EndGlobal diff --git a/Source/PresidentsBrigade/BasePawn.cpp b/Source/PresidentsBrigade/BasePawn.cpp index 0656841..372387d 100755 --- a/Source/PresidentsBrigade/BasePawn.cpp +++ b/Source/PresidentsBrigade/BasePawn.cpp @@ -34,6 +34,7 @@ ABasePawn::ABasePawn(const FObjectInitializer &object_initializer): // Set defaults. max_health = 100; + max_ammo = 25; } // Called when the game starts or when spawned @@ -51,6 +52,7 @@ void ABasePawn::BeginPlay() * Set base state. */ current_health = max_health; + current_ammo = max_ammo; } void ABasePawn::handle_hit( @@ -143,25 +145,28 @@ void ABasePawn::stop_shooting() void ABasePawn::shoot() { - FVector player_location = player_mesh->GetComponentLocation(); - const float y = yaw.calculate_yaw(); - LogInfo(FString::Printf(TEXT("Raw yaw: %f"), y)); - const FRotator rotator(0, y, 0); - FVector forward = FRotationMatrix(rotator).GetUnitAxis(EAxis::X) * 100; + if (current_ammo > 0) + { + FVector player_location = player_mesh->GetComponentLocation(); + const float y = yaw.calculate_yaw(); + const FRotator rotator(0, y, 0); + FVector forward = FRotationMatrix(rotator).GetUnitAxis(EAxis::X) * 100; - FVector spawn_location = player_location + forward; - FActorSpawnParameters spawnParameters; - spawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; - spawnParameters.Owner = this; - spawnParameters.Instigator = this; - AActor* bullet = GetWorld()->SpawnActor( - bullet_actor_class, - spawn_location, - rotator, - spawnParameters - ); + FVector spawn_location = player_location + forward; + FActorSpawnParameters spawnParameters; + spawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + spawnParameters.Owner = this; + spawnParameters.Instigator = this; + AActor* bullet = GetWorld()->SpawnActor( + bullet_actor_class, + spawn_location, + rotator, + spawnParameters + ); - shoot_time_elapsed = 0; + shoot_time_elapsed = 0; + current_ammo -= 1; + } } void ABasePawn::handle_death() diff --git a/Source/PresidentsBrigade/BasePawn.h b/Source/PresidentsBrigade/BasePawn.h index 67f342a..b73d6db 100755 --- a/Source/PresidentsBrigade/BasePawn.h +++ b/Source/PresidentsBrigade/BasePawn.h @@ -68,7 +68,7 @@ protected: UPROPERTY(EditAnywhere, Category="Player") UBoxComponent* collision; - UPROPERTY(BlueprintReadWrite, Category="Player") + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Player") UStaticMeshComponent* player_mesh; UPROPERTY(EditAnywhere, Category="Movement") @@ -105,9 +105,18 @@ protected: UPROPERTY(EditAnywhere, Category = "Attack") int32 max_health; + /** + * Bullet fire rate. + */ UPROPERTY(EditAnywhere, Category = "Attack") float fire_rate_s; + /** + * Max ammor. + */ + UPROPERTY(EditAnywhere, Category = "Attack") + int32 max_ammo; + /** * Shooting enabled; */ @@ -123,6 +132,11 @@ protected: */ int32 current_health; + /** + * Current ammo. + */ + int32 current_ammo; + /** * Last yaw. */ diff --git a/Source/PresidentsBrigade/EnemyPawn.cpp b/Source/PresidentsBrigade/EnemyPawn.cpp new file mode 100755 index 0000000..b70c808 --- /dev/null +++ b/Source/PresidentsBrigade/EnemyPawn.cpp @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "EnemyPawn.h" +#include "Pickup.h" + +void AEnemyPawn::BeginPlay() +{ + Super::BeginPlay(); + + /* + * Initialize random stream. + */ + random.Initialize(FMath::Rand()); +} + +void AEnemyPawn::destroy_self() +{ + const bool drop_pickup = random.GetFraction() > .5; + + if (drop_pickup) + { + FVector location = get_location() + FVector(100, 100, 0); + FActorSpawnParameters spawnParameters; + spawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + APickup* pickup = GetWorld()->SpawnActor( + pickup_class, + location, + FRotator(0,0,0), + spawnParameters + ); + } + + ABasePawn::destroy_self(); +} diff --git a/Source/PresidentsBrigade/EnemyPawn.h b/Source/PresidentsBrigade/EnemyPawn.h new file mode 100755 index 0000000..f25072d --- /dev/null +++ b/Source/PresidentsBrigade/EnemyPawn.h @@ -0,0 +1,33 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "BasePawn.h" +#include "EnemyPawn.generated.h" + +class APickup; + +/** + * + */ +UCLASS() +class PRESIDENTSBRIGADE_API AEnemyPawn : public ABasePawn +{ + GENERATED_BODY() +protected: + virtual void BeginPlay() override; + virtual void destroy_self() override; + + /** + * Pickup class to spawn on death. + */ + UPROPERTY(EditAnywhere, Category = "Player") + TSubclassOf pickup_class; + +private: + /** + * Random number stream. + */ + FRandomStream random; +}; diff --git a/Source/PresidentsBrigade/Pickup.cpp b/Source/PresidentsBrigade/Pickup.cpp new file mode 100755 index 0000000..81fbe7c --- /dev/null +++ b/Source/PresidentsBrigade/Pickup.cpp @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Pickup.h" +#include "Components/BoxComponent.h" + +// Sets default values +APickup::APickup(const FObjectInitializer &object_initializer) +{ + collision = object_initializer.CreateDefaultSubobject(this, FName("Collision")); + RootComponent = collision; + collision->SetCollisionProfileName(FName("Pickup")); + + mesh = object_initializer.CreateDefaultSubobject(this, FName("Mesh")); + mesh->SetupAttachment(RootComponent); + mesh->SetCollisionEnabled(ECollisionEnabled::NoCollision); + + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; +} + +// Called when the game starts or when spawned +void APickup::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void APickup::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + diff --git a/Source/PresidentsBrigade/Pickup.h b/Source/PresidentsBrigade/Pickup.h new file mode 100755 index 0000000..32ba469 --- /dev/null +++ b/Source/PresidentsBrigade/Pickup.h @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "Pickup.generated.h" + +class UBoxComponent; + +UCLASS() +class PRESIDENTSBRIGADE_API APickup : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + APickup(const FObjectInitializer &object_initializer); + + // Called every frame + virtual void Tick(float DeltaTime) override; +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + + UPROPERTY(EditAnywhere, Category="Pickup") + UBoxComponent* collision; + + UPROPERTY(EditAnywhere, Category="Pickup") + UStaticMeshComponent* mesh; +}; diff --git a/Source/PresidentsBrigade/PlayerPawn.cpp b/Source/PresidentsBrigade/PlayerPawn.cpp index 9ed9462..e64c883 100755 --- a/Source/PresidentsBrigade/PlayerPawn.cpp +++ b/Source/PresidentsBrigade/PlayerPawn.cpp @@ -7,6 +7,7 @@ #include "Math/UnrealMathUtility.h" #include "Util.h" +#define LogInfo(Msg) Util::log_info(TEXT("APlayerPawn"), Msg) #define LogError(Msg) Util::log_error(TEXT("APlayerPawn"), Msg) APlayerPawn::APlayerPawn(const FObjectInitializer &object_initializer): @@ -38,6 +39,39 @@ void APlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen PlayerInputComponent->BindAction("Boost", EInputEvent::IE_Released, this, &APlayerPawn::reset_boost); } +void APlayerPawn::BeginPlay() +{ + Super::BeginPlay(); + + /* + * Setup collision handler. + */ + collision->OnComponentBeginOverlap.AddDynamic(this, &APlayerPawn::handle_overlap); +} + +void APlayerPawn::handle_overlap( + UPrimitiveComponent *overlapped_component, + AActor *other_actor, + UPrimitiveComponent *other_component, + int32 other_body_index, + bool from_sweep, + const FHitResult& hit) +{ + UClass* other_class = other_actor->GetClass(); + if (ammo_class_map.Contains(other_class)) + { + // Update current ammo. + current_ammo += ammo_class_map[other_class]; + if (current_ammo > max_ammo) + { + current_ammo = max_ammo; + } + + other_actor->Destroy(); + LogInfo(FString::Printf(TEXT("Total ammo %d"), current_ammo)); + } +} + void APlayerPawn::Tick(float delta_time) { Super::Tick(delta_time); diff --git a/Source/PresidentsBrigade/PlayerPawn.h b/Source/PresidentsBrigade/PlayerPawn.h index 12298ac..66ca0e6 100755 --- a/Source/PresidentsBrigade/PlayerPawn.h +++ b/Source/PresidentsBrigade/PlayerPawn.h @@ -24,6 +24,7 @@ public: // Called to bind functionality to input virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; protected: + virtual void BeginPlay() override; virtual void destroy_self() override; UPROPERTY(EditAnywhere, Category="Player") @@ -35,6 +36,12 @@ protected: UPROPERTY(EditAnywhere, Category = "Player") float respawn_s; + /** + * Classes that can add ammo to this object. + */ + UPROPERTY(EditAnywhere, Category = "Player") + TMap ammo_class_map; + /** * Multiplier to apply to current speed while boosting. Applies to max speed and accleration. */ @@ -54,6 +61,16 @@ protected: float cooldown_threshold_s; private: + UFUNCTION() + void handle_overlap( + UPrimitiveComponent *overlapped_component, + AActor *other_actor, + UPrimitiveComponent *other_component, + int32 other_body_index, + bool from_sweep, + const FHitResult& hit + ); + void boost(); void reset_boost(); void respawn(); diff --git a/todo.txt b/todo.txt index 33c95c2..4c6e0d6 100644 --- a/todo.txt +++ b/todo.txt @@ -13,15 +13,14 @@ xAdd dash xShoot from any direction xShoot at continuous rate when holding shoot button xAdd player damage -Add player ammo -Add HUD UI +xAdd player ammo Add win condition - Time based. Keep president alive until he reaches destination. +Add HUD UI Add menu Add local multiplayer x Blueprint - C++ -Add netcode Add art - Car models - Street shader @@ -29,3 +28,4 @@ Add sounds Add juice Add muzzle on shoot Camera zoom out based on screen size? Looks too small when I shrink the window +Add netcode