From 28683a51903d573ac5b13eb1fc316faff44d7ac2 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Sat, 5 Aug 2006 03:01:51 +0000 Subject: [PATCH] Added code and placeholder graphics (selfmade, GPL/GFDL) of a pushbutton SVN-Revision: 4123 --- data/images/objects/pushbutton/pushbutton-0.png | Bin 0 -> 904 bytes data/images/objects/pushbutton/pushbutton-1.png | Bin 0 -> 809 bytes data/images/objects/pushbutton/pushbutton.sprite | 12 ++++ data/images/objects/pushbutton/pushbutton.xcf | Bin 0 -> 12528 bytes data/levels/test/pushbutton.stl | 70 +++++++++++++++++++ src/object/pushbutton.cpp | 83 +++++++++++++++++++++++ src/object/pushbutton.hpp | 47 +++++++++++++ 7 files changed, 212 insertions(+) create mode 100644 data/images/objects/pushbutton/pushbutton-0.png create mode 100644 data/images/objects/pushbutton/pushbutton-1.png create mode 100644 data/images/objects/pushbutton/pushbutton.sprite create mode 100644 data/images/objects/pushbutton/pushbutton.xcf create mode 100644 data/levels/test/pushbutton.stl create mode 100644 src/object/pushbutton.cpp create mode 100644 src/object/pushbutton.hpp diff --git a/data/images/objects/pushbutton/pushbutton-0.png b/data/images/objects/pushbutton/pushbutton-0.png new file mode 100644 index 0000000000000000000000000000000000000000..ada44882c3e1fd79df1a195b83da437eacf79524 GIT binary patch literal 904 zcmV;319$w1P)WFU8GbZ8({Xk{QrNlj4iWF>9@00QhuL_t(Y$E}nwD-)veY{zv`;$GG0)}V1L^RKnXaoID&@%S+>>aVZYb=XgC_Z z6-J|BJ|34L&-am#yKv7iD}vceAq06!O}kwF?kQa%B|!@aplzBzmUaD0it)_dXFw(R z4e2Rxc?9Viz%dL4@YTzs(R;5P92BF&!(e5JO(xLq6VK04N?;us61bxnAtltd>$QZ| zVDYxan})PpvT7P)j8qpFzL?GCDa+1MN>5XaU%wAu*fC6t5YDFKaWN@N+dDWQACHMw zS9o2ME-uzh? zo}LoxnqEqT7?DH(isxvTfK@j;uo+oF`1w=LRc!VKIyRfL&gA*}!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732bsSuy$UGQwVr5FhwDfkyystSh&9&h^sxdnlLBLcn; zEZ1;hP~V0ma-w_m#3r~8n0RiCPMkc+pQ9^$ec-a=AYXTTYPr;Sh0+j*Rp-nSb-lWEGrOVUpmybO9$gFTZk0m~o(ZL-j z!1B&f?^g;Y7OSGjNE&Jf+RahX<8*o7W$D3%C^Tw}^9_`jTppL(`7$u9_41wwUl;f+ zNHMo(a2d8cx7K(E7NJH*O$miu@bh&|LB*JYwA>tma*zyN43M(~o;W!hNPBQI4-<^n zv$WcX)<*OcV|1f5iXpqT;PpsyJIadYeG(w|$7QLgaTfQ=-@)3SI>&By3!g_XMT$nE z*IuOYPyMwIZ`kz8)?GW_dTld>?)K?7t^Zel`aS;XIYiC)6BUSSFA`OgLtQ4)RpjZl Z7YX$ +// +// 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 2 +// 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, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include +#include + +#include "pushbutton.hpp" +#include "object_factory.hpp" +#include "player.hpp" +#include "audio/sound_manager.hpp" +#include "sprite/sprite_manager.hpp" +#include "sector.hpp" +#include "log.hpp" + +namespace { + const std::string BUTTON_SOUND = "sounds/switch.ogg"; + //14 -> 8 +} + +PushButton::PushButton(const lisp::Lisp& lisp) + : MovingSprite(lisp, "images/objects/pushbutton/pushbutton.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_MOVING), state(OFF) +{ + sound_manager->preload(BUTTON_SOUND); + set_action("off", -1); + bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); + + if (!lisp.get("script", script)) throw std::runtime_error("no script set"); +} + +void +PushButton::update(float elapsed_time) +{ +} + +HitResponse +PushButton::collision(GameObject& other, const CollisionHit& hit) +{ + Player* player = dynamic_cast(&other); + if (!player) return FORCE_MOVE; + float vy = player->physic.get_velocity_y(); + + //player->add_velocity(Vector(0, -150)); + player->physic.set_velocity_y(-150); + + if (state != OFF) return FORCE_MOVE; + if (!hit.top) return FORCE_MOVE; + if (vy <= 0) return FORCE_MOVE; + + // change appearance + state = ON; + float old_bbox_height = bbox.get_height(); + set_action("on", -1); + float new_bbox_height = bbox.get_height(); + set_pos(get_pos() + Vector(0, old_bbox_height - new_bbox_height)); + + // play sound + sound_manager->play(BUTTON_SOUND); + + // run script + std::istringstream stream(script); + Sector::current()->run_script(stream, "PushButton"); + + return FORCE_MOVE; +} + +IMPLEMENT_FACTORY(PushButton, "pushbutton"); + diff --git a/src/object/pushbutton.hpp b/src/object/pushbutton.hpp new file mode 100644 index 000000000..55f3fc792 --- /dev/null +++ b/src/object/pushbutton.hpp @@ -0,0 +1,47 @@ +// $Id$ +// +// SuperTux - PushButton running a script +// Copyright (C) 2006 Christoph Sommer +// +// 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 2 +// 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, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef SUPERTUX_BUTTON_H +#define SUPERTUX_BUTTON_H + +#include "moving_sprite.hpp" +#include "lisp/lisp.hpp" + +/** + * PushButton - jump on it to run a script + */ +class PushButton : public MovingSprite +{ +public: + PushButton(const lisp::Lisp& reader); + + HitResponse collision(GameObject& other, const CollisionHit& hit); + void update(float elapsed_time); + +private: + enum PushButtonState { + OFF, + ON + }; + + std::string script; + PushButtonState state; +}; + +#endif -- 2.11.0