Exemplo n.º 1
0
            public void Blast(Level l)
            {
                if (Death)
                {
                    return;
                }

                Position p = l.GetSpritePosition(this);

                for (int y = p.y - 1; y <= p.y + 1; y++)
                {
                    for (int x = p.x - 1; x <= p.x + 1; x++)
                    {
                        if ((x > 0) && (x < 19) && (y > 0) && (y < 13))
                        {
                            if (l.GetSprite(x, y).GetType() == typeof(Digger))
                            {
                                Digger d = (Digger)l.GetSprite(x, y);
                                l.Digger.Die();
                            }
                            else
                            {
                                if (l.GetSprite(x, y).GetType().BaseType == typeof(Ghost))
                                {
                                    Ghost g = (Ghost)l.GetSprite(x, y);
                                    g.Die();
                                    l.Score += 99;
                                }

                                l.SetSprite(x, y, new Nothing());
                            }
                        }
                    }
                }

                Die();
            }
Exemplo n.º 2
0
            public void Move(Level l)
            {
                if (dead)
                {
                    return;
                }

                Position p = l.GetSpritePosition(this);
                Position d = new Position(p);
                Position z = new Position(d);

                direction = Directions.None;
                if (Keys[0])
                {
                    z.x--; direction = Directions.Left;
                }
                else
                {
                    stone[0] = false;
                    if (Keys[1])
                    {
                        z.x++; direction = Directions.Right;
                    }
                    else
                    {
                        stone[1] = false;
                        if (Keys[2])
                        {
                            z.y--; direction = Directions.Up;
                        }
                        else
                        {
                            if (Keys[3])
                            {
                                z.y++; direction = Directions.Down;
                            }
                        }
                    }
                }

                if (!d.Equal(z))
                {
                    // Nothing
                    if (l.GetSprite(z.x, z.y).GetType() == typeof(Nothing))
                    {
                        l.SetSprite(d.x, d.y, this);
                    }

                    // Diamond
                    if (l.GetSprite(z.x, z.y).GetType() == typeof(Diamond))
                    {
                        l.Collected += 1;
                        l.Score     += 3;
                    }

                    // Stone
                    if (l.GetSprite(z.x, z.y).GetType() == typeof(Stone))
                    {
                        if ((z.x > d.x) && (l.GetSprite(z.x + 1, z.y).GetType() == typeof(Nothing)))
                        {
                            if (stone[1])
                            {
                                l.SetSprite(d.x + 2, d.y, l.GetSprite(d.x + 1, d.y));
                                l.SetSprite(d.x + 1, d.y, new Nothing());
                            }
                            stone[1] = !stone[1];
                        }

                        if ((z.x < d.x) && (l.GetSprite(z.x - 1, z.y).GetType() == typeof(Nothing)))
                        {
                            if (stone[0])
                            {
                                l.SetSprite(d.x - 2, d.y, l.GetSprite(d.x - 1, d.y));
                                l.SetSprite(d.x - 1, d.y, new Nothing());
                            }
                            stone[0] = !stone[0];
                        }
                    }

                    // Ground
                    if (l.GetSprite(z.x, z.y).GetType() == typeof(Nothing) ||
                        l.GetSprite(z.x, z.y).GetType() == typeof(Ground) ||
                        l.GetSprite(z.x, z.y).GetType() == typeof(Diamond))
                    {
                        l.SetSprite(z.x, z.y, this);
                        l.SetSprite(d.x, d.y, new Buffer());
                    }

                    // Exit
                    if (l.GetSprite(z.x, z.y).GetType() == typeof(Exit))
                    {
                        l.Exit();
                    }

                    // Ghost
                    if (l.GetSprite(z.x, z.y).GetType().BaseType == typeof(Ghost))
                    {
                        l.Digger.Die();
                    }
                }

                Animate(l, z.x, z.y);
            }
Exemplo n.º 3
0
            public override void Move(Level l)
            {
                if (Death)
                {
                    return;
                }

                Position p = l.GetSpritePosition(this);

                Position[] w = { new Position(p), new Position(p), new Position(p), new Position(p) };

                if (Direction == Directions.Left)
                {
                    w[0].x--; w[1].y--; w[2].y++; w[3].x++;
                }
                if (Direction == Directions.Right)
                {
                    w[0].x++; w[1].y++; w[2].y--; w[3].x--;
                }
                if (Direction == Directions.Up)
                {
                    w[0].y--; w[1].x++; w[2].x--; w[3].y++;
                }
                if (Direction == Directions.Down)
                {
                    w[0].y++; w[1].x--; w[2].x++; w[3].y--;
                }

                for (int i = 0; i < 4; i++)
                {
                    if (!p.Equal(w[i]))
                    {
                        Position d = new Position(w[i]);

                        // Digger
                        if (l.GetSprite(d.x, d.y).GetType() == typeof(Digger))
                        {
                            l.Digger.Die();
                        }

                        // Nothing
                        if (l.GetSprite(d.x, d.y).GetType() == typeof(Nothing))
                        {
                            if (d.x < p.x)
                            {
                                Direction = Directions.Left;
                            }
                            if (d.x > p.x)
                            {
                                Direction = Directions.Right;
                            }
                            if (d.y < p.y)
                            {
                                Direction = Directions.Up;
                            }
                            if (d.y > p.y)
                            {
                                Direction = Directions.Down;
                            }

                            l.SetSprite(d.x, d.y, this);
                            l.SetSprite(p.x, p.y, new Nothing());

                            return;
                        }
                    }
                }
            }