public void MarioHandleCollision() { switch (Type) { case MarioType.MT_Fire: { Type = Character.MarioType.MT_Big; StartBlinking(); SetMarioProperties(); break; } case MarioType.MT_Big: { Type = Character.MarioType.MT_Small; StartBlinking(); SetMarioProperties(); break; } case MarioType.MT_Small: { MarioDie(); break; } } }
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); }
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); }
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; } }
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; } } }