Ejemplo n.º 1
0
        //-------------------------------------------------------------------
        // main loop of the world to handle drawing, hiding, and showing of the
        // resources. When mario runs out of lives the thread is killed and cleaned
        // up. read: GAME OVER!
        //-------------------------------------------------------------------
        static bool Restart()
        {
            bool PlayWorld = false;

            TextStatus = false;
            //InitStatus();

            Blocks.InitBlocks();
            TmpObj.InitTempObj();
            Glitter.ClearGlitter();
            Enemies.ClearEnemies();

            // ShowPage

            Buffers.GameDone = false;
            Buffers.Passed   = false;

            for (int i = Enemies.StartEnemiesAt * -1; i < Buffers.NH + Enemies.StartEnemiesAt; i++)
            {
                int j = (Buffers.XView / Buffers.W) + i;
                Enemies.StartEnemies(j, (short)(1 - 2 * System.Convert.ToByte(j > Players.MapX)));
            }

            //   SetYOffset (YBase);

            /*for (int i = 0; i < FormMarioPort.MAX_PAGE; i++)
             * {
             * //      DrawSky (XView, 0, NH * W, NV * H);
             *
             * //      StartClouds();
             *
             * for (int x = Buffers.XView / Buffers.W; x < Buffers.XView / Buffers.W + Buffers.NH; x++)
             *    for (int y = 0; y < Buffers.NV - 1; y++)
             *       Figures.Redraw(x, y);
             *
             * BackGr.DrawBackGr(true);
             * //ReadColorMap();
             *
             * if (Buffers.Options.Stars != 0)
             *    Stars.ShowStars();
             *
             * Enemies.ShowEnemies();
             * if (!OnlyDraw)
             *    Players.DrawPlayer();
             *
             * FormMarioPort.formRef.ShowPage();
             * }
             */

            Buffers.Demo = Buffers.dmNoDemo;
            Waiting      = false;

            //Palettes.NewPalette (P256*);
            //for (int i = 1; i < 100; i++)
            //{
            //Waterfalls()?
            //Palettes.BlinkPalette();
            //}

            Figures.SetSkyPalette();
            BackGr.DrawPalBackGr();
            //Palettes.InitGrass();

            if (OnlyDraw)
            {
                return(false);
            }

            //   Palettes.UnLockPal();
            //   FadeUp (64);
            //   Palettes.ReadPalette (Palette);

            TextStatus = Stat;// && !KeyBoard.PlayingMacro());

            //uint counter = 0;
            do //until gamedone
            {
                try
                {
                    //Console.WriteLine("Restart Loop");

                    //if (!Keyboard.PlayingMacro)
                    //{
                    //   if (Key = 31) //'S'
                    //   {
                    //      Stat = !Stat;
                    //      TextStatus = Stat;
                    //      Keyboard.Key = 255;
                    //   }
                    //   if (Keyboard.Key = 16) //'Q'
                    //   {
                    //      if (Buffers.BeeperSound)
                    //         Buffers.BeeperOff();
                    //      else
                    //      {
                    //         Buffers.BeeperOn();
                    //         Buffers.Beep (80);
                    //      }
                    //      Key = 255;
                    //   }

                    //   if (Key == 197 || Key == 198) //Pause/Break
                    //   {
                    //      Music.PauseMusic();
                    //      //do
                    //      //{
                    //      //   while (Keyboard.Key = 197) {} //busy wait of some sort?
                    //      //} while //(Keyboard.kbHit);
                    //   }
                    //   else
                    //   {
                    //      if (Keyboard.Key != 0)
                    //      {
                    //         Buffers.GameDone = true;
                    //         Buffers.Passed = true;
                    //      }
                    //   }

                    //   if (Buffers.TextCounter) //in 40..40+MAX_PAGE
                    //      ShowObjects = false;

                    //   HideGlitter();
                    //   if (Options.Stars != 0)
                    //      HideStars();
                    //   if (ShowObjects)
                    //      HideTempObj();
                    //   if (ShowScore)
                    //      HideTotalBack();
                    //   ErasePlayer();
                    //   if (ShowObjects)
                    //   {
                    //      HideEnemies();
                    //      EraseBlocks();
                    //   }
                    //}

                    // { Fade };
                    Buffers.LavaCounter++;

                    if (!Waiting)
                    {
                        if (Buffers.Demo == Buffers.dmNoDemo)
                        {
                            Enemies.MoveEnemies();
                            Players.MovePlayer();
                        }
                        else
                        {
                            Players.DoDemo();
                        }
                    }



                    if (!Waiting)
                    {
                        if (Buffers.Passed)
                        {
                            if (Buffers.Demo == Buffers.dmNoDemo || Players.InPipe)
                            {
                                Waiting             = true;
                                Buffers.TextCounter = 0;
                            }
                            Buffers.TextCounter++;
                            if (!ShowScore && (Buffers.TextCounter >= 50 && Buffers.TextCounter < 50 + FormMarioPort.MAX_PAGE)) //in 50..50 + MAX_PAGE
                            {
                                //SetFont (0, Bold + Shadow);
                                //TXT.CenterText (20, Buffers.PlayerName [Buffers.Player], 30.ToString("X"));
                                //SetFont(1, Bold + Shadow);
                                //TXT.CenterText (40, "STAGE CLEAR!", 31);
                                if (Buffers.TextCounter == (50 + FormMarioPort.MAX_PAGE))
                                {
                                    ShowScore = true;
                                }
                            }
                        }
                        else
                        if (Buffers.GameDone)
                        {
                            Buffers.data.lives[Buffers.Player]--;
                            Buffers.data.mode[Buffers.Player] = Buffers.mdSmall;
                            Buffers.TextCounter = 0;
                            Buffers.data.score[Buffers.Player] += Buffers.LevelScore;
                            Waiting          = true;
                            Buffers.GameDone = false;
                        }
                    }



                    //if (Keyboard.Key = 25) //P
                    //   Pause();

                    if (ShowScore && (Buffers.TextCounter == 120) && (Buffers.LevelScore > 0))
                    {
                        int i = (int)(Buffers.LevelScore - 50);
                        if (i < 0)
                        {
                            i = 0;
                        }
                        Buffers.data.score[Buffers.Player] += Buffers.LevelScore - 1;
                        Buffers.LevelScore  = i;
                        Buffers.TextCounter = 119;
                        CountingScore       = true;
                    }
                    else
                    {
                        CountingScore = false;
                    }

                    if (Waiting)
                    {
                        Buffers.TextCounter++;
                        if (Buffers.data.lives[Buffers.Player] == 0)
                        {
                            if (Buffers.TextCounter >= 100 && Buffers.TextCounter < 100 + FormMarioPort.MAX_PAGE) //in 100..100 + MAX_PAGE
                            {
                                //SetFont (0, Bold + Shadow);
                                //CenterText (20, Buffers.PlayerName[Buffers.Player], 30.ToString("X"));
                                //SetFont (1, Bold + Shadow);
                                //CenterText (40, "GAME OVER", 31);
                                ShowScore = true;
                            }
                            if (Buffers.TextCounter > 350)
                            {
                                Buffers.GameDone = true;
                            }
                        }
                        else
                        if (Buffers.Passed)
                        {
                            if (Buffers.TextCounter > 250)
                            {
                                Waiting = false;
                            }
                        }
                        else
                        if (Buffers.TextCounter > 100)
                        {
                            Buffers.GameDone = true;
                        }
                    }

                    TmpObj.MoveTempObj();
                    Blocks.MoveBlocks();

                    if (Keyboard.kbEsc)
                    {
                        Buffers.QuitGame = true;
                    }

                    MoveScreen();
                    TmpObj.RunRemove();

                    if (Buffers.Options.Horizon < Buffers.NV)
                    {
                        int j = Buffers.Options.Horizon;
                        for (int i = 0 / Buffers.W; i < Buffers.NH; i++)
                        {
                            int k = Buffers.XView / Buffers.W + (i + Buffers.LavaCounter / 8) % (Buffers.NH + 1);
                            if (Buffers.WorldMap[k, j] == '%')
                            {
                                Figures.Redraw(k, j);
                            }
                        }
                    }


                    //FormMarioPort.formRef.ResetStack();

                    if (ShowObjects)
                    {
                        Blocks.DrawBlocks();
                        Enemies.ShowEnemies();
                    }
                    Players.DrawPlayer();

                    if (ShowScore)
                    {
                        ShowTotalBack();
                    }
                    //if (TextStatus)
                    //   Status.ShowStatus();
                    if (ShowObjects)
                    {
                        TmpObj.ShowTempObj();
                    }
                    if (Buffers.Options.Stars != 0)
                    {
                        Stars.ShowStars();
                    }
                    Glitter.ShowGlitter();

                    Buffers.LastXView[FormMarioPort.formRef.CurrentPage()] = Buffers.XView;

                    //if (ShowRetrace)
                    //   SetPalette(0, 0, 0, 0);

                    // ShowPage

                    //if (ShowRetrace)
                    //   SetPalette( 0, 63, 63, 63);

                    BackGr.DrawPalBackGr();

                    //Palette.BlinkPalette();

                    Music.PlayMusic();

                    if (Players.InPipe && Keyboard.PlayingMacro)
                    {
                        Buffers.GameDone = true;
                    }


                    if (Players.InPipe && !Buffers.GameDone && !Waiting)
                    {
                        Enemies.StopEnemies();
                        Glitter.ClearGlitter();
                        //FadeDown(64);
                        //FormMarioPort.formRef.LockPal();
                        //FormMarioPort.formRef.ClearVGAMem();

                        switch (Players.PipeCode[1])
                        {
                        case 'à':
                            FindPipeExit();
                            //Delay(100);
                            break;

                        case 'á':
                            //Swap();
                            FindPipeExit();
                            break;

                        case 'ç':
                            Buffers.GameDone = true;
                            PlayWorld        = true;
                            break;
                        }

                        Players.InitPlayer(Players.MapX * Buffers.W + Buffers.W / 2, (Players.MapY - 1) * Buffers.H, Buffers.Player);

                        FormMarioPort.formRef.SetView(Buffers.XView, Buffers.YView);

                        for (int i = 0; i < FormMarioPort.MAX_PAGE; i++)
                        {
                            Buffers.LastXView[i] = Buffers.XView;
                        }

                        if (Players.PipeCode[1] == 'à')
                        {
                            Restart();
                        }
                        else
                        if (Players.PipeCode[1] == 'á')
                        {
                            BuildLevel();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("error" + e);
                }

                FormMarioPort.formRef.PaintForm();
                System.Threading.Thread.Sleep(1 / 60 * 1000);
            } while (!Buffers.GameDone && !Buffers.QuitGame);
            return(PlayWorld);
        }
Ejemplo n.º 2
0
        //-------------------------------------------------------------------
        // Sets up and reads in a new world to the buffer. After the world
        // has been read, it will build and then finally start running the
        // world.
        //    N1: char, the first part (before the hyphen) of the world name.
        //    N2: char, the second part (before the hyphen) of the world name.
        //    Map1: char[,], the map to play
        //    Opt1: WorldOptions, options for the aboveground world of Map1
        //    Opt1b, WorldOptions, options for the underground world of Map1
        //    Map2, char[,] the underground of the map to play
        //    Opt2, WorldOptions, options for the abovegound world of Map2
        //    Opt2b, WorldOptions, options for the underground world of Map2
        //    Player, byte, the player to put in the world.
        //-------------------------------------------------------------------
        public static bool PlayWorld(char N1, char N2, char[,] Map1, Buffers.WorldOptions Opt1, Buffers.WorldOptions Opt1b,
                                     char[,] Map2, Buffers.WorldOptions Opt2, Buffers.WorldOptions Opt2b, byte Player)
        {
            int j, k, x, y;

            int[] TotalBackGrAddr = new int[FormMarioPort.MAX_PAGE];
            //PlayWorld = false;
            //Keyboard.Key = 0;


            //Palettes.ClearPalette();
            //Palettes.LockPal();

            Buffers.TextCounter = 0;

            Buffers.WorldNumber = new string[] { N1.ToString(), "-", N2.ToString() };
            OnlyDraw            = ((N1 == '0') && (N2 == '0'));

            ShowObjects = true;

            Players.InPipe   = false;
            Players.PipeCode = new char[] { ' ', ' ' };
            Buffers.Demo     = Buffers.dmNoDemo;

            Buffers.InitLevelScore();

            //FillChar (TotalBackGrAddr, TotalBackGrAddr.Size(), 0);
            for (int i = 0; i < TotalBackGrAddr.Length; i++)
            {
                TotalBackGrAddr[i] = 0;
            }
            ShowScore = false;

            if (!Enemies.Turbo)
            {
                Buffers.ReadWorld(Map2, ref Buffers.WorldMap, Opt2);
                Buffers.Swap();
                Buffers.ReadWorld(Map1, ref Buffers.WorldMap, Opt1);
            }
            else
            {
                Buffers.ReadWorld(Map2, ref Buffers.WorldMap, Opt2b);
                Buffers.Swap();
                Buffers.ReadWorld(Map1, ref Buffers.WorldMap, Opt1b);
            }
            //Console.WriteLine("Done Reading World");
            Players.InitPlayer(Buffers.Options.InitX, Buffers.Options.InitY, Buffers.Player);
            Players.MapX = Buffers.Options.InitX;
            Players.MapY = Buffers.Options.InitY;

            Buffers.XView = 0;
            Buffers.YView = 0;

            //FillChar (LastXView, LastXView.Size(), 0);
            for (int i = 0; i < Buffers.LastXView.Length; i++)
            {
                Buffers.LastXView[i] = 0;
            }
            FormMarioPort.formRef.SetView(Buffers.XView, Buffers.YView);

            BuildLevel();
            try
            {
                if (Restart())
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: ", e);
            }


            Enemies.ClearEnemies();
            //ClearGlitter();
            //Palettes.FadeDown(64);
            //Palettes.ClearPalette();
            //Music.StopMusic();

            return(false);
            //http://en.wikipedia.org/wiki/Return_statement#Syntax
            //"In Pascal there is no return statement." ...wat!?
        }
Ejemplo n.º 3
0
        //-------------------------------------------------------------------
        // Scrolls the screen to move along with mario as he moves.
        //-------------------------------------------------------------------
        public static void MoveScreen()
        {
            int    Scroll;
            int    N1, N2;
            int    OldX, NewX, Page;
            Random rand = new Random();

            Page   = FormMarioPort.formRef.CurrentPage();
            Scroll = Buffers.XView - Buffers.LastXView[Page];
            if (!Players.EarthQuake)
            {
                FormMarioPort.formRef.SetView(Buffers.XView, Buffers.YView);
            }
            else
            {
                Players.EarthQuakeCounter++;
                if (Players.EarthQuakeCounter > 0)
                {
                    Players.EarthQuake = false;
                }
                int Rand1 = rand.Next(0, 2);
                int Rand2 = rand.Next(0, 2);
                FormMarioPort.formRef.SetView(Buffers.XView, Buffers.YView + Rand1 - Rand2);
            }
            if (Scroll < 0)
            {
                Enemies.StartEnemies((Buffers.XView / Buffers.W) - Enemies.StartEnemiesAt, 1);
            }
            else if (Scroll > 0)
            {
                Enemies.StartEnemies((Buffers.XView / Buffers.W) + Buffers.NH + Enemies.StartEnemiesAt, -1);
            }

            int i = Buffers.Options.Horizon;

            BackGr.DrawBackGr(false);
            Buffers.Options.Horizon = (byte)i;

            if (Scroll > 0)
            {
                for (int j = Buffers.LastXView[Page]; j < Buffers.XView; j++)
                {
                    i = j - Buffers.W - Buffers.W;
                    if (i >= 0)
                    {
                        FormMarioPort.formRef.PutPixel(i, 0, 0);
                    }
                    i = Buffers.W - j % Buffers.W - 1;
                    Figures.Redraw(j / Buffers.W + Buffers.NH + 1, i);
                }
            }

            if (Scroll < 0)
            {
                for (int j = Buffers.LastXView[Page]; j > Buffers.XView; j--)
                {
                    i = Buffers.W - j % Buffers.W - 1;
                    Figures.Redraw(j / Buffers.W - 1, i);
                }
            }
        }
Ejemplo n.º 4
0
      //-------------------------------------------------------------------
      // main function to drive the program, will determine if the game should
      // start in the menu or start up a world. after deciding that will initialize
      // the appropriate values 
      // finally, when the user either dies or quits the game, it will
      // clear all the buffers and stop the program.
      //-------------------------------------------------------------------
      public static void main()
      {
         try
         {
            int level = -1;

            Buffers.data.numPlayers = 1;
            //ReadConfig(args);

#if DEBUG
            do
            {
#endif
               Players.InitPlayerFigures();
               Enemies.InitEnemyFigures();

               EndGame = false;

               if (MENU)
                  Intro();

               //Randomize();

               if (Buffers.data.numPlayers == 2)
                  if (Buffers.data.progress[Buffers.plMario] > Buffers.data.progress[Buffers.plLuigi])
                     Buffers.data.progress[Buffers.plLuigi] = Buffers.data.progress[Buffers.plMario];
                  else
                     Buffers.data.progress[Buffers.plMario] = Buffers.data.progress[Buffers.plLuigi];

               Buffers.data.lives[Buffers.plMario] = 3;
               Buffers.data.lives[Buffers.plLuigi] = 3;
               Buffers.data.coins[Buffers.plMario] = 0;
               Buffers.data.coins[Buffers.plLuigi] = 0;
               Buffers.data.score[Buffers.plMario] = 0;
               Buffers.data.score[Buffers.plLuigi] = 0;
               Buffers.data.mode[Buffers.plMario] = Buffers.mdSmall;
               Buffers.data.mode[Buffers.plLuigi] = Buffers.mdSmall;

               do //until EndGame or QuitGame 
               {
                  if (Buffers.data.numPlayers == 1)
                     Buffers.data.lives[Buffers.plLuigi] = 0;
                  for (CurPlayer = Buffers.plMario; CurPlayer < Buffers.data.numPlayers; CurPlayer++)
                  {
                     if (!(EndGame || Buffers.QuitGame))
                        if (Buffers.data.lives[CurPlayer] >= 1)
                        {
                           //Turbo = (ConfigData.Games[GameNumber].progress[CurPlayer] >= NUM_LEV);
                           if (Buffers.data.progress[CurPlayer] > LAST_LEV)
                              Buffers.data.progress[CurPlayer] = NUM_LEV;
#if MENU
      						ShowPlayerName (CurPlayer);
#endif

                           if (Keyboard.kb1)
                              level = 0;
                           else if (Keyboard.kb2)
                              level = 1;
                           else if (Keyboard.kb3)
                              level = 2;
                           else if (Keyboard.kb4)
                              level = 3;
                           else if (Keyboard.kb5)
                              level = 4;
                           else if (Keyboard.kb6)
                              level = 5;
                           //else if (level == -1) return;
                           else break;

                           //switch(Buffers.data.progress[CurPlayer] % NUM_LEV)
                           switch (level)
                           {
                              case 0:
                                 Passed = Play.PlayWorld('x', '1', Worlds.Level_1a(),
                                        Worlds.Options_1a(), Worlds.Opt_1a(),
                                        Worlds.Level_1b(), Worlds.Options_1b(),
                                        Worlds.Options_1b(), Convert.ToByte(CurPlayer));
                                 break;
                              case 1:
                                 Passed = Play.PlayWorld('x', '2', Worlds.Level_2a(),
                                        Worlds.Options_2a(), Worlds.Opt_2a(),
                                        Worlds.Level_2b(), Worlds.Options_2b(),
                                        Worlds.Options_2b(), Convert.ToByte(CurPlayer));
                                 break;
                              case 2:
                                 Passed = Play.PlayWorld('x', '3', Worlds.Level_3a(),
                                        Worlds.Options_3a(), Worlds.Opt_3a(),
                                        Worlds.Level_3b(), Worlds.Options_3b(),
                                        Worlds.Options_3b(), Convert.ToByte(CurPlayer));
                                 break;
                              case 3:
                                 Passed = Play.PlayWorld('x', '4', Worlds.Level_5a(),
                                        Worlds.Options_5a(), Worlds.Opt_5a(),
                                        Worlds.Level_5b(), Worlds.Options_5b(),
                                        Worlds.Options_5b(), Convert.ToByte(CurPlayer));
                                 break;
                              case 4:
                                 Passed = Play.PlayWorld('x', '5', Worlds.Level_6a(),
                                        Worlds.Options_6a(), Worlds.Opt_6a(),
                                        Worlds.Level_6b(), Worlds.Options_6b(),
                                        Worlds.Options_6b(), Convert.ToByte(CurPlayer));
                                 break;
                              case 5:
                                 Passed = Play.PlayWorld('x', '6', Worlds.Level_4a(),
                                         Worlds.Options_4a(), Worlds.Opt_4a(),
                                        Worlds.Level_4b(), Worlds.Options_4b(),
                                        Worlds.Options_4b(), Convert.ToByte(CurPlayer));
                                 break;
                              default:
                                 EndGame = true;
                                 break;
                           }
                           //Console.WriteLine("I want to play a world");
                           if (Passed)
                              Buffers.data.progress[CurPlayer]++;
                           if (Buffers.QuitGame)
                           {
                              EndGame = true;
#if MENU
      							QuitGame = false;
#endif
                           }
                        }
                  }
                  //FormMarioPort.formRef.Invalidate();
               } while (!(EndGame || Buffers.QuitGame || (Buffers.data.lives[Buffers.plMario] +
                  Buffers.data.lives[Buffers.plLuigi] == 0)));

               if (GameNumber != -1)
                  Config.Games[GameNumber] = Buffers.data;
#if MENU
      	} while (!QuitGame)
#endif
               WriteConfig();
            } while (!Buffers.QuitGame);
         }
Ejemplo n.º 5
0
        //-------------------------------------------------
        // Move the player
        //-------------------------------------------------
        public static void MovePlayer()
        {
            int  MaxSpeed, MinSpeed, OldXVel, OldXView;
            bool CheckX;
            byte OldDir;
            bool LastKeyRight, LastKeyLeft;

            if (InPipe)
            {
                if (Buffers.WorldMap[MapX, MapY + 1] == '0')
                {
                    StartDemo(Buffers.dmUpOutOfPipe);
                }
                else
                if (Buffers.WorldMap[MapX, MapY - 1] == '0')
                {
                    StartDemo(Buffers.dmDownOutOfPipe);
                }
                return;
            }

            if (Enemies.cdChamp != 0)
            {
                if (Buffers.data.mode[Buffers.Player] == Buffers.mdSmall)
                {
                    Buffers.data.mode[Buffers.Player] = Buffers.mdLarge;
                    Growing     = true;
                    GrowCounter = 0;
                }
                //StartMusic (GrowMusic );
                Enemies.cdChamp = 0;
            }

            if (Enemies.cdLife != 0)
            {
                Enemies.cdLife = 0;
                TmpObj.AddLife();
            }
            if (Enemies.cdFlower != 0)
            {
                Buffers.data.mode[Buffers.Player] = Buffers.mdFire;
                Fired       = true;
                FireCounter = 0;
                //StartMusic (GrowMusic );
                Growing          = true;
                GrowCounter      = 0;
                Enemies.cdFlower = 0;
            }

            //if ( !Blinking && !Enemies.Star && !Growing )
            if (!Blinking && !Growing)
            {
                if (Enemies.cdHit != 0)
                {
                    switch (Buffers.data.mode[Buffers.Player])
                    {
                    case Buffers.mdSmall:
                    {
                        BlinkCounter = 0;
                        Blinking     = true;
                        StartDemo(Buffers.dmDead);
                        //StartMusic (DeadMusic );
                        return;
                    }

                    case Buffers.mdLarge:
                    case Buffers.mdFire:
                    {
                        Buffers.data.mode[Buffers.Player] = Buffers.mdSmall;
                        BlinkCounter = 0;
                        Blinking     = true;
                        //StartMusic (HitMusic );
                        break;
                    }

                    default:
                        break;
                    }
                }
                Enemies.cdHit = 0;
            }
            else
            {
                Enemies.cdHit = 0;
            }

            if (Blinking)
            {
                BlinkCounter++;
                if (BlinkCounter >= BlinkTime)
                {
                    Blinking = false;
                }
            }

            if (Enemies.cdStar != 0)
            {
                //StartMusic(StarMusic );
                StarCounter  = 0;
                Enemies.Star = true;
            }

            if (Enemies.Star)
            {
                StarCounter++;
                if (StarCounter >= StarTime)
                {
                    Enemies.Star = false;
                }
                if (StarCounter % 3 == 0)
                {
                    Glitter.StartGlitter(X, Y + 11 * Convert.ToByte(Buffers.data.mode[Buffers.Player] = Buffers.mdSmall), Buffers.W, Buffers.H + 3 + 11 * Convert.ToByte(Buffers.data.mode[Buffers.Player] != Buffers.mdSmall));
                }
                Enemies.cdStar = 0;
            }

            if (Growing)
            {
                GrowCounter++;
                if (GrowCounter > GrowTime)
                {
                    Growing = false;
                }
            }

            Counter++;
            if ((XVel == 0) && (YVel == 0))
            {
                Counter = 0;
            }
            CheckX = (Counter % Slip == 0);

            OldDir  = Direction;
            OldXVel = XVel;

//         LastKeyLeft = Keyboard.keyLeft;
//         LastKeyRight = Keyboard.keyRight;

            keyLeft  = Keyboard.kbLeftArrow;
            keyRight = Keyboard.kbRightArrow;
            keyUp    = Keyboard.kbUpArrow;
            keyDown  = Keyboard.kbDownArrow;
            keyAlt   = Keyboard.kbAlt;
            keyCtrl  = Keyboard.kbCtrl;
            keySpace = Keyboard.kbSP;

            if (keyRight && (Direction == Buffers.dirLeft))
            {
                OldDir  = Buffers.dirRight;
                OldXVel = -XVel;
            }
            if (keyLeft && (Direction == Buffers.dirRight))
            {
                OldDir  = Buffers.dirLeft;
                OldXVel = -XVel;
            }

            if (Fired && (!keySpace))
            {
                Fired = false;
            }

            if (keySpace && (!Fired) && (Buffers.data.mode[Buffers.Player] == Buffers.mdFire))
            {
                FireCounter = 0;
                Enemies.NewEnemy(EnemyType.tpFireBall, 0, X / Buffers.W + Direction, (Y + Buffers.H) / Buffers.H,
                                 10 * (-1 + 2 * Direction), 3 + 3 * (Convert.ToByte(keyDown) - Convert.ToByte(keyUp)), 2);
                Fired = true;
            }

            if (Enemies.cdLift != 0)
            {
                Y      = Enemies.PlayerY1;
                XVel   = Enemies.PlayerXVel;
                YVel   = Enemies.PlayerYVel;
                Status = stOnTheGround;
            }
            if (Enemies.cdStopJump != 0)
            {
                Jumped             = true;
                Enemies.cdStopJump = 0;
            }

            if (Jumped && (!keyAlt))
            {
                Jumped = false;
            }

            MaxSpeed = +MAX_SPEED - 1 + Convert.ToByte(keyCtrl) + Convert.ToByte(Enemies.Turbo) + Math.Abs(Enemies.cdLift * Enemies.PlayerXVel);
            MinSpeed = -MAX_SPEED + 1 - Convert.ToByte(keyCtrl) - Convert.ToByte(Enemies.Turbo) - Math.Abs(Enemies.cdLift * Enemies.PlayerXVel);

            if (keyLeft)
            {
                if ((XVel > MinSpeed))
                {
                    if (CheckX || (Enemies.cdLift != 0))
                    {
                        XVel -= 1 + Convert.ToByte((Enemies.cdLift != 0) && keyCtrl);
                    }
                }
                else
                {
                    XVel = MinSpeed;
                }
                Direction = Convert.ToByte(XVel > 0);
                if (X + XVel < 0)
                {
                    XVel = -X;
                }
            }
            else
            if ((XVel < 0) && CheckX && (Enemies.cdLift == 0))
            {
                XVel++;
            }

            if (keyRight)
            {
                if ((XVel < MaxSpeed))
                {
                    if (CheckX || Enemies.cdLift != 0)
                    {
                        XVel += 1 + Convert.ToByte(Enemies.cdLift != 0 && keyCtrl);
                    }
                }
                else
                {
                    XVel = MaxSpeed;
                }
                Direction = Convert.ToByte(XVel >= 0);
            }
            else
            if ((XVel > 0) && CheckX && (Enemies.cdLift == 0))
            {
                XVel--;
            }

            if (keyLeft && keyRight)
            {
                Direction = OldDir;
                XVel      = OldXVel;
            }

            if (Y + YVel >= Buffers.NV * Buffers.H)
            {
                Buffers.GameDone = true;
                //StartMusic (DeadMusic );
            }

            if (Status == stOnTheGround)
            {
                HitEnemy = false;
            }

            Check();

            if ((Status == stOnTheGround) && YVel == 0)
            {
                if ((XVel == 0) || ((Enemies.cdLift != 0) && (XVel == Enemies.PlayerXVel)))
                {
                    Walkingmode = 0;
                    WalkCount   = 0;
                }
                else
                {
                    WalkCount++;
                    WalkCount   = (byte)(WalkCount & 0xf);
                    Walkingmode = Convert.ToByte(WalkCount < 0x8);
                }
            }
            else
            {
                if (YVel < 0)
                {
                    Walkingmode = 2;
                }
                else
                {
                    Walkingmode = 3;
                }
            }

            if (keyDown)
            {
                CheckPipeBelow();
            }

            X += XVel;
            Y += YVel;

            OldXView      = Buffers.XView;
            Buffers.XView = Buffers.XView - System.Convert.ToByte(Keyboard.kbShiftl) + System.Convert.ToByte(Keyboard.kbShiftr);
            if (X + Buffers.W + SCROLL_AT > Buffers.XView + 320)
            {
                Buffers.XView = X + Buffers.W + SCROLL_AT - 320;
            }
            if (X < Buffers.XView + SCROLL_AT)
            {
                Buffers.XView = X - SCROLL_AT;
            }
            if (Buffers.XView - OldXView > MAX_SPEED + Convert.ToByte(Enemies.Turbo))
            {
                Buffers.XView = OldXView + MAX_SPEED + Convert.ToByte(Enemies.Turbo);
            }
            if (Buffers.XView - OldXView < -MAX_SPEED - Convert.ToByte(Enemies.Turbo))
            {
                Buffers.XView = OldXView - MAX_SPEED - Convert.ToByte(Enemies.Turbo);
            }
            if (Buffers.XView < 0)
            {
                Buffers.XView = 0;
                if (X < 0)
                {
                    X = 0;
                }
            }

            if (Buffers.XView > (Buffers.Options.XSize - Buffers.NH) * Buffers.W)
            {
                Buffers.XView = (Buffers.Options.XSize - Buffers.NH) * Buffers.W;
            }
            if (Buffers.XView < OldXView)
            {
                if ((Buffers.WorldMap[Buffers.XView / Buffers.W, Buffers.NV] == 254))
                {
                    if ((Buffers.WorldMap[(Buffers.XView / Buffers.W), (int)(Enemies.PlayerY1 / Buffers.H)] != ' '))
                    {
                        Buffers.XView = OldXView;
                    }
                }
            }
            if (Buffers.XView > OldXView)
            {
                if ((Buffers.WorldMap[((Buffers.XView - 1) / Buffers.W + Buffers.NH), Buffers.NV] == 255))
                {
                    if ((Buffers.WorldMap[((Buffers.XView - 1) / Buffers.W + Buffers.NH), (int)(Enemies.PlayerY1 / Buffers.H)] != ' '))
                    {
                        Buffers.XView = OldXView;
                    }
                }
            }

            Enemies.PlayerX1 = X + XVel;
            Enemies.PlayerX2 = Enemies.PlayerX1 + Buffers.W - 1;
            Enemies.PlayerY1 = Y;
            if (Buffers.data.mode[Buffers.Player] == Buffers.mdSmall)
            {
                Enemies.PlayerY1 = Y + Buffers.H;
            }
            else
            {
                Enemies.PlayerY1 = Y;
            }
            Enemies.PlayerY2   = Y + 2 * Buffers.H - 1;
            Enemies.PlayerXVel = XVel;
            Enemies.PlayerYVel = YVel;

            if (Enemies.cdLift != 0)
            {
                Enemies.PlayerYVel += 2 - YVel;
                Enemies.cdLift      = 0;
            }
        }
Ejemplo n.º 6
0
        //-------------------------------------------------
        // Check the player for actions
        //-------------------------------------------------
        private static void Check()
        {
            bool Small;

            NewCh1 = ' ';
            NewCh2 = ' ';
            NewCh3 = ' ';

            Side  = System.Convert.ToByte(XVel > 0) * (Buffers.W - 1);
            NewX1 = (X + Side) / Buffers.W;
            NewX2 = (X + Side + XVel) / Buffers.W;
            Small = Buffers.data.mode[Buffers.Player] == Buffers.mdSmall;

            if (NewX1 != NewX2)
            {
                Y1 = (Y + HSafe + (4)) / Buffers.H - Safe;
                Y2 = (Y + HSafe + Buffers.H) / Buffers.H - Safe;
                Y3 = (Y + HSafe + 2 * Buffers.H - 1) / Buffers.H - Safe;

                // Hack to fix negative Y
                Y1 = Y1 < 0 ? 1 : Y1;
                Y2 = Y2 < 0 ? 1 : Y2;
                Y3 = Y3 < 0 ? 1 : Y3;

                NewCh1 = (char)Buffers.WorldMap[NewX2, Y1];
                NewCh2 = (char)Buffers.WorldMap[NewX2, Y2];
                NewCh3 = (char)Buffers.WorldMap[NewX2, Y3];

                if (NewCh3 == '*')
                {
                    TmpObj.HitCoin(NewX2 * Buffers.W, Y3 * Buffers.H, false);
                }

                if (NewCh2 == '*')
                {
                    TmpObj.HitCoin(NewX2 * Buffers.W, Y2 * Buffers.H, false);
                }
                else if (NewCh2 == 'z')
                {
                    Enemies.Turbo = true;
                }


                if (!Small && NewCh1 == '*')
                {
                    TmpObj.HitCoin(NewX2 * Buffers.W, Y1 * Buffers.H, false);
                }

                Hold1 = (Buffers.CanHoldYou(NewCh1)) && (!Small);
                Hold2 = (Buffers.CanHoldYou(NewCh2));
                Hold3 = (Buffers.CanHoldYou(NewCh3));

                if (Hold1 || Hold2 || Hold3)
                {
                    XVel        = 0;
                    Walkingmode = 0;
                }
            }

            NewX1 = (X + XVel) / Buffers.W;
            NewX2 = (X + XVel + Buffers.W - 1) / Buffers.W;

            if (Enemies.cdEnemy != 0)
            {
                CheckJump();
            }

            if ((Status == stJumping))
            {
                NewY = (Y + 1 + (4) + (Buffers.H - 1 - (4)) * Convert.ToByte(Small) + YVel + HSafe) / Buffers.H - Safe;
            }
            else
            {
                NewY = (Y + 1 + 2 * Buffers.H + YVel + HSafe) / Buffers.H - Safe;
            }

            if (NewY < 0)
            {
                NewY = 12;
                Y    = 12;
            }

            NewCh1 = (char)Buffers.WorldMap[NewX1, NewY];
            NewCh2 = (char)Buffers.WorldMap[NewX2, NewY];
            NewCh3 = (char)Buffers.WorldMap[(X + XVel + Buffers.W / 2) / Buffers.W, NewY];
            Hold1  = (Buffers.CanHoldYou(NewCh1) || Buffers.CanStandOn(NewCh1));
            Hold2  = (Buffers.CanHoldYou(NewCh2) || Buffers.CanStandOn(NewCh2));
            Hold3  = (Buffers.CanHoldYou(NewCh3) || Buffers.CanStandOn(NewCh3));

            switch (Status)
            {
            case stFalling:
            {
                CheckFall();
                break;
            }

            case stOnTheGround:
            {
                if ((Enemies.cdLift == 0))
                {
                    if (!(Hold1 || Hold2))
                    {
                        Status = stFalling;
                        if (Math.Abs(XVel) < 2)
                        {
                            Y++;
                        }
                    }
                    else
                    {
                        if ((NewCh1 == 'K') || (NewCh2 == 'K'))
                        {
                            CheckFall();
                        }
                        else
                        {
                            if (XVel == 0)
                            {
                                Below1 = NewCh1;
                                Below2 = NewCh2;
                                MapX   = NewX1; //Codes for pipes
                                MapY   = NewY - 1;
                                AtCh1  = (char)Buffers.WorldMap[MapX, MapY];
                                AtCh2  = (char)Buffers.WorldMap[MapX + 1, MapY];

                                Mo = (X + XVel) % Buffers.W;
                                if (!Hold1 && (Mo >= 1 && Mo <= 5))
                                {
                                    XVel--;
                                }
                                if (!Hold2 && (Mo >= Buffers.W - 5 && Mo <= Buffers.W - 1))
                                {
                                    XVel++;
                                }
                            }
                        }
                        CheckJump();
                    }
                }
                else
                {
                    YVel = Enemies.PlayerYVel;
                    CheckJump();
                }
                break;
            }

            case stJumping:
            {
                Hold1 = (Buffers.CanHoldYou(NewCh1) || Buffers.CanStandOn(NewCh1));
                Hold2 = (Buffers.CanHoldYou(NewCh2) || Buffers.CanStandOn(NewCh2));
                Hold3 = (Buffers.CanHoldYou(NewCh3) || Buffers.CanStandOn(NewCh3));

                Hit = (Hold1 || Hold2);
                if (Hit)
                {
                    Mo = (X + XVel) % Buffers.W;
                    if ((Mo >= 1 && Mo <= 4 && Mo >= Buffers.W - 4 && Mo <= Buffers.W - 1) && (!Hold3))
                    {
                        if (!((NewCh1 == Buffers.Hidden) && (NewCh2 == Buffers.Hidden)))
                        {
                            Hit = false;
                        }
                        if ((Mo < Buffers.W / 2) && (!(NewCh2 == Buffers.Hidden)))
                        {
                            X -= Mo;
                        }
                        else
                        if ((Mo >= Buffers.W / 2) && (!(NewCh1 == Buffers.Hidden)))
                        {
                            X += Buffers.W - Mo;
                        }
                    }
                }
                if (!Hit)
                {
                    if (NewCh1 == '*')
                    {
                        TmpObj.HitCoin(NewX1 * Buffers.W, NewY * Buffers.H, false);
                    }

                    if (NewCh1 == '*')
                    {
                        TmpObj.HitCoin(NewX2 * Buffers.W, NewY * Buffers.H, false);
                    }

                    if ((Counter % (JumpDelay + Convert.ToByte(HighJump)) == 0) || ((!keyAlt) && (!HitEnemy)))
                    {
                        YVel++;
                    }

                    if (YVel >= 0)
                    {
                        YVel   = 0;
                        Status = stFalling;
                    }
                }
                else
                {
                    char Ch = (char)0;

                    if (Mo >= 0 && Mo <= (Buffers.W / 2 - 1))
                    {
                        if (Buffers.CanHoldYou(NewCh1) || Buffers.CanStandOn(NewCh1))
                        {
                            Ch    = NewCh1;
                            NewX2 = NewX1;
                        }
                        else
                        {
                            Ch = NewCh2;
                        }
                    }
                    else if (Mo >= (Buffers.W / 2) && Mo <= Buffers.W - 1)
                    {
                        Ch = NewCh2;
                        if (!(Buffers.CanHoldYou(Ch) || Ch == Buffers.Hidden))
                        {
                            Ch    = NewCh1;
                            NewX2 = NewX1;
                        }
                    }

                    switch (Ch)
                    {
                    case '=':
                        Enemies.cdHit = 1;
                        break;

                    case '0':
                    case '1':
                        if (keyUp)
                        {
                            CheckPipeAbove(NewCh1, NewCh2);
                        }
                        break;

                    case '?':
                    case '$':
                    case 'J':
                    case 'K':
                    {
                        Mo = 0;

                        if (Buffers.WorldMap[NewX2, NewY - 1] >= 'à' && Buffers.WorldMap[NewX2, NewY - 1] <= 'â')
                        {
                            Buffers.WorldMap[NewX2, NewY] = '?';
                            Ch = '?';
                        }
                        else if (Buffers.WorldMap[NewX2, NewY - 1] == 'ï')
                        {
                            Buffers.WorldMap[NewX2, NewY] = 'K';
                            Ch = 'K';
                        }
                        else
                        {
                            if (!Small && (Ch == 'J'))
                            {
                                TmpObj.BreakBlock(NewX2, NewY);
                                Buffers.AddScore(10);
                                Mo = 1;
                            }
                        }

                        if (Mo == 0)
                        {
                            Blocks.BumpBlock(NewX2 * Buffers.W, NewY * Buffers.H);
                            //Beep (110 );
                        }

                        if (Buffers.WorldMap[NewX2, NewY - 1] >= 'ã' && Buffers.WorldMap[NewX2, NewY - 1] <= 'ì')
                        {
                            if (!(Ch == 'J' || Ch == 'K'))
                            {
                                TmpObj.HitCoin(NewX2 * Buffers.W, NewY * Buffers.H, true);
                                if (Buffers.WorldMap[NewX2, NewY - 1] != ' ')
                                {
                                    Buffers.WorldMap[NewX2, NewY - 1] = (char)(Buffers.WorldMap[NewX2, NewY - 1] + 1);
                                    if (Buffers.WorldMap[NewX2, NewY] == '$')
                                    {
                                        TmpObj.Remove(NewX2 * Buffers.W, NewY * Buffers.H, Buffers.W, Buffers.H, 2);
                                        Buffers.WorldMap[NewX2, NewY] = '?';
                                    }
                                }
                            }
                        }
                        else if (Buffers.WorldMap[NewX2, NewY - 1] == 'à')
                        {
                            if (Buffers.data.mode[Buffers.Player] == Buffers.mdSmall)
                            {
                                Enemies.NewEnemy(EnemyType.tpRisingChamp, 0, NewX2, NewY, 0, -1, 2);
                            }
                            else
                            {
                                Enemies.NewEnemy(EnemyType.tpRisingFlower, 0, NewX2, NewY, 0, -1, 2);
                            }
                        }
                        else if (Buffers.WorldMap[NewX2, NewY - 1] == 'á')
                        {
                            Enemies.NewEnemy(EnemyType.tpRisingLife, 0, NewX2, NewY, 0, -1, 2);
                        }
                        else if (Buffers.WorldMap[NewX2, NewY - 1] == 'â')
                        {
                            Enemies.NewEnemy(EnemyType.tpRisingStar, 0, NewX2, NewY, 0, -1, 1);
                        }
                        else if (Buffers.WorldMap[NewX2, NewY - 1] == '*')
                        {
                            TmpObj.HitCoin(NewX2 * Buffers.W, (NewY - 1) * Buffers.H, false);
                        }
                        else if (Buffers.WorldMap[NewX2, NewY - 1] == 'í')
                        {
                            Enemies.NewEnemy(EnemyType.tpRisingChamp, 1, NewX2, NewY, 0, -1, 2);
                        }

                        Enemies.HitAbove(NewX2, NewY - 1);
                        if (Ch == 'K')
                        {
                            TmpObj.Remove(NewX2 * Buffers.W, NewY * Buffers.H, Buffers.W, Buffers.H, TmpObj.tpNote);
                            Buffers.WorldMap[NewX2, NewY] = 'K';
                        }
                        else
                        {
                            if (Ch != 'J')
                            {
                                if (!(Buffers.WorldMap[NewX2, NewY - 1] >= 'ã' && Buffers.WorldMap[NewX2, NewY - 1] <= 'ì'))
                                {
                                    TmpObj.Remove(NewX2 * Buffers.W, NewY * Buffers.H, Buffers.W, Buffers.H, 1);
                                    Buffers.WorldMap[NewX2, NewY] = '@';
                                }
                            }
                        }
                        break;
                    }

                    default:
                        //Beep (30);
                        break;
                    }

                    if ((Ch != 'J') || (Buffers.data.mode[Buffers.Player] == Buffers.mdSmall))
                    {
                        YVel   = 0;
                        Status = stFalling;
                    }
                    if (Ch == 'K')
                    {
                        YVel = 3;
                    }
                }
                break;
            }
            }
        }