-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaseObject.cpp
More file actions
45 lines (38 loc) · 1.02 KB
/
BaseObject.cpp
File metadata and controls
45 lines (38 loc) · 1.02 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
#include "stdafx.h"
#include "BaseObject.h"
#include "Game.h"
//static variable to keep track of next id number
int BaseObject::m_sNextId = 0;
//Constructor to be called by derived classes
BaseObject::BaseObject(float newX, float newY, bool isVisible, bool isSolid, std::string filename, dlb::ObjectType type): m_isVisible(isVisible),
m_isSolid(isSolid),
m_id(m_sNextId),
m_objectType(type)
{
m_position.x = newX;
m_position.y = newY;
//increment static id number so next object has valid, correct id
++m_sNextId;
// Attempt to Load Image
if (!m_Image.LoadFromFile(filename))
{
//If it doesn't load
m_isLoaded = false;
Game::Error("Image Load " + filename + " failed.");
}
else //loaded
{
m_Sprite.SetImage(m_Image);
m_Sprite.SetCenter(0.0f, 0.0f);
m_isLoaded = true;
}
m_Sprite.SetPosition(newX, newY);
}
BaseObject::~BaseObject()
{}
//If loaded successfully and is visible, Draw the sf::Sprite
void BaseObject::Draw(sf::RenderWindow& window)
{
if (m_isLoaded && m_isVisible == true)
window.Draw(m_Sprite);
}