Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/editor/input_center.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "math/rectf.hpp"
#include "object/ambient_sound.hpp"
#include "object/camera.hpp"
#include "object/enemy_blocker.hpp"
#include "object/invisible_wall.hpp"
#include "object/path.hpp"
#include "object/platform.hpp"
Expand Down Expand Up @@ -316,8 +317,9 @@ EditorInputCenter::mark_object() {
auto dc5 = dynamic_cast<SequenceTrigger*>(dragged_object);
auto dc6 = dynamic_cast<Wind*>(dragged_object);
auto dc7 = dynamic_cast<InvisibleWall*>(dragged_object);
auto dc8 = dynamic_cast<EnemyBlocker*>(dragged_object);

if (dc1 || dc2 || dc3 || dc4 || dc5 || dc6 || dc7) {
if (dc1 || dc2 || dc3 || dc4 || dc5 || dc6 || dc7 || dc8) {
marked_object = dragged_object;
dragged_object->edit_bbox();
return;
Expand Down
80 changes: 80 additions & 0 deletions src/object/enemy_blocker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SuperTux
// Copyright (C) 2007 Kovago Zoltan <[email protected]>
//
// 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 "object/enemy_blocker.hpp"

#include "editor/editor.hpp"
#include "badguy/badguy.hpp"
#include "supertux/object_factory.hpp"
#include "util/gettext.hpp"
#include "util/reader_mapping.hpp"
#include "video/drawing_context.hpp"

EnemyBlocker::EnemyBlocker(const ReaderMapping& lisp):
width(),
height()
{
if (!lisp.get("name" , name)) name = "";
if (!lisp.get("x", bbox.p1.x)) bbox.p1.x = 0;
if (!lisp.get("y", bbox.p1.y)) bbox.p1.y = 0;
if (!lisp.get("width", width)) width = 32;
if (!lisp.get("height", height)) height = 32;

bbox.set_size(width, height);
}

ObjectSettings
EnemyBlocker::get_settings() {
width = bbox.get_width();
height = bbox.get_height();

ObjectSettings result = MovingObject::get_settings();
result.options.push_back( ObjectOption(MN_NUMFIELD, _("Width"), &width, "width"));
result.options.push_back( ObjectOption(MN_NUMFIELD, _("Height"), &height, "height"));

return result;
}

void
EnemyBlocker::after_editor_set() {
bbox.set_size(width, height);
}

HitResponse
EnemyBlocker::collision(GameObject& other, const CollisionHit& )
{
BadGuy* badguy = dynamic_cast<BadGuy*> (&other);

if (badguy == 0)
Copy link
Member

@Hypernoot Hypernoot Aug 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done via the function collides.

return ABORT_MOVE;
return FORCE_MOVE;
}

void
EnemyBlocker::draw(DrawingContext& context)
{
if (Editor::is_active()) {
context.draw_filled_rect(bbox, Color(0.96f, 0.38f, 0.0f, 0.8f),
0.0f, LAYER_OBJECTS);
}
}

void
EnemyBlocker::update(float )
{
}

/* EOF */
51 changes: 51 additions & 0 deletions src/object/enemy_blocker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SuperTux
// Copyright (C) 2007 Kovago Zoltan <[email protected]>
//
// 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/>.

#ifndef HEADER_SUPERTUX_OBJECT_ENEMY_BLOCKER_HPP
#define HEADER_SUPERTUX_OBJECT_ENEMY_BLOCKER_HPP

#include "supertux/moving_object.hpp"
#include "util/reader_fwd.hpp"

/** An object that only solid for badguys. */
class EnemyBlocker : public MovingObject
{
public:
EnemyBlocker(const ReaderMapping& lisp);

HitResponse collision(GameObject& other, const CollisionHit& hit);

void draw(DrawingContext& context);

std::string get_class() const {
return "enemy_blocker";
}
std::string get_display_name() const {
return _("Enemy blocker");
}

virtual ObjectSettings get_settings();
virtual void after_editor_set();

private:
void update(float elapsed_time);

float width, height;
};

#endif

/* EOF */
2 changes: 2 additions & 0 deletions src/supertux/object_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
#include "object/endsequence.hpp"
#include "object/endsequence_walkleft.hpp"
#include "object/endsequence_walkright.hpp"
#include "object/enemy_blocker.hpp"
#include "object/explosion.hpp"
#include "object/falling_coin.hpp"
#include "object/firefly.hpp"
Expand Down Expand Up @@ -253,6 +254,7 @@ ObjectFactory::init_factories()
add_factory<Coin>("coin");
add_factory<CometParticleSystem>("particles-comets");
add_factory<Decal>("decal");
add_factory<EnemyBlocker>("enemy_blocker");
add_factory<Explosion>("explosion");
add_factory<Firefly>("firefly");
add_factory<GhostParticleSystem>("particles-ghosts");
Expand Down