/
cellmaster.cpp
executable file
·85 lines (74 loc) · 2.63 KB
/
cellmaster.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* G.O.L.F.
// Copyright (C) 2015 LucKey Productions (luckeyproductions.nl)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "cellmaster.h"
namespace Urho3D {
template <> unsigned MakeHash(const IntVector2& value)
{
return LucKey::IntVector2ToHash(value);
}
}
CellMaster::CellMaster(Context *context, MasterControl *masterControl):
Object(context),
masterControl_{masterControl},
width_{200},
height_{60}
{
rootNode_ = masterControl_->world_.scene_->CreateChild("CellMaster");
rootNode_->SetPosition(Vector3::ZERO);
for (int i = 0; i < width_; ++i){
CellRing* newRing = new CellRing(context_, masterControl_, this, height_, i);
newRing->rootNode_->SetPosition(Vector3(0.0f, 0.0f, 10.0f));
newRing->rootNode_->RotateAround(rootNode_->GetPosition(), Quaternion(0.0f, 360.0f*i/width_, 0.0f), TS_PARENT);
rings_.Push(newRing);
}
SetTargetRoll(180.0f);
}
void CellMaster::AddCellToMaps(Cell* cell, IntVector2 coords)
{
unsigned id = cell->GetID();
cellsById_[id] = SharedPtr<Cell>(cell);
cellCoords_[coords] = id;
}
void CellMaster::SetTargetRoll(float angle)
{
for (unsigned r = 0; r < rings_.Size(); ++r){
rings_[r]->SetTargetRotation(LucKey::Cycle(angle, 0.0f, 360.0f));
}
}
void CellMaster::UpdateCells()
{
Vector<SharedPtr<Cell> > cells{cellsById_.Values()};
for (unsigned c = 0; c < cells.Size(); ++c){
IntVector2 coords = cells[c]->GetCoords();
cells[c]->SetType(masterControl_->game_->GetCell(coords.x_, coords.y_));
}
}
Cell* CellMaster::GetCell(unsigned id)
{
return cellsById_[id].Get();
}
float CellMaster::RowToRotation(int row)
{
float normalizedRow = static_cast<float>(row) / static_cast<float>(height_);
return normalizedRow * 360.0f;
}
float CellMaster::ColumnToRotation(int row)
{
float normalizedColumn = static_cast<float>(row) / static_cast<float>(width_);
return normalizedColumn * 360.0f - 90.0f;
}