X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fmoving_sprite.cpp;h=646addbd1882eb150c5d683c7feaa4fe6dc1a134;hb=53209e9747f4c830eeeb926d3a44918ed86621ba;hp=193d856b4820f7aada10c8862872c5d2346604e8;hpb=0e30fd4c781d35883e08e22b0f8124a41bb50cac;p=supertux.git diff --git a/src/object/moving_sprite.cpp b/src/object/moving_sprite.cpp index 193d856b4..646addbd1 100644 --- a/src/object/moving_sprite.cpp +++ b/src/object/moving_sprite.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux - MovingSprite Base Class // 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 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 @@ -14,29 +12,18 @@ // 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 +// along with this program. If not, see . -#include "moving_sprite.hpp" -#include "video/drawing_context.hpp" +#include "object/moving_sprite.hpp" +#include "sprite/sprite.hpp" #include "sprite/sprite_manager.hpp" -#include "player.hpp" -#include "sector.hpp" -#include "player_status.hpp" -#include "gameobjs.hpp" -#include "statistics.hpp" -#include "object_factory.hpp" -#include "level.hpp" -#include "random_generator.hpp" -#include "audio/sound_source.hpp" -#include "audio/sound_manager.hpp" -#include "timer.hpp" - -MovingSprite::MovingSprite(const Vector& pos, const std::string& sprite_name, int layer, CollisionGroup collision_group) - : sprite_name(sprite_name), layer(layer) +#include "util/reader.hpp" + +MovingSprite::MovingSprite(const Vector& pos, const std::string& sprite_name, + int layer, CollisionGroup collision_group) : + sprite_name(sprite_name), + sprite(), + layer(layer) { bbox.set_pos(pos); sprite = sprite_manager->create(sprite_name); @@ -44,47 +31,63 @@ MovingSprite::MovingSprite(const Vector& pos, const std::string& sprite_name, in set_group(collision_group); } -MovingSprite::MovingSprite(const lisp::Lisp& reader, const Vector& pos, int layer, CollisionGroup collision_group) - : layer(layer) +MovingSprite::MovingSprite(const Reader& reader, const Vector& pos, int layer, CollisionGroup collision_group) : + sprite_name(sprite_name), + sprite(), + layer(layer) { bbox.set_pos(pos); - if (!reader.get("sprite", sprite_name)) throw std::runtime_error("no sprite name set"); + if (!reader.get("sprite", sprite_name)) + throw std::runtime_error("no sprite name set"); + sprite = sprite_manager->create(sprite_name); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); set_group(collision_group); } -MovingSprite::MovingSprite(const lisp::Lisp& reader, const std::string& sprite_name, int layer, CollisionGroup collision_group) - : sprite_name(sprite_name), layer(layer) +MovingSprite::MovingSprite(const Reader& reader, const std::string& sprite_name, int layer, CollisionGroup collision_group) : + sprite_name(sprite_name), + sprite(), + layer(layer) { - if (!reader.get("x", bbox.p1.x)) throw std::runtime_error("no x position set"); - if (!reader.get("y", bbox.p1.y)) throw std::runtime_error("no y position set"); - sprite = sprite_manager->create(sprite_name); + reader.get("x", bbox.p1.x); + reader.get("y", bbox.p1.y); + reader.get("sprite", this->sprite_name); + + sprite = sprite_manager->create(this->sprite_name); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); set_group(collision_group); } -MovingSprite::MovingSprite(const lisp::Lisp& reader, int layer, CollisionGroup collision_group) - : layer(layer) +MovingSprite::MovingSprite(const Reader& reader, int layer, CollisionGroup collision_group) : + sprite_name(), + sprite(), + layer(layer) { - if (!reader.get("x", bbox.p1.x)) throw std::runtime_error("no x position set"); - if (!reader.get("y", bbox.p1.y)) throw std::runtime_error("no y position set"); - if (!reader.get("sprite", sprite_name)) throw std::runtime_error("no sprite name set"); + reader.get("x", bbox.p1.x); + reader.get("y", bbox.p1.y); + if (!reader.get("sprite", sprite_name)) + throw std::runtime_error("no sprite name set"); + sprite = sprite_manager->create(sprite_name); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); set_group(collision_group); } -MovingSprite::MovingSprite(const MovingSprite& other) - : MovingObject(other), layer(other.layer) +MovingSprite::MovingSprite(const MovingSprite& other) : + MovingObject(other), + sprite_name(), + sprite(), + layer(other.layer) { - sprite = new Sprite(*other.sprite); + sprite.reset(new Sprite(*other.sprite)); } - -MovingSprite& -MovingSprite::operator=(const MovingSprite& other) -{ - if (this == &other) return *this; +/* + MovingSprite& + MovingSprite::operator=(const MovingSprite& other) + { + if (this == &other) + return *this; delete sprite; sprite = new Sprite(*other.sprite); @@ -92,11 +95,10 @@ MovingSprite::operator=(const MovingSprite& other) layer = other.layer; return *this; -} - + } +*/ MovingSprite::~MovingSprite() { - delete sprite; } void @@ -105,9 +107,36 @@ MovingSprite::draw(DrawingContext& context) sprite->draw(context, get_pos(), layer); } -void +void MovingSprite::update(float ) { } +void +MovingSprite::set_action(const std::string& action, int loops) +{ + sprite->set_action(action, loops); + set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); +} + +void +MovingSprite::set_action_centered(const std::string& action, int loops) +{ + Vector old_size = bbox.get_size(); + sprite->set_action(action, loops); + set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); + set_pos(get_pos() - (bbox.get_size() - old_size) / 2); +} + +void +MovingSprite::set_action(const std::string& action, int loops, AnchorPoint anchorPoint) +{ + Rect old_bbox = bbox; + sprite->set_action(action, loops); + float w = sprite->get_current_hitbox_width(); + float h = sprite->get_current_hitbox_height(); + set_size(w, h); + set_pos(get_anchor_pos(old_bbox, w, h, anchorPoint)); +} +/* EOF */