-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDLGameObject.cpp
67 lines (63 loc) · 1.34 KB
/
SDLGameObject.cpp
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
#include "SDLGameObject.h"
#include "Game.h"
SDLGameObject::SDLGameObject() : GameObject(),
m_position(Vector2D(0,0)),
m_velocity(Vector2D(0,0)),
m_acceleration(Vector2D(0,0)),
m_width(0),
m_height(0),
m_textureID(""),
m_currentRow(1),
m_currentFrame(0),
m_numFrames(0)
{
}
void SDLGameObject::load(const LoaderParams* pParams)
{
m_position = Vector2D(pParams->getX(), pParams->getY());
m_velocity = Vector2D(0,0);
m_acceleration = Vector2D(0,0);
m_width = pParams->getWidth();
m_height = pParams->getHeight();
m_textureID = pParams->getTextureID();
m_currentRow, m_currentFrame = 1;
m_numFrames = pParams->getNumFrames();
}
void SDLGameObject::draw()
{
if(m_velocity.getX() > 0)
{
TheTextureManager::instance()->drawFrame(
m_textureID,
(int)m_position.getX(),
(int)m_position.getY(),
m_width,
m_height,
m_currentRow,
m_currentFrame,
TheGame::instance()->getRenderer(),
SDL_FLIP_HORIZONTAL
);
}
else
{
TheTextureManager::instance()->drawFrame(
m_textureID,
(int)m_position.getX(),
(int)m_position.getY(),
m_width,
m_height,
m_currentRow,
m_currentFrame,
TheGame::instance()->getRenderer()
);
}
}
void SDLGameObject::update()
{
m_velocity += m_acceleration;
m_position += m_velocity;
}
void SDLGameObject::clean()
{
}