/
title_screen.cpp
150 lines (128 loc) · 4.34 KB
/
title_screen.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// SuperTux
// Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// 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 3 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, see <http://www.gnu.org/licenses/>.
#include "supertux/title_screen.hpp"
#include "audio/sound_manager.hpp"
#include "gui/menu.hpp"
#include "gui/menu_manager.hpp"
#include "lisp/parser.hpp"
#include "object/camera.hpp"
#include "object/player.hpp"
#include "supertux/fadeout.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#include "supertux/menu/menu_storage.hpp"
#include "supertux/resources.hpp"
#include "supertux/screen_manager.hpp"
#include "supertux/sector.hpp"
#include "supertux/textscroller.hpp"
#include "supertux/world.hpp"
#include "util/file_system.hpp"
#include "util/gettext.hpp"
#include "util/reader.hpp"
#include "video/drawing_context.hpp"
#include <sstream>
#include <version.h>
TitleScreen::TitleScreen(PlayerStatus* player_status) :
frame(),
controller(),
titlesession(),
copyright_text()
{
controller.reset(new CodeController());
titlesession.reset(new GameSession("levels/misc/menu.stl", player_status));
Player* player = titlesession->get_current_sector()->player;
player->set_controller(controller.get());
player->set_speedlimit(230); //MAX_WALK_XM
frame = Surface::create("images/engine/menu/frame.png");
copyright_text = "SuperTux " PACKAGE_VERSION "\n" +
_("Copyright") + " (c) 2003-2014 SuperTux Devel Team\n" +
_("This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to\n"
"redistribute it under certain conditions; see the file COPYING for details.\n"
);
}
void
TitleScreen::make_tux_jump()
{
static bool jumpWasReleased = true;
Sector* sector = titlesession->get_current_sector();
Player* tux = sector->player;
controller->update();
controller->press(Controller::RIGHT);
// Check if we should press the jump button
Rectf lookahead = tux->get_bbox();
lookahead.p2.x += 96;
bool pathBlocked = !sector->is_free_of_statics(lookahead);
if ((pathBlocked && jumpWasReleased) || !tux->on_ground()) {
controller->press(Controller::JUMP);
jumpWasReleased = false;
} else {
jumpWasReleased = true;
}
// Wrap around at the end of the level back to the beginning
if(sector->get_width() - 320 < tux->get_pos().x) {
sector->activate("main");
sector->camera->reset(tux->get_pos());
}
}
TitleScreen::~TitleScreen()
{
}
void
TitleScreen::setup()
{
Sector* sector = titlesession->get_current_sector();
if(Sector::current() != sector) {
sector->play_music(LEVEL_MUSIC);
sector->activate(sector->player->get_pos());
}
MenuManager::instance().set_menu(MenuStorage::MAIN_MENU);
}
void
TitleScreen::leave()
{
Sector* sector = titlesession->get_current_sector();
sector->deactivate();
MenuManager::instance().clear_menu_stack();
}
void
TitleScreen::draw(DrawingContext& context)
{
Sector* sector = titlesession->get_current_sector();
sector->draw(context);
// FIXME: Add something to scale the frame to the resolution of the screen
//context.draw_surface(frame, Vector(0,0),LAYER_FOREGROUND1);
context.draw_text(Resources::small_font,
copyright_text,
Vector(5, SCREEN_HEIGHT - 50),
ALIGN_LEFT, LAYER_FOREGROUND1);
}
void
TitleScreen::update(float elapsed_time)
{
g_screen_manager->set_speed(0.6f);
Sector* sector = titlesession->get_current_sector();
sector->update(elapsed_time);
make_tux_jump();
MenuManager::instance().check_menu();
// reopen menu if user closed it (so that the app doesn't close when user
// accidently hit ESC)
if(!MenuManager::instance().is_active() && g_screen_manager->has_no_pending_fadeout())
{
MenuManager::instance().set_menu(MenuStorage::MAIN_MENU);
}
}
/* EOF */