Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WorldGen.h
- #pragma once
- #include "Tile.h"
- #include "GameFramework/Actor.h"
- #include "WorldGen.generated.h"
- UCLASS()
- class SNEAKYSNAKE_API AWorldGen : public AActor
- {
- GENERATED_BODY()
- public:
- // Sets default values for this actor's properties
- AWorldGen();
- // Called when the game starts or when spawned
- virtual void BeginPlay() override;
- // Called every frame
- virtual void Tick( float DeltaSeconds ) override;
- UPROPERTY(EditAnywhere)
- FVector2D size;
- UPROPERTY(EditAnywhere)
- int splits;
- UPROPERTY(EditAnywhere)
- int doors;
- private:
- TArray<TArray<ATile>> levelMap;
- };
- ___________________________________________________________________
- worldgen.cpp
- #include "SneakySnake.h"
- #include "WorldGen.h"
- #include "Tile.h"
- // Sets default values
- AWorldGen::AWorldGen()
- {
- // 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 AWorldGen::BeginPlay()
- {
- Super::BeginPlay();
- TArray<ATile> row;
- for (int j = 0; j < size.X; j++) {
- for (int k = 0; k < size.Y; k++) {
- row.Add(ATile(j, k));
- }
- levelMap.Add(row);
- }
- //UE_LOG(LogTemp, Warning, TEXT("tile exists at %d, %d"), levelMap[size.X - 1][size.Y - 1].position.X, levelMap[size.X - 1][size.Y - 1].position.Y);
- }
- // Called every frame
- void AWorldGen::Tick( float DeltaTime )
- {
- Super::Tick( DeltaTime );
- }
- ______________________________________________
- tile.h
- #pragma once
- #include "GameFramework/Actor.h"
- #include "Tile.generated.h"
- UCLASS()
- class SNEAKYSNAKE_API ATile : public AActor
- {
- GENERATED_BODY()
- public:
- // Sets default values for this actor's properties
- ATile();
- ATile(int,int);
- // Called when the game starts or when spawned
- virtual void BeginPlay() override;
- // Called every frame
- virtual void Tick( float DeltaSeconds ) override;
- FVector position;
- };
- _______________________________________________
- tile.cpp
- #include "SneakySnake.h"
- #include "Tile.h"
- // Sets default values
- ATile::ATile()
- {
- // 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;
- }
- ATile::ATile(int x, int y)
- {
- // 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;
- position.X = x;
- position.Y = y;
- }
- // Called when the game starts or when spawned
- void ATile::BeginPlay()
- {
- Super::BeginPlay();
- }
- // Called every frame
- void ATile::Tick( float DeltaTime )
- {
- Super::Tick( DeltaTime );
- }
Advertisement
Add Comment
Please, Sign In to add comment