X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Fbullet.cpp;h=b26bd35d8294b6ba1684932fe42a148a3aae0b84;hb=d097f456b8ab4f42058545bdd4f8f676d151e974;hp=564b7ba0feb44400645d93ab5b120a0f63029d11;hpb=ab215c41de1a14f594221e8b43a442d607b6a775;p=supertux.git diff --git a/src/object/bullet.cpp b/src/object/bullet.cpp index 564b7ba0f..b26bd35d8 100644 --- a/src/object/bullet.cpp +++ b/src/object/bullet.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux // 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 -// 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,36 +12,42 @@ // 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 +// along with this program. If not, see . -#include -#include "bullet.hpp" -#include "resources.hpp" -#include "camera.hpp" -#include "sector.hpp" +#include "math/random_generator.hpp" +#include "object/bullet.hpp" +#include "object/camera.hpp" +#include "sprite/sprite.hpp" #include "sprite/sprite_manager.hpp" -#include "badguy/badguy.hpp" -#include "main.hpp" +#include "supertux/globals.hpp" +#include "supertux/sector.hpp" namespace { - const float BULLET_XM = 600; - const float BULLET_STARTING_YM = 0; +const float BULLET_XM = 600; } -Bullet::Bullet(const Vector& pos, float xm, int dir, BonusType type) - : life_count(3), type(type) +Bullet::Bullet(const Vector& pos, float xm, int dir, BonusType type_) : + physic(), + life_count(3), + sprite(), + light(0.0f,0.0f,0.0f), + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")), + type(type_) { float speed = dir == RIGHT ? BULLET_XM : -BULLET_XM; physic.set_velocity_x(speed + xm); if(type == FIRE_BONUS) { - sprite.reset(sprite_manager->create("images/objects/bullets/firebullet.sprite")); - } else if(type == ICE_BONUS) { + sprite = SpriteManager::current()->create("images/objects/bullets/firebullet.sprite"); + lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + lightsprite->set_color(Color(0.3f, 0.1f, 0.0f)); + } else if(type == ICE_BONUS) { + life_count = 10; + sprite = SpriteManager::current()->create("images/objects/bullets/icebullet.sprite"); + } else { + log_warning << "Bullet::Bullet called with unknown BonusType" << std::endl; life_count = 10; - sprite.reset(sprite_manager->create("images/objects/bullets/icebullet.sprite")); + sprite = SpriteManager::current()->create("images/objects/bullets/firebullet.sprite"); } bbox.set_pos(pos); @@ -57,6 +61,11 @@ Bullet::~Bullet() void Bullet::update(float elapsed_time) { + // cause fireball color to flicker randomly + if (gameRandom.rand(5) != 0) { + lightsprite->set_color(Color(0.3f + gameRandom.rand(10)/100.0f, 0.1f + gameRandom.rand(20)/100.0f, gameRandom.rand(10)/100.0f)); + } else + lightsprite->set_color(Color(0.3f, 0.1f, 0.0f)); // remove bullet when it's offscreen float scroll_x = Sector::current()->camera->get_translation().x; @@ -64,7 +73,7 @@ Bullet::update(float elapsed_time) Sector::current()->camera->get_translation().y; if (get_pos().x < scroll_x || get_pos().x > scroll_x + SCREEN_WIDTH || -// get_pos().y < scroll_y || + // get_pos().y < scroll_y || get_pos().y > scroll_y + SCREEN_HEIGHT || life_count <= 0) { remove_me(); @@ -77,7 +86,19 @@ Bullet::update(float elapsed_time) void Bullet::draw(DrawingContext& context) { + //Draw the Sprite. sprite->draw(context, get_pos(), LAYER_OBJECTS); + //Draw the light if fire and dark + if(type == FIRE_BONUS){ + context.get_light( get_bbox().get_middle(), &light ); + if (light.red + light.green < 2.0){ + context.push_target(); + context.set_target(DrawingContext::LIGHTMAP); + sprite->draw(context, get_pos(), LAYER_OBJECTS); + lightsprite->draw(context, get_bbox().get_middle(), 0); + context.pop_target(); + } + } } void @@ -95,7 +116,7 @@ Bullet::collision_solid(const CollisionHit& hit) } } -void +void Bullet::ricochet(GameObject& , const CollisionHit& hit) { collision_solid(hit); @@ -106,3 +127,5 @@ Bullet::collision(GameObject& , const CollisionHit& ) { return FORCE_MOVE; } + +/* EOF */