Guest User

unreal4 dynamic 2d tarray

a guest
Jan 19th, 2017
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. WorldGen.h
  2. #pragma once
  3.  
  4. #include "Tile.h"
  5. #include "GameFramework/Actor.h"
  6. #include "WorldGen.generated.h"
  7.  
  8. UCLASS()
  9. class SNEAKYSNAKE_API AWorldGen : public AActor
  10. {
  11.     GENERATED_BODY()
  12.    
  13. public:
  14.     // Sets default values for this actor's properties
  15.     AWorldGen();
  16.  
  17.     // Called when the game starts or when spawned
  18.     virtual void BeginPlay() override;
  19.    
  20.     // Called every frame
  21.     virtual void Tick( float DeltaSeconds ) override;
  22.  
  23.     UPROPERTY(EditAnywhere)
  24.         FVector2D size;
  25.     UPROPERTY(EditAnywhere)
  26.         int splits;
  27.     UPROPERTY(EditAnywhere)
  28.         int doors;
  29. private:
  30.     TArray<TArray<ATile>> levelMap;
  31. };
  32. ___________________________________________________________________
  33. worldgen.cpp
  34. #include "SneakySnake.h"
  35. #include "WorldGen.h"
  36. #include "Tile.h"
  37.  
  38. // Sets default values
  39. AWorldGen::AWorldGen()
  40. {
  41.     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  42.     PrimaryActorTick.bCanEverTick = true;
  43. }
  44.  
  45. // Called when the game starts or when spawned
  46. void AWorldGen::BeginPlay()
  47. {
  48.     Super::BeginPlay();
  49.    
  50.     TArray<ATile> row;
  51.     for (int j = 0; j < size.X; j++) {
  52.         for (int k = 0; k < size.Y; k++) {
  53.             row.Add(ATile(j, k));
  54.         }
  55.         levelMap.Add(row);
  56.     }
  57.     //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);
  58. }
  59.  
  60. // Called every frame
  61. void AWorldGen::Tick( float DeltaTime )
  62. {
  63.     Super::Tick( DeltaTime );
  64. }
  65. ______________________________________________
  66. tile.h
  67. #pragma once
  68.  
  69. #include "GameFramework/Actor.h"
  70. #include "Tile.generated.h"
  71.  
  72. UCLASS()
  73. class SNEAKYSNAKE_API ATile : public AActor
  74. {
  75.     GENERATED_BODY()
  76.    
  77. public:
  78.     // Sets default values for this actor's properties
  79.     ATile();
  80.     ATile(int,int);
  81.  
  82.     // Called when the game starts or when spawned
  83.     virtual void BeginPlay() override;
  84.    
  85.     // Called every frame
  86.     virtual void Tick( float DeltaSeconds ) override;
  87.  
  88.     FVector position;
  89. };
  90. _______________________________________________
  91. tile.cpp
  92. #include "SneakySnake.h"
  93. #include "Tile.h"
  94.  
  95. // Sets default values
  96. ATile::ATile()
  97. {
  98.     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  99.     PrimaryActorTick.bCanEverTick = true;
  100. }
  101.  
  102. ATile::ATile(int x, int y)
  103. {
  104.     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  105.     PrimaryActorTick.bCanEverTick = true;
  106.     position.X = x;
  107.     position.Y = y;
  108. }
  109.  
  110. // Called when the game starts or when spawned
  111. void ATile::BeginPlay()
  112. {
  113.     Super::BeginPlay();
  114. }
  115.  
  116. // Called every frame
  117. void ATile::Tick( float DeltaTime )
  118. {
  119.     Super::Tick( DeltaTime );
  120. }
Advertisement
Add Comment
Please, Sign In to add comment