-rw-r--r-- | noncore/games/kpacman/referee.cpp | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/noncore/games/kpacman/referee.cpp b/noncore/games/kpacman/referee.cpp index 81f331b..6d8f3fb 100644 --- a/noncore/games/kpacman/referee.cpp +++ b/noncore/games/kpacman/referee.cpp | |||
@@ -601,273 +601,259 @@ void Referee::confTiming(bool defGroup) | |||
601 | dyingPostAnimationMS = cfg->readNumEntry("DyingPostAnimationMS", 500); | 601 | dyingPostAnimationMS = cfg->readNumEntry("DyingPostAnimationMS", 500); |
602 | if (defGroup || cfg->hasKey("IntroAnimationMS")) | 602 | if (defGroup || cfg->hasKey("IntroAnimationMS")) |
603 | introAnimationMS = cfg->readNumEntry("IntroAnimationMS", 800); | 603 | introAnimationMS = cfg->readNumEntry("IntroAnimationMS", 800); |
604 | if (defGroup || cfg->hasKey("IntroPostAnimationMS")) | 604 | if (defGroup || cfg->hasKey("IntroPostAnimationMS")) |
605 | introPostAnimationMS = cfg->readNumEntry("IntroPostAnimationMS", 1000); | 605 | introPostAnimationMS = cfg->readNumEntry("IntroPostAnimationMS", 1000); |
606 | if (defGroup || cfg->hasKey("LevelUpPreAnimationMS")) | 606 | if (defGroup || cfg->hasKey("LevelUpPreAnimationMS")) |
607 | levelUpPreAnimationMS = cfg->readNumEntry("LevelUpPreAnimationMS", 2000); | 607 | levelUpPreAnimationMS = cfg->readNumEntry("LevelUpPreAnimationMS", 2000); |
608 | if (defGroup || cfg->hasKey("LevelUpAnimationMS")) | 608 | if (defGroup || cfg->hasKey("LevelUpAnimationMS")) |
609 | levelUpAnimationMS = cfg->readNumEntry("LevelUpAnimationMS", 2000); | 609 | levelUpAnimationMS = cfg->readNumEntry("LevelUpAnimationMS", 2000); |
610 | if (defGroup || cfg->hasKey("EnergizerAnimationMS")) | 610 | if (defGroup || cfg->hasKey("EnergizerAnimationMS")) |
611 | energizerAnimationMS = cfg->readNumEntry("EnergizerAnimationMS", 200); | 611 | energizerAnimationMS = cfg->readNumEntry("EnergizerAnimationMS", 200); |
612 | APP_CONFIG_END( cfg ); | 612 | APP_CONFIG_END( cfg ); |
613 | } | 613 | } |
614 | 614 | ||
615 | void Referee::confScoring(bool defGroup) | 615 | void Referee::confScoring(bool defGroup) |
616 | { | 616 | { |
617 | APP_CONFIG_BEGIN( cfg ); | 617 | APP_CONFIG_BEGIN( cfg ); |
618 | if (defGroup || cfg->hasKey("PointScore")) | 618 | if (defGroup || cfg->hasKey("PointScore")) |
619 | pointScore = cfg->readNumEntry("PointScore", 10); | 619 | pointScore = cfg->readNumEntry("PointScore", 10); |
620 | if (defGroup || cfg->hasKey("EnergizerScore")) | 620 | if (defGroup || cfg->hasKey("EnergizerScore")) |
621 | energizerScore = cfg->readNumEntry("EnergizerScore", 50); | 621 | energizerScore = cfg->readNumEntry("EnergizerScore", 50); |
622 | if (defGroup || cfg->hasKey("FruitScore")) | 622 | if (defGroup || cfg->hasKey("FruitScore")) |
623 | fillArray(fruitScore, cfg->readEntry("FruitScore", "100,300,500,,700,,1000,,2000,,3000,,5000"), maxLevel+1); | 623 | fillArray(fruitScore, cfg->readEntry("FruitScore", "100,300,500,,700,,1000,,2000,,3000,,5000"), maxLevel+1); |
624 | if (defGroup || cfg->hasKey("MonsterScore")) | 624 | if (defGroup || cfg->hasKey("MonsterScore")) |
625 | fillArray(monsterScore, cfg->readEntry("MonsterScore", "200,400,800,1600"), 4); | 625 | fillArray(monsterScore, cfg->readEntry("MonsterScore", "200,400,800,1600"), 4); |
626 | if (defGroup || cfg->hasKey("ExtraLifeScore")) | 626 | if (defGroup || cfg->hasKey("ExtraLifeScore")) |
627 | fillArray(extraLifeScore, cfg->readEntry("ExtraLifeScore", "10000"), -1); | 627 | fillArray(extraLifeScore, cfg->readEntry("ExtraLifeScore", "10000"), -1); |
628 | APP_CONFIG_END( cfg ); | 628 | APP_CONFIG_END( cfg ); |
629 | } | 629 | } |
630 | 630 | ||
631 | void Referee::confScheme() | 631 | void Referee::confScheme() |
632 | { | 632 | { |
633 | APP_CONFIG_BEGIN( cfg ); | 633 | APP_CONFIG_BEGIN( cfg ); |
634 | SAVE_CONFIG_GROUP( cfg, oldgroup ); | 634 | SAVE_CONFIG_GROUP( cfg, oldgroup ); |
635 | QString newgroup; | 635 | QString newgroup; |
636 | 636 | ||
637 | // if not set, read mode and scheme from the configfile | 637 | // if not set, read mode and scheme from the configfile |
638 | if (mode == -1 && scheme == -1) { | 638 | if (mode == -1 && scheme == -1) { |
639 | scheme = cfg->readNumEntry("Scheme", -1); | 639 | scheme = cfg->readNumEntry("Scheme", -1); |
640 | mode = cfg->readNumEntry("Mode", -1); | 640 | mode = cfg->readNumEntry("Mode", -1); |
641 | 641 | ||
642 | // if mode is not set in the defGroup-group, lookup the scheme group | 642 | // if mode is not set in the defGroup-group, lookup the scheme group |
643 | if (scheme != -1 || mode == -1) { | 643 | if (scheme != -1 || mode == -1) { |
644 | newgroup.sprintf("Scheme %d", scheme); | 644 | newgroup.sprintf("Scheme %d", scheme); |
645 | cfg->setGroup(newgroup); | 645 | cfg->setGroup(newgroup); |
646 | 646 | ||
647 | mode = cfg->readNumEntry("Mode", -1); | 647 | mode = cfg->readNumEntry("Mode", -1); |
648 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 648 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
649 | } | 649 | } |
650 | } | 650 | } |
651 | 651 | ||
652 | confLevels(); | 652 | confLevels(); |
653 | 653 | ||
654 | if (mode != -1) { | 654 | if (mode != -1) { |
655 | newgroup.sprintf("Mode %d", mode); | 655 | newgroup.sprintf("Mode %d", mode); |
656 | cfg->setGroup(newgroup); | 656 | cfg->setGroup(newgroup); |
657 | 657 | ||
658 | confLevels(FALSE); | 658 | confLevels(FALSE); |
659 | } | 659 | } |
660 | 660 | ||
661 | if (scheme != -1) { | 661 | if (scheme != -1) { |
662 | newgroup.sprintf("Scheme %d", scheme); | 662 | newgroup.sprintf("Scheme %d", scheme); |
663 | cfg->setGroup(newgroup); | 663 | cfg->setGroup(newgroup); |
664 | 664 | ||
665 | confLevels(FALSE); | 665 | confLevels(FALSE); |
666 | } | 666 | } |
667 | 667 | ||
668 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 668 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
669 | 669 | ||
670 | confMisc(); | 670 | confMisc(); |
671 | confTiming(); | 671 | confTiming(); |
672 | confScoring(); | 672 | confScoring(); |
673 | 673 | ||
674 | if (mode != -1) { | 674 | if (mode != -1) { |
675 | newgroup.sprintf("Mode %d", mode); | 675 | newgroup.sprintf("Mode %d", mode); |
676 | cfg->setGroup(newgroup); | 676 | cfg->setGroup(newgroup); |
677 | 677 | ||
678 | confMisc(FALSE); | 678 | confMisc(FALSE); |
679 | confTiming(FALSE); | 679 | confTiming(FALSE); |
680 | confScoring(FALSE); | 680 | confScoring(FALSE); |
681 | } | 681 | } |
682 | 682 | ||
683 | if (scheme != -1) { | 683 | if (scheme != -1) { |
684 | newgroup.sprintf("Scheme %d", scheme); | 684 | newgroup.sprintf("Scheme %d", scheme); |
685 | cfg->setGroup(newgroup); | 685 | cfg->setGroup(newgroup); |
686 | 686 | ||
687 | confMisc(FALSE); | 687 | confMisc(FALSE); |
688 | confTiming(FALSE); | 688 | confTiming(FALSE); |
689 | confScoring(FALSE); | 689 | confScoring(FALSE); |
690 | } | 690 | } |
691 | 691 | ||
692 | fillMapName(); | 692 | fillMapName(); |
693 | 693 | ||
694 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); | 694 | RESTORE_CONFIG_GROUP( cfg, oldgroup ); |
695 | APP_CONFIG_END( cfg ); | 695 | APP_CONFIG_END( cfg ); |
696 | } | 696 | } |
697 | 697 | ||
698 | void Referee::setScheme(int Scheme, int Mode, Bitfont *font) | 698 | void Referee::setScheme(int Scheme, int Mode, Bitfont *font) |
699 | { | 699 | { |
700 | mode = Mode; | 700 | mode = Mode; |
701 | scheme = Scheme; | 701 | scheme = Scheme; |
702 | 702 | ||
703 | confScheme(); | 703 | confScheme(); |
704 | 704 | ||
705 | pix->setScheme(scheme, mode, font); | 705 | pix->setScheme(scheme, mode, font); |
706 | 706 | ||
707 | pacman->setMaxPixmaps(pix->maxPixmaps(PacmanPix)); | 707 | pacman->setMaxPixmaps(pix->maxPixmaps(PacmanPix)); |
708 | fruit->setMaxPixmaps(pix->maxPixmaps(FruitPix)); | 708 | fruit->setMaxPixmaps(pix->maxPixmaps(FruitPix)); |
709 | 709 | ||
710 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 710 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
711 | if (m) | 711 | if (m) |
712 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); | 712 | m->setMaxPixmaps(pix->maxPixmaps(MonsterPix), pix->maxPixmaps(EyesPix)); |
713 | 713 | ||
714 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) | 714 | for (Energizer *e = energizers->first(); e != 0; e = energizers->next()) |
715 | if (e) | 715 | if (e) |
716 | e->setMaxPixmaps(pix->maxPixmaps(EnergizerPix)); | 716 | e->setMaxPixmaps(pix->maxPixmaps(EnergizerPix)); |
717 | 717 | ||
718 | if (gameState.testBit(Introducing)) | 718 | if (gameState.testBit(Introducing)) |
719 | for (int i = 0; i < (gameState.testBit(Init) ? timerCount : 15); i++) | 719 | for (int i = 0; i < (gameState.testBit(Init) ? timerCount : 15); i++) |
720 | introPaint(i); | 720 | introPaint(i); |
721 | 721 | ||
722 | setFixedSize(pix->levelPix().size()); | 722 | setFixedSize(pix->levelPix().size()); |
723 | repaint(); | 723 | repaint(); |
724 | } | 724 | } |
725 | 725 | ||
726 | void Referee::keyPressEvent( QKeyEvent *k ) | 726 | void Referee::keyPressEvent( QKeyEvent *k ) |
727 | { | 727 | { |
728 | uint key = k->key(); | 728 | uint key = k->key(); |
729 | #ifdef QWS | 729 | |
730 | // "OK" => new game | 730 | if ( !gameState.testBit(Playing) && ( key == Key_Up || key == Key_Down || key == Key_Left || key == Key_Right ) ) |
731 | if ( key == Key_F33 || key == Key_F2 || key == Key_Enter ) | ||
732 | play(); | ||
733 | else if ( !gameState.testBit(Playing) && | ||
734 | ( key == Key_Up || | ||
735 | key == Key_Down || | ||
736 | key == Key_Right || | ||
737 | key == Key_Left )) | ||
738 | play(); | 731 | play(); |
739 | // "Space" => pause | ||
740 | //else if ( key == Key_Space || key == Key_F3 ) | ||
741 | // pause(); | ||
742 | // "Menu" => hall of fame | ||
743 | //else if ( key == Key_F11 || key == Key_F4 ) | ||
744 | // toggleHallOfFame(); | ||
745 | #endif | ||
746 | 732 | ||
747 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame) || | 733 | if (gameState.testBit(Paused) || gameState.testBit(HallOfFame) || |
748 | gameState.testBit(Demonstration) || gameState.testBit(Dying) || | 734 | gameState.testBit(Demonstration) || gameState.testBit(Dying) || |
749 | gameState.testBit(Ready) || gameState.testBit(LevelDone) || | 735 | gameState.testBit(Ready) || gameState.testBit(LevelDone) || |
750 | !gameState.testBit(Playing)) | 736 | !gameState.testBit(Playing)) |
751 | return; | 737 | return; |
752 | 738 | ||
753 | if (key == UpKey) | 739 | if (key == UpKey) |
754 | pacman->setDirection(N); | 740 | pacman->setDirection(N); |
755 | else if (key == DownKey) | 741 | else if (key == DownKey) |
756 | pacman->setDirection(S); | 742 | pacman->setDirection(S); |
757 | else if (key == RightKey) | 743 | else if (key == RightKey) |
758 | pacman->setDirection(E); | 744 | pacman->setDirection(E); |
759 | else if (key == LeftKey) | 745 | else if (key == LeftKey) |
760 | pacman->setDirection(W); | 746 | pacman->setDirection(W); |
761 | 747 | ||
762 | #ifdef CHEATS | 748 | #ifdef CHEATS |
763 | else if (key == Key_L) { printf("levelUp()\n"); levelUp(); } | 749 | else if (key == Key_L) { printf("levelUp()\n"); levelUp(); } |
764 | else if (key == Key_F) { printf("fruit->move(TRUE)\n"); fruit->move(TRUE); repaint(FALSE); } | 750 | else if (key == Key_F) { printf("fruit->move(TRUE)\n"); fruit->move(TRUE); repaint(FALSE); } |
765 | else if (key == Key_E) { printf("setLifes(++lifes)\n"); emit setLifes(++lifes); } | 751 | else if (key == Key_E) { printf("setLifes(++lifes)\n"); emit setLifes(++lifes); } |
766 | #endif | 752 | #endif |
767 | 753 | ||
768 | else { | 754 | else { |
769 | k->ignore(); | 755 | k->ignore(); |
770 | return; | 756 | return; |
771 | } | 757 | } |
772 | k->accept(); | 758 | k->accept(); |
773 | } | 759 | } |
774 | 760 | ||
775 | void Referee::score(int p) | 761 | void Referee::score(int p) |
776 | { | 762 | { |
777 | if (!gameState.testBit(Playing)) | 763 | if (!gameState.testBit(Playing)) |
778 | return; | 764 | return; |
779 | 765 | ||
780 | if ((points += p) < 0) | 766 | if ((points += p) < 0) |
781 | points = 0; | 767 | points = 0; |
782 | 768 | ||
783 | emit setPoints(points); | 769 | emit setPoints(points); |
784 | 770 | ||
785 | if (points >= nextExtraLifeScore) { | 771 | if (points >= nextExtraLifeScore) { |
786 | emit setLifes(++lifes); | 772 | emit setLifes(++lifes); |
787 | if (extraLifeScoreIndex < (int) extraLifeScore.size()-1) | 773 | if (extraLifeScoreIndex < (int) extraLifeScore.size()-1) |
788 | extraLifeScoreIndex++; | 774 | extraLifeScoreIndex++; |
789 | if (extraLifeScore[extraLifeScoreIndex] < 0) | 775 | if (extraLifeScore[extraLifeScoreIndex] < 0) |
790 | nextExtraLifeScore = extraLifeScore[extraLifeScoreIndex] * -1; | 776 | nextExtraLifeScore = extraLifeScore[extraLifeScoreIndex] * -1; |
791 | else | 777 | else |
792 | nextExtraLifeScore += extraLifeScore[extraLifeScoreIndex]; | 778 | nextExtraLifeScore += extraLifeScore[extraLifeScoreIndex]; |
793 | } | 779 | } |
794 | } | 780 | } |
795 | 781 | ||
796 | void Referee::eaten() | 782 | void Referee::eaten() |
797 | { | 783 | { |
798 | if (gameState.testBit(Ready)) | 784 | if (gameState.testBit(Ready)) |
799 | return; | 785 | return; |
800 | 786 | ||
801 | stop(); | 787 | stop(); |
802 | 788 | ||
803 | if (monstersEaten < 4) | 789 | if (monstersEaten < 4) |
804 | monstersEaten++; | 790 | monstersEaten++; |
805 | 791 | ||
806 | gameState.setBit(Scoring); | 792 | gameState.setBit(Scoring); |
807 | score(monsterScore[monstersEaten-1]); | 793 | score(monsterScore[monstersEaten-1]); |
808 | 794 | ||
809 | repaint(pix->rect(pix->rect(pacman->position(), MonsterPix), | 795 | repaint(pix->rect(pix->rect(pacman->position(), MonsterPix), |
810 | pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))); | 796 | pix->rect(pacman->position(), MonsterScorePix, monstersEaten-1))); |
811 | 797 | ||
812 | if (--timerCount > 0) | 798 | if (--timerCount > 0) |
813 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(eaten())); | 799 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(eaten())); |
814 | else { | 800 | else { |
815 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) | 801 | for (Monster *m = monsters->first(); m != 0; m = monsters->next()) |
816 | if (m && m->direction() == X && !gameState.testBit(Introducing)) | 802 | if (m && m->direction() == X && !gameState.testBit(Introducing)) |
817 | m->setDirection(N); | 803 | m->setDirection(N); |
818 | if (monstersEaten != 4 || !gameState.testBit(Introducing)) | 804 | if (monstersEaten != 4 || !gameState.testBit(Introducing)) |
819 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(start())); | 805 | QTimer::singleShot( monsterScoreDurMS, this, SLOT(start())); |
820 | } | 806 | } |
821 | } | 807 | } |
822 | 808 | ||
823 | void Referee::toggleHallOfFame() | 809 | void Referee::toggleHallOfFame() |
824 | { | 810 | { |
825 | gameState.toggleBit(HallOfFame); | 811 | gameState.toggleBit(HallOfFame); |
826 | } | 812 | } |
827 | 813 | ||
828 | void Referee::hallOfFame() | 814 | void Referee::hallOfFame() |
829 | { | 815 | { |
830 | if (gameState.testBit(HallOfFame)) // If the HallOfFame is switched on manually, toggle the | 816 | if (gameState.testBit(HallOfFame)) // If the HallOfFame is switched on manually, toggle the |
831 | toggleHallOfFame(); // bit twice. | 817 | toggleHallOfFame(); // bit twice. |
832 | 818 | ||
833 | emit setLevel(0); // Clear status display for hall of fame | 819 | emit setLevel(0); // Clear status display for hall of fame |
834 | emit setScore(level, 0); | 820 | emit setScore(level, 0); |
835 | emit forcedHallOfFame(TRUE); | 821 | emit forcedHallOfFame(TRUE); |
836 | } | 822 | } |
837 | 823 | ||
838 | void Referee::pause() | 824 | void Referee::pause() |
839 | { | 825 | { |
840 | static int pausedTimer = 0; | 826 | static int pausedTimer = 0; |
841 | 827 | ||
842 | if (!gameState.testBit(Paused)) { | 828 | if (!gameState.testBit(Paused)) { |
843 | pausedTimer = gameTimer; | 829 | pausedTimer = gameTimer; |
844 | stop(); | 830 | stop(); |
845 | stopEnergizer(); | 831 | stopEnergizer(); |
846 | gameState.setBit(Paused); | 832 | gameState.setBit(Paused); |
847 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); | 833 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); |
848 | } else { | 834 | } else { |
849 | gameState.clearBit(Paused); | 835 | gameState.clearBit(Paused); |
850 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); | 836 | repaint(pix->rect((BoardWidth*BoardHeight)/2-BoardWidth, tr("PAUSED")), FALSE); |
851 | if (pausedTimer) { | 837 | if (pausedTimer) { |
852 | pausedTimer = 0; | 838 | pausedTimer = 0; |
853 | start(); | 839 | start(); |
854 | } | 840 | } |
855 | } | 841 | } |
856 | emit togglePaused(); | 842 | emit togglePaused(); |
857 | } | 843 | } |
858 | 844 | ||
859 | void Referee::intro() | 845 | void Referee::intro() |
860 | { | 846 | { |
861 | stop(); | 847 | stop(); |
862 | stopEnergizer(); | 848 | stopEnergizer(); |
863 | bool paused = gameState.testBit(Paused); | 849 | bool paused = gameState.testBit(Paused); |
864 | 850 | ||
865 | gameState.fill(FALSE); | 851 | gameState.fill(FALSE); |
866 | gameState.setBit(Introducing); | 852 | gameState.setBit(Introducing); |
867 | gameState.setBit(Init); | 853 | gameState.setBit(Init); |
868 | 854 | ||
869 | if (paused) | 855 | if (paused) |
870 | gameState.setBit(Paused); | 856 | gameState.setBit(Paused); |
871 | 857 | ||
872 | level = 0; | 858 | level = 0; |
873 | emit setLevel(level); | 859 | emit setLevel(level); |