X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fgameobjs.cpp;h=bcbbdd503bb07bdd7766653f687329e6a7c69052;hb=ab9eab4c870195c2b60ce76b77044c35b31e8806;hp=bce0f212340e7efb8538ca73120940ef21e78434;hpb=ef57479f613b900b73eba8e8f4d026aae0de25cc;p=supertux.git diff --git a/src/object/gameobjs.cpp b/src/object/gameobjs.cpp index bce0f2123..bcbbdd503 100644 --- a/src/object/gameobjs.cpp +++ b/src/object/gameobjs.cpp @@ -1,8 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2000 Bill Kendrick -// Copyright (C) 2004 Tobias Glaesser +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -13,34 +12,36 @@ // 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. +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include #include #include -#include "app/globals.h" -#include "tile.h" -#include "tile_manager.h" -#include "gameloop.h" -#include "gameobjs.h" -#include "special/sprite_manager.h" -#include "resources.h" -#include "sector.h" -#include "tilemap.h" -#include "video/drawing_context.h" -#include "camera.h" +#include "tile.hpp" +#include "tile_manager.hpp" +#include "game_session.hpp" +#include "gameobjs.hpp" +#include "sprite/sprite_manager.hpp" +#include "sprite/sprite.hpp" +#include "resources.hpp" +#include "sector.hpp" +#include "tilemap.hpp" +#include "video/drawing_context.hpp" +#include "camera.hpp" +#include "main.hpp" +#include "random_generator.hpp" BouncyCoin::BouncyCoin(const Vector& pos) : position(pos) { timer.start(.3); - sprite = sprite_manager->create("coin"); + sprite = sprite_manager->create("images/objects/coin/coin.sprite"); sprite->set_action("still"); } @@ -50,7 +51,7 @@ BouncyCoin::~BouncyCoin() } void -BouncyCoin::action(float elapsed_time) +BouncyCoin::update(float elapsed_time) { position.y += -200 * elapsed_time; @@ -61,7 +62,7 @@ BouncyCoin::action(float elapsed_time) void BouncyCoin::draw(DrawingContext& context) { - sprite->draw(context, position, LAYER_OBJECTS); + sprite->draw(context, position, LAYER_OBJECTS + 5); } //--------------------------------------------------------------------------- @@ -79,7 +80,7 @@ BrokenBrick::~BrokenBrick() } void -BrokenBrick::action(float elapsed_time) +BrokenBrick::update(float elapsed_time) { position += movement * elapsed_time; @@ -91,7 +92,7 @@ void BrokenBrick::draw(DrawingContext& context) { sprite->draw_part(context, - Vector(rand() % 16, rand() % 16), Vector(16, 16), + Vector(systemRandom.rand(16), systemRandom.rand(16)), Vector(16, 16), position, LAYER_OBJECTS + 1); } @@ -118,7 +119,7 @@ FloatingText::FloatingText(const Vector& pos, int score) } void -FloatingText::action(float elapsed_time) +FloatingText::update(float elapsed_time) { position.y -= 1.4 * elapsed_time; @@ -152,111 +153,25 @@ SmokeCloud::SmokeCloud(const Vector& pos) : position(pos) { timer.start(.3); + sprite = sprite_manager->create("images/objects/particles/stomp.sprite"); } -void -SmokeCloud::action(float elapsed_time) +SmokeCloud::~SmokeCloud() { - position.y -= 120 * elapsed_time; - - if(timer.check()) - remove_me(); + delete sprite; } void -SmokeCloud::draw(DrawingContext& context) +SmokeCloud::update(float elapsed_time) { - img_smoke_cloud->draw(context, position, LAYER_OBJECTS+1); -} - -Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, - const Vector& initial_velocity, const Vector& acceleration, int number, - Color color_, int size_, float life_time, int drawing_layer_) - : accel(acceleration), color(color_), size(size_), drawing_layer(drawing_layer_) -{ - if(life_time == 0) { - live_forever = true; - } else { - live_forever = false; - timer.start(life_time); - } - - // create particles - for(int p = 0; p < number; p++) - { - Particle* particle = new Particle; - particle->pos = epicenter; - - float angle = ((rand() % (max_angle-min_angle))+min_angle) - * (M_PI / 180); // convert to radius - particle->vel.x = /*fabs*/(sin(angle)) * initial_velocity.x; -// if(angle >= M_PI && angle < M_PI*2) -// particle->vel.x *= -1; // work around to fix signal - particle->vel.y = /*fabs*/(cos(angle)) * initial_velocity.y; -// if(angle >= M_PI_2 && angle < 3*M_PI_2) -// particle->vel.y *= -1; - - particles.push_back(particle); - } -} - -Particles::~Particles() -{ - // free particles - for(std::vector::iterator i = particles.begin(); - i < particles.end(); i++) - delete (*i); -} + position.y -= 120 * elapsed_time; -void -Particles::action(float elapsed_time) -{ - Vector camera = Sector::current()->camera->get_translation(); - - // update particles - for(std::vector::iterator i = particles.begin(); - i != particles.end(); ) { - (*i)->pos.x += (*i)->vel.x * elapsed_time; - (*i)->pos.y += (*i)->vel.y * elapsed_time; - - (*i)->vel.x += accel.x * elapsed_time; - (*i)->vel.y += accel.y * elapsed_time; - - if((*i)->pos.x < camera.x || (*i)->pos.x > screen->w + camera.x || - (*i)->pos.y < camera.y || (*i)->pos.y > screen->h + camera.y) { - delete (*i); - i = particles.erase(i); - } else { - ++i; - } - } - - if((timer.check() && !live_forever) || particles.size() == 0) + if(timer.check()) remove_me(); } void -Particles::draw(DrawingContext& context) -{ - // draw particles - for(std::vector::iterator i = particles.begin(); - i != particles.end(); i++) { - context.draw_filled_rect((*i)->pos, Vector(size,size), color,drawing_layer); - } -} - -void load_object_gfx() -{ -#if 0 - img_trampoline = sprite_manager->load("trampoline"); - img_trampoline->start_animation(0); - img_flying_platform = sprite_manager->load("flying_platform"); -#endif - img_smoke_cloud = sprite_manager->create("stomp"); -} - -void free_object_gfx() +SmokeCloud::draw(DrawingContext& context) { - delete img_smoke_cloud; + sprite->draw(context, position, LAYER_OBJECTS+1); } -