Skip to content

Commit

Permalink
Merge pull request #30 from nonorze-VOXX/easyRoad
Browse files Browse the repository at this point in the history
Easy road
  • Loading branch information
huhuhu0420 authored Apr 6, 2023
2 parents 7bfc903 + 82e3c53 commit 036234f
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 51 deletions.
19 changes: 9 additions & 10 deletions Source/Game/BtdClass/Bloon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ namespace Btd

void Bloon::Move(vector<Vector2> route)
{
Vector2 nowLocal;
nowLocal.X = static_cast<float>(GetLeft());
nowLocal.Y = static_cast<float>(GetTop());
Vector2 nowLocal = GetBottomCenter();
Vector2 target = route[nowRouteTarget];
if (static_cast<int>(target.X) == static_cast<int>(nowLocal.X) && static_cast<int>(target.Y) == static_cast<int>
(nowLocal.Y))
Expand All @@ -65,14 +63,15 @@ namespace Btd
Vector2 moveDirection = Normailize(deltaMove);
float speed = GetSpeed();
deltaMove = {moveDirection.X * speed, moveDirection.Y * speed};
int left = GetLeft() + static_cast<int>(deltaMove.X);
int top = GetTop() + static_cast<int>(deltaMove.Y);
if (Vector2Distance({static_cast<float>(left), static_cast<float>(top)}, target) < speed * 2 / 3)

int x = static_cast<int>(nowLocal.X) + static_cast<int>(deltaMove.X);
int y = static_cast<int>(nowLocal.Y) + static_cast<int>(deltaMove.Y);
if (Vector2Distance({static_cast<float>(x), static_cast<float>(y)}, target) < speed * 2 / 3)
{
left = static_cast<int>(target.X);
top = static_cast<int>(target.Y);
x = static_cast<int>(target.X);
y = static_cast<int>(target.Y);
}
SetTopLeft(left, top);
SetBottomCenter(x, y);
}

BloonType::BloonType Bloon::GetType()
Expand All @@ -82,7 +81,6 @@ namespace Btd

void Bloon::Pop(int damage, DamageType damageType)
{
this;
if (resistDamegeMap[type][damageType])
{
_layer -= damage;
Expand All @@ -93,6 +91,7 @@ namespace Btd
return;
}
SetFrameIndexOfBitmap(_layer);
Setspeed(static_cast<float>(0.5 * _layer * _layer + _layer + 3));
}

bool Bloon::IsPoped()
Expand Down
23 changes: 0 additions & 23 deletions Source/Game/BtdClass/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,15 @@
namespace Btd
{
void GameManager::OnBeginState()

{
GameFlow = Prepare;
round = 0;
TowerFactory::TowerVector.clear();
Vector2 mapSize = {
static_cast<float>(map->GetBackground().GetWidth()),
static_cast<float>(map->GetBackground().GetHeight())
};
map->InitFactoryButton();
map->SetStartPosition({static_cast<float>(0), mapSize.Y * 0.4F});
BloonFactory::ClearActiveBloon();
live = map->InitLives;
money = map->InitMoney;
db.LoadRounds();
map->SetRoute({
{mapSize.X * 0.11F, mapSize.Y * 0.4F},
{mapSize.X * 0.11F, mapSize.Y * 0.12F},
{mapSize.X * 0.3F, mapSize.Y * 0.12F},
{mapSize.X * 0.3F, mapSize.Y * 0.67F},
{mapSize.X * 0.05F, mapSize.Y * 0.67F},
{mapSize.X * 0.05F, mapSize.Y * 0.85F},
{mapSize.X * 0.65F, mapSize.Y * 0.85F},
{mapSize.X * 0.65F, mapSize.Y * 0.53F},
{mapSize.X * 0.45F, mapSize.Y * 0.53F},
{mapSize.X * 0.45F, mapSize.Y * 0.3F},
{mapSize.X * 0.65F, mapSize.Y * 0.3F},
{mapSize.X * 0.65F, mapSize.Y * 0.06F},
{mapSize.X * 0.38F, mapSize.Y * 0.06F},
{mapSize.X * 0.38F, mapSize.Y * 0.F},
{mapSize.X * 0.38F, mapSize.Y * -0.08F},
});
map->SetRounds(db.GetRounds());
BloonFactory::SetNextRound(map->GetRounds()[round]);
IsLose = false;
Expand Down
13 changes: 12 additions & 1 deletion Source/Game/BtdClass/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,20 @@ namespace Btd

void GameObject::SetCenter(int x, int y)
{
SetTopLeft(x-GetWidth()/2, y-GetHeight()/2);
SetTopLeft(x - GetWidth() / 2, y - GetHeight() / 2);
}

void GameObject::SetBottomCenter(int x, int y)
{
SetTopLeft(x - GetWidth() / 2, y - GetHeight());
}

Vector2 GameObject::GetBottomCenter()
{
return {static_cast<float>(GetLeft()) + GetWidth() / 2, static_cast<float>(GetTop()) + GetHeight()};
}


bool GameObject::IsCursorFocus()
{
if (GetLeft() < GetCursorPosX() && GetCursorPosX() < GetLeft() + GetWidth() &&
Expand Down
3 changes: 3 additions & 0 deletions Source/Game/BtdClass/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ namespace Btd
string GetTag();
Vector2 GetCenter();
void SetCenter(int x, int y);
void SetBottomCenter(int x, int y);
Vector2 GetBottomCenter();
bool IsCursorFocus();
void SetClicked(bool clicked);
void SetHeight(int height);
void SetWidth(int width);
};

bool IsOverlap(GameObject& character, GameObject& other);
bool IsCursorInObj(GameObject target);
}
67 changes: 60 additions & 7 deletions Source/Game/BtdClass/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,59 @@

namespace Btd
{
void Map::SetRoutesByMap(MapType::MapType type)
{
Vector2 mapSize = {
static_cast<float>(GetBackground().GetWidth()),
static_cast<float>(GetBackground().GetHeight())
};
switch (type)
{
case MapType::easy:
SetStartPosition({static_cast<float>(0), mapSize.Y * 0.4F});
SetRoute({
{mapSize.X * 0.29F, mapSize.Y * 0.5F},
{mapSize.X * 0.29F, mapSize.Y * 0.25F},
{mapSize.X * 0.17F, mapSize.Y * 0.25F},
{mapSize.X * 0.17F, mapSize.Y * 0.08F},
{mapSize.X * 0.65F, mapSize.Y * 0.08F},
{mapSize.X * 0.65F, mapSize.Y * 0.25F},
{mapSize.X * 0.45F, mapSize.Y * 0.25F},
{mapSize.X * 0.45F, mapSize.Y * 0.43F},
{mapSize.X * 0.65F, mapSize.Y * 0.43F},
{mapSize.X * 0.65F, mapSize.Y * 0.62F},
{mapSize.X * 0.16F, mapSize.Y * 0.62F},
{mapSize.X * 0.16F, mapSize.Y * 0.9F},
{mapSize.X * 0.35F, mapSize.Y * 0.9F},
{mapSize.X * 0.35F, mapSize.Y * 0.75F},
{mapSize.X * 0.55F, mapSize.Y * 0.75F},
{mapSize.X * 0.55F, mapSize.Y * 1.0F},
});
break;
case MapType::medium:
SetStartPosition({static_cast<float>(0), mapSize.Y * 0.5F});
SetRoute({
{mapSize.X * 0.14F, mapSize.Y * 0.5F},
{mapSize.X * 0.14F, mapSize.Y * 0.22F},
{mapSize.X * 0.32F, mapSize.Y * 0.22F},
{mapSize.X * 0.32F, mapSize.Y * 0.72F},
{mapSize.X * 0.07F, mapSize.Y * 0.72F},
{mapSize.X * 0.07F, mapSize.Y * 0.90F},
{mapSize.X * 0.67F, mapSize.Y * 0.90F},
{mapSize.X * 0.67F, mapSize.Y * 0.63F},
{mapSize.X * 0.47F, mapSize.Y * 0.63F},
{mapSize.X * 0.47F, mapSize.Y * 0.4F},
{mapSize.X * 0.67F, mapSize.Y * 0.4F},
{mapSize.X * 0.67F, mapSize.Y * 0.13F},
{mapSize.X * 0.40F, mapSize.Y * 0.13F},
{mapSize.X * 0.40F, mapSize.Y * -0.18F},
});
break;
case MapType::hard: break;
default: ;
}
}

void Map::InitRoad(MapType::MapType type)
{
int roadSize[3];
Expand All @@ -33,17 +86,17 @@ namespace Btd
{
}
};
for (int i =0; i<3; i++)
for (int i = 0; i < 3; i++)
{
roadSize[i] = (int)location[i].size();
roadSize[i] = static_cast<int>(location[i].size());
}
for (int i = 0; i < roadSize[type]; i++)
{
GameObject tmpRoad;
string filePath = "resources/map/" + roadPath[type] + "/roads/road_" + std::to_string(i + 1) + ".bmp";
tmpRoad.LoadBitmapByString({filePath});
tmpRoad.SetHeight(tmpRoad.GetHeight()-10);
tmpRoad.SetWidth(tmpRoad.GetWidth()-10);
tmpRoad.SetHeight(tmpRoad.GetHeight() - 10);
tmpRoad.SetWidth(tmpRoad.GetWidth() - 10);
tmpRoad.SetTopLeft(static_cast<int>(location[type][i].X), static_cast<int>(location[type][i].Y));
tmpRoad.SetTag("road");
_road.push_back(tmpRoad);
Expand All @@ -52,7 +105,7 @@ namespace Btd

void Map::ShowRoad()
{
for (int i = 0; i < (int)_road.size(); i++)
for (int i = 0; i < static_cast<int>(_road.size()); i++)
{
_road[i].ShowBitmap();
}
Expand Down Expand Up @@ -140,9 +193,9 @@ namespace Btd

bool Map::IsOverLapRoad(GameObject target)
{
for (int i=0; i<(int)_road.size(); i++)
for (int i = 0; i < static_cast<int>(_road.size()); i++)
{
if(Btd::IsOverlap(_road[i], target))
if (Btd::IsOverlap(_road[i], target))
{
return true;
}
Expand Down
1 change: 1 addition & 0 deletions Source/Game/BtdClass/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Btd
public:
Map() = default;
~Map() override = default;
void SetRoutesByMap(MapType::MapType type);
const int InitMoney = 650;
const int InitLives = 40;
virtual void InitRoad(MapType::MapType type);
Expand Down
20 changes: 10 additions & 10 deletions Source/Game/mygame_initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ CGameStateInit::CGameStateInit(CGame* g) : CGameState(g)
{
}

void CGameStateInit::InitSelectedMaps ()
void CGameStateInit::InitSelectedMaps()
{
vector<string> backgroundBmps[3] = {
{"resources/map/easy/map.bmp"},
{"resources/map/medium/map.bmp"},
{"resources/map/hard/map.bmp"}
{"resources/map/hard/map.bmp"}
};
for (int i=0; i<3; i++)
for (int i = 0; i < 3; i++)
{
shared_ptr<Btd::Map> m = make_shared<Btd::Map>(Btd::Map());
auto m = make_shared<Btd::Map>(Btd::Map());
m->InitBackground(static_cast<Btd::MapType::MapType>(i));
m->InitRoad(static_cast<Btd::MapType::MapType>(i));
selectedMaps.push_back(m);
Expand Down Expand Up @@ -72,11 +72,12 @@ void CGameStateInit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)

void CGameStateInit::OnLButtonDown(UINT nFlags, CPoint point)
{
for (int i=0; i<3; i++)
for (int i = 0; i < 3; i++)
{
if (Btd::IsCursorInObj(static_cast<Btd::GameObject>(_mapButton[i])))
if (IsCursorInObj(static_cast<Btd::GameObject>(_mapButton[i])))
{
_mapButton[i].SetClicked(true);
map->SetRoutesByMap(static_cast<Btd::MapType::MapType>(i));
Btd::GameManager::map = map;
GotoGameState(GAME_STATE_RUN);
}
Expand All @@ -85,14 +86,13 @@ void CGameStateInit::OnLButtonDown(UINT nFlags, CPoint point)

void CGameStateInit::OnMouseMove(UINT nFlags, CPoint point)
{
for (int i=0; i<3; i++)
for (int i = 0; i < 3; i++)
{
if (Btd::IsCursorInObj(static_cast<Btd::GameObject>(_mapButton[i])))
if (IsCursorInObj(static_cast<Btd::GameObject>(_mapButton[i])))
{
map = selectedMaps[i];
}
}

}

void showInfoText()
Expand All @@ -115,7 +115,7 @@ void CGameStateInit::OnShow()
map->ShowBackground();
map->ShowRoad();
startButton.ShowBitmap();
for (int i=0; i< 3; i++)
for (int i = 0; i < 3; i++)
{
_mapButton[i].ShowBitmap();
}
Expand Down

0 comments on commit 036234f

Please sign in to comment.