Skip to content
This repository has been archived by the owner on Jun 7, 2018. It is now read-only.

Commit

Permalink
Add built-in ability jump_over_water
Browse files Browse the repository at this point in the history
Closes #530.
  • Loading branch information
christopho committed Jun 23, 2016
1 parent 4edd9c9 commit ba4b61e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Expand Up @@ -22,6 +22,7 @@ Engine changes
* Improve the performance of custom entity collisions.
* Improve the performance of collisions by using a quadtree.
* Entities far from the camera are no longer suspended.
* The hero no longer automatically jumps when arriving on water (#530).
* Destinations can now set to update or not the starting location (#819).
* Teletransporters on the side of the map now work on all layers (#850).
* Streams can now have a speed of zero (#496).
Expand Down Expand Up @@ -60,6 +61,7 @@ Changes that introduce incompatibilities:
* chest:on_empty() is replaced by chest:on_opened(treasure) (#483).
* Enemy ranks no longer exists, set_hurt_style() needs to be called (#449).
* Items with amount now have a default max amount of 1000 (#688).
* New ability "jump_over_water" in game:get/set_ability(), off by default (#530).
* Fix hero state name "freezed", renamed it to "frozen" (#813).
* Fix map:get_entities() not returning the hero (#670).
* map:get_camera_position() is now deprecated, use camera:get_position().
Expand Down
8 changes: 5 additions & 3 deletions include/solarus/Ability.h
@@ -1,16 +1,16 @@
/*
* Copyright (C) 2006-2016 Christopho, Solarus - http://www.solarus-games.org
*
*
* Solarus 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.
*
*
* Solarus 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/>.
*/
Expand All @@ -31,6 +31,8 @@ enum class Ability {
SHIELD, /**< Allows to stop attacks from enemies. */
LIFT, /**< Lifting destructible objects. */
SWIM, /**< Swimming in deep water. */
JUMP_OVER_WATER, /**< Automatically jumping when arriving in water
* without the SWIM ability. */
RUN, /**< Running faster. */
DETECT_WEAK_WALLS, /**< Be notified of weak walls nearby. */
};
Expand Down
1 change: 1 addition & 0 deletions include/solarus/Savegame.h
Expand Up @@ -77,6 +77,7 @@ class SOLARUS_API Savegame: public ExportableToLua {
static const std::string KEY_ABILITY_SHIELD;
static const std::string KEY_ABILITY_LIFT;
static const std::string KEY_ABILITY_SWIM;
static const std::string KEY_ABILITY_JUMP_OVER_WATER;
static const std::string KEY_ABILITY_RUN;
static const std::string KEY_ABILITY_DETECT_WEAK_WALLS;
static const std::string KEY_ABILITY_GET_BACK_FROM_DEATH;
Expand Down
1 change: 1 addition & 0 deletions src/AbilityInfo.cpp
Expand Up @@ -28,6 +28,7 @@ const EnumInfo<Ability>::names_type EnumInfoTraits<Ability>::names = {
{ Ability::SHIELD, "shield" },
{ Ability::LIFT, "lift" },
{ Ability::SWIM, "swim" },
{ Ability::JUMP_OVER_WATER, "jump_over_water" },
{ Ability::RUN, "run" },
{ Ability::DETECT_WEAK_WALLS, "detect_weak_walls" }
};
Expand Down
7 changes: 5 additions & 2 deletions src/Equipment.cpp
Expand Up @@ -562,8 +562,11 @@ std::string Equipment::get_ability_savegame_variable(Ability ability) const {
case Ability::LIFT:
return Savegame::KEY_ABILITY_LIFT;

case Ability::SWIM:
return Savegame::KEY_ABILITY_SWIM;
case Ability::SWIM:
return Savegame::KEY_ABILITY_SWIM;

case Ability::JUMP_OVER_WATER:
return Savegame::KEY_ABILITY_JUMP_OVER_WATER;

case Ability::RUN:
return Savegame::KEY_ABILITY_RUN;
Expand Down
2 changes: 2 additions & 0 deletions src/Savegame.cpp
Expand Up @@ -65,6 +65,8 @@ const std::string Savegame::KEY_ABILITY_SWORD_KNOWLEDGE =
const std::string Savegame::KEY_ABILITY_SHIELD = "_ability_shield"; /**< Protection level. */
const std::string Savegame::KEY_ABILITY_LIFT = "_ability_lift"; /**< Lift level. */
const std::string Savegame::KEY_ABILITY_SWIM = "_ability_swim"; /**< Swim level. */
const std::string Savegame::KEY_ABILITY_JUMP_OVER_WATER =
"_ability_jump_over_water"; /**< Jump over water level. */
const std::string Savegame::KEY_ABILITY_RUN = "_ability_run"; /**< Run level. */
const std::string Savegame::KEY_ABILITY_DETECT_WEAK_WALLS =
"_ability_detect_weak_walls"; /**< Weak walls detection level. */
Expand Down
15 changes: 11 additions & 4 deletions src/entities/Hero.cpp
Expand Up @@ -2175,22 +2175,29 @@ void Hero::notify_game_over_finished() {
*/
void Hero::start_deep_water() {

const bool can_swim = get_equipment().has_ability(Ability::SWIM);
const bool can_jump_over_water = get_equipment().has_ability(Ability::JUMP_OVER_WATER);

if (!get_state().is_touching_ground()) {
// plunge into the water
// Entering water from above the ground
// (e.g. after a jump).
set_state(new PlungingState(*this));
}
else {
// move to state swimming or jumping
if (get_equipment().has_ability(Ability::SWIM)) {
// Entering water normally (e.g. by walking).
if (can_swim) {
set_state(new SwimmingState(*this));
}
else {
else if (can_jump_over_water) {
int direction8 = get_wanted_movement_direction8();
if (direction8 == -1) {
direction8 = get_animation_direction() * 2;
}
start_jumping(direction8, 32, false, true);
}
else {
set_state(new PlungingState(*this));
}
}
}

Expand Down

0 comments on commit ba4b61e

Please sign in to comment.