Skip to content
Snippets Groups Projects
Commit 70b3c323 authored by Max Cherris's avatar Max Cherris
Browse files

Add building selection

parent 4b69d0a8
No related branches found
No related tags found
1 merge request!15Merge units into main
......@@ -29,6 +29,16 @@ bool Level::clickCheck(int mouseX, int mouseY) {
int tileX = mouseX/(16*RENDERING_SCALE);
int tileY = mouseY/(16*RENDERING_SCALE);
if(selectUnit(tileX, tileY)) return true;
if(selectBuilding(tileX, tileY)) return true;
std::cout << "Neither building nor unit clicked" << std::endl;
return false;
}
bool Level::selectUnit (int tileX, int tileY) {
for (auto& unit : units) {
if(unit.x == tileX && unit.y == tileY) {
......@@ -37,8 +47,23 @@ bool Level::clickCheck(int mouseX, int mouseY) {
return true;
}
}
selectedUnit = nullptr;
return false;
}
bool Level::selectBuilding (int tileX, int tileY) {
for (auto& building : buildings) {
if(building.x == tileX && building.y == tileY) {
//std::cout << "X:" << unit.x << "Y:" << unit.y << std::endl;
selectedBuilding = &building;
return true;
}
}
selectedBuilding = nullptr;
return false;
}
void Level::handleEvent(Engine &engine, SDL_Event &event) {
......@@ -50,8 +75,16 @@ void Level::handleEvent(Engine &engine, SDL_Event &event) {
{
case SDL_MOUSEBUTTONDOWN:
if(clickCheck(event.button.x, event.button.y)) {
if(selectedUnit) {
selectedUnit->onClick(event, units);
}
if(selectedBuilding) {
//building stuff
}
}
break;
default:
......
......@@ -34,6 +34,9 @@ private:
std::vector<Unit> units;
std::vector<Effect> effects;
Unit* selectedUnit;
Building* selectedBuilding;
bool selectUnit (int tileX, int tileY);
bool selectBuilding(int tileX, int tileY);
bool clickCheck(int mouseX, int mouseY);
};
......
......@@ -106,6 +106,19 @@ namespace advanced_wars
this->y = posY;
}
/*
Features:
//select unit
- show context menu
- show move range
- MAYBE show valid targets
//deselect unit
//attack unit
- show context menu
*/
void Unit::onClick(SDL_Event event, std::vector<Unit> &unitVector)
{
......@@ -129,6 +142,8 @@ namespace advanced_wars
};
}
*/
//make move range calc
break;
case SDL_BUTTON_RIGHT:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment