Beispiel #1
0
        //----------------------------------------------------------------
        //Method to handle when a coin object is hit
        //----------------------------------------------------------------
        public static void HitCoin(int X, int Y, bool ThrowUp)
        {
            int MapX, MapY;

            MapX = X / Buffers.W;
            MapY = Y / Buffers.H;
            if (Buffers.WorldMap[MapX, MapY] == ' ')
            {
                return;
            }
            if (ThrowUp)
            {
                NewTempObj(tpCoin, X, Y - Buffers.H, 0, CoinSpeed, Buffers.W, Buffers.H);
            }
            else
            {
                Buffers.WorldMap[MapX, MapY] = ' ';
                Remove(X, Y, Buffers.W, Buffers.H, 0);
                Glitter.CoinGlitter(X, Y);
            }

            Buffers.data.coins[Buffers.Player]++;
            Buffers.AddScore(50);
            if (Buffers.data.coins[Buffers.Player] % 100 == 0)
            {
                AddLife();
                Buffers.data.coins[Buffers.Player] = 0;
            }
        }
Beispiel #2
0
        //----------------------------------------------------------------
        // Method to be able to move the temp object
        //----------------------------------------------------------------
        public static void MoveTempObj()
        {
            int i;

            for (i = 0; i < MaxTempObj; i++)
            {
                if (TempObj[i].Alive == true)
                {
                    switch (TempObj[i].Tp)
                    {
                    case tpBroken:
                        TempObj[i].DelayCounter++;
                        if (TempObj[i].DelayCounter > BrokenDelay)
                        {
                            TempObj[i].DelayCounter = 0;
                            TempObj[i].YVel++;
                            if (TempObj[i].YPos > Buffers.NV * Buffers.H)
                            {
                                TempObj[i].Alive = false;
                            }
                        }
                        break;

                    case tpCoin:
                        TempObj[i].DelayCounter++;
                        if (TempObj[i].DelayCounter > CoinDelay)
                        {
                            TempObj[i].YVel++;
                            if (TempObj[i].YVel > MaxCoinYVel)
                            {
                                TempObj[i].Alive = false;
                                Glitter.CoinGlitter(TempObj[i].XPos + TempObj[i].XVel, TempObj[i].YPos + TempObj[i].YVel);
                            }
                        }
                        break;

                    case tpHit:
                        TempObj[i].DelayCounter++;
                        if (TempObj[i].DelayCounter > HitTime)
                        {
                            TempObj[i].Alive = false;
                        }
                        break;

                    case tpFire:
                        TempObj[i].DelayCounter++;
                        if (TempObj[i].DelayCounter > HitTime)
                        {
                            TempObj[i].Alive = false;
                        }
                        break;
                    }
                }
                TempObj[i].XPos++;
                TempObj[i].XVel++;
                TempObj[i].YPos++;
                TempObj[i].YVel++;
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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;
            }
        }