epr24pr42-ojanssen2/Vector2d.cpp

48 lines
899 B
C++
Raw Normal View History

2025-01-19 18:23:50 +01:00
#include "Vector2d.h"
2025-01-19 17:59:26 +01:00
namespace game
{
Vector2d::Vector2d(const int x, const int y)
{
this->x = x;
this->y = y;
}
void Vector2d::update(const int& x, const int& y)
{
this->x = x;
this->y = y;
}
void Vector2d::change_x(const int& amount) {
this->x += amount;
}
void Vector2d::change_y(const int& amount) {
this->y += amount;
}
Vector2d Vector2d::normalize() {
Vector2d v = *this;
if (v.x < 0)
v.x *= -1;
if (v.y < 0)
v.y *= -1;
return v;
}
bool Vector2d::eq(const Vector2d& position) const {
return this->x == position.x && this->y == position.y;
}
Vector2d Vector2d::get_new_updated(const int& diff_x, const int& diff_y) const {
Vector2d new_position = *this;
new_position.change_x(diff_x);
new_position.change_y(diff_y);
return new_position;
}
} // game