SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${SUPERTUX_OPENGL_SOURCES})
ENDIF(HAVE_OPENGL)
-## Precompile "a few" headers in GCC
-OPTION(PRECOMPILE_HEADERS "Precompile headers (experimental)" OFF)
-IF(PRECOMPILE_HEADERS)
- FILE(GLOB PRECOMPILED_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/badguy/badguy.hpp
- src/scripting/wrapper.hpp src/video/*.hpp src/math/*.hpp)
- FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "// Precompiled headers\n")
- FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "#ifndef __SUPERTUX_PRECOMPILED_HEADER\n")
- FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "#define __SUPERTUX_PRECOMPILED_HEADER\n")
- FOREACH(PRECOMPILED_HEADER ${PRECOMPILED_HEADERS})
- FILE(RELATIVE_PATH PRECOMPILED_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/src "${CMAKE_CURRENT_SOURCE_DIR}/${PRECOMPILED_HEADER}")
- FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "#include \"${PRECOMPILED_HEADER}\"\n")
- ENDFOREACH(PRECOMPILED_HEADER)
- FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh "#endif /*__SUPERTUX_PRECOMPILED_HEADER*/\n")
+## Build miniswig and generate miniswig wrapper
+
+OPTION(GENERATE_WRAPPER "Build miniswig and generate the wrapper" ${DEBUG})
+IF(GENERATE_WRAPPER)
+ ADD_SUBDIRECTORY(tools/miniswig)
ADD_CUSTOM_COMMAND(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch
- COMMAND ${CMAKE_CXX_COMPILER} -x "c++-header" $(CXX_FLAGS) ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh
- DEPENDS ${PRECOMPILED_HEADERS}
- COMMENT "Building precompiled header..."
+ OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp
+ COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_CXX_COMPILER}
+ ARGS -x "c++" -E -CC -DSCRIPTING_API src/scripting/wrapper.interface.hpp -o ${CMAKE_CURRENT_BINARY_DIR}/miniswig.tmp -I${CMAKE_CURRENT_SOURCE_DIR}/src
+ COMMAND tools/miniswig/miniswig
+ ARGS --input miniswig.tmp --output-cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp --output-hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp --module supertux --select-namespace scripting
+ DEPENDS tools/miniswig/miniswig
+ IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.interface.hpp
)
- ## Make certain it is built
- SET(SUPERTUX_SOURCES_CXX ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch ${SUPERTUX_SOURCES_CXX})
- SET(CMAKE_CXX_FLAGS "-include ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh ${CMAKE_CXX_FLAGS}")
-ELSE(PRECOMPILE_HEADERS)
- IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh)
- FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh)
- ENDIF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh)
- IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch)
- FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch)
- ENDIF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/precompile.hh.gch)
-ENDIF(PRECOMPILE_HEADERS)
+ENDIF(GENERATE_WRAPPER)
+IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
+ SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
+ENDIF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
+
+## Compile everything at once (roughly equivalent to cat *.cpp | gcc)
+
+OPTION(COMPILE_AMALGATION "Compile all the files together at once (experimental)" OFF)
+IF(COMPILE_AMALGATION)
+ FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "// Includes all source files of the project\n")
+ FOREACH(ST_FILE ${SUPERTUX_SOURCES_CXX})
+ FILE(RELATIVE_PATH CXX_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src "${CMAKE_CURRENT_SOURCE_DIR}/${ST_FILE}")
+ FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp "#include \"${CXX_FILE}\"\n")
+ ENDFOREACH(ST_FILE)
+ ## Build instead of CXX sources
+ SET(SUPERTUX_SOURCES_CXX ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
+ELSE(COMPILE_AMALGATION)
+ IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
+ FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
+ ENDIF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/amalgation.cpp)
+ENDIF(COMPILE_AMALGATION)
## Debug options
OPTION(WERROR "Stop on first compiler warning" OFF)
-OPTION(WARNINGS "Enable long list of warnings for compiler to check" ON)
+OPTION(WARNINGS "Enable long list of warnings for compiler to check" ${DEBUG})
IF(CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g" CACHE STRING "Debug flags")
REMOVE_DEFINITIONS(-Werror)
ENDIF(WERROR)
IF(WARNINGS)
- ADD_DEFINITIONS(-fdiagnostics-show-option -pedantic -Wno-long-long -Wcast-align -Wdisabled-optimization -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wredundant-decls -Wstack-protector)
- SET(CMAKE_CXX_FLAGS "-Weffc++ -Wabi -Wctor-dtor-privacy -Wstrict-null-sentinel" CACHE STRING "CXX Flags")
+ ADD_DEFINITIONS(-fdiagnostics-show-option -pedantic -Wno-long-long -Wcast-align -Wdisabled-optimization -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wredundant-decls -Wstack-protector -Wconversion -Wundef -Wsign-conversion -Wshadow -Winline -Wunsafe-loop-optimizations -Wfloat-equal -Wswitch-default -Wswitch-enum -Wcast-qual -Wsign-promo -Woverloaded-virtual -Wmissing-format-attribute -Wstrict-overflow=5 -Wformat=2-Weffc++ -Wabi -Wctor-dtor-privacy -Wstrict-null-sentinel)
# -ansi fails in MinGW
- # still left: -Wold-style-cast -Wpadded -Wconversion -Wundef -Wsign-conversion -Wshadow -Winline -Wunsafe-loop-optimizations -Wfloat-equal -Wswitch-default -Wswitch-enum -Wcast-qual -Wsign-promo -Woverloaded-virtual -Wmissing-format-attribute -Wstrict-overflow=5 -Wformat=2
+ # still left: -Wold-style-cast -Wpadded
ENDIF(WARNINGS)
ENDIF(CMAKE_COMPILER_IS_GNUCC)
-## Build miniswig and generate miniswig wrapper
-
-OPTION(GENERATE_WRAPPER "Build miniswig and generate the wrapper" ${DEBUG})
-IF(GENERATE_WRAPPER)
- ADD_SUBDIRECTORY(tools/miniswig)
- ADD_CUSTOM_COMMAND(
- OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp
- COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${CMAKE_CXX_COMPILER}
- ARGS -x "c++" -E -CC -DSCRIPTING_API src/scripting/wrapper.interface.hpp -o ${CMAKE_CURRENT_BINARY_DIR}/miniswig.tmp -I${CMAKE_CURRENT_SOURCE_DIR}/src
- COMMAND tools/miniswig/miniswig
- ARGS --input miniswig.tmp --output-cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp --output-hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.hpp --module supertux --select-namespace scripting
- DEPENDS tools/miniswig/miniswig
- IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.interface.hpp
- )
-ENDIF(GENERATE_WRAPPER)
-
-IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
- SET(SUPERTUX_SOURCES_CXX ${SUPERTUX_SOURCES_CXX} ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
-ENDIF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripting/wrapper.cpp)
-
## If xgettext is available, generate messages.pot for sources
OPTION(GENERATE_MESSAGESPOT "Generate messages.pot files" ${DEBUG})
* split files with multiple classes into multiple files with one class each
-* static vs anonymous namespace
+* Decide what to do with magic constants of objects (static vs anonymous namespace vs lisp property)
-* check the code with Valgrind
+* check the code with Valgrind and profilers
* use Vector in Physics for 'a' and 'v'
-* replace random generator with mersene twister and/or move to external/
-
-* write/finish scripts for include sorting and include guard checking that
- can be run automatically
+* replace random generator with mersenne twister and/or move to external/
* md5.hpp and random_generator.hpp could go to external/
-* write scripts to automatically check for:
+* write/finish scripts to automatically:
+
+ - make all includes relative to top level dir
- - all includes are relative to top level dir
+ - sort includes (.hpp file, then system includes, then other project files)
- - include guards are proper
+ - include guards proper and of the form HEADER_SUPERTUX_${PATH_TO_FILE}_HPP
TODO
====
* add --datadir DIR (data/) and --userdir DIR (~/.supertux/)
-* make gravity a constant
-
-* funky side effect of too much global variables: when having a
- savegame with large or firetux and then starting that game, Tux in
- the menu background will grow and be visible that way for a fraction
- of a second
+* make gravity constant
* rename Vector -> Vector2f
* get rid of global SDL_Screen* screen variable
-* identify all global variables and make them ugly (g_ or globals::)
-
-* get rid of SCREEN_WIDTH/SCREEN_HEIGHT
-
-* is version.h actually needed?
+* get rid of SCREEN_WIDTH/SCREEN_HEIGHT overuse
* resolution menu entry moves the wrong way around
* having dictionary_manager in Lisp is extremely ugly
-* enforce proper naming of files to match their class
+* enforce proper naming of files to match their class (SomeClass -> some_class.?pp or so)
+
+* file naming is inconsistent: some times we use '_' to separate
+ words, sometimes we don't
* get rid of NDEBUG and conditional compilation, these should be
reserved for a few tiny cases, not spread all over the code
-* split particlesystem_interactive
-
-* collect all manager classe into globals.hpp
+* collect all manager classes into globals.hpp
* more moving directories around?
* having hitbox in Sprite is fugly
-* write decal object
+* write decal object that doesn't have hitbox
* implement surface and/or sprite scaling (MipMaps?)
* last line has been repeated X times
-* file naming is inconsistent: some times we use '_' to separate
- words, sometimes we don't
-
* implement: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
* workaround for Ubuntu pulseaudio/OpenAL brokeness:
* add pipe graphics that makes a 90 degree turn
-* keep possible future SDL1.3 upgrade in mind
+* keep possible future SDL1.3 upgrade in mind (what has changed?)
* cleanup scripting interface
-* remove cloud tiles, replace with decal
+* replace cloud tiles with decals
* option menu has text overlap in "aspect ratio"
-* jumping up from an enemy doesn't make a sound
+* jumping up from an enemy doesn't make a sound?
* add support for automatic scrolling backgrounds
===========================================
* random idea to restructure engine stuff (might lead to nicer code
- and easier scriptability and a need to rewrite lots of stuff...):
+ and easier scriptability (and a need to rewrite lots of stuff...):
class SomeBadGuy : public PhysicsCallbackListener // or use boost::function
{
* right now a switch doesn't seem to be worth it
* core issue right now isn't SVN, but old SVN version on lethargik.org
- (lacks merge tracking and issues with viewvc)
+ (lacks merge tracking, issues with viewvc)
* cleanup SVN to make import into other version control systems possible:
* lack of sparse/narrow/shallow checkout, this means initial checkout
will be 200MB instead of 100MB
-* no free hoster that allows >1GB repositories (haven't checked all,
- but those I did came out way short) -> could use lethargik.org
-
-* some free hosters that might allow >1GB repositories don't allow
- having multiple repositories
+* no free hoster that allow multiple >1GB repositories -> could use lethargik.org
* git submodule doesn't seem to be quite ready to replace our
trunk/supertux, trunk/supertux-editor, trunk/media/, ... layout as
return (1 - parallax) * screen + parallax * tiles * 32
\f
-Supported Resolution
+Supported Resolutions
====================
SuperTux shall support resolutions from 640x480 to 1280x800 at a magnification of 1x.
#include "sprite/sprite.hpp"
#include "supertux/object_factory.hpp"
-static const float SPEED = 240;
+static const float CHARGE_SPEED = 240;
static const float CHARGE_TIME = .5;
static const float ATTACK_TIME = 1;
timer.start(ATTACK_TIME);
state = ATTACKING;
physic.enable_gravity(false);
- physic.set_velocity_x(SPEED * attackDirection.x);
- physic.set_velocity_y(SPEED * attackDirection.y);
+ physic.set_velocity_x(CHARGE_SPEED * attackDirection.x);
+ physic.set_velocity_y(CHARGE_SPEED * attackDirection.y);
oldWallDirection.x = 0;
oldWallDirection.y = 0;
}
#include "supertux/object_factory.hpp"
static const float JUMPSPEED = -450;
-static const float WALKSPEED = 80;
+static const float BSNOWBALL_WALKSPEED = 80;
BouncingSnowball::BouncingSnowball(const Reader& reader)
: BadGuy(reader, "images/creatures/bouncing_snowball/bouncing_snowball.sprite")
void
BouncingSnowball::initialize()
{
- physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
+ physic.set_velocity_x(dir == LEFT ? -BSNOWBALL_WALKSPEED : BSNOWBALL_WALKSPEED);
sprite->set_action(dir == LEFT ? "left" : "right");
}
#include "supertux/object_factory.hpp"
namespace {
-const float SPEED = 200;
+const float DART_SPEED = 200;
}
-static const std::string SOUNDFILE = "sounds/flame.wav";
+static const std::string DART_SOUND = "sounds/flame.wav";
Dart::Dart(const Reader& reader) :
BadGuy(reader, "images/creatures/dart/dart.sprite"),
{
physic.enable_gravity(false);
countMe = false;
- sound_manager->preload(SOUNDFILE);
+ sound_manager->preload(DART_SOUND);
sound_manager->preload("sounds/darthit.wav");
sound_manager->preload("sounds/stomp.wav");
}
{
physic.enable_gravity(false);
countMe = false;
- sound_manager->preload(SOUNDFILE);
+ sound_manager->preload(DART_SOUND);
sound_manager->preload("sounds/darthit.wav");
sound_manager->preload("sounds/stomp.wav");
}
void
Dart::initialize()
{
- physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED);
+ physic.set_velocity_x(dir == LEFT ? -::DART_SPEED : ::DART_SPEED);
sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
}
void
Dart::activate()
{
- sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
+ sound_source.reset(sound_manager->create_sound_source(DART_SOUND));
sound_source->set_position(get_pos());
sound_source->set_looping(true);
sound_source->set_gain(1.0);
namespace {
-const float WALKSPEED = 80; /**< speed at which we walk around */
+const float IGEL_SPEED = 80; /**< speed at which we walk around */
const float TURN_RECOVER_TIME = 0.5; /**< seconds before we will again turn around when shot at */
const float RANGE_OF_VISION = 256; /**< range in px at which we can see bullets */
WalkingBadguy(reader, "images/creatures/igel/igel.sprite", "walking-left", "walking-right"),
turn_recover_timer()
{
- walk_speed = WALKSPEED;
+ walk_speed = IGEL_SPEED;
max_drop_height = 16;
}
WalkingBadguy(pos, d, "images/creatures/igel/igel.sprite", "walking-left", "walking-right"),
turn_recover_timer()
{
- walk_speed = WALKSPEED;
+ walk_speed = IGEL_SPEED;
max_drop_height = 16;
}
#include "sprite/sprite.hpp"
#include "supertux/object_factory.hpp"
-static const float JUMPSPEED=-600;
+static const float JUMPYSPEED=-600;
static const float JUMPY_MID_TOLERANCE=4;
static const float JUMPY_LOW_TOLERANCE=2;
groundhit_pos_set = true;
}
- physic.set_velocity_y((frozen || get_state() == STATE_FALLING) ? 0 : JUMPSPEED);
+ physic.set_velocity_y((frozen || get_state() == STATE_FALLING) ? 0 : JUMPYSPEED);
// TODO create a nice sound for this...
//sound_manager->play("sounds/skid.wav");
} else if(chit.top) {
* On impact he is destroyed, trying to kill what he hit or hit him.
*/
namespace{
- static const float SPEED = 200;
+ static const float KAMIKAZE_SPEED = 200;
const std::string SPLAT_SOUND = "sounds/splat.wav";
}
void
KamikazeSnowball::initialize()
{
- physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED);
+ physic.set_velocity_x(dir == LEFT ? -KAMIKAZE_SPEED : KAMIKAZE_SPEED);
physic.enable_gravity(false);
sprite->set_action(dir == LEFT ? "left" : "right");
}
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "badguy/kugelblitz.hpp"
+
+#include <math.h>
+
#include "math/random_generator.hpp"
#include "object/camera.hpp"
#include "object/player.hpp"
#define BASE_SPEED 200
#define RAND_SPEED 150
-static const float X_OFFSCREEN_DISTANCE = 1600;
-static const float Y_OFFSCREEN_DISTANCE = 1200;
-
Kugelblitz::Kugelblitz(const Reader& reader) :
BadGuy(reader, "images/creatures/kugelblitz/kugelblitz.sprite"),
pos_groundhit(),
void
Kugelblitz::try_activate()
{
- //FIXME: Don't activate Kugelblitz before it's on-screen
- float scroll_x = Sector::current()->camera->get_translation().x;
- float scroll_y = Sector::current()->camera->get_translation().y;
-
- /* Activate badguys if they're just around the screen to avoid
- * the effect of having badguys suddenly popping up from nowhere.
- */
- if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
- start_position.x < scroll_x - bbox.get_width() &&
- start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
- start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) {
- dir = RIGHT;
- set_state(STATE_ACTIVE);
- activate();
- } else if (start_position.x > scroll_x &&
- start_position.x < scroll_x + X_OFFSCREEN_DISTANCE &&
- start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
- start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) {
- dir = LEFT;
- set_state(STATE_ACTIVE);
- activate();
- } else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
- start_position.x < scroll_x + X_OFFSCREEN_DISTANCE &&
- ((start_position.y > scroll_y &&
- start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) ||
- (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
- start_position.y < scroll_y))) {
- dir = start_position.x < scroll_x ? RIGHT : LEFT;
- set_state(STATE_ACTIVE);
- activate();
- } else if(state == STATE_INIT
- && start_position.x > scroll_x - X_OFFSCREEN_DISTANCE
- && start_position.x < scroll_x + X_OFFSCREEN_DISTANCE
- && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE
- && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) {
- dir = LEFT;
+ // Much smaller offscreen distances to pop out of nowhere and surprise Tux
+ float X_OFFSCREEN_DISTANCE = 400;
+ float Y_OFFSCREEN_DISTANCE = 600;
+
+ Player* player = get_nearest_player();
+ if (!player) return;
+ Vector dist = player->get_bbox().get_middle() - get_bbox().get_middle();
+ if ((fabsf(dist.x) <= X_OFFSCREEN_DISTANCE) && (fabsf(dist.y) <= Y_OFFSCREEN_DISTANCE)) {
set_state(STATE_ACTIVE);
+ if (!is_initialized) {
+
+ // if starting direction was set to AUTO, this is our chance to re-orient the badguy
+ if (start_dir == AUTO) {
+ Player* player = get_nearest_player();
+ if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) {
+ dir = RIGHT;
+ } else {
+ dir = LEFT;
+ }
+ }
+
+ initialize();
+ is_initialized = true;
+ }
activate();
}
}
#include <math.h>
-static const float WALKSPEED = 100;
+static const float TREE_SPEED = 100;
static const float POISONIVY_WIDTH = 32;
static const float POISONIVY_HEIGHT = 32;
MrTree::MrTree(const Reader& reader)
: WalkingBadguy(reader, "images/creatures/mr_tree/mr_tree.sprite","left","right")
{
- walk_speed = WALKSPEED;
+ walk_speed = TREE_SPEED;
max_drop_height = 16;
sound_manager->preload("sounds/mr_tree.ogg");
}
#include "sprite/sprite.hpp"
#include "supertux/object_factory.hpp"
-static const float WALKSPEED = 80;
+static const float PLANT_SPEED = 80;
static const float WAKE_TIME = .5;
Plant::Plant(const Reader& reader) :
if(timer.check()) {
// start walking
sprite->set_action(dir == LEFT ? "left" : "right");
- physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
+ physic.set_velocity_x(dir == LEFT ? -PLANT_SPEED : PLANT_SPEED);
state = PLANT_WALKING;
}
}
#include <math.h>
namespace {
-const float KICKSPEED = 500;
-const int MAXSQUISHES = 10;
-const float KICKSPEED_Y = -500; /**< y-velocity gained when kicked */
+const float SNAIL_KICK_SPEED = 500;
+const int MAX_SNAIL_SQUISHES = 10;
+const float SNAIL_KICK_SPEED_Y = -500; /**< y-velocity gained when kicked */
}
Snail::Snail(const Reader& reader) :
case STATE_KICKED_DELAY:
if (kicked_delay_timer.check()) {
- physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED);
- physic.set_velocity_y(KICKSPEED_Y);
+ physic.set_velocity_x(dir == LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED);
+ physic.set_velocity_y(SNAIL_KICK_SPEED_Y);
state = STATE_KICKED;
}
break;
{
Player* player = dynamic_cast<Player*>(&object);
squishcount++;
- if ((squishcount >= MAXSQUISHES) || (player && player->does_buttjump)) {
+ if ((squishcount >= MAX_SNAIL_SQUISHES) || (player && player->does_buttjump)) {
kill_fall();
return true;
}
if(state == BT_SHOW_INFO)
{
Vector offset;
- if(pos.x + tanslation.x < 100 && pos.y + tanslation.y > SCREEN_SIZE.height - 20)
+ if(pos.x + tanslation.x < 100 && pos.y + tanslation.y > SCREEN_HEIGHT - 20)
offset = Vector(size.x, - 10);
else if(pos.x + tanslation.x < 100)
offset = Vector(size.x, 0);
if(mouse_left_button)
{
- pos.x += int(event.motion.xrel * float(SCREEN_SIZE.width)/g_screen->w);
- pos.y += int(event.motion.yrel * float(SCREEN_SIZE.height)/g_screen->h);
+ pos.x += int(event.motion.xrel * float(SCREEN_WIDTH)/g_screen->w);
+ pos.y += int(event.motion.yrel * float(SCREEN_HEIGHT)/g_screen->h);
caught_event = true;
}
if(event.button.x > pos.x-12 && event.button.x < pos.x+16 + buttons_box.x*buttons_size.x &&
delete_character = 0;
mn_input_char = '\0';
- pos = SCREEN_SIZE/2.0f;
+ pos.x = SCREEN_WIDTH/2;
+ pos.y = SCREEN_HEIGHT/2;
arrange_left = 0;
active_item = -1;
}
void
-Menu::set_pos(Vector loc, Vector r)
+Menu::set_pos(float x, float y, float rw, float rh)
{
- pos = loc + get_size() * r;
+ pos.x = x + get_width() * rw;
+ pos.y = y + get_height() * rh;
}
/* Add an item to a menu */
if (menu_height > SCREEN_HEIGHT)
{ // Scrolling
int scroll_offset = (menu_height - SCREEN_HEIGHT) / 2 + 32;
- pos_y = SCREEN_HEIGHT/2 - scroll_offset * ((float(active_item) / (items.size()-1)) - 0.5f) * 2.0f;
+ pos.y = SCREEN_HEIGHT/2 - scroll_offset * ((float(active_item) / (items.size()-1)) - 0.5f) * 2.0f;
}
effect_progress = (real_time - effect_start_time) * 6.0f;
MenuItem& pitem = *(items[index]);
Color text_color = default_color;
- float x_pos = pos_x;
- float y_pos = pos_y + 24*index - menu_height/2 + 12;
+ float x_pos = pos.x;
+ float y_pos = pos.y + 24*index - menu_height/2 + 12;
int shadow_size = 2;
int text_width = int(Resources::normal_font->get_text_width(pitem.text));
int input_width = int(Resources::normal_font->get_text_width(pitem.input) + 10);
int list_width = 0;
- float left = pos_x - menu_width/2 + 16;
- float right = pos_x + menu_width/2 - 16;
+ float left = pos.x - menu_width/2 + 16;
+ float right = pos.x + menu_width/2 - 16;
if(pitem.list.size() > 0) {
list_width = (int) Resources::normal_font->get_text_width(pitem.list[pitem.selected]);
if(active_item == index)
{
float blink = (sinf(real_time * M_PI * 1.0f)/2.0f + 0.5f) * 0.5f + 0.25f;
- context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2 + 10 - 2, y_pos - 12 - 2),
- Vector(pos_x + menu_width/2 - 10 + 2, y_pos + 12 + 2)),
+ context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2 + 10 - 2, y_pos - 12 - 2),
+ Vector(pos.x + menu_width/2 - 10 + 2, y_pos + 12 + 2)),
Color(1.0f, 1.0f, 1.0f, blink),
14.0f,
LAYER_GUI-10);
- context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2 + 10, y_pos - 12),
- Vector(pos_x + menu_width/2 - 10, y_pos + 12)),
+ context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2 + 10, y_pos - 12),
+ Vector(pos.x + menu_width/2 - 10, y_pos + 12)),
Color(1.0f, 1.0f, 1.0f, 0.5f),
12.0f,
LAYER_GUI-10);
case MN_INACTIVE:
{
context.draw_text(Resources::normal_font, pitem.text,
- Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)),
+ Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI, inactive_color);
break;
}
case MN_HL:
{
// TODO
- float x = pos_x - menu_width/2;
+ float x = pos.x - menu_width/2;
float y = y_pos - 12;
/* Draw a horizontal line with a little 3d effect */
context.draw_filled_rect(Vector(x, y + 6),
case MN_LABEL:
{
context.draw_text(Resources::big_font, pitem.text,
- Vector(pos_x, y_pos - int(Resources::big_font->get_height()/2)),
+ Vector(pos.x, y_pos - int(Resources::big_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI, label_color);
break;
}
case MN_BACK:
{
context.draw_text(Resources::Resources::normal_font, pitem.text,
- Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)),
+ Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI, text_color);
context.draw_surface(back,
Vector(x_pos + text_width/2 + 16, y_pos - 8),
case MN_TOGGLE:
{
context.draw_text(Resources::normal_font, pitem.text,
- Vector(pos_x - menu_width/2 + 16, y_pos - (Resources::normal_font->get_height()/2)),
+ Vector(pos.x - menu_width/2 + 16, y_pos - (Resources::normal_font->get_height()/2)),
ALIGN_LEFT, LAYER_GUI, text_color);
if(pitem.toggled)
}
case MN_ACTION:
context.draw_text(Resources::normal_font, pitem.text,
- Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)),
+ Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI, text_color);
break;
case MN_GOTO:
context.draw_text(Resources::normal_font, pitem.text,
- Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)),
+ Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI, text_color);
break;
}
}
/* Draw a transparent background */
- context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2-4, pos_y - menu_height/2 - 10-4),
- Vector(pos_x + menu_width/2+4, pos_y - menu_height/2 + 10 + menu_height+4)),
+ context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2-4, pos.y - menu_height/2 - 10-4),
+ Vector(pos.x + menu_width/2+4, pos.y - menu_height/2 + 10 + menu_height+4)),
Color(0.2f, 0.3f, 0.4f, 0.8f),
20.0f,
LAYER_GUI-10);
- context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2, pos_y - menu_height/2 - 10),
- Vector(pos_x + menu_width/2, pos_y - menu_height/2 + 10 + menu_height)),
+ context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2, pos.y - menu_height/2 - 10),
+ Vector(pos.x + menu_width/2, pos.y - menu_height/2 + 10 + menu_height)),
Color(0.6f, 0.7f, 0.8f, 0.5f),
16.0f,
LAYER_GUI-10);
int text_width = (int) Resources::normal_font->get_text_width(items[active_item]->help);
int text_height = (int) Resources::normal_font->get_text_height(items[active_item]->help);
- Rectf text_rect(pos_x - text_width/2 - 8,
+ Rectf text_rect(pos.x - text_width/2 - 8,
SCREEN_HEIGHT - 48 - text_height/2 - 4,
- pos_x + text_width/2 + 8,
+ pos.x + text_width/2 + 8,
SCREEN_HEIGHT - 48 + text_height/2 + 4);
context.draw_filled_rect(Rectf(text_rect.p1 - Vector(4,4),
LAYER_GUI-10);
context.draw_text(Resources::normal_font, items[active_item]->help,
- Vector(pos_x, SCREEN_HEIGHT - 48 - text_height/2),
+ Vector(pos.x, SCREEN_HEIGHT - 48 - text_height/2),
ALIGN_CENTER, LAYER_GUI);
}
int x = int(event.motion.x * float(SCREEN_WIDTH)/g_screen->w);
int y = int(event.motion.y * float(SCREEN_HEIGHT)/g_screen->h);
- if(x > pos_x - get_width()/2 &&
- x < pos_x + get_width()/2 &&
- y > pos_y - get_height()/2 &&
- y < pos_y + get_height()/2)
+ if(x > pos.x - get_width()/2 &&
+ x < pos.x + get_width()/2 &&
+ y > pos.y - get_height()/2 &&
+ y < pos.y + get_height()/2)
{
menuaction = MENU_ACTION_HIT;
}
float x = event.motion.x * SCREEN_WIDTH/g_screen->w;
float y = event.motion.y * SCREEN_HEIGHT/g_screen->h;
- if(x > pos_x - get_width()/2 &&
- x < pos_x + get_width()/2 &&
- y > pos_y - get_height()/2 &&
- y < pos_y + get_height()/2)
+ if(x > pos.x - get_width()/2 &&
+ x < pos.x + get_width()/2 &&
+ y > pos.y - get_height()/2 &&
+ y < pos.y + get_height()/2)
{
int new_active_item
- = static_cast<int> ((y - (pos_y - get_height()/2)) / 24);
+ = static_cast<int> ((y - (pos.y - get_height()/2)) / 24);
/* only change the mouse focus to a selectable item */
if ((items[new_active_item]->kind != MN_HL)
#include <memory>
#include <SDL.h>
-#include "math/sizef.hpp"
+#include "math/vector.hpp"
#include "video/color.hpp"
#include "video/surface_ptr.hpp"
void set_active_item(int id);
void draw(DrawingContext& context);
- void set_pos(Vector loc, Vector r = Vector(0,0));
+ void set_pos(float x, float y, float rw = 0, float rh = 0);
void event(const SDL_Event& event);
protected:
void additem(MenuItem* pmenu_item);
- Sizef get_size() const;
+ float get_width() const;
+ float get_height() const;
private:
void check_controlfield_change_event(const SDL_Event& event);
#include <iosfwd>
-#include "math/vector.hpp"
+class Sizef;
class Size
{
lhs.height / divisor);
}
-inline Vector operator/(const Size& lhs, float divisor)
-{
- return Vector(lhs.width / divisor,
- lhs.height / divisor);
-}
-
inline Size operator+(const Size& lhs, const Size& rhs)
{
return Size(lhs.width + rhs.width,
#include <iosfwd>
-#include "math/vector.hpp"
-
class Size;
class Sizef
lhs.height + rhs.height);
}
-inline Vector operator+(const Vector& lhs, const Sizef& rhs) const
-{
- return Vector(lhs.x + rhs.width,
- lhs.y + rhs.height);
-}
-
-inline Vector operator*(const Vector& lhs, const Sizef& rhs) const
-{
- return Vector(lhs.x * rhs.width,
- lhs.y * rhs.height);
-}
-
-inline Vector operator*(const Sizefr& lhs, const Vector& rhs) const
-{
- return Vector(lhs.width * rhs.x,
- lhs.height * rhs.y);
-}
-
inline Sizef operator-(const Sizef& lhs, const Sizef& rhs)
{
return Sizef(lhs.width - rhs.width,
int(trans_y * speed_y)));
}
- float start_x = context.get_translation().x;
- float start_y = context.get_translation().y;
+ int tsx = int((context.get_translation().x - x_offset) / 32); // tilestartindex x
+ int tsy = int((context.get_translation().y - y_offset) / 32); // tilestartindex y
+ float start_x = tsx * 32 + x_offset;
+ float start_y = tsy * 32 + y_offset;
float end_x = start_x + SCREEN_WIDTH + 32;
float end_y = start_y + SCREEN_HEIGHT + 32;
- int tsx = std::max(int((start_x - x_offset) / 32), 0); // tilestartindex x
- int tsy = std::max(int((start_y - y_offset) / 32), 0); // tilestartindex y
Vector pos;
int tx, ty;
#include "scripting/camera.hpp"
#include "util/log.hpp"
-#define NOIMPL log_fatal << __FUNCTION__ << " not implemented."
-
namespace scripting {
Camera::Camera(::Camera* camera)
: camera(camera)
#include "object/candle.hpp"
#include "scripting/candle.hpp"
-#define NOIMPL log_fatal << __PRETTY_FUNCTION__ << " not implemented."
-
namespace scripting {
Candle::Candle(::Candle* candle)
class JoystickKeyboardController;
class PlayerStatus;
class ScreenManager;
-class Size;
class SoundManager;
class SpriteManager;
class TextureManager;
class TileManager;
class TileSet;
-/** The width/height of the display (this is a logical value, not the
+/** The width of the display (this is a logical value, not the
physical value, since aspect_ration and projection_area might
shrink or scale things) */
-extern Size SCREEN_SIZE;
+extern int SCREEN_WIDTH;
+
+/** The width of the display (this is a logical value, not the
+ physical value, since aspect_ration and projection_area might
+ shrink or scale things) */
+extern int SCREEN_HEIGHT;
// global variables
extern JoystickKeyboardController* g_main_controller;