allowing now space characters in names, tweaked bonus point calculation and fixed a ViewState bug
parent
b08a835bfb
commit
934bb1f30e
|
@ -332,7 +332,7 @@ bool Model::PullGlobalHighscore(std::stringstream &highscore_stream) {
|
|||
if (ip_address[3] < 0)
|
||||
ip_address[3] += 256;
|
||||
|
||||
Engine::LogMessage ("Pulling global highscore from server %s (%d.%d.%d.%d)",
|
||||
Engine::LogDebug ("Pulling global highscore from server %s (%d.%d.%d.%d)",
|
||||
Model::HighscoreServerName.GetStringValue().c_str(),
|
||||
ip_address[0],
|
||||
ip_address[1],
|
||||
|
@ -389,7 +389,7 @@ bool Model::PullGlobalHighscore(std::stringstream &highscore_stream) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Model::SubmitGlobalHigscoreEntry (const std::string &name, const unsigned int points) {
|
||||
bool Model::SubmitGlobalHigscoreEntry (std::string name, const unsigned int points) {
|
||||
IPaddress server_address;
|
||||
|
||||
if (SDLNet_ResolveHost (&server_address, Model::HighscoreServerName.GetStringValue().c_str(), 80) == -1) {
|
||||
|
@ -416,6 +416,13 @@ bool Model::SubmitGlobalHigscoreEntry (const std::string &name, const unsigned i
|
|||
if (ip_address[3] < 0)
|
||||
ip_address[3] += 256;
|
||||
|
||||
std::string escaped_name = name;
|
||||
|
||||
while (escaped_name.find(" ") != std::string::npos) {
|
||||
escaped_name.replace (escaped_name.find(" "), 1, "%20");
|
||||
}
|
||||
|
||||
Engine::LogDebug ("Escaped name (%u) = '%s'", escaped_name.size(), escaped_name.c_str());
|
||||
|
||||
Engine::LogDebug ("Submitting highscore player_name='%s' score_value='%d' to server %s (%d.%d.%d.%d)",
|
||||
name.c_str(),
|
||||
|
@ -444,11 +451,13 @@ bool Model::SubmitGlobalHigscoreEntry (const std::string &name, const unsigned i
|
|||
std::string http_query_string;
|
||||
http_query_string = std::string ("GET ")
|
||||
+ Model::HighscoreServerPath.GetStringValue()
|
||||
+ std::string("&player_name=") + name
|
||||
+ std::string("&player_name=") + escaped_name
|
||||
+ std::string("&score_value=") + points_stringstream.str()
|
||||
+ std::string("&key=") + key
|
||||
+ std::string(" HTTP/1.1\r\nHost: asteroids.fysx.org\r\nConnection: close\r\n\r\n");
|
||||
|
||||
Engine::LogDebug ("http submitting query: %s", http_query_string.c_str());
|
||||
|
||||
int bytes_sent;
|
||||
bytes_sent = SDLNet_TCP_Send (server_socket, http_query_string.c_str(), http_query_string.size());
|
||||
|
||||
|
@ -697,7 +706,6 @@ void Model::SetGameState (const unsigned int &state) {
|
|||
|
||||
bool Model::OnGameOver() {
|
||||
Engine::LogDebug ("Points = %d lowest = %d", mPoints, mHighscoreList.back().points );
|
||||
SubmitHighscoreEntry (mPlayerName, mPoints);
|
||||
|
||||
if (mPoints > mHighscoreList.back().points) {
|
||||
Engine::LogMessage ("New Highscore!");
|
||||
|
@ -721,6 +729,10 @@ void Model::OnNewGame() {
|
|||
void Model::OnShipExplode () {
|
||||
Engine::PlaySound(Engine::GetResourceFullPath("/data/sounds/ship_destroyed.wav"));
|
||||
|
||||
if (GetPlayerEntityId() == Engine::NullEntityId) {
|
||||
return;
|
||||
}
|
||||
|
||||
mPlayerLives --;
|
||||
|
||||
if (mPlayerLives == 0) {
|
||||
|
@ -742,18 +754,19 @@ void Model::OnLevelComplete() {
|
|||
|
||||
if (level_time <= level_par_time) {
|
||||
// secret time bonus formula
|
||||
float a = 1.8,
|
||||
float a = 2,
|
||||
b = -4.2,
|
||||
c = 2;
|
||||
c = 2.2;
|
||||
float t_n = mLevelTimeSeconds / mLevelParTimeSeconds;
|
||||
float bonus_points_f = roundf ( (a * t_n * t_n + b * t_n + c) * static_cast<float>( mLevelPoints ));
|
||||
if (bonus_points_f < 0.)
|
||||
bonus_points_f = 0.;
|
||||
|
||||
// round to the closest decimal number
|
||||
bonus_points_f = roundf (bonus_points_f / 10.) * 10. + 100.;
|
||||
mLevelTimeBonusPoints = static_cast<unsigned int> (bonus_points_f);
|
||||
|
||||
Engine::LogMessage("Bonus Points: t_n = %f bonus_points_f = %f bonus_points = %u", t_n, bonus_points_f, mLevelTimeBonusPoints);
|
||||
Engine::LogDebug("Bonus Points: t_n = %f bonus_points_f = %f bonus_points = %u", t_n, bonus_points_f, mLevelTimeBonusPoints);
|
||||
|
||||
} else {
|
||||
mLevelTimeBonusPoints = 0;
|
||||
|
|
|
@ -74,7 +74,7 @@ class Model : public Engine::ModelBase {
|
|||
void ParseHighscoreStream (std::istream &highscore_stream);
|
||||
void LoadHighscoreList ();
|
||||
bool PullGlobalHighscore (std::stringstream &highscore_stream);
|
||||
bool SubmitGlobalHigscoreEntry (const std::string &name, const unsigned int points);
|
||||
bool SubmitGlobalHigscoreEntry (std::string name, const unsigned int points);
|
||||
void SubmitHighscoreEntry (const std::string &name, const unsigned int points);
|
||||
unsigned int AddLocalHighscoreEntry(const std::string &name, const unsigned int points);
|
||||
void LoadLocalHighscoreList ();
|
||||
|
|
|
@ -32,7 +32,7 @@ using namespace std;
|
|||
|
||||
namespace asteroids {
|
||||
|
||||
bool level_assemble_mode = true;
|
||||
static Engine::Variable VarCheatMode ("cheat_mode", "false");
|
||||
|
||||
int View::OnInit (int argc, char* argv[]) {
|
||||
ViewBase::OnInit (argc, argv);
|
||||
|
@ -527,31 +527,31 @@ void View::DrawUiMainMenu() {
|
|||
}
|
||||
|
||||
void View::DrawUiGameRunning() {
|
||||
// We choose a different font and also draw it aligned to the right as this
|
||||
// looks nicer with the points
|
||||
// SelectFont ("AldotheApache.ttf size=20 color=#ffffff");
|
||||
SelectFont("console.ttf size=23 color=#ffffff");
|
||||
|
||||
float str_width, str_height;
|
||||
std::ostringstream out_stream;
|
||||
|
||||
// --- Player Lives ---
|
||||
out_stream << GetModel()->GetPlayerLives() << " x ";
|
||||
DrawGLStringMeasure (out_stream.str().c_str(), &str_width, &str_height);
|
||||
Engine::GUI::Label (1, out_stream.str().c_str(), screen_right - str_width - 45, screen_bottom - 5);
|
||||
|
||||
mGUIShipSprite.DrawAt2D (screen_right - 20, screen_bottom - 8);
|
||||
|
||||
// --- Level Score ---
|
||||
out_stream.str("");
|
||||
out_stream << "Level Score: " << setw(5) << GetModel()->GetLevelPoints();
|
||||
DrawGLStringMeasure (out_stream.str().c_str(), &str_width, &str_height);
|
||||
Engine::GUI::Label (1, out_stream.str().c_str(), screen_right - str_width - 12, str_height + 48);
|
||||
|
||||
// --- Game Score ---
|
||||
out_stream.str("");
|
||||
out_stream << "Score: " << GetModel()->GetPoints();
|
||||
DrawGLStringMeasure (out_stream.str().c_str(), &str_width, &str_height);
|
||||
Engine::GUI::Label (1, out_stream.str().c_str(), screen_left + 3, str_height + 48);
|
||||
|
||||
if (level_assemble_mode) {
|
||||
if (VarCheatMode.GetBoolValue()) {
|
||||
if (Engine::GUI::CheckKeyPress(SDLK_PAGEDOWN)) {
|
||||
Engine::EventBasePtr level_complete_event (new Engine::EventBase());
|
||||
level_complete_event->mEventType = EventLevelComplete;
|
||||
|
@ -607,8 +607,8 @@ void View::DrawUiGameOver() {
|
|||
screen_bottom * 0.5 + 80, button_width, button_height)) {
|
||||
// We do not want the background to show the remaining bits of the game
|
||||
GetModel()->SetGameState(GameStatePaused);
|
||||
GetModel()->SubmitHighscoreEntry(GetModel()->GetPlayerName(), GetModel()->GetPoints());
|
||||
|
||||
PopViewState();
|
||||
PopViewState();
|
||||
PushViewState(ViewStateShowHighscore);
|
||||
}
|
||||
|
@ -617,7 +617,7 @@ void View::DrawUiGameOver() {
|
|||
void View::DrawUiLevelIntro() {
|
||||
SelectFont ("console.ttf size=23");
|
||||
|
||||
if (level_assemble_mode) {
|
||||
if (VarCheatMode.GetBoolValue()) {
|
||||
GetModel()->SetPlayerLives(100);
|
||||
}
|
||||
|
||||
|
@ -789,6 +789,17 @@ void View::DrawUiLevelComplete() {
|
|||
level_time_xpos, level_time_ypos + 3
|
||||
);
|
||||
|
||||
// ----- Level Points -----
|
||||
unsigned int level_points = GetModel()->GetLevelPoints() - GetModel()->GetLevelTimeBonusPoints();
|
||||
temp_stream.str("");
|
||||
temp_stream << "Level Points: " << setw(value_width) << level_points;
|
||||
|
||||
level_time_ypos += 32;
|
||||
|
||||
Engine::GUI::Label (1, temp_stream.str().c_str(),
|
||||
level_time_xpos, level_time_ypos + 3
|
||||
);
|
||||
|
||||
// ----- Bonus Points -----
|
||||
unsigned int bonus_points = GetModel()->GetLevelTimeBonusPoints();
|
||||
temp_stream.str("");
|
||||
|
@ -1177,7 +1188,7 @@ void View::DrawUiEnterPlayername() {
|
|||
SelectFont("console.ttf size=23");
|
||||
Engine::GUI::Label (1, "Enter your name: ", screen_right * 0.5 - 220, 250);
|
||||
|
||||
std::string valid_chars ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890-_!.");
|
||||
std::string valid_chars ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890-_!. ");
|
||||
|
||||
if (Engine::GUI::LineEditMasked (2, screen_right * 0.5 + 20, 238, player_name, 16, valid_chars)) {
|
||||
GetModel()->SetPlayerName(player_name);
|
||||
|
|
Loading…
Reference in New Issue