Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
GameObject.cpp
Go to the documentation of this file.
1
2#include "GameObject.h"
3#include "Level.h"
4
5uint32_t GameObject::s_count = 0;
6Level *GameObject::s_pCurrentLevel = nullptr;
7
8
10{
11 m_index = s_count;
12 s_count++;
13}
14
15void GameObject::Update(const GameTime& gameTime)
16{
17 if (!IsActive()) return;
18 if (!s_pCurrentLevel) return;
19
20 s_pCurrentLevel->UpdateSectorPosition(this);
21}
22
24{
25 return Vector2(m_collisionRadius, m_collisionRadius);
26}
27
28void GameObject::SetPosition(const float x, const float y)
29{
30 m_previousPosition = m_position;
31 m_position.Set(x, y);
32}
33
34void GameObject::SetPosition(const Vector2 &position)
35{
36 SetPosition(position.X, position.Y);
37}
38
39void GameObject::TranslatePosition(const float x, const float y)
40{
41 SetPosition(m_position.X + x, m_position.Y + y);
42}
43
45{
46 TranslatePosition(offset.X, offset.Y);
47}
48
50{
51 if (m_position.Y - GetHalfDimensions().Y >= Game::GetScreenHeight()) return false;
52 if (m_position.Y + GetHalfDimensions().Y <= 0) return false;
53 if (m_position.X - GetHalfDimensions().X >= Game::GetScreenWidth()) return false;
54 if (m_position.X + GetHalfDimensions().X <= 0) return false;
55
56 return true;
57}
GameObject()
Instantiate a game object.
Definition GameObject.cpp:9
virtual void TranslatePosition(const float x, const float y)
virtual void SetPosition(const float x, const float y)
virtual bool IsOnScreen() const
virtual bool IsActive() const
Flag to determine if the object is active.
Definition GameObject.h:42
virtual Vector2 GetHalfDimensions() const
Get the half dimensions of the object.
virtual void Update(const GameTime &gameTime)
Update the object.
static int GetScreenHeight()
Gets the screen width in pixels.
Definition Game.h:40
static int GetScreenWidth()
Gets the screen width in pixels.
Definition Game.h:36
Contains timing values for game updates and rendering.
Definition GameTime.h:21
Defines a vector with 2 components (x and y).
Definition Vector2.h:21
float Y
The y-coordinate of the vector.
Definition Vector2.h:187
void Set(const float x, const float y)
Sets the components of the vector.
Definition Vector2.h:49
float X
The x-coordinate of the vector.
Definition Vector2.h:186
Represents a level in the game.
Definition Level.h:15
virtual void UpdateSectorPosition(GameObject *pGameObject)
Update the position of a game object within the level, based on its collision sector (only objects wi...
Definition Level.cpp:153