![]() |
Kukatz 3D
0.1
Török Attila szakdolgozata
|
00001 /* 00002 * gameover.cpp - Kukatz 3D 00003 * Copyright (c) 2012 - TÖRÖK Attila (torokati44@gmail.com) 00004 * 00005 * This software is provided 'as-is', without any express or implied 00006 * warranty. In no event will the authors be held liable for any damages 00007 * arising from the use of this software. 00008 * 00009 * Permission is granted to anyone to use this software for any purpose, 00010 * including commercial applications, and to alter it and redistribute it 00011 * freely, subject to the following restrictions: 00012 * 00013 * 1. The origin of this software must not be misrepresented; you must not 00014 * claim that you wrote the original software. If you use this software 00015 * in a product, an acknowledgment in the product documentation would be 00016 * appreciated but is not required. 00017 * 00018 * 2. Altered source versions must be plainly marked as such, and must not be 00019 * misrepresented as being the original software. 00020 * 00021 * 3. This notice may not be removed or altered from any source 00022 * distribution. 00023 */ 00024 00025 #include "gameover.hpp" 00026 00027 #include <cstdio> 00028 #include <cmath> 00029 00030 #include "opengl.hpp" 00031 #include "guiimage.hpp" 00032 00033 #include "statemanager.hpp" 00034 #include "highscores.hpp" 00035 #include "scoremanager.hpp" 00036 #include "humanplayer.hpp" 00037 00038 GameOver::GameOver(unsigned int w, unsigned int h, const std::vector< Player* >& plyrs): 00039 StateBase(w, h), viewport(w, h), highscore(false) 00040 { 00041 resize(sf::Vector2i(w, h)); 00042 00043 gui.attach(new GUIImage("GROUND_2", 0.5f), 1, GUIElement::SCALE_MODE_BIGGER, 0.5f, 0.5f); 00044 00045 title = new GUIString(L"Játék vége", "#44"); 00046 00047 GUIElementContainer* square = new GUIElementContainer(4.0f / 3.0f); 00048 gui.attach(square, 1.0f, GUIElement::SCALE_MODE_SMALLER, 0.5f, 0.5f); 00049 00050 square->attach(title, 0.2f, GUIElement::SCALE_MODE_VERTICAL, 0.5f, 0.9f); 00051 00052 table = new GUIElementContainer(1.8f); 00053 square->attach(table, 0.6, GUIElement::SCALE_MODE_VERTICAL, 0.5, 0.2); 00054 00055 for (unsigned int i = 0; i < plyrs.size(); ++i) 00056 { 00057 players.push_back(player_t(plyrs[i]->name, plyrs[i]->score)); 00058 00059 HumanPlayer* hum_plyr = dynamic_cast< HumanPlayer* >(plyrs[i]); 00060 if (hum_plyr) 00061 { 00062 if (ScoreManager::instance().submit(hum_plyr->name, hum_plyr->score)) 00063 { 00064 highscore = true; 00065 } 00066 } 00067 } 00068 00069 for (int i = 0; i < int(players.size() - 1); ++i) 00070 { 00071 for (int j = i + 1; j < (int)players.size(); ++j) 00072 { 00073 if (players[i].score < players[j].score) 00074 { 00075 player_t temp = players[i]; 00076 players[i] = players[j]; 00077 players[j] = temp; 00078 } 00079 } 00080 } 00081 00082 for (unsigned int i = 0; i < players.size(); ++i) 00083 { 00084 table->attach(new GUIString(players[i].name, "#44"), 1.0f / 6.0f, 00085 GUIElement::SCALE_MODE_VERTICAL, 0.0f, 00086 1.0f - ((float)i * 0.2f)); 00087 00088 char buffer[32]; 00089 sprintf(buffer, "%d", (int)round(players[i].score)); 00090 00091 table->attach(new GUIString(buffer, "#44"), 1.0f / 6.0f, 00092 GUIElement::SCALE_MODE_VERTICAL, 1.0f, 00093 1.0f - ((float)i * 0.2f)); 00094 } 00095 } 00096 00097 void GameOver::process_events(std::vector< sf::Event >& events) 00098 { 00099 for (unsigned int i = 0; i < events.size(); ++i) 00100 { 00101 switch (events[i].Type) 00102 { 00103 case sf::Event::KeyPressed: 00104 { 00105 switch (events[i].Key.Code) 00106 { 00107 case sf::Key::Escape: 00108 case sf::Key::Return: 00109 { 00110 pop(); 00111 if (highscore) 00112 { 00113 StateManager::instance().push_state(new HighScores(size.x, size.y)); 00114 } 00115 } 00116 break; 00117 default: 00118 { 00119 00120 } 00121 break; 00122 } 00123 } 00124 break; 00125 default: 00126 { 00127 00128 } 00129 break; 00130 } 00131 } 00132 } 00133 00134 void GameOver::render() 00135 { 00136 viewport.look_2d(); 00137 gui.render(); 00138 } 00139 00140 void GameOver::update(float) 00141 { 00142 00143 } 00144 00145 void GameOver::resize(const sf::Vector2i& s) 00146 { 00147 viewport.size = s; 00148 gui.size = s; 00149 size = s; 00150 } 00151 00152 GameOver::~GameOver() 00153 { 00154 00155 }