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
|
// Copyright 2005 by Anthony Liekens anthony@liekens.net
#include <math.h>
#include "coordinate.h"
#include "settings.h"
Coordinate::Coordinate() {
x = y = 0;
}
Coordinate::Coordinate( double x, double y ) {
this->x = x;
this->y = y;
}
void
Coordinate::setX( double x ) {
this->x = x;
}
void
Coordinate::setY( double y ) {
this->y = y;
}
void
Coordinate::setXMapped( int x ) {
this->x = ( (double)x - Settings::getGameOffsetX() ) / Settings::getGameWidth();
}
void
Coordinate::setYMapped( int y ) {
this->y = (double)y / Settings::getGameHeight();
}
double
Coordinate::getX() const {
return x;
}
double
Coordinate::getY() const {
return y;
}
int
Coordinate::getXMapped() const {
return Settings::getGameOffsetX() + ( int )( Settings::getGameWidth() * x );
}
int
Coordinate::getYMapped() const {
return ( int )( Settings::getGameHeight() * y );
}
double
Coordinate::distance( const Coordinate& c ) const {
double dx = c.getX() - getX();
double dy = c.getY() - getY();
return sqrt( dx * dx + dy * dy );
}
bool
Coordinate::operator==( const Coordinate &that) const
{
return x == that.x && y == that.y;
}
|