Debian Codegraph @

src/game/carstatusview.cpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2013 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #include "carstatusview.hpp"
17 #include "car.hpp"
18 #include "renderer.hpp"
19
20 #include <MCAssetManager>
21 #include <MCSurface>
22
23 CarStatusView::CarStatusView()
24 : m_body(MCAssetManager::instance().surfaceManager().surface("tireStatusIndicatorBody"))
25 , m_tires(MCAssetManager::instance().surfaceManager().surface("tireStatusIndicatorTires"))
26 , m_car(nullptr)
27 {
28 setDimensions(static_cast<int>(m_body->height()), static_cast<int>(m_tires->width()));
29
30 m_body->setColor(MCGLColor(1.0f, 1.0f, 1.0f, 0.9f));
31 }
32
33 void CarStatusView::render()
34 {
35 const float damageLevel = m_car->damageLevel();
36 m_body->setColor(MCGLColor(1.0f, damageLevel, damageLevel, 0.9f));
37 m_body->render(nullptr, MCVector3dF(x(), y(), 0), 0);
38
39 const float tireWearLevel = m_car->tireWearLevel();
40 m_tires->setColor(MCGLColor(1.0f, tireWearLevel, tireWearLevel, 0.9f));
41 m_tires->render(nullptr, MCVector3dF(x(), y(), 0), 0);
42 }
43
44 void CarStatusView::setCarToFollow(const Car & car)
45 {
46 m_car = &car;
47 }