Beispiel #1
0
        public void OnJumpTick(Object sender, EventArgs e)
        {
            if (State != MarioJumpState.J_None)
            {
                SetDirections();
                TimeCount      += (350.0 / 1000.0);
                OldPosition     = CurrentPosition;
                CurrentPosition = CalcMarioJumpPosition();
                if (State == MarioJumpState.J_Up)
                {
                    y = (int)(CurrentPosition);
                }
                else
                {
                    y += 6 + (int)TimeCount;
                }

                LevelGenerator.CurrentLevel.Update_ScreensY();

                if (State == MarioJumpState.J_Up)
                {
                    if (CurrentPosition > OldPosition)
                    {
                        State     = MarioJumpState.JDown;
                        TimeCount = 0;
                    }
                }

                //LevelGenerator.Raise_Event(LevelGenerator.LevelEvent.LE_Check_Collision);
            }
            else
            {
                TimeCount = 0;
            }
        }
Beispiel #2
0
        public Mario(int x, int y)
            : base(ObjectType.OT_Mario)
        {
            FireBalls = new List<FireBall>();
            for (int i = 0; i < 2; i++)
                FireBalls.Add(new FireBall(0, 0));

            for (int i = 0; i < 2; i++)
                AddObject(FireBalls[i]);

            Type = MarioType.MT_Small;
            SetMarioProperties();

            this.x = x * 16;
            this.y = LevelGenerator.LevelHeight - 16 * y - height;
            Visible = true;
            ControlPressed = false;
            Blinking = false;
            BlinkingShow = true;

            Moving = false;
            Jumping = false;
            Direction = MarioDir.MD_Right;

            State = MarioJumpState.J_None;
            MoveState = MarioMoveState.J_None;

            TimerGenerator.AddTimerEventHandler(TimerType.TT_100, OnAnimate);
            TimerGenerator.AddTimerEventHandler(TimerType.TT_50, OnJumpTick);
            TimerGenerator.AddTimerEventHandler(TimerType.TT_50, OnMoveTick);
            TimerGenerator.AddTimerEventHandler(TimerType.TT_50, OnCheckCollisions);
        }
Beispiel #3
0
        public void StartJump(Boolean Kill, double DefeaultVelocity)
        {
            if (Kill == false)
            {
                UpPressed = true;
            }

            if (State == MarioJumpState.J_None || Kill == true)
            {
                Media.PlaySound(Media.SoundType.ST_Jump);
                State           = MarioJumpState.J_Up;
                StartPosition   = y;
                OldPosition     = y;
                CurrentPosition = y;
                TimeCount       = 0;
                if (DefeaultVelocity != 0)
                {
                    StartVelocity = DefeaultVelocity;
                }
                else
                {
                    StartVelocity = -38;
                }
            }
        }
Beispiel #4
0
 public void StopJump()
 {
     UpPressed = false;
     if (State != MarioJumpState.J_None)
     {
         State         = MarioJumpState.JDown;
         StartPosition = y;
         TimeCount     = 0;
         StartVelocity = 0;
     }
 }
Beispiel #5
0
        public override void Intersection_None()
        {
            base.Intersection_None();

            if (State == MarioJumpState.J_None)
            {
                State         = MarioJumpState.JDown;
                StartPosition = y;
                TimeCount     = 0;
                StartVelocity = 0;
            }
        }
Beispiel #6
0
        public Character(int x, int y)
            : base(ObjectType.OT_Mario)
        {
            FireBalls = new List <FireBall>();
            for (int i = 0; i < 2; i++)
            {
                FireBalls.Add(new FireBall(0, 0));
            }

            for (int i = 0; i < 2; i++)
            {
                AddObject(FireBalls[i]);
            }

            Type = MarioType.MT_Small;
            SetMarioProperties();

            this.x                 = x * 16;
            this.y                 = LevelGenerator.LevelHeight - 16 * y - height;
            Visible                = true;
            UpPressed              = false;
            Blinking               = false;
            BlinkingShow           = true;
            NumberOfCollectedCoins = 0;


            Moving       = true;
            Jumping      = false;
            Direction    = MarioDir.MD_Right;
            EnterPressed = true;


            State     = MarioJumpState.J_None;
            MoveState = MarioMoveState.J_Right;

            TimerGenerator.AddTimerEventHandler(TimerType.TT_100, OnAnimate);
            TimerGenerator.AddTimerEventHandler(TimerType.TT_50, OnJumpTick);
            TimerGenerator.AddTimerEventHandler(TimerType.TT_50, OnMoveTick);
            TimerGenerator.AddTimerEventHandler(TimerType.TT_50, OnCheckCollisions);
        }
Beispiel #7
0
        public override void Intersection(Collision c, GraphicObject g)
        {
            base.Intersection(c, g);
            switch (g.OT)
            {
            case ObjectType.OT_Exit:
            {
                if (EnterPressed)
                {
                    EnterPressed = false;
                    Moving       = false;
                    MoveState    = MarioMoveState.J_None;
                    //OnLevelCompleted?.Invoke();
                    //StartJump(true, 0);
                    System.Windows.Forms.DialogResult dialog = System.Windows.Forms.MessageBox.Show("You won");
                    if (dialog == System.Windows.Forms.DialogResult.OK)
                    {
                        System.Windows.Forms.Application.Exit();
                    }
                    StopMove();
                }
                break;
            }

            case ObjectType.OT_Goomba:
            {
                if (c.Dir == CollisionDirection.CD_Up)
                {
                    if (((Monster)g).FallDie == false)        // Jump On Goomba with Up Presses
                    {
                        if (UpPressed)
                        {
                            StartJump(true, 0);
                        }
                        else
                        {
                            StartJump(true, -20);
                        }

                        ((Monster)g).GoombaDie();
                    }
                }

                if (c.Dir == CollisionDirection.CD_Left)
                {
                    Globals.setDeathPositionX(x);
                    Globals.deathPositionY = y;
                    //System.Windows.Forms.MessageBox.Show("X : " + Globals.deathPositionX + " Y : " + Globals.deathPositionY);
                }
                break;
            }

            case ObjectType.OT_MovingBlock:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_SolidBlock:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_PipeUp:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_BlockQuestion:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_BlockQuestionHidden:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_Brick:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_Grass:
            {
                SetDirections();

                if (c.Dir == CollisionDirection.CD_TopLeft)
                {
                    if (g.OT == ObjectType.OT_Brick)
                    {
                        //if (MoveState == MarioMoveState.J_Right)
                        //    x -= (int)XAdd;
                        //if (MoveState == MarioMoveState.J_Left)
                        //    x += (int)XAdd;

                        //Intersection_None();
                    }
                }
                if (c.Dir == CollisionDirection.CD_Up)
                {
                    if (g.OT == ObjectType.OT_MovingBlock)
                    {
                        this.y = g.newy - this.height;
                    }
                    else
                    {
                        if (State != MarioJumpState.J_None)
                        {
                            this.y = g.newy - this.height;
                        }
                    }
                    if (State != MarioJumpState.J_None)
                    {
                        State = MarioJumpState.J_None;
                    }
                    SetDirections();
                }

                if (c.Dir == CollisionDirection.CD_Left)
                {
                    this.x = g.newx - width;
                    //if (g.OT == ObjectType.OT_SolidBlock)
                    //    Intersection_None();
                    if (g.OT == ObjectType.OT_Brick)
                    {
                        //if (MoveState == MarioMoveState.J_Right)
                        //    x -= (int)XAdd;
                        //if (MoveState == MarioMoveState.J_Left)
                        //    x += (int)XAdd;
                        StartJump(true, 0);
                        this.x = g.newx - width;
                    }
                }

                if (c.Dir == CollisionDirection.CD_Down)
                {
                    if (State == MarioJumpState.J_Up)
                    {
                        State         = MarioJumpState.JDown;
                        StartPosition = y;
                        TimeCount     = 0;
                        StartVelocity = 0;
                        if (g.OT == ObjectType.OT_Brick)
                        {
                            if (Type == MarioType.MT_Big || Type == MarioType.MT_Fire)
                            {
                                ((Block)g).BreakBrick();
                            }
                            else
                            {
                            }
                        }
                    }
                }
                if (c.Dir == CollisionDirection.CD_Right)
                {
                    this.x = g.newx + g.width;
                    //if (g.OT == ObjectType.OT_SolidBlock)
                    //    Intersection_None();
                    //XAdd = 0;
                }
                break;
            }
            }
        }
Beispiel #8
0
 public void StopJump()
 {
     ControlPressed = false;
     if (State != MarioJumpState.J_None)
     {
         State = MarioJumpState.JDown;
         StartPosition = y;
         TimeCount = 0;
         StartVelocity = 0;
     }
 }
Beispiel #9
0
        public void StartJump(Boolean Kill, double DefeaultVelocity)
        {
            if (Kill == false)
                ControlPressed = true;

            if (State == MarioJumpState.J_None || Kill == true)
            {
                Media.PlaySound(Media.SoundType.ST_Jump);
                State = MarioJumpState.J_Up;
                StartPosition = y;
                OldPosition = y;
                CurrentPosition = y;
                TimeCount = 0;
                if (DefeaultVelocity != 0)
                    StartVelocity = DefeaultVelocity;
                else
                    StartVelocity = -38;
            }
        }
Beispiel #10
0
        public void OnJumpTick(Object sender, EventArgs e)
        {
            if (State != MarioJumpState.J_None)
            {
                SetDirections();
                TimeCount += (350.0 / 1000.0);
                OldPosition = CurrentPosition;
                CurrentPosition = CalcMarioJumpPosition();
                if (State == MarioJumpState.J_Up)
                    y = (int)(CurrentPosition);
                else
                    y += 6 + (int)TimeCount;

                LevelGenerator.CurrentLevel.Update_ScreensY();

                if (State == MarioJumpState.J_Up)
                    if (CurrentPosition > OldPosition)
                    {
                        State = MarioJumpState.JDown;
                        TimeCount = 0;
                    }

                //LevelGenerator.Raise_Event(LevelGenerator.LevelEvent.LE_Check_Collision);

            }
            else
            {
                TimeCount = 0;
            }
        }
Beispiel #11
0
        public override void Intersection_None()
        {
            base.Intersection_None();

            if (State == MarioJumpState.J_None)
            {
                State = MarioJumpState.JDown;
                StartPosition = y;
                TimeCount = 0;
                StartVelocity = 0;

            }
        }
Beispiel #12
0
        public override void Intersection(Collision c, GraphicObject g)
        {
            base.Intersection(c, g);
            switch (g.OT)
            {
                case ObjectType.OT_Exit:
                    {
                        if (UpPressed)
                        {
                            UpPressed = false;
                            System.Windows.Forms.MessageBox.Show("Very Good !");

                        }
                    } break;
                case ObjectType.OT_Flower:
                    {
                        ((Flower)g).Visible = false;
                        if (Type != MarioType.MT_Fire)
                        {
                            Type = MarioType.MT_Fire;
                            SetMarioProperties();
                            Media.PlaySound(Media.SoundType.ST_Mush);
                        }

                    } break;
                case ObjectType.OT_Mush:
                    {
                        ((MushRed)g).Visible = false;
                        ((MushRed)g).Animated = false;
                        ((MushRed)g).Live = false;
                        if (Type == MarioType.MT_Small)
                        {
                            Type = MarioType.MT_Big;
                            SetMarioProperties();
                            Media.PlaySound(Media.SoundType.ST_Mush);
                        }

                    } break;

                case ObjectType.OT_Coin:
                    {
                        ((CoinBlock)g).Animated = false;
                        ((CoinBlock)g).Visible = false;
                        Media.PlaySound(Media.SoundType.ST_Coin);

                    } break;
                case ObjectType.OT_Goomba:
                    {
                        if (c.Dir == CollisionDirection.CD_Up)
                        {
                            // Jump On Goomba with Control Presses
                            if (((MonsterGoomba)g).FallDie == false)
                            {
                                if (ControlPressed)
                                    StartJump(true, 0);
                                else
                                    StartJump(true, -20);

                                ((MonsterGoomba)g).GoombaDie();
                                Media.PlaySound(Media.SoundType.ST_Stomp);
                            }
                        }

                    } break;
                case ObjectType.OT_Koopa:
                    {
                        if (c.Dir == CollisionDirection.CD_Up)
                        {
                            // Jump On Koopa with Control Presses
                            if (((MonsterKoopa)g).State == MonsterKoopa.KoopaState.KS_Walking)
                            {
                                if (ControlPressed)
                                    StartJump(true, 0);
                                else
                                    StartJump(true, -20);

                                ((MonsterKoopa)g).SetKoopaState(MonsterKoopa.KoopaState.KS_Shield);
                                Media.PlaySound(Media.SoundType.ST_Stomp);
                            }
                            else
                                if ((((MonsterKoopa)g).State == MonsterKoopa.KoopaState.KS_Shield) &&
                                    (((MonsterKoopa)g).ReturningTime >= 3))
                                {
                                    ((MonsterKoopa)g).SetKoopaState(MonsterKoopa.KoopaState.KS_ShieldMoving);

                                }
                                else if (((MonsterKoopa)g).State == MonsterKoopa.KoopaState.KS_ShieldMoving)
                                {
                                    if (ControlPressed)
                                        StartJump(true, 0);
                                    else
                                        StartJump(true, -20);

                                    ((MonsterKoopa)g).SetKoopaState(MonsterKoopa.KoopaState.KS_Shield);

                                }
                        }

                    } break;

                case ObjectType.OT_MovingBlock:
                    goto case ObjectType.OT_Grass;

                case ObjectType.OT_SolidBlock:
                    goto case ObjectType.OT_Grass;
                case ObjectType.OT_PipeUp:
                    goto case ObjectType.OT_Grass;
                case ObjectType.OT_BlockQuestion:
                    goto case ObjectType.OT_Grass;
                case ObjectType.OT_BlockQuestionHidden:
                    goto case ObjectType.OT_Grass;
                case ObjectType.OT_Brick:
                    goto case ObjectType.OT_Grass;
                case ObjectType.OT_Grass:
                    {
                        SetDirections();

                        if (c.Dir == CollisionDirection.CD_TopLeft)
                        {
                            if (g.OT == ObjectType.OT_Brick)
                            {
                                //if (MoveState == MarioMoveState.J_Right)
                                //    x -= (int)XAdd;
                                //if (MoveState == MarioMoveState.J_Left)
                                //    x += (int)XAdd;

                                //Intersection_None();
                            }

                        }
                        if (c.Dir == CollisionDirection.CD_Up)
                        {

                            if (g.OT == ObjectType.OT_MovingBlock)
                            {
                                this.y = g.newy - this.height;
                                ((BlockMoving)g).MarioOn = true;

                            }
                            else
                            {
                                if (State != MarioJumpState.J_None)
                                    this.y = g.newy - this.height;
                            }
                            if (State != MarioJumpState.J_None)
                                State = MarioJumpState.J_None;
                            SetDirections();

                        }

                        if (c.Dir == CollisionDirection.CD_Left)
                        {
                            this.x = g.newx - width;
                            //if (g.OT == ObjectType.OT_SolidBlock)
                            //    Intersection_None();
                            if (g.OT == ObjectType.OT_Brick)
                            {
                                //if (MoveState == MarioMoveState.J_Right)
                                //    x -= (int)XAdd;
                                //if (MoveState == MarioMoveState.J_Left)
                                //    x += (int)XAdd;
                                this.x = g.newx - width;

                            }

                        }

                        if (c.Dir == CollisionDirection.CD_Down)
                        {
                            if (State == MarioJumpState.J_Up)
                            {
                                State = MarioJumpState.JDown;
                                StartPosition = y;
                                TimeCount = 0;
                                StartVelocity = 0;
                                if (g.OT == ObjectType.OT_BlockQuestion || g.OT == ObjectType.OT_BlockQuestionHidden)
                                {
                                    ((BlockQuestion)g).isMonsterExist();
                                    ((BlockQuestion)g).StartMove();
                                    if (((BlockQuestion)g).HiddenObject.OT != ObjectType.OT_Coin)
                                        Media.PlaySound(Media.SoundType.ST_Block);
                                }
                                if (g.OT == ObjectType.OT_Brick)
                                {
                                    if (Type == MarioType.MT_Big || Type == MarioType.MT_Fire)
                                    {
                                        ((BlockBrick)g).BreakBrick();
                                        Media.PlaySound(Media.SoundType.ST_Brick);
                                    }
                                    else
                                    {
                                        Media.PlaySound(Media.SoundType.ST_Block);
                                    }

                                }
                            }

                        }
                        if (c.Dir == CollisionDirection.CD_Right)
                        {
                            this.x = g.newx + g.width;
                            //if (g.OT == ObjectType.OT_SolidBlock)
                            //    Intersection_None();
                            //XAdd = 0;
                        }

                    } break;

            }
        }
Beispiel #13
0
        public override void Intersection(Collision c, GraphicObject g)
        {
            base.Intersection(c, g);
            switch (g.OT)
            {
            case ObjectType.OT_Exit:
            {
                if (EnterPressed)
                {
                    EnterPressed = false;
                    OnLevelCompleted?.Invoke();
                    //System.Windows.Forms.MessageBox.Show("Very Good !");
                }
                break;
            }

            case ObjectType.OT_Flower:
            {
                ((Flower)g).Visible = false;
                if (Type != MarioType.MT_Fire)
                {
                    Type = MarioType.MT_Fire;
                    SetMarioProperties();
                    Media.PlaySound(Media.SoundType.ST_Mush);
                }
                break;
            }

            case ObjectType.OT_Mush:
            {
                ((MushRed)g).Visible  = false;
                ((MushRed)g).Animated = false;
                ((MushRed)g).Live     = false;
                if (Type == MarioType.MT_Small)
                {
                    Type = MarioType.MT_Big;
                    SetMarioProperties();
                    Media.PlaySound(Media.SoundType.ST_Mush);
                }
                break;
            }

            case ObjectType.OT_MushLife:
            {
                ((MushLife)g).Visible  = false;
                ((MushLife)g).Animated = false;
                ((MushLife)g).Live     = false;
                LevelManager.Instance.MarioLives++;
                break;
            }

            case ObjectType.OT_Coin:
            {
                ((CoinBlock)g).Animated = false;
                ((CoinBlock)g).Visible  = false;
                Media.PlaySound(Media.SoundType.ST_Coin);
                NumberOfCollectedCoins++;
                break;
            }

            case ObjectType.OT_Goomba:
            {
                if (c.Dir == CollisionDirection.CD_Up)
                {
                    if (((MonsterGoomba)g).FallDie == false)        // Jump On Goomba with Up Presses
                    {
                        if (UpPressed)
                        {
                            StartJump(true, 0);
                        }
                        else
                        {
                            StartJump(true, -20);
                        }

                        ((MonsterGoomba)g).GoombaDie();
                        Media.PlaySound(Media.SoundType.ST_Stomp);
                    }
                }
                break;
            }

            case ObjectType.OT_Pirana:
            {
                if (c.Dir == CollisionDirection.CD_Up)          // Jump On Piranah with Up Presses
                {
                    if (UpPressed)
                    {
                        StartJump(true, 0);
                    }
                    else
                    {
                        StartJump(true, -20);
                    }

                    ((MonsterPiranah)g).PiranahDie();
                    Media.PlaySound(Media.SoundType.ST_Stomp);
                }
                break;
            }

            case ObjectType.OT_Koopa:
            {
                if (c.Dir == CollisionDirection.CD_Up)      // Jump On Koopa with Up Presses
                {
                    if (((MonsterKoopa)g).State == MonsterKoopa.KoopaState.KS_Walking)
                    {
                        if (UpPressed)
                        {
                            StartJump(true, 0);
                        }
                        else
                        {
                            StartJump(true, -20);
                        }

                        ((MonsterKoopa)g).SetKoopaState(MonsterKoopa.KoopaState.KS_Shield);
                        Media.PlaySound(Media.SoundType.ST_Stomp);
                    }
                    else
                    {
                        if ((((MonsterKoopa)g).State == MonsterKoopa.KoopaState.KS_Shield) && (((MonsterKoopa)g).ReturningTime >= 3))
                        {
                            ((MonsterKoopa)g).SetKoopaState(MonsterKoopa.KoopaState.KS_ShieldMoving);
                        }
                        else if (((MonsterKoopa)g).State == MonsterKoopa.KoopaState.KS_ShieldMoving)
                        {
                            if (UpPressed)
                            {
                                StartJump(true, 0);
                            }
                            else
                            {
                                StartJump(true, -20);
                            }

                            ((MonsterKoopa)g).SetKoopaState(MonsterKoopa.KoopaState.KS_Shield);
                        }
                    }
                }
                break;
            }

            case ObjectType.OT_MovingBlock:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_SolidBlock:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_PipeUp:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_BlockQuestion:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_BlockQuestionHidden:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_Brick:
                goto case ObjectType.OT_Grass;

            case ObjectType.OT_Grass:
            {
                SetDirections();

                if (c.Dir == CollisionDirection.CD_TopLeft)
                {
                    if (g.OT == ObjectType.OT_Brick)
                    {
                        //if (MoveState == MarioMoveState.J_Right)
                        //    x -= (int)XAdd;
                        //if (MoveState == MarioMoveState.J_Left)
                        //    x += (int)XAdd;

                        //Intersection_None();
                    }
                }
                if (c.Dir == CollisionDirection.CD_Up)
                {
                    if (g.OT == ObjectType.OT_MovingBlock)
                    {
                        this.y = g.newy - this.height;
                        ((BlockMoving)g).MarioOn = true;
                    }
                    else
                    {
                        if (State != MarioJumpState.J_None)
                        {
                            this.y = g.newy - this.height;
                        }
                    }
                    if (State != MarioJumpState.J_None)
                    {
                        State = MarioJumpState.J_None;
                    }
                    SetDirections();
                }

                if (c.Dir == CollisionDirection.CD_Left)
                {
                    this.x = g.newx - width;
                    //if (g.OT == ObjectType.OT_SolidBlock)
                    //    Intersection_None();
                    if (g.OT == ObjectType.OT_Brick)
                    {
                        //if (MoveState == MarioMoveState.J_Right)
                        //    x -= (int)XAdd;
                        //if (MoveState == MarioMoveState.J_Left)
                        //    x += (int)XAdd;
                        this.x = g.newx - width;
                    }
                }

                if (c.Dir == CollisionDirection.CD_Down)
                {
                    if (State == MarioJumpState.J_Up)
                    {
                        State         = MarioJumpState.JDown;
                        StartPosition = y;
                        TimeCount     = 0;
                        StartVelocity = 0;
                        if (g.OT == ObjectType.OT_BlockQuestion || g.OT == ObjectType.OT_BlockQuestionHidden)
                        {
                            ((BlockQuestion)g).isMonsterExist();
                            ((BlockQuestion)g).StartMove();
                            if (((BlockQuestion)g).HiddenObject.OT != ObjectType.OT_Coin)
                            {
                                Media.PlaySound(Media.SoundType.ST_Block);
                            }
                            else
                            {
                                NumberOfCollectedCoins++;
                                Media.PlaySound(Media.SoundType.ST_Coin);
                            }
                        }
                        if (g.OT == ObjectType.OT_Brick)
                        {
                            if (Type == MarioType.MT_Big || Type == MarioType.MT_Fire)
                            {
                                ((BlockBrick)g).BreakBrick();
                                Media.PlaySound(Media.SoundType.ST_Brick);
                            }
                            else
                            {
                                Media.PlaySound(Media.SoundType.ST_Block);
                            }
                        }
                    }
                }
                if (c.Dir == CollisionDirection.CD_Right)
                {
                    this.x = g.newx + g.width;
                    //if (g.OT == ObjectType.OT_SolidBlock)
                    //    Intersection_None();
                    //XAdd = 0;
                }
                break;
            }
            }
        }