-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameWorld.cpp
More file actions
100 lines (95 loc) · 2.16 KB
/
GameWorld.cpp
File metadata and controls
100 lines (95 loc) · 2.16 KB
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
#include "GameWorld.h"
#include "GameObject.h"
#include "Camera.h"
void GameWorld::set_depth(float depth)
{
this->depth = depth;
}
void GameWorld::set_width(float width)
{
this->width = width;
}
void GameWorld::set_height(float height)
{
this->height = height;
}
float GameWorld::get_depth()
{
return this->depth;
}
float GameWorld::get_width()
{
return this->width;
}
float GameWorld::get_height()
{
return this->height;
}
void GameWorld::add_object(GameObject* object)
{
if(this->objects != NULL)
{
if(this->objects[objects_counter] != NULL)
delete[] this->objects[objects_counter];
this->objects[objects_counter++] = object;
if(objects_counter == capacity)
{
GameObject** p = this->objects;
this->objects = new GameObject*[capacity+50];
for(int i = 0; i<objects_counter; i++)
this->objects[i] = p[i];
for(int i = objects_counter; i<capacity+50; i++)
this->objects[i] = NULL;
delete[] p;
capacity += 50;
}
}
else
{
capacity = 50;
objects_counter = 0;
this->objects = new GameObject*[capacity];
for(int i = 0; i<capacity; i++)
this->objects[i] = NULL;
this->objects[objects_counter++] = object;
}
}
void GameWorld::set_camera(Camera*& camera)
{
this->camera = camera;
}
Camera*& GameWorld::get_camera()
{
return this->camera;
}
GameWorld::GameWorld()
{
this->camera = NULL;
this->objects = NULL;
this->width = 200;
this->height = 200;
this->depth = 200;
}
GameWorld::GameWorld(float width, float height, float depth, Camera*& camera)
{
set_width(width);
set_height(height);
set_depth(depth);
set_camera(camera);
this->capacity = 50;
this->objects_counter = 0;
this->objects = new GameObject*[capacity];
}
GameWorld::~GameWorld()
{
for(int i = 0; i<capacity; i++)
delete this->objects[i];
delete[] this->objects;
//not sure for camera!
}
void GameWorld::draw()
{
for(int i = 0; i<objects_counter; i++)
if(objects[i] != NULL)
objects[i]->draw();
}