-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.cpp
More file actions
113 lines (92 loc) · 2.18 KB
/
Copy pathItem.cpp
File metadata and controls
113 lines (92 loc) · 2.18 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
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "headers.h"
#include "Item.h"
void Item::initSprite(sf::Texture* texture)
{
m_item = new sf::Sprite;
m_item->setTexture(*texture);
}
void Item::initVariables()
{
m_isOnGround = false;
m_isInHand = true;
m_speed = 500.0f;
}
//Constructors / Descructors
Item::Item(sf::Texture* texture)
{
this->initSprite(texture);
this->initVariables();
}
Item::~Item()
{
}
void Item::updateItemPosition(const sf::Vector2i& mousePosition, const sf::Vector2f& position,const sf::Vector2f& creatureSize)
{
if (m_isInHand == true)
{
sf::Vector2f newPosition{
position.x + creatureSize.x / 3.0f,
position.y + creatureSize.y / 4.0f
};
m_item->setPosition(newPosition);
this->inHandRotation(mousePosition);
}
else if (m_isInHand == false && m_isOnGround == false)
{
this->dragItemDown();
}
}
void Item::inHandRotation(const sf::Vector2i& mousePosition)
{
m_item->setRotation(Geometry::getAngleRelativelyToGround(m_item->getPosition(), mousePosition));
}
void Item::setItemPosition(sf::Vector2f position)
{
m_itemPosition = position;
m_item->setPosition(position);
}
void Item::dragItemDown()
{
m_item->move(0.0f, m_speed * deltaTime::timePerFrame);
}
void Item::itemGroundCollision(Tile& collisionTile)
{
sf::FloatRect tileBounds{ collisionTile.m_tile.getGlobalBounds() };
sf::FloatRect itemNextBounds{ m_item->getGlobalBounds() };
itemNextBounds.top += m_speed * deltaTime::timePerFrame;
if (itemNextBounds.intersects(tileBounds) &&
m_isOnGround == false &&
collisionTile.m_tileType == Tile::Type::Grass)
{
m_item->setPosition(m_item->getPosition().x, tileBounds.top - m_item->getGlobalBounds().height);
m_isOnGround = true;
}
}
const bool& Item::isItemOnGround() const
{
return m_isOnGround;
}
const bool& Item::isItemEquiped() const
{
return m_isInHand;
}
const sf::Vector2f Item::getPosition() const
{
return m_item->getPosition();
}
const Item::Type& Item::itemType() const
{
return m_itemType;
}
void Item::setPointerToMousePosition(sf::Vector2i& mousePositionMap)
{
m_mousePositionMapPtr = &mousePositionMap;
}
void Item::setItemType(Type itemType)
{
m_itemType = itemType;
}
void Item::setScale(float scaleX, float scaleY)
{
m_item->setScale(scaleX, scaleY);
}