The Table Engine
transform.cpp
Go to the documentation of this file.
1 #include "transform.h"
2 #include "gameobject.h"
3 #include "scenemanager.h"
4 
5 #include "SDL2/SDL.h"
6 
7 #include <iostream>
8 
10 {
11  setName("transform");
12  mTransform = new SDL_Rect();
13  mPosition = Vec2(0, 0);
14 }
15 
16 Transform::Transform(int x, int y)
17 {
18  Transform();
19  mTransform->x = x;
20  mTransform->y = y;
21  mPosition = Vec2(x, y);
22 }
23 
25 {
26  delete mTransform;
27 }
28 
30 {
31  return mTransform;
32 }
33 
35 {
36  return mPosition;
37 }
38 
40 {
41  return Vec2(mTransform->x, mTransform->y);
42 }
43 
45 {
46  return mSize;
47 }
48 
49 void Transform::setWorldPosition(float x, float y)
50 {
51  mPosition = Vec2(x, y);
52 }
53 
55 {
56  mPosition = pos;
57 }
58 
59 void Transform::setWorldSize(float w, float h)
60 {
61  mSize = Vec2(w, h);
62 }
63 
65 {
66  mSize = size;
67 }
68 
69 void Transform::updateWorldPosition(float dx, float dy)
70 {
71  mPosition.x += dx;
72  mPosition.y += dy;
73 }
74 
76 {
77  mPosition.x += dpos.x;
78  mPosition.y += dpos.y;
79 }
80 
82 {
84 
85  /* calculate screen position relative to the player (camera follows player) */
86  mTransform->x = mPosition.x - cameraPosition.x + 320;
87  mTransform->y = mPosition.y - cameraPosition.y + 240;
88  mTransform->w = mSize.x;
89  mTransform->h = mSize.y;
90 }
void setName(std::string name)
Sets the name of the component.
Definition: component.cpp:19
static SceneManager & getInstance()
Retrieves the singleton instance of SceneManager.
Vec2 getCameraWorldPosition()
Retrieves the world position of the camera.
void updateWorldPosition(float dx, float dy)
Update the world position by a delta value.
Definition: transform.cpp:69
Vec2 getScreenSize()
Get the size of the Transform in screen space.
Definition: transform.cpp:44
void update()
Render function for the Transform component, handling visual updates.
Definition: transform.cpp:81
Vec2 getScreenPosition()
Get the screen space position calculated from world space.
Definition: transform.cpp:39
void setWorldPosition(float x, float y)
Set the world space position of the Transform.
Definition: transform.cpp:49
Vec2 mPosition
Position in world space.
Definition: transform.h:26
Transform()
Default constructor.
Definition: transform.cpp:9
~Transform()
Destructor.
Definition: transform.cpp:24
Vec2 mSize
Size in world space.
Definition: transform.h:27
SDL_Rect * mTransform
Holds position and size relative to the screen.
Definition: transform.h:25
void setWorldSize(float w, float h)
Set the world space size of the Transform.
Definition: transform.cpp:59
Vec2 getWorldPosition()
Get the world space position of the Transform.
Definition: transform.cpp:34
SDL_Rect * getScreenRect()
Get the SDL_Rect describing the position and size on the screen.
Definition: transform.cpp:29
Defines the SceneManager class for managing scenes in the game.
A structure to represent 2D vectors.
Definition: vec2.h:16
float y
Y coordinate of the vector.
Definition: vec2.h:18
float x
X coordinate of the vector.
Definition: vec2.h:17
Provides the Transform component for positioning and sizing game objects.