Fix pickatile & some warnings
This commit is contained in:
parent
a8ab13f978
commit
15075e33af
2
ADG5.cpp
2
ADG5.cpp
@ -14,7 +14,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
auto console = tcod::Console(80, 50);
|
||||
auto params = TCOD_ContextParams{};
|
||||
auto tileset = tcod::load_tilesheet("terminal10x16_gs_ro.png", { 16, 16 }, tcod::CHARMAP_CP437);
|
||||
auto tileset = tcod::load_tilesheet("imgs/terminal10x16_gs_ro.png", { 16, 16 }, tcod::CHARMAP_CP437);
|
||||
params.tileset = tileset.get();
|
||||
params.console = console.get();
|
||||
params.window_title = "Andrew's Dungeon Game 5";
|
||||
|
@ -41,7 +41,7 @@ Actor::~Actor() {
|
||||
float Actor::getDistance(int cx, int cy) const {
|
||||
int dx = x - cx;
|
||||
int dy = y - cy;
|
||||
return sqrtf(dx * dx + dy * dy);
|
||||
return sqrtf((float)(dx * dx + dy * dy));
|
||||
}
|
||||
|
||||
void Actor::save(TCODZip& zip) {
|
||||
|
4
Ai.cpp
4
Ai.cpp
@ -68,8 +68,8 @@ void PlayerAi::update(Actor* owner) {
|
||||
engine->context->convert_event_coordinates(event);
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_MOUSE_MOTION:
|
||||
engine->mouse.cx = event.motion.x;
|
||||
engine->mouse.cy = event.motion.y;
|
||||
engine->mouse.cx = (int)event.motion.x;
|
||||
engine->mouse.cy = (int)event.motion.y;
|
||||
break;
|
||||
case SDL_EVENT_KEY_UP:
|
||||
switch (event.key.key) {
|
||||
|
@ -27,12 +27,7 @@ endif()
|
||||
|
||||
add_custom_command(
|
||||
TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/menu_background1.png
|
||||
${CMAKE_CURRENT_BINARY_DIR}/menu_background1.png)
|
||||
add_custom_command(
|
||||
TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/terminal10x16_gs_ro.png
|
||||
${CMAKE_CURRENT_BINARY_DIR}/terminal10x16_gs_ro.png)
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/imgs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/imgs)
|
||||
# TODO: Add tests and install targets if needed.
|
||||
|
26
Engine.cpp
26
Engine.cpp
@ -24,6 +24,8 @@ Engine::Engine(int screenWidth, int screenHeight, tcod::Context *context, tcod::
|
||||
mouse.cy = 0;
|
||||
mouse.rbutton_pressed = false;
|
||||
mouse.lbutton_pressed = false;
|
||||
gameStatus = STARTUP;
|
||||
stairs = nullptr;
|
||||
}
|
||||
|
||||
void Engine::init() {
|
||||
@ -147,22 +149,29 @@ bool Engine::pickATile(int* x, int* y, float maxRange) {
|
||||
while (true) {
|
||||
render(false);
|
||||
|
||||
int offset_x = engine->player->x - Engine::VIEW_WIDTH / 2;
|
||||
int offset_y = engine->player->y - Engine::VIEW_HEIGHT / 2;
|
||||
|
||||
// highlight the possible range
|
||||
for (int cx = 0; cx < map->width; cx++) {
|
||||
for (int cy = 0; cy < map->height; cy++) {
|
||||
for (int cx = offset_x; cx < offset_x + engine->VIEW_WIDTH; cx++) {
|
||||
for (int cy = offset_y; cy < offset_y + engine->VIEW_HEIGHT; cy++) {
|
||||
if (map->isInFov(cx, cy)
|
||||
&& (maxRange == 0 || player->getDistance(cx, cy) <= maxRange)) {
|
||||
TCOD_ColorRGBA col = console->at(cx, cy).bg;
|
||||
TCOD_ColorRGBA col = console->at(cx - offset_x, cy - offset_y).bg;
|
||||
|
||||
col.r = (int)((float)col.r * 1.2f);
|
||||
col.g = (int)((float)col.g * 1.2f);
|
||||
col.b = (int)((float)col.b * 1.2f);
|
||||
|
||||
console->at(cx, cy).bg = col;
|
||||
console->at(cx - offset_x, cy - offset_y).bg = col;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_Event event;
|
||||
|
||||
mouse.lbutton_pressed = false;
|
||||
mouse.rbutton_pressed = false;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
engine->context->convert_event_coordinates(event);
|
||||
switch (event.type) {
|
||||
@ -180,16 +189,17 @@ bool Engine::pickATile(int* x, int* y, float maxRange) {
|
||||
}
|
||||
}
|
||||
|
||||
if (map->isInFov(mouse.cx, mouse.cy)
|
||||
&& (maxRange == 0 || player->getDistance(mouse.cx, mouse.cy) <= maxRange)) {
|
||||
if (map->isInFov(mouse.cx + offset_x, mouse.cy + offset_y)
|
||||
&& (maxRange == 0 || player->getDistance(mouse.cx + offset_x, mouse.cy + offset_y) <= maxRange)) {
|
||||
console->at(mouse.cx, mouse.cy).bg = TCOD_ColorRGBA(100, 100, 100, 255);
|
||||
if (mouse.lbutton_pressed) {
|
||||
*x = mouse.cx;
|
||||
*y = mouse.cy;
|
||||
*x = mouse.cx + offset_x;
|
||||
*y = mouse.cy + offset_y;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mouse.rbutton_pressed) {
|
||||
|
||||
return false;
|
||||
}
|
||||
context->present(*console);
|
||||
|
19
Gui.cpp
19
Gui.cpp
@ -48,8 +48,8 @@ void Gui::render() {
|
||||
TCOD_ColorRGB(255,100,100), TCOD_ColorRGB(100, 0, 0));
|
||||
// draw the XP bar
|
||||
PlayerAi* ai = (PlayerAi*)engine->player->ai;
|
||||
renderBar(1, 5, BAR_WIDTH, "XP(" + std::to_string(ai->xpLevel) + ")", engine->player->destructible->xp,
|
||||
ai->getNextLevelXp(),
|
||||
renderBar(1, 5, BAR_WIDTH, "XP(" + std::to_string(ai->xpLevel) + ")", (float)engine->player->destructible->xp,
|
||||
(float)ai->getNextLevelXp(),
|
||||
TCOD_ColorRGB(255, 100, 255), TCOD_ColorRGB(100,0,100));
|
||||
|
||||
tcod::print(con, { 3, 3 }, "Dungeon level " + std::to_string(engine->level), TCOD_ColorRGB(255, 255, 255), std::nullopt);
|
||||
@ -59,7 +59,7 @@ void Gui::render() {
|
||||
float colorCoef = 0.4f;
|
||||
for (Message** it = log.begin(); it != log.end(); it++) {
|
||||
Message* message = *it;
|
||||
tcod::print(con, { MSG_X, y }, message->text, TCOD_ColorRGB(message->col.r * colorCoef, message->col.g * colorCoef, message->col.b * colorCoef), std::nullopt);
|
||||
tcod::print(con, { MSG_X, y }, message->text, TCOD_ColorRGB((int)((float)message->col.r * colorCoef), (int)((float)message->col.g * colorCoef), (int)((float)message->col.b * colorCoef)), std::nullopt);
|
||||
y++;
|
||||
if (colorCoef < 1.0f) {
|
||||
colorCoef += 0.3f;
|
||||
@ -97,7 +97,7 @@ void Gui::message(const TCOD_ColorRGB& col, const char* text, ...) {
|
||||
va_list ap;
|
||||
char buf[128];
|
||||
va_start(ap, text);
|
||||
vsprintf(buf, text, ap);
|
||||
vsnprintf(buf, 128, text, ap);
|
||||
va_end(ap);
|
||||
|
||||
char* lineBegin = buf;
|
||||
@ -130,20 +130,21 @@ void Gui::renderMouseLook() {
|
||||
}
|
||||
char buf[128] = "";
|
||||
bool first = true;
|
||||
std::stringstream ss;
|
||||
for (Actor** it = engine->actors.begin(); it != engine->actors.end(); it++) {
|
||||
Actor* actor = *it;
|
||||
// find actors under the mouse cursor
|
||||
if (actor->x == engine->mouse.cx && actor->y == engine->mouse.cy) {
|
||||
if (!first) {
|
||||
strcat(buf, ", ");
|
||||
ss << ", ";
|
||||
}
|
||||
else {
|
||||
first = false;
|
||||
}
|
||||
strcat(buf, actor->name.c_str());
|
||||
ss << actor->name;
|
||||
}
|
||||
}
|
||||
tcod::print(con, { 1, 0 }, buf, TCOD_ColorRGB(200, 200, 200), std::nullopt);
|
||||
tcod::print(con, { 1, 0 }, ss.str(), TCOD_ColorRGB(200, 200, 200), std::nullopt);
|
||||
}
|
||||
|
||||
void Gui::save(TCODZip& zip) {
|
||||
@ -198,8 +199,8 @@ Menu::MenuItemCode Menu::pick(tcod::Context *ctx, tcod::Console *con, DisplayMod
|
||||
menuy += 3;
|
||||
}
|
||||
else {
|
||||
static TCODImage img("menu_background1.png");
|
||||
img.blit2x(*con, 0, 0);
|
||||
static TCODImage img("imgs/menu_background1.png");
|
||||
tcod::draw_quartergraphics(*con, img);
|
||||
TCOD_ColorRGB fg(200, 180, 50);
|
||||
TCOD_ColorRGB bg(0, 0, 0);
|
||||
menux = 7;
|
||||
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
Loading…
x
Reference in New Issue
Block a user