From 61fefdd27bed4650cfb515f2511c4fb3de393193 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sun, 22 Jan 2006 13:12:49 +0000 Subject: [PATCH] first very unfinished and unpolished version of the intro SVN-Revision: 3016 --- data/levels/test/default.nut | 4 +- data/levels/test/script.stl | 10 +-- data/levels/world1/default.nut | 73 +++++++++++++++++++ data/levels/world1/intro.stl | 144 ++++++++++++++++++++++++++++++++++++++ data/levels/world2/default.nut | 2 +- src/audio/sound_manager.cpp | 25 ++++--- src/audio/sound_manager.hpp | 2 +- src/audio/sound_source.cpp | 5 ++ src/audio/sound_source.hpp | 2 + src/audio/stream_sound_source.cpp | 44 +++++++----- src/audio/stream_sound_source.hpp | 14 +++- src/object/display_effect.cpp | 102 ++++++++++++++++++--------- src/object/display_effect.hpp | 19 ++--- src/object/player.cpp | 15 ++++ src/object/player.hpp | 5 ++ src/object/scripted_object.cpp | 4 +- src/object/scripted_object.hpp | 4 +- src/scripting/display_effect.hpp | 4 +- src/scripting/player.hpp | 9 +++ src/scripting/scripted_object.hpp | 4 +- src/scripting/wrapper.cpp | 67 ++++++++++++++---- src/sector.cpp | 1 - 22 files changed, 457 insertions(+), 102 deletions(-) create mode 100644 data/levels/world1/default.nut create mode 100644 data/levels/world1/intro.stl diff --git a/data/levels/test/default.nut b/data/levels/test/default.nut index 42ba95d09..dbafc8eb2 100644 --- a/data/levels/test/default.nut +++ b/data/levels/test/default.nut @@ -3,10 +3,10 @@ function intro() { DisplayEffect.sixteen_to_nine(); - PENNY.set_animation("stand"); + PENNY.set_action("stand"); Text.set_centered(true); Text.set_text(translate("SuperTux\nMilestone 2")); Text.fade_in(2); wait(4); Text.fade_out(1); -} \ No newline at end of file +} diff --git a/data/levels/test/script.stl b/data/levels/test/script.stl index 9e2267b97..875877e72 100644 --- a/data/levels/test/script.stl +++ b/data/levels/test/script.stl @@ -140,7 +140,7 @@ (init-script " Text.set_text(translate(\"The Crazy Nolok Dance\")); Text.fade_in(2); -TUX.set_animation(\"jump\"); +TUX.set_action(\"jump\"); wait(4); Text.fade_out(1); wait(1); @@ -159,14 +159,14 @@ while(true) { tuxjumps--; wait(0.5); if(PENNY.get_animation() == \"stand\") { - PENNY.set_animation(\"throw\"); + PENNY.set_action(\"throw\"); } else if(PENNY.get_animation() == \"throw\") { - PENNY.set_animation(\"jump\"); + PENNY.set_action(\"jump\"); } else if(PENNY.get_animation() == \"jump\") { - PENNY.set_animation(\"dead\"); + PENNY.set_action(\"dead\"); } else { Sound.play(\"sounds/grow.wav\"); - PENNY.set_animation(\"stand\"); + PENNY.set_action(\"stand\"); PENNY.set_velocity(0, 900); } } diff --git a/data/levels/world1/default.nut b/data/levels/world1/default.nut new file mode 100644 index 000000000..335649ceb --- /dev/null +++ b/data/levels/world1/default.nut @@ -0,0 +1,73 @@ +function intro() +{ + SUPERTUX.set_action("stand-right"); + Tux.deactivate(); + Tux.set_visible(false); + DisplayEffect.sixteen_to_nine(0); + DisplayEffect.fade_in(2); + wait(2); + + Text.set_text(translate("Tux and Penny were out having a\n nice picnic on the\nice fields of Antarctica.")); + Text.fade_in(1); +// TODO play some tux sounds... + wait(1); + + Sound.play("speech/tux_rap.ogg"); + wait(5); + Text.fade_out(1); + wait(15); + + Text.set_text(translate("Then suddenly...")); + Text.fade_in(1); + +// let's shake the bush... + // Sound.play("sounds/rustle.wav"); + local bushx = BUSH.get_pos_x(); + local bushy = BUSH.get_pos_y(); + for(local i = 0; i < 20; ++i) { + BUSH.set_pos(bushx + rand() % 6 - 3, bushy); + wait(0.1); + } + Text.fade_out(1); + +// NOLOK jumps out of the bush + wait(0.5); + print("jump"); + NOLOK.set_velocity(70, 600); + + wait(1) + NOLOK.set_velocity(-120, 700); + wait(2); + +// nolok casts his spell... + NOLOK.set_action("throw"); + // TODO we really need fade to white here and some thunder sound... + DisplayEffect.fade_out(0.3); + wait(0.3); + DisplayEffect.fade_in(0); + wait(0.3); + DisplayEffect.fade_out(0.5); + wait(0.5); + DisplayEffect.fade_in(0); + wait(0.4); + DisplayEffect.fade_out(0.2); + wait(2.5); + NOLOK.set_visible(false); + PENNY.set_visible(false); + DisplayEffect.fade_in(1); + wait(1); + + Text.set_text("Oh No!\nPenny has been captured"); + Text.fade_in(1); + wait(3); + Text.fade_out(1); + + Text.set_text("Tux has to rescue her"); + Text.fade_in(1); + wait(5); + +// fade out + DisplayEffect.fade_out(2); + wait(2); + Level.finish(); +} diff --git a/data/levels/world1/intro.stl b/data/levels/world1/intro.stl new file mode 100644 index 000000000..40ad26115 --- /dev/null +++ b/data/levels/world1/intro.stl @@ -0,0 +1,144 @@ +;; Generated by Flexlay Editor +(supertux-level + (version 2) + (name (_ "Intro")) + (author "Development Team") + (sector + (name "main") + (init-script "intro()") + (gravity 10.000000) + (tilemap + (layer "background") + (solid #f) + (speed 1.000000) + (width 25) + (height 20) + (tiles + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + )) + (tilemap + (layer "interactive") + (solid #t) + (speed 1.000000) + (width 25) + (height 20) + (tiles + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 122 209 209 123 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 124 210 210 125 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 124 210 210 125 0 0 0 0 0 0 0 0 0 + 0 0 122 123 0 0 0 0 0 0 0 0 124 210 210 125 0 0 0 0 0 0 0 0 0 + 0 0 124 125 0 0 0 0 0 0 0 0 124 210 210 125 0 0 122 123 0 0 0 0 0 + 0 0 124 125 0 0 0 0 0 0 0 0 124 210 210 125 0 0 124 125 0 0 0 0 0 + 0 0 1345 1344 0 0 0 0 0 0 0 0 1345 1346 1346 1344 0 0 1345 1344 0 0 0 0 0 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (tilemap + (layer "foreground") + (solid #f) + (speed 1.000000) + (width 25) + (height 20) + (tiles + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 1350 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (camera + (mode "normal") + ) + + (background + (image "semi_arctic.jpg") + (speed 0.500000) + ) + (spawnpoint (name "main") (x 320) (y 416)) + (particles-snow + ) + (scriptedobject + (x 286) (y 443) + (name "PENNY") + (sprite "images/creatures/penny/penny.sprite") + (layer 100) + (visible #t) + (physic-enabled #f) + (solid #f) + ) + (scriptedobject + (x 492) (y 440) + (name "NOLOK") + (sprite "images/creatures/nolok/nolok.sprite") + (layer 100) + (visible #t) + (physic-enabled #t) + (solid #f) + ) + (scriptedobject + (x 465) (y 390) + (name "BUSH") + (sprite "images/tiles/doodads/iceshrub.sprite") + (layer 105) + (visible #t) + (physic-enabled #f) + (solid #f) + ) + (scriptedobject + (x 187) (y 442) + (name "SUPERTUX") + (sprite "images/creatures/tux_big/tux.sprite") + (layer 100) + (visible #t) + (physic-enabled #t) + (solid #f) + ) + ) + ) + +;; EOF ;; diff --git a/data/levels/world2/default.nut b/data/levels/world2/default.nut index ea54a7e37..ca65fc778 100644 --- a/data/levels/world2/default.nut +++ b/data/levels/world2/default.nut @@ -10,7 +10,7 @@ function level2_init() add_key(KEY_BRASS); add_key(KEY_IRON); Tux.deactivate(); - DisplayEffect.sixteen_to_nine(); + DisplayEffect.sixteen_to_nine(2); Text.set_text(translate("---Insert Cutscene Here---")); Tux.walk(100); Text.fade_in(2); diff --git a/src/audio/sound_manager.cpp b/src/audio/sound_manager.cpp index 656caacff..aa52e289b 100644 --- a/src/audio/sound_manager.cpp +++ b/src/audio/sound_manager.cpp @@ -60,12 +60,9 @@ SoundManager::~SoundManager() } ALuint -SoundManager::load_file_into_buffer(const std::string& filename) +SoundManager::load_file_into_buffer(SoundFile* file) { - // open sound file - std::auto_ptr file (load_sound_file(filename)); - - ALenum format = get_sample_format(file.get()); + ALenum format = get_sample_format(file); ALuint buffer; alGenBuffers(1, &buffer); check_al_error("Couldn't create audio buffer: "); @@ -98,8 +95,17 @@ SoundManager::create_sound_source(const std::string& filename) if(i != buffers.end()) { buffer = i->second; } else { - buffer = load_file_into_buffer(filename); - buffers.insert(std::make_pair(filename, buffer)); + // Load sound file + std::auto_ptr file (load_sound_file(filename)); + + if(file->size < 100000) { + buffer = load_file_into_buffer(file.get()); + buffers.insert(std::make_pair(filename, buffer)); + } else { + StreamSoundSource* source = new StreamSoundSource(); + source->set_sound_file(file.release()); + return source; + } } SoundSource* source = new SoundSource(); @@ -224,9 +230,12 @@ SoundManager::update() return; lastticks = current_ticks; - // check for finished sound sources + // update and check for finished sound sources for(SoundSources::iterator i = sources.begin(); i != sources.end(); ) { SoundSource* source = *i; + + source->update(); + if(!source->playing()) { delete source; i = sources.erase(i); diff --git a/src/audio/sound_manager.hpp b/src/audio/sound_manager.hpp index 1d3f76531..a1b59d6c7 100644 --- a/src/audio/sound_manager.hpp +++ b/src/audio/sound_manager.hpp @@ -50,7 +50,7 @@ private: friend class SoundSource; friend class StreamSoundSource; - static ALuint load_file_into_buffer(const std::string& filename); + static ALuint load_file_into_buffer(SoundFile* file); static ALenum get_sample_format(SoundFile* file); void print_openal_version(); diff --git a/src/audio/sound_source.cpp b/src/audio/sound_source.cpp index 399f3a3f7..421e0975c 100644 --- a/src/audio/sound_source.cpp +++ b/src/audio/sound_source.cpp @@ -40,6 +40,11 @@ SoundSource::playing() } void +SoundSource::update() +{ +} + +void SoundSource::set_looping(bool looping) { alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE); diff --git a/src/audio/sound_source.hpp b/src/audio/sound_source.hpp index 4860eaec9..b20204348 100644 --- a/src/audio/sound_source.hpp +++ b/src/audio/sound_source.hpp @@ -14,6 +14,8 @@ public: void stop(); bool playing(); + virtual void update(); + void set_looping(bool looping); /// Set volume (0.0 is silent, 1.0 is normal) void set_gain(float gain); diff --git a/src/audio/stream_sound_source.cpp b/src/audio/stream_sound_source.cpp index 4e3b5d0b0..868b4bce2 100644 --- a/src/audio/stream_sound_source.cpp +++ b/src/audio/stream_sound_source.cpp @@ -30,7 +30,8 @@ StreamSoundSource::set_sound_file(SoundFile* newfile) ALint queued; alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); for(size_t i = 0; i < STREAMFRAGMENTS - queued; ++i) { - fillBufferAndQueue(buffers[i]); + if(fillBufferAndQueue(buffers[i]) == false) + break; } } @@ -44,11 +45,12 @@ StreamSoundSource::update() alSourceUnqueueBuffers(source, 1, &buffer); SoundManager::check_al_error("Couldn't unqueu audio buffer: "); - fillBufferAndQueue(buffer); + if(fillBufferAndQueue(buffer) == false) + break; } if(!playing()) { - if(processed == 0) + if(processed == 0 || !looping) return; // we might have to restart the source if we had a buffer underrun @@ -56,12 +58,6 @@ StreamSoundSource::update() play(); } -#ifdef DEBUG - ALint queued; - alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); - assert(queued == (ALint) STREAMFRAGMENTS); -#endif - if(fade_state == FadingOn) { Uint32 ticks = SDL_GetTicks(); float time = (ticks - fade_start_ticks) / 1000.0; @@ -91,7 +87,7 @@ StreamSoundSource::set_fading(FadeState state, float fade_time) this->fade_start_ticks = SDL_GetTicks(); } -void +bool StreamSoundSource::fillBufferAndQueue(ALuint buffer) { // fill buffer @@ -100,16 +96,26 @@ StreamSoundSource::fillBufferAndQueue(ALuint buffer) do { bytesread += file->read(bufferdata + bytesread, STREAMFRAGMENTSIZE - bytesread); + // end of sound file if(bytesread < STREAMFRAGMENTSIZE) { - file->reset(); + if(looping) + file->reset(); + else + break; } } while(bytesread < STREAMFRAGMENTSIZE); - - ALenum format = SoundManager::get_sample_format(file); - alBufferData(buffer, format, bufferdata, STREAMFRAGMENTSIZE, file->rate); - delete[] bufferdata; - SoundManager::check_al_error("Couldn't refill audio buffer: "); - - alSourceQueueBuffers(source, 1, &buffer); - SoundManager::check_al_error("Couldn't queue audio buffer: "); + + if(bytesread > 0) { + ALenum format = SoundManager::get_sample_format(file); + alBufferData(buffer, format, bufferdata, bytesread, file->rate); + delete[] bufferdata; + SoundManager::check_al_error("Couldn't refill audio buffer: "); + + alSourceQueueBuffers(source, 1, &buffer); + SoundManager::check_al_error("Couldn't queue audio buffer: "); + } + + // return false if there aren't more buffers to fill + return bytesread >= STREAMFRAGMENTSIZE; } + diff --git a/src/audio/stream_sound_source.hpp b/src/audio/stream_sound_source.hpp index 05342eb48..657405ccd 100644 --- a/src/audio/stream_sound_source.hpp +++ b/src/audio/stream_sound_source.hpp @@ -20,9 +20,18 @@ public: void set_fading(FadeState state, float fadetime); FadeState get_fade_state() const { - return fade_state; + return fade_state; } void update(); + + void set_looping(bool looping) + { + this->looping = looping; + } + bool get_looping() const + { + return looping; + } private: static const size_t STREAMBUFFERSIZE = 1024 * 500; @@ -30,13 +39,14 @@ private: static const size_t STREAMFRAGMENTSIZE = STREAMBUFFERSIZE / STREAMFRAGMENTS; - void fillBufferAndQueue(ALuint buffer); + bool fillBufferAndQueue(ALuint buffer); SoundFile* file; ALuint buffers[STREAMFRAGMENTS]; FadeState fade_state; Uint32 fade_start_ticks; float fade_time; + bool looping; }; #endif diff --git a/src/object/display_effect.cpp b/src/object/display_effect.cpp index 1f67b43e8..ffa154dc9 100644 --- a/src/object/display_effect.cpp +++ b/src/object/display_effect.cpp @@ -5,12 +5,13 @@ #include "video/drawing_context.hpp" #include "main.hpp" +static const float BORDER_SIZE = 75; + DisplayEffect::DisplayEffect() - : type(NO_FADE), fadetime(0), fading(0), black(false) + : screen_fade(NO_FADE), screen_fadetime(0), screen_fading(0), + border_fade(NO_FADE), border_fadetime(0), border_size(0), + black(false), borders(false) { - border_size = 0; - borders_fading = false; - borders_active = false; } DisplayEffect::~DisplayEffect() @@ -20,33 +21,48 @@ DisplayEffect::~DisplayEffect() void DisplayEffect::update(float elapsed_time) { - if (borders_fading) { - if (border_size < 75) border_size += 1.5; - else borders_active = true; - } - else if (borders_active) { - if (border_size > 0) border_size -= 1.5; - else borders_active = false; - } - switch(type) { + switch(screen_fade) { case NO_FADE: - return; + break; case FADE_IN: - fading -= elapsed_time; - if(fading < 0) { - type = NO_FADE; + screen_fading -= elapsed_time; + if(screen_fading < 0) { + screen_fade = NO_FADE; } break; case FADE_OUT: - fading -= elapsed_time; - if(fading < 0) { - type = NO_FADE; + screen_fading -= elapsed_time; + if(screen_fading < 0) { + screen_fade = NO_FADE; black = true; } break; default: assert(false); } + + switch(border_fade) { + case NO_FADE: + break; + case FADE_IN: + border_fading -= elapsed_time; + if(border_fading < 0) { + border_fade = NO_FADE; + } + border_size = border_fading / border_fading * BORDER_SIZE; + break; + case FADE_OUT: + border_fading -= elapsed_time; + if(border_fading < 0) { + borders = false; + border_fade = NO_FADE; + } + border_size = (border_fadetime - border_fading) + / border_fadetime * BORDER_SIZE; + break; + default: + assert(false); + } } void @@ -55,17 +71,17 @@ DisplayEffect::draw(DrawingContext& context) context.push_transform(); context.set_translation(Vector(0, 0)); - if(black || type != NO_FADE) { + if(black || screen_fade != NO_FADE) { float alpha; if(black) { alpha = 1.0f; } else { - switch(type) { + switch(screen_fade) { case FADE_IN: - alpha = fading / fadetime; + alpha = screen_fading / screen_fadetime; break; case FADE_OUT: - alpha = (fadetime-fading) / fadetime; + alpha = (screen_fadetime - screen_fading) / screen_fadetime; break; default: alpha = 0; @@ -76,7 +92,7 @@ DisplayEffect::draw(DrawingContext& context) Color(0, 0, 0, alpha), LAYER_GUI-10); } - if (borders_fading || borders_active) { + if (borders) { context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, border_size), Color(0, 0, 0, 1.0f), LAYER_GUI-10); context.draw_filled_rect(Vector(0, SCREEN_HEIGHT - border_size), Vector(SCREEN_WIDTH, border_size), @@ -90,18 +106,18 @@ void DisplayEffect::fade_out(float fadetime) { black = false; - this->fadetime = fadetime; - fading = fadetime; - type = FADE_OUT; + screen_fadetime = fadetime; + screen_fading = fadetime; + screen_fade = FADE_OUT; } void DisplayEffect::fade_in(float fadetime) { black = false; - this->fadetime = fadetime; - fading = fadetime; - type = FADE_IN; + this->screen_fadetime = fadetime; + screen_fading = fadetime; + screen_fade = FADE_IN; } void @@ -117,14 +133,30 @@ DisplayEffect::is_black() } void -DisplayEffect::sixteen_to_nine() +DisplayEffect::sixteen_to_nine(float fadetime) { - borders_fading = true; + if(fadetime == 0) { + borders = true; + border_size = BORDER_SIZE; + } else { + borders = true; + border_size = 0; + border_fade = FADE_IN; + border_fadetime = fadetime; + border_fading = border_fadetime; + } } void -DisplayEffect::four_to_three() +DisplayEffect::four_to_three(float fadetime) { - borders_fading = false; + if(fadetime == 0) { + borders = false; + } else { + border_size = BORDER_SIZE; + border_fade = FADE_OUT; + border_fadetime = fadetime; + border_fading = border_fadetime; + } } diff --git a/src/object/display_effect.hpp b/src/object/display_effect.hpp index eec97772e..033d8adae 100644 --- a/src/object/display_effect.hpp +++ b/src/object/display_effect.hpp @@ -17,20 +17,23 @@ public: void fade_in(float fadetime); void set_black(bool enabled); bool is_black(); - void sixteen_to_nine(); - void four_to_three(); + void sixteen_to_nine(float fadetime); + void four_to_three(float fadetime); private: enum FadeType { NO_FADE, FADE_IN, FADE_OUT }; - FadeType type; - float fadetime; - float fading; - bool black; - bool borders_fading; - bool borders_active; + FadeType screen_fade; + float screen_fadetime; + float screen_fading; + FadeType border_fade; + float border_fadetime; + float border_fading; float border_size; + + bool black; + bool borders; }; #endif diff --git a/src/object/player.cpp b/src/object/player.cpp index 1748059fc..beaeb7088 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -522,6 +522,18 @@ Player::set_bonus(BonusType type, bool animate) } void +Player::set_visible(bool visible) +{ + this->visible = visible; +} + +bool +Player::get_visible() +{ + return visible; +} + +void Player::kick() { kick_timer.start(KICK_TIME); @@ -530,6 +542,9 @@ Player::kick() void Player::draw(DrawingContext& context) { + if(!visible) + return; + TuxBodyParts* tux_body; if (player_status->bonus == GROWUP_BONUS) diff --git a/src/object/player.hpp b/src/object/player.hpp index 69396a737..fa4b80fd4 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -153,6 +153,9 @@ public: bool is_dead() const { return dead; } bool is_big(); + + void set_visible(bool visible); + bool get_visible(); private: void handle_input(); @@ -168,6 +171,8 @@ private: void deactivate(); void walk(float speed); + bool visible; + Portable* grabbed_object; Sprite* smalltux_gameover; diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index 9cb154b11..b9378fde5 100644 --- a/src/object/scripted_object.cpp +++ b/src/object/scripted_object.cpp @@ -100,13 +100,13 @@ ScriptedObject::is_visible() } void -ScriptedObject::set_animation(const std::string& animation) +ScriptedObject::set_action(const std::string& animation) { sprite->set_action(animation); } std::string -ScriptedObject::get_animation() +ScriptedObject::get_action() { return sprite->get_action_name(); } diff --git a/src/object/scripted_object.hpp b/src/object/scripted_object.hpp index 5a285a51d..699a0540b 100644 --- a/src/object/scripted_object.hpp +++ b/src/object/scripted_object.hpp @@ -20,8 +20,8 @@ public: // --- Scripting Interface stuff --- - void set_animation(const std::string& animation); - std::string get_animation(); + void set_action(const std::string& animation); + std::string get_action(); void move(float x, float y); void set_pos(float x, float y); diff --git a/src/scripting/display_effect.hpp b/src/scripting/display_effect.hpp index 01d448823..3fff42414 100644 --- a/src/scripting/display_effect.hpp +++ b/src/scripting/display_effect.hpp @@ -21,9 +21,9 @@ public: /// check if display is set to black virtual bool is_black() = 0; /// set black borders for cutscenes - virtual void sixteen_to_nine() = 0; + virtual void sixteen_to_nine(float fadetime) = 0; /// deactivate borders - virtual void four_to_three() = 0; + virtual void four_to_three(float fadetime) = 0; // fade display until just a small visible circle is left // (like what happens in some cartoons at the end) diff --git a/src/scripting/player.hpp b/src/scripting/player.hpp index fee8f69ee..579652463 100644 --- a/src/scripting/player.hpp +++ b/src/scripting/player.hpp @@ -43,6 +43,15 @@ public: * Make Tux walk */ virtual void walk(float speed) = 0; + /** + * Set player visible or not visible + */ + virtual void set_visible(bool visible) = 0; + /** + * returns true if the player is currently visible (that is he was not set + * inivisible by the set_visible method) + */ + virtual bool get_visible() = 0; }; } diff --git a/src/scripting/scripted_object.hpp b/src/scripting/scripted_object.hpp index 9bb0b4411..3db792185 100644 --- a/src/scripting/scripted_object.hpp +++ b/src/scripting/scripted_object.hpp @@ -12,8 +12,8 @@ public: {} #endif - virtual void set_animation(const std::string& animation) = 0; - virtual std::string get_animation() = 0; + virtual void set_action(const std::string& animation) = 0; + virtual std::string get_action() = 0; virtual void move(float x, float y) = 0; virtual void set_pos(float x, float y) = 0; diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 4554f5457..ab1a764e5 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -76,8 +76,10 @@ static int DisplayEffect_sixteen_to_nine_wrapper(HSQUIRRELVM v) { Scripting::DisplayEffect* _this; sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + float arg0; + sq_getfloat(v, 2, &arg0); - _this->sixteen_to_nine(); + _this->sixteen_to_nine(arg0); return 0; } @@ -86,8 +88,10 @@ static int DisplayEffect_four_to_three_wrapper(HSQUIRRELVM v) { Scripting::DisplayEffect* _this; sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + float arg0; + sq_getfloat(v, 2, &arg0); - _this->four_to_three(); + _this->four_to_three(arg0); return 0; } @@ -189,24 +193,24 @@ static int ScriptedObject_release_hook(SQUserPointer ptr, int ) return 0; } -static int ScriptedObject_set_animation_wrapper(HSQUIRRELVM v) +static int ScriptedObject_set_action_wrapper(HSQUIRRELVM v) { Scripting::ScriptedObject* _this; sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); const char* arg0; sq_getstring(v, 2, &arg0); - _this->set_animation(arg0); + _this->set_action(arg0); return 0; } -static int ScriptedObject_get_animation_wrapper(HSQUIRRELVM v) +static int ScriptedObject_get_action_wrapper(HSQUIRRELVM v) { Scripting::ScriptedObject* _this; sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); - std::string return_value = _this->get_animation(); + std::string return_value = _this->get_action(); sq_pushstring(v, return_value.c_str(), return_value.size()); return 1; @@ -491,6 +495,29 @@ static int Player_walk_wrapper(HSQUIRRELVM v) return 0; } +static int Player_set_visible_wrapper(HSQUIRRELVM v) +{ + Scripting::Player* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + SQBool arg0; + sq_getbool(v, 2, &arg0); + + _this->set_visible(arg0); + + return 0; +} + +static int Player_get_visible_wrapper(HSQUIRRELVM v) +{ + Scripting::Player* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + + bool return_value = _this->get_visible(); + + sq_pushbool(v, return_value); + return 1; +} + static int display_text_file_wrapper(HSQUIRRELVM v) { const char* arg0; @@ -954,19 +981,19 @@ void register_supertux_wrapper(HSQUIRRELVM v) msg << "Couldn't create new class 'ScriptedObject'"; throw SquirrelError(v, msg.str()); } - sq_pushstring(v, "set_animation", -1); - sq_newclosure(v, &ScriptedObject_set_animation_wrapper, 0); + sq_pushstring(v, "set_action", -1); + sq_newclosure(v, &ScriptedObject_set_action_wrapper, 0); if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; - msg << "Couldn't register function'set_animation'"; + msg << "Couldn't register function'set_action'"; throw SquirrelError(v, msg.str()); } - sq_pushstring(v, "get_animation", -1); - sq_newclosure(v, &ScriptedObject_get_animation_wrapper, 0); + sq_pushstring(v, "get_action", -1); + sq_newclosure(v, &ScriptedObject_get_action_wrapper, 0); if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; - msg << "Couldn't register function'get_animation'"; + msg << "Couldn't register function'get_action'"; throw SquirrelError(v, msg.str()); } @@ -1185,6 +1212,22 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, msg.str()); } + sq_pushstring(v, "set_visible", -1); + sq_newclosure(v, &Player_set_visible_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'set_visible'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "get_visible", -1); + sq_newclosure(v, &Player_get_visible_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'get_visible'"; + throw SquirrelError(v, msg.str()); + } + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'Player'"; diff --git a/src/sector.cpp b/src/sector.cpp index 69ab89da6..cbdc96fba 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -70,7 +70,6 @@ Sector::Sector() : gravity(10), player(0), solids(0), camera(0), currentmusic(LEVEL_MUSIC) { - song_title = "chipdisko.ogg"; player = new Player(player_status); add_object(player); -- 2.11.0