2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "audio/sound_manager.hpp"
20 #include "object/growup.hpp"
21 #include "object/player.hpp"
22 #include "sprite/sprite.hpp"
23 #include "sprite/sprite_manager.hpp"
25 GrowUp::GrowUp(Direction direction) :
26 MovingSprite(Vector(0,0), "images/powerups/egg/egg.sprite", LAYER_OBJECTS, COLGROUP_MOVING),
28 light(0.0f,0.0f,0.0f),
29 lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
31 physic.enable_gravity(true);
32 physic.set_velocity_x((direction == LEFT)?-100:100);
33 sound_manager->preload("sounds/grow.ogg");
34 //set light for glow effect
35 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
36 lightsprite->set_color(Color(0.2f, 0.2f, 0.0f));
40 GrowUp::update(float elapsed_time)
42 movement = physic.get_movement(elapsed_time);
46 GrowUp::draw(DrawingContext& context){
47 //Set Sprite rotation angle
48 sprite->set_angle(get_pos().x * 360.0f / (32.0f * M_PI));
50 MovingSprite::draw(context);
51 //Draw the light when dark
52 context.get_light( get_bbox().get_middle(), &light );
53 if (light.red + light.green < 2.0){
54 context.push_target();
55 context.set_target(DrawingContext::LIGHTMAP);
56 lightsprite->draw(context, get_bbox().get_middle(), 0);
62 GrowUp::collision_solid(const CollisionHit& hit)
65 physic.set_velocity_y(0);
66 if(hit.bottom && physic.get_velocity_y() > 0)
67 physic.set_velocity_y(0);
68 if(hit.left || hit.right)
69 physic.set_velocity_x(-physic.get_velocity_x());
73 GrowUp::collision(GameObject& other, const CollisionHit& hit )
75 Player* player = dynamic_cast<Player*>(&other);
77 if(!player->add_bonus(GROWUP_BONUS, true)){
78 // Tux can't grow right now.
79 collision_solid( hit );
83 sound_manager->play("sounds/grow.ogg");
95 physic.set_velocity_y(-300);