Пример #1
0
        public int CollDetection(Rectangle collRect, string position, GameLevel level)
        {
            if (position == "heroDown")
            {
                if (level.hero.CollRect.IntersectsWith(collRect))
                {
                    return(level.hero.CollRect.Y + level.hero.CollRect.Height - collRect.Y);
                }
            }
            if (position == "heroNotDown")
            {
                if (level.hero.CollRect.IntersectsWith(collRect))
                {
                    level.hero.marioDeath();
                }
            }

            for (int i = 0; i < level.map.Hoogte; i++)
            {
                for (int j = 0; j < level.map.Breedte; j++)
                {
                    if (level.spriteArray[j, i] != null && level.spriteArray[j, i].Collrect.IntersectsWith(collRect))
                    {
                        if (level.spriteArray[j, i].GetType() == typeof(Coin) && level.hero.CollRect == collRect)
                        {
                            level.spriteArray[j, i] = null;
                            level.CoinCount++;
                        }
                        if (level.spriteArray[j, i] != null)
                        {
                            if (level.hero.CollRect.IntersectsWith(collRect)) //nodig omdat collrect om 1 of andere reden de coll rect van de sprite geeft
                            {
                                if (level.spriteArray[j, i].GetType() == typeof(EnemyShell) || level.spriteArray[j, i].GetType() == typeof(AngryStone))
                                {
                                    level.hero.marioDeath();
                                }
                                if (level.spriteArray[j, i].GetType() == typeof(Spikes))
                                {
                                    Spikes spike = (Spikes)level.spriteArray[j, i];
                                    spike.ShowSpikes();
                                    level.hero.marioDeath();
                                }
                            }

                            if (!(level.spriteArray[j, i].GetType()).IsSubclassOf(typeof(Enemy)) && level.spriteArray[j, i].GetType() != typeof(Coin))
                            {
                                if (level.spriteArray[j, i].GetType() == typeof(InvisibleWall))
                                {
                                    InvisibleWall wall = (InvisibleWall)level.spriteArray[j, i];
                                    wall.ShowWall();
                                }
                                if (position == "left")
                                {
                                    if (level.hero.CollRect.X == collRect.X || level.spriteArray[j, i].GetType() != typeof(Cannon)) // nodig voor rocket bug
                                    {
                                        return(level.spriteArray[j, i].Collrect.X + level.spriteArray[j, i].Width - collRect.X);
                                    }
                                }
                                if (position == "right")
                                {
                                    return(collRect.X + collRect.Width - level.spriteArray[j, i].Collrect.X);
                                }
                                if (position == "up")
                                {
                                    if (level.spriteArray[j, i].GetType() == typeof(CoinBlock))
                                    {
                                        CoinBlock coinBlock = (CoinBlock)level.spriteArray[j, i];
                                        coinBlock.CoinBlockHit(level, j, i);
                                    }
                                    return(level.spriteArray[j, i].Y + level.spriteArray[j, i].Height - collRect.Y);
                                }
                                if (position == "down")
                                {
                                    return(collRect.Y + collRect.Height - level.spriteArray[j, i].Y);
                                }
                            }
                        }
                    }
                }
            }
            return(-5);
        }
Пример #2
0
        private void DrawBackground()
        {
            for (int i = 0; i < map.Hoogte; i++)
            {
                for (int j = 0; j < map.Breedte; j++)
                {
                    switch (map.GetElement(j, i))
                    {
                    case 0:

                        break;

                    case 1:
                        spriteArray[j, i] = new Grass(j, i, video, @"Sprites\grass\grass.png");
                        break;

                    case 2:
                        spriteArray[j, i] = new Grass(j, i, video, @"Sprites\grass\grassRight.png");
                        break;

                    case 3:
                        spriteArray[j, i] = new Grass(j, i, video, @"Sprites\grass\grassLeft.png");
                        break;

                    case 4:
                        spriteArray[j, i] = new Grass(j, i, video, @"Sprites\grass\grassCornerRight.png");
                        break;

                    case 5:
                        spriteArray[j, i] = new Grass(j, i, video, @"Sprites\grass\grassCornerLeft.png");
                        break;

                    case 6:
                        spriteArray[j, i] = new Sand(j, i, video, @"Sprites\sand\sand.png");
                        break;

                    case 7:
                        spriteArray[j, i] = new Sand(j, i, video, @"Sprites\sand\sandBorderLeft.png");
                        break;

                    case 8:
                        spriteArray[j, i] = new Sand(j, i, video, @"Sprites\sand\sandBorderRight.png");
                        break;

                    case 9:
                        spriteArray[j, i] = new Sand(j, i, video, @"Sprites\sand\sandCornerRight.png");
                        break;

                    case 10:
                        spriteArray[j, i] = new Sand(j, i, video, @"Sprites\sand\sandCornerLeft.png");
                        break;

                    case 11:
                        spriteArray[j, i] = new Finish(j, i, video);
                        break;

                    case 12:
                        spriteArray[j, i] = new CoinBlock(j, i, video);
                        break;

                    case 13:
                        spriteArray[j, i] = new InvisibleWall(j, i, video);
                        break;

                    case 14:
                        spriteArray[j, i] = new Cannon(j, i, video);
                        break;

                    case 15:
                        spriteArray[j, i] = new EnemyShell(j, i, video);
                        break;

                    case 16:
                        spriteArray[j, i] = new Spikes(j, i, video, @"Sprites\enemies\spikesUp.png");
                        break;

                    case 17:
                        spriteArray[j, i] = new Spikes(j, i, video, @"Sprites\enemies\spikesDown.png");
                        break;

                    case 18:
                        spriteArray[j, i] = new Spikes(j, i, video, @"Sprites\enemies\spikesRight.png");
                        break;

                    case 19:
                        spriteArray[j, i] = new Spikes(j, i, video, @"Sprites\enemies\spikesLeft.png");
                        break;

                    case 20:
                        spriteArray[j, i] = new Block(j, i, video);
                        break;

                    case 21:
                        spriteArray[j, i] = new AngryStone(j, i, video);
                        break;

                    case 22:
                        spriteArray[j, i] = new DroppingGround(j, i, video);
                        break;
                    }
                }
            }
        }