2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 #include "Tutorial.hpp"
23 #include "Audio/Sounds.hpp"
24 #include "Audio/openal_wrapper.hpp"
25 #include "Level/Awards.hpp"
26 #include "Objects/Person.hpp"
27 #include "Utils/Input.hpp"
29 extern bool reversaltrain;
30 extern bool canattack;
33 extern float damagedealt;
34 extern bool againbonus;
35 extern float screenwidth, screenheight;
38 bool Tutorial::active = false;
39 int Tutorial::stage = 0;
40 float Tutorial::stagetime = 0;
41 float Tutorial::maxtime = 0;
42 float Tutorial::success = 0;
44 void Tutorial::Do(float multiplier)
46 if (stagetime > maxtime) {
89 Person::players[1]->coords = (temp + temp2) / 2;
91 emit_sound_at(fireendsound, Person::players[1]->coords);
93 for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) {
94 if (Random() % 2 == 0) {
95 if (!Person::players[1]->skeleton.free)
96 temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2;
97 if (Person::players[1]->skeleton.free)
98 temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2;
99 if (!Person::players[1]->skeleton.free)
100 temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords;
101 if (Person::players[1]->skeleton.free)
102 temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords;
103 Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
124 if (bonus == cannon) {
134 Person::players[1]->aitype = attacktypecutoff;
143 Person::players[0]->escapednum = 0;
149 Person::players[1]->aitype = passivetype;
162 Person::players[1]->aitype = attacktypecutoff;
168 Person::players[1]->aitype = passivetype;
176 Person::players[1]->aitype = attacktypecutoff;
182 Person::players[1]->aitype = passivetype;
195 w.position = (temp + temp2) / 2;
196 w.tippoint = (temp + temp2) / 2;
206 weapons.push_back(w);
215 weapons[0].owner = 1;
216 Person::players[0]->weaponactive = -1;
217 Person::players[0]->num_weapons = 0;
218 Person::players[1]->weaponactive = 0;
219 Person::players[1]->num_weapons = 1;
220 Person::players[1]->weaponids[0] = 0;
224 Person::players[1]->aitype = attacktypecutoff;
229 weapons[0].owner = 1;
230 Person::players[0]->weaponactive = -1;
231 Person::players[0]->num_weapons = 0;
232 Person::players[1]->weaponactive = 0;
233 Person::players[1]->num_weapons = 1;
234 Person::players[1]->weaponids[0] = 0;
239 weapons[0].owner = 1;
240 Person::players[0]->weaponactive = -1;
241 Person::players[0]->num_weapons = 0;
242 Person::players[1]->weaponactive = 0;
243 Person::players[1]->num_weapons = 1;
244 Person::players[1]->weaponids[0] = 0;
246 weapons[0].setType(sword);
263 w.position = (temp + temp2) / 2;
264 w.tippoint = (temp + temp2) / 2;
274 weapons.push_back(w);
276 weapons[0].owner = 1;
277 weapons[1].owner = 0;
278 Person::players[0]->weaponactive = 0;
279 Person::players[0]->num_weapons = 1;
280 Person::players[0]->weaponids[0] = 1;
281 Person::players[1]->weaponactive = 0;
282 Person::players[1]->num_weapons = 1;
283 Person::players[1]->weaponids[0] = 0;
290 Person::players[1]->aitype = passivetype;
294 weapons[0].owner = 1;
295 weapons[1].owner = 0;
296 Person::players[0]->weaponactive = 0;
297 Person::players[0]->num_weapons = 1;
298 Person::players[0]->weaponids[0] = 1;
299 Person::players[1]->weaponactive = 0;
300 Person::players[1]->num_weapons = 1;
301 Person::players[1]->weaponids[0] = 0;
303 if (Person::players[0]->weaponactive != -1)
304 weapons[Person::players[0]->weaponids[Person::players[0]->weaponactive]].setType(staff);
306 weapons[0].setType(staff);
311 Person::players[1]->aitype = passivetype;
315 weapons[1].position = 1000;
316 weapons[1].tippoint = 1000;
318 weapons[0].setType(knife);
320 weapons[0].owner = 0;
321 Person::players[1]->weaponactive = -1;
322 Person::players[1]->num_weapons = 0;
323 Person::players[0]->weaponactive = 0;
324 Person::players[0]->num_weapons = 1;
325 Person::players[0]->weaponids[0] = 0;
332 emit_sound_at(fireendsound, Person::players[1]->coords);
334 for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) {
335 if (Random() % 2 == 0) {
336 if (!Person::players[1]->skeleton.free)
337 temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2;
338 if (Person::players[1]->skeleton.free)
339 temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2;
340 if (!Person::players[1]->skeleton.free)
341 temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords;
342 if (Person::players[1]->skeleton.free)
343 temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords;
344 Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
348 Person::players[1]->num_weapons = 0;
349 Person::players[1]->weaponstuck = -1;
350 Person::players[1]->weaponactive = -1;
366 if (stagetime < maxtime - 3) {
369 if (Game::deltah || Game::deltav)
370 success += multiplier;
373 if (Person::players[0]->forwardkeydown || Person::players[0]->backkeydown || Person::players[0]->leftkeydown || Person::players[0]->rightkeydown)
374 success += multiplier;
377 if (Person::players[0]->jumpkeydown)
381 if (Person::players[0]->isCrouch())
385 if (Person::players[0]->animTarget == rollanim)
389 if (Person::players[0]->animTarget == sneakanim)
390 success += multiplier;
393 if (Person::players[0]->animTarget == rabbitrunninganim || Person::players[0]->animTarget == wolfrunninganim)
394 success += multiplier;
397 if (Person::players[0]->isWallJump())
401 if (Person::players[0]->animTarget == flipanim)
405 if (Person::players[0]->animTarget == upunchanim || Person::players[0]->animTarget == winduppunchanim)
409 if (Person::players[0]->animTarget == winduppunchanim)
413 if (Person::players[0]->animTarget == spinkickanim)
417 if (Person::players[0]->animTarget == sweepanim)
421 if (Person::players[0]->animTarget == dropkickanim)
425 if (Person::players[0]->animTarget == rabbitkickanim)
433 if (bonus == spinecrusher)
437 if (Person::players[0]->animTarget == walljumprightkickanim || Person::players[0]->animTarget == walljumpleftkickanim)
441 if (Person::players[0]->animTarget == rabbittacklinganim)
445 if (Person::players[0]->animTarget == backhandspringanim)
449 if (Animation::animations[Person::players[0]->animTarget].attack == reversed && Person::players[0]->feint)
453 if (Person::players[0]->escapednum == 2) {
457 Person::players[1]->aitype = passivetype;
465 if (Animation::animations[Person::players[0]->animTarget].attack == reversal) {
470 if (Animation::animations[Person::players[0]->animTarget].attack == reversal) {
474 Person::players[1]->aitype = passivetype;
478 if (Person::players[0]->num_weapons > 0) {
483 if (Person::players[0]->weaponactive == -1 && Person::players[0]->num_weapons > 0) {
488 if (Person::players[0]->animTarget == knifeslashstartanim) {
493 if (Person::players[1]->weaponstuck != -1) {
501 stagetime = maxtime - 3;
504 if (stagetime == maxtime - 3) {
505 emit_sound_np(consolesuccesssound);
509 if (stage == 34 || stage == 35) {
510 stagetime = maxtime - 1;
515 if (stage < 14 || stage >= 50) {
516 Person::players[1]->coords.y = 300;
517 Person::players[1]->velocity = 0;
521 void Tutorial::DrawTextInfo()
523 std::string string = " ";
524 std::string string2 = " ";
525 std::string string3 = " ";
532 string = "Welcome to the Lugaru training level!";
535 string = "BASIC MOVEMENT:";
538 string = "You can move the mouse to rotate the camera.";
541 string = std::string("Try using the ") +
542 Input::keyToChar(Game::forwardkey) + ", " +
543 Input::keyToChar(Game::leftkey) + ", " +
544 Input::keyToChar(Game::backkey) + " and " +
545 Input::keyToChar(Game::rightkey) + " keys to move around.";
546 string2 = "All movement is relative to the camera.";
549 string = std::string("Please press ") + Input::keyToChar(Game::jumpkey) + " to jump.";
550 string2 = "You can hold it longer to jump higher.";
553 string = std::string("You can press ") + Input::keyToChar(Game::crouchkey) + " to crouch.";
554 string2 = "You can jump higher from a crouching position.";
557 string = std::string("While running, you can press ") + Input::keyToChar(Game::crouchkey) + " to roll.";
560 string = "While crouching, you can sneak around silently";
561 string2 = "using the movement keys.";
564 string = "Release the crouch key while sneaking and hold the movement keys";
565 string2 = "to run animal-style.";
568 string = "ADVANCED MOVEMENT:";
571 string = std::string("When you jump at a wall, you can hold ") + Input::keyToChar(Game::jumpkey) + " again";
572 string2 = "during impact to perform a walljump.";
573 string3 = "Be sure to use the movement keys to press against the wall";
576 string = "While in the air, you can press crouch to flip.";
577 string2 = "Walljumps and flips confuse enemies and give you more control.";
580 string = "BASIC COMBAT:";
583 string = "There is now an imaginary enemy";
584 string2 = "in the middle of the training area.";
587 if (Game::attackkey == MOUSEBUTTON1) {
588 string = "Click to attack when you are near an enemy.";
590 string = std::string("Press ") + Input::keyToChar(Game::attackkey) + " to attack when you are near an enemy.";
592 string2 = "You can punch by standing still near an enemy and attacking.";
595 string = "If you are close, you will perform a weak punch.";
596 string2 = "The weak punch is excellent for starting attack combinations.";
599 string = "Attacking while running results in a spin kick.";
600 string2 = "This is one of your most powerful ground attacks.";
603 string = "Sweep the enemy's legs out by attacking while crouched.";
604 string2 = "This is a very fast attack, and easy to follow up.";
607 string = "When an enemy is on the ground, you can deal some extra";
608 string2 = "damage by running up and drop-kicking him.";
609 string3 = "(Try knocking them down with a sweep first)";
612 string = "Your most powerful individual attack is the rabbit kick.";
613 if (Game::attackkey == MOUSEBUTTON1) {
614 string2 = "Run at the enemy while holding the mouse button, and press";
616 string2 = std::string("Run at the enemy while holding ") + Input::keyToChar(Game::attackkey) + ", and press";
618 string3 = std::string("the jump key (") + Input::keyToChar(Game::jumpkey) + ") to attack.";
621 string = "This attack is devastating if timed correctly.";
622 string2 = "Even if timed incorrectly, it will knock the enemy over.";
624 string3 = "Try rabbit-kicking the imaginary enemy again.";
626 string3 = "Try rabbit-kicking the imaginary enemy.";
630 string = "If you sneak behind an enemy unnoticed, you can kill";
631 string2 = "him instantly. Move close behind this enemy";
632 string3 = "and attack.";
635 string = "Another important attack is the wall kick. When an enemy";
636 string2 = "is near a wall, perform a walljump nearby and hold";
637 string3 = "the attack key during impact with the wall.";
640 string = "You can tackle enemies by running at them animal-style";
641 if (Game::attackkey == MOUSEBUTTON1) {
642 string2 = std::string("and pressing jump (") + Input::keyToChar(Game::jumpkey) + ") or attack(mouse button).";
644 string2 = std::string("and pressing jump (") + Input::keyToChar(Game::jumpkey) + ") or attack(" + Input::keyToChar(Game::attackkey) + ").";
646 string3 = "This is especially useful when they are running away.";
649 string = "Dodge by pressing back and attack. Dodging is essential";
650 string2 = "against enemies with swords or other long weapons.";
653 string = "REVERSALS AND COUNTER-REVERSALS";
656 string = "The enemy can now reverse your attacks.";
659 string = "If you attack, you will notice that the enemy now sometimes";
660 string2 = "catches your attack and uses it against you. Hold";
661 string3 = std::string("crouch (") + Input::keyToChar(Game::crouchkey) + ") after attacking to escape from reversals.";
664 string = "Try escaping from two more reversals in a row.";
670 string = std::string("To reverse an attack, you must tap crouch (") + Input::keyToChar(Game::crouchkey) + ") during the";
671 string2 = "enemy's attack. You must also be close to the enemy;";
672 string3 = "this is especially important against armed opponents.";
675 string = "The enemy can attack in " + to_string(int(maxtime - stagetime)) + " seconds.";
676 string2 = "This imaginary opponents attacks will be highlighted";
677 string3 = "to make this easier.";
680 string = "Reverse three enemy attacks!";
683 string = "Reverse two more enemy attacks!";
686 string = "Reverse one more enemy attack!";
689 string = "Excellent!";
692 string = "Now spar with the enemy for " + to_string(int(maxtime - stagetime)) + " more seconds.";
693 string2 = "Damage dealt: " + to_string(int(damagedealt));
694 string3 = "Damage taken: " + to_string(int(damagetaken));
700 string = "There is now an imaginary knife";
701 string2 = "in the center of the training area.";
704 string = "Stand, roll or handspring over the knife";
705 string2 = std::string("while pressing ") + Input::keyToChar(Game::throwkey) + " to pick it up.";
706 string3 = "You can crouch and press the same key to drop it again.";
709 string = std::string("You can equip and unequip weapons using the ") + Input::keyToChar(Game::drawkey) + " key.";
710 string2 = "Sometimes it is best to keep them unequipped to";
711 string3 = "prevent enemies from taking them. ";
714 string = "The knife is the smallest weapon and the least encumbering.";
715 string2 = "You can equip or unequip it while standing, crouching,";
716 string3 = "running or flipping.";
719 string = "You perform weapon attacks the same way as unarmed attacks,";
720 string2 = "but sharp weapons cause permanent damage, instead of the";
721 string3 = "temporary trauma from blunt weapons, fists and feet.";
724 string = "The enemy now has your knife!";
725 string2 = "Please reverse two of his knife attacks.";
728 string = "Please reverse one more of his knife attacks.";
731 string = "Now he has a sword!";
732 string2 = "The sword has longer reach than your arms, so you";
733 string3 = "must move close to reverse the sword slash.";
736 string = "Long weapons like the sword and staff are also useful for defense;";
737 string2 = "you can parry enemy weapon attacks by pressing the attack key";
738 string3 = "at the right time. Please try parrying the enemy's attacks!";
741 string = "The staff is like the sword, but has two main attacks.";
742 string2 = "The standing smash is fast and effective, and the running";
743 string3 = "spin smash is slower and more powerful.";
746 string = std::string("When facing an enemy, you can throw the knife with ") + Input::keyToChar(Game::throwkey) + ".";
747 string2 = "It is possible to throw the knife while flipping,";
748 string3 = "but it is very inaccurate.";
751 string = "You now know everything you can learn from training.";
752 string2 = "Everything else you must learn from experience!";
755 string = "Walk out of the training area to return to the main menu.";
759 float opacity = maxtime - stagetime;
768 Game::text->glPrintOutlined(1, 1, 1, opacity, screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5, string, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
769 Game::text->glPrintOutlined(1, 1, 1, opacity, screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 20 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
770 Game::text->glPrintOutlined(1, 1, 1, opacity, screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024, screenheight / 16 + screenheight * 4 / 5 - 40 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024, screenwidth, screenheight);
772 string = "Press 'tab' to skip to the next item.";
773 string2 = "Press escape at any time to";
774 string3 = "pause or exit the tutorial.";
776 Game::text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10, string, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
777 Game::text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string2.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 20 * .8 * screenwidth / 1024, string2, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
778 Game::text->glPrintOutlined(0.5, 0.5, 0.5, 1, screenwidth / 2 - 7.6 * string3.size()*screenwidth / 1024 * .8, 0 + screenheight * 1 / 10 - 40 * .8 * screenwidth / 1024, string3, 1, 1.5 * screenwidth / 1024 * .8, screenwidth, screenheight);
781 void Tutorial::DoStuff(float multiplier)
800 if (distsq(&temp, &Person::players[0]->coords) >= distsq(&temp, &temp2) - 1 || distsq(&temp3, &Person::players[0]->coords) < 4) {
801 OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
802 OPENAL_SetFrequency(OPENAL_ALL);
804 emit_stream_np(stream_menutheme);
814 if (distsq(&temp, &Person::players[0]->coords) >= distsq(&temp, &temp2) - 1 || distsq(&temp3, &Person::players[0]->coords) < 4) {
815 emit_sound_at(fireendsound, Person::players[0]->coords);
817 Person::players[0]->coords = (oldtemp + oldtemp2) / 2;
822 if (stage >= 14 && stage < 50) {
823 if (distsq(&temp, &Person::players[1]->coords) >= distsq(&temp, &temp2) - 1 || distsq(&temp3, &Person::players[1]->coords) < 4) {
824 emit_sound_at(fireendsound, Person::players[1]->coords);
826 for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) {
827 if (Random() % 2 == 0) {
828 if (!Person::players[1]->skeleton.free)
829 temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2;
830 if (Person::players[1]->skeleton.free)
831 temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2;
832 if (!Person::players[1]->skeleton.free)
833 temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords;
834 if (Person::players[1]->skeleton.free)
835 temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords;
836 Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
840 Person::players[1]->coords = (oldtemp + oldtemp2) / 2;
841 for (unsigned i = 0; i < Person::players[1]->skeleton.joints.size(); i++) {
842 Person::players[1]->skeleton.joints[i].velocity = 0;
843 if (Random() % 2 == 0) {
844 if (!Person::players[1]->skeleton.free)
845 temp2 = (Person::players[1]->coords - Person::players[1]->oldcoords) / multiplier / 2; //velocity/2;
846 if (Person::players[1]->skeleton.free)
847 temp2 = Person::players[1]->skeleton.joints[i].velocity * Person::players[1]->scale / 2;
848 if (!Person::players[1]->skeleton.free)
849 temp = DoRotation(DoRotation(DoRotation(Person::players[1]->skeleton.joints[i].position, 0, 0, Person::players[1]->tilt), Person::players[1]->tilt2, 0, 0), 0, Person::players[1]->yaw, 0) * Person::players[1]->scale + Person::players[1]->coords;
850 if (Person::players[1]->skeleton.free)
851 temp = Person::players[1]->skeleton.joints[i].position * Person::players[1]->scale + Person::players[1]->coords;
852 Sprite::MakeSprite(breathsprite, temp, temp2, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);