pacman/lib/Atlas.hpp

93 lines
2.4 KiB
C++
Raw Normal View History

2021-06-24 11:32:52 +00:00
#pragma once
2021-07-01 12:53:52 +00:00
2021-06-24 11:32:52 +00:00
#include "Direction.hpp"
#include "Position.hpp"
#include "assert.h"
2021-07-01 12:53:52 +00:00
#include <array>
2021-06-24 11:32:52 +00:00
namespace Atlas {
enum class Ghost {
blinky = 2,
speedy = 3,
inky = 4,
clyde = 5,
};
constexpr PositionInt pacman_right_wide = { 0, 0 };
constexpr PositionInt pacman_right_narrow = { 1, 0 };
constexpr PositionInt pacman_closed = { 2, 0 };
constexpr PositionInt pacman_left_narrow = { 3, 0 };
constexpr PositionInt pacman_left_wide = { 4, 0 };
constexpr PositionInt pacman_up_wide = { 5, 0 };
constexpr PositionInt pacman_up_narrow = { 6, 0 };
constexpr PositionInt pacman_down_wide = { 7, 0 };
constexpr PositionInt pacman_down_narrow = { 8, 0 };
2021-06-28 10:42:21 +00:00
constexpr PositionInt ghost_frightened1 = { 0, 7 };
constexpr PositionInt ghost_frightened2 = { 1, 7 };
constexpr PositionInt ghost_frightened3 = { 2, 7 };
constexpr PositionInt ghost_frightened4 = { 3, 7 };
constexpr PositionInt eyeSprite(Direction direction) {
int x = 0;
switch (direction) {
case Direction::RIGHT:
x = 0;
break;
case Direction::DOWN:
x = 2;
break;
case Direction::LEFT:
x = 4;
break;
case Direction::UP:
x = 6;
break;
default:
x = 0;
break;
}
return { x, 6 };
}
2021-06-24 11:32:52 +00:00
constexpr PositionInt ghostSprite(Ghost ghost, Direction direction, bool alternative) {
assert(ghost >= Ghost::blinky && ghost <= Ghost::clyde && "Invalid Ghost");
int y = static_cast<int>(ghost);
int x = 0;
switch (direction) {
case Direction::RIGHT:
x = 0;
break;
case Direction::DOWN:
x = 2;
break;
case Direction::LEFT:
x = 4;
break;
case Direction::UP:
x = 6;
break;
default:
x = 0;
break;
}
if (alternative)
x++;
return { x, y };
}
2021-07-01 12:53:52 +00:00
constexpr PositionInt initialFrightened(int animationIndex) {
return (animationIndex % 2) == 0 ? Atlas::ghost_frightened2 : Atlas::ghost_frightened1;
}
constexpr PositionInt endingFrightened(int animationIndex) {
std::array<PositionInt, 4> positions = { Atlas::ghost_frightened1,
Atlas::ghost_frightened2,
Atlas::ghost_frightened3,
Atlas::ghost_frightened4 };
return positions[animationIndex];
}
2021-06-24 11:32:52 +00:00
}