You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.3 KiB
67 lines
1.3 KiB
/** |
|
* @file engine.cpp |
|
* |
|
* Implementation of basic engine helper functions: |
|
* - Sprite blitting |
|
* - Drawing |
|
* - Angle calculation |
|
* - RNG |
|
* - Memory allocation |
|
* - File loading |
|
* - Video playback |
|
*/ |
|
|
|
#include <array> |
|
#include <cassert> |
|
#include <cstdint> |
|
#include <cstring> |
|
|
|
#include "lighting.h" |
|
#include "movie.h" |
|
#include "options.h" |
|
|
|
namespace devilution { |
|
|
|
Direction GetDirection(Point start, Point destination) |
|
{ |
|
Direction md; |
|
|
|
int mx = destination.x - start.x; |
|
int my = destination.y - start.y; |
|
if (mx >= 0) { |
|
if (my >= 0) { |
|
if (5 * mx <= (my * 2)) // mx/my <= 0.4, approximation of tan(22.5) |
|
return Direction::SouthWest; |
|
md = Direction::South; |
|
} else { |
|
my = -my; |
|
if (5 * mx <= (my * 2)) |
|
return Direction::NorthEast; |
|
md = Direction::East; |
|
} |
|
if (5 * my <= (mx * 2)) // my/mx <= 0.4 |
|
md = Direction::SouthEast; |
|
} else { |
|
mx = -mx; |
|
if (my >= 0) { |
|
if (5 * mx <= (my * 2)) |
|
return Direction::SouthWest; |
|
md = Direction::West; |
|
} else { |
|
my = -my; |
|
if (5 * mx <= (my * 2)) |
|
return Direction::NorthEast; |
|
md = Direction::North; |
|
} |
|
if (5 * my <= (mx * 2)) |
|
md = Direction::NorthWest; |
|
} |
|
return md; |
|
} |
|
|
|
int CalculateWidth2(int width) |
|
{ |
|
return (width - 64) / 2; |
|
} |
|
|
|
} // namespace devilution
|
|
|