-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpawnLevel.cpp
123 lines (104 loc) · 2.91 KB
/
SpawnLevel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Fill out your copyright notice in the Description page of Project Settings.
#include "SpawnLevel.h"
#include "BaseLevel.h"
#include "Engine.h"
#include "Components/BoxComponent.h"
// Sets default values
ASpawnLevel::ASpawnLevel()
{
// 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 ASpawnLevel::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ASpawnLevel::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
SpawnLevel(true);
SpawnLevel(false);
SpawnLevel(false);
SpawnLevel(false);
}
void ASpawnLevel::SpawnLevel(bool IsFirst)
{
SpawnLocation = FVector(0.0f, 1000.0f, 0.0f);
SpawnRotation = FRotator(0, 90, 0);
if (!IsFirst)
{
ABaseLevel* LastLevel = LevelList.Last();
SpawnLocation = LastLevel->GetSpawnLocation()->GetComponentTransform().GetTranslation();
}
RandomLevel = FMath::RandRange(1, 10);
ABaseLevel* NewLevel = nullptr;
if (RandomLevel == 1)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level1,
SpawnLocation, SpawnRotation, SpawnInfo);
}
else if (RandomLevel == 2)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level2,
SpawnLocation, SpawnRotation, SpawnInfo);
}
else if (RandomLevel == 3)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level3,
SpawnLocation, SpawnRotation, SpawnInfo);
}
else if (RandomLevel == 4)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level4,
SpawnLocation, SpawnRotation, SpawnInfo);
}
else if (RandomLevel == 5)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level5,
SpawnLocation, SpawnRotation, SpawnInfo);
}
else if (RandomLevel == 6)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level6,
SpawnLocation, SpawnRotation, SpawnInfo);
}
else if (RandomLevel == 7)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level7,
SpawnLocation, SpawnRotation, SpawnInfo);
}
else if (RandomLevel == 8)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level8,
SpawnLocation, SpawnRotation, SpawnInfo);
}
else if (RandomLevel == 9)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level9,
SpawnLocation, SpawnRotation, SpawnInfo);
}
else if (RandomLevel == 10)
{
NewLevel = GetWorld()->SpawnActor<ABaseLevel>(Level10,
SpawnLocation, SpawnRotation, SpawnInfo);
}
if (NewLevel)
{
if (NewLevel->GetTrigger())
{
NewLevel->GetTrigger()->OnComponentBeginOverlap.
AddDynamic(this, &ASpawnLevel::OnOverlapBegin);
}
}
LevelList.Add(NewLevel);
if (LevelList.Num() > 5)
{
LevelList.RemoveAt(0);
}
}
void ASpawnLevel::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
SpawnLevel(false);
}