示例#1
0
        public void Update(LD44Game game, Level level, float delta)
        {
            PlayerMob playerMob = level.Mobs.OfType <PlayerMob>().First();

            if (Vector2.Distance(playerMob.Body.Position, Body.Position) < 7f)
            {
                if (playerMob.Body.Position.X > Body.Position.X)
                {
                    Sprite.Effects = SpriteEffects.FlipHorizontally;
                }
                else if (playerMob.Body.Position.X < Body.Position.X)
                {
                    Sprite.Effects = SpriteEffects.None;
                }

                _shootCharger -= delta;
                if (_shootCharger <= 0f)
                {
                    game.Content.Load <SoundEffect>("Sounds/projectile").Play();

                    var projectile = new ProjectileMob {
                        Animation = new AnimationState <Sprite>(game.SpriteAnimations["projectile"], 0.2f)
                        {
                            IsLooping = true
                        }
                    };
                    projectile.Body.Position = Body.Position;
                    projectile.Body.Velocity = Vector2.Normalize(playerMob.Body.Position - Body.Position) * 20f;
                    level.FutureMobs.Add(projectile);

                    _shootCharger = 3f;
                }
            }
        }
示例#2
0
        public void Update(LD44Game game, Level level, float delta)
        {
            if (Body.Velocity.X < 0f)
            {
                Sprite.Rotation -= 5f * delta;
            }
            else
            {
                Sprite.Rotation += 5f * delta;
            }

            if (_life > delta)
            {
                _life -= delta;
            }
            else
            {
                _life = 0f;
                Dead  = true;
            }

            float p = _life / 2f;

            Sprite.Scale = new Vector2(1f - (float)Math.Pow(1f - p, 5f));
        }
示例#3
0
 public void Update(LD44Game game, Level level, float delta)
 {
     if (_life > delta)
     {
         _life -= delta;
     }
     else
     {
         _life = 0f;
         Dead  = true;
     }
 }
示例#4
0
        public void Update(LD44Game game, Level level, float delta)
        {
            Sprite.Rotation += _rotation * delta;

            if (_life > delta)
            {
                _life -= delta;
            }
            else
            {
                _life = 0f;
                Dead  = true;
            }

            float p  = _life / 0.25f;
            float ip = 1f - p;

            Sprite.Scale = new Vector2(ip);
            Sprite.Color = Color.White * (1f - (ip * ip * ip * ip * ip * ip));
        }
示例#5
0
        public void Update(LD44Game game, Level level, float delta)
        {
            if (Body.Contact.X < 0f)
            {
                _left = false;
            }
            else if (Body.Contact.X > 0f)
            {
                _left = true;
            }

            if (_left)
            {
                Sprite.Effects = SpriteEffects.None;
                Body.Velocity  = new Vector2(-3f, 0f);
            }
            else
            {
                Sprite.Effects = SpriteEffects.FlipHorizontally;
                Body.Velocity  = new Vector2(3f, 0f);
            }
        }
示例#6
0
        public void Update(LD44Game game, Level level, float delta)
        {
            if (_hasTarget)
            {
                _timer += delta;
                if (_timer > _speed)
                {
                    _timer = _speed;
                }

                float p = _timer / _speed;
                p = 1f - (float)Math.Pow(1f - p, _smoothing);

                Body.Position = _startPosition * (1f - p) + _targetPosition * p - new Vector2(0f, _arc * (float)Math.Sin(p * (float)Math.PI));
            }

            switch (_state)
            {
            case State.None: {
                _thinkTimer -= delta;

                if (_thinkTimer <= 0f)
                {
                    int action = _random.Next(3);

                    if (action == _lastAction)
                    {
                        action--;
                        if (action < 0)
                        {
                            action = 2;
                        }
                    }

                    _lastAction = action;

                    switch (action)
                    {
                    case 0: {
                        if (_random.Next(2) == 0)
                        {
                            _state = State.PreparingToChargeLeft;

                            _hasTarget      = true;
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(25.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 2f;
                            _arc            = 2f;
                            _smoothing      = 3f;

                            _chargeNum = 0;
                        }
                        else
                        {
                            _state = State.PreparingToChargeRight;

                            _hasTarget      = true;
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(6.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 2f;
                            _arc            = 2f;
                            _smoothing      = 3f;

                            _chargeNum = 0;
                            break;
                        }
                        break;
                    }

                    case 1: {
                        _state = State.Summoning;

                        _hasTarget      = true;
                        _startPosition  = Body.Position;
                        _targetPosition = new Vector2(12f + 8f * (float)_random.NextDouble(), 13.5f);
                        _timer          = 0f;
                        _speed          = 2f;
                        _arc            = 1f;
                        _smoothing      = 2f;
                        break;
                    }

                    case 2: {
                        _state = State.PreparingToShoot;

                        _hasTarget      = true;
                        _startPosition  = Body.Position;
                        _targetPosition = new Vector2(12f + 8f * (float)_random.NextDouble(), 9.5f);
                        _timer          = 0f;
                        _speed          = 2f;
                        _arc            = 2f;
                        _smoothing      = 3f;
                        break;
                    }
                    }
                }
                break;
            }

            case State.PreparingToChargeLeft: {
                if (_timer >= _speed)
                {
                    _startPosition  = Body.Position;
                    _targetPosition = new Vector2(5.5f, 15.5f);
                    _timer          = 0f;
                    _speed          = 1.75f - _chargeNum / 7f;
                    _state          = State.ChargingLeft;
                    _arc            = 0f;
                    _smoothing      = 1.5f;

                    game.Content.Load <SoundEffect>("Sounds/dash").Play();
                }
                break;
            }

            case State.PreparingToChargeRight: {
                if (_timer >= _speed)
                {
                    _startPosition  = Body.Position;
                    _targetPosition = new Vector2(26.5f, 15.5f);
                    _timer          = 0f;
                    _speed          = 1.75f - _chargeNum / 7f;
                    _state          = State.ChargingRight;
                    _arc            = 0f;
                    _smoothing      = 1.5f;

                    game.Content.Load <SoundEffect>("Sounds/dash").Play();
                }
                break;
            }

            case State.ChargingLeft: {
                if (_timer >= _speed)
                {
                    _chargeNum++;

                    if (_chargeNum < 5)
                    {
                        if (_random.Next(3) == 0)
                        {
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(26.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 1.75f - _chargeNum / 7f;
                            _state          = State.ChargingRight;
                            _arc            = 0f;
                            _smoothing      = 1.5f;

                            game.Content.Load <SoundEffect>("Sounds/dash").Play();
                        }
                        else
                        {
                            _state = State.PreparingToChargeLeft;

                            _hasTarget      = true;
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(25.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 2f - _chargeNum / 5f;
                            _arc            = 2f;
                            _smoothing      = 3f - _chargeNum / 5f;
                        }
                    }
                    else
                    {
                        _state      = State.None;
                        _thinkTimer = 2f;
                    }
                }
                break;
            }

            case State.ChargingRight: {
                if (_timer >= _speed)
                {
                    _chargeNum++;

                    if (_chargeNum < 5)
                    {
                        if (_random.Next(3) == 0)
                        {
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(5.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 1.75f - _chargeNum / 7f;
                            _state          = State.ChargingLeft;
                            _arc            = 0f;
                            _smoothing      = 1.5f;

                            game.Content.Load <SoundEffect>("Sounds/dash").Play();
                        }
                        else
                        {
                            _state = State.PreparingToChargeRight;

                            _hasTarget      = true;
                            _startPosition  = Body.Position;
                            _targetPosition = new Vector2(6.5f, 15.5f);
                            _timer          = 0f;
                            _speed          = 2f - _chargeNum / 5f;
                            _arc            = 2f;
                            _smoothing      = 3f - _chargeNum / 5f;
                        }
                    }
                    else
                    {
                        _state      = State.None;
                        _thinkTimer = 2f;
                    }
                }
                break;
            }

            case State.Summoning: {
                if (_timer > _speed * 3f / 4f)
                {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_aiming"], 1f);
                }

                if (_timer >= _speed)
                {
                    var bat = new EliteBatMob {
                        Animation = new AnimationState <Sprite>(game.SpriteAnimations["elite_bat_flying"], 0.5f)
                        {
                            IsLooping = true
                        }
                    };
                    bat.Body.Position = new Vector2(6.5f + 19f * (float)_random.NextDouble(), 12f);
                    level.FutureMobs.Add(bat);

                    _state      = State.None;
                    _thinkTimer = 2f;

                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_idle"], 0.5f)
                    {
                        IsLooping = true
                    };
                }
                break;
            }

            case State.PreparingToShoot: {
                if (_timer >= _speed)
                {
                    _state      = State.Shooting;
                    _shootTimer = 0.5f;
                    _shotNum    = 0;
                }
                break;
            }

            case State.Shooting: {
                _shootTimer -= delta;

                if (_shootTimer < 0.2f)
                {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_aiming"], 1f);
                }
                else if (Animation.Animation != game.SpriteAnimations["valgox_idle"])
                {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_idle"], 0.5f)
                    {
                        IsLooping = true
                    };
                }

                if (_shootTimer <= 0f)
                {
                    game.Content.Load <SoundEffect>("Sounds/projectile").Play();

                    PlayerMob playerMob = level.Mobs.OfType <PlayerMob>().First();

                    var projectile = new ProjectileMob {
                        Animation = new AnimationState <Sprite>(game.SpriteAnimations["projectile"], 0.2f)
                        {
                            IsLooping = true
                        }
                    };
                    projectile.Body.Position = Body.Position;
                    projectile.Body.Velocity = Vector2.Normalize(playerMob.Body.Position - Body.Position) * 20f;
                    level.FutureMobs.Add(projectile);

                    _shotNum++;
                    _shootTimer += 2f / _shotNum;

                    _hasTarget      = true;
                    _startPosition  = Body.Position;
                    _targetPosition = new Vector2(12f + 8f * (float)_random.NextDouble(), 9f + 3f * (float)_random.NextDouble());
                    _timer          = 0f;
                    _speed          = _shootTimer;
                    _arc            = 0f;
                    _smoothing      = 2f;
                }

                if (_shotNum >= 8)
                {
                    _state      = State.None;
                    _thinkTimer = 2f;

                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_idle"], 0.5f)
                    {
                        IsLooping = true
                    };
                }
                break;
            }
            }
        }
示例#7
0
 public void Update(LD44Game game, Level level, float delta)
 {
 }
示例#8
0
        public void Update(LD44Game game, Level level, float delta)
        {
            if (_charging)
            {
                _chargeTimer -= delta;
                if (_chargeTimer <= 0f)
                {
                    _charging = false;
                }

                if (Body.Velocity != Vector2.Zero)
                {
                    float p  = _chargeTimer / 0.5f;
                    float ip = 1f - p;

                    var dir = Vector2.Normalize(Body.Velocity);
                    Body.Velocity = dir * 10f * (1f - ip * ip * ip * ip);
                }

                return;
            }

            PlayerMob playerMob = level.Mobs.OfType <PlayerMob>().First();

            Body.Velocity = Vector2.Zero;

            if (!_sighted)
            {
                if (Vector2.Distance(playerMob.Body.Position, Body.Position) < 10f)
                {
                    _sighted = true;
                }
            }
            else if (playerMob.Body.Position != Body.Position)
            {
                float distance = Vector2.Distance(playerMob.Body.Position, Body.Position);

                if (_preparing)
                {
                    if (distance > 5f)
                    {
                        _preparing = false;
                    }
                    else
                    {
                        _prepareTimer += delta;

                        if (_prepareTimer > 2f)
                        {
                            var flash = new FlashMob(_random);
                            flash.Body.Position = Body.Position;
                            level.FutureMobs.Add(flash);

                            _charging    = true;
                            _chargeTimer = 0.5f;

                            Vector2 dir = (playerMob.Body.Position - Body.Position) / distance;
                            Body.Velocity = dir * 10f;

                            _prepareTimer = 0f;
                        }
                    }
                }
                else if (distance > 2f)
                {
                    Vector2 dir = (playerMob.Body.Position - Body.Position) / distance;
                    Body.Velocity = dir * 4f;

                    if (_prepareTimer > 0f)
                    {
                        _prepareTimer -= delta;
                    }
                }
                else
                {
                    _preparing = true;
                }

                if (playerMob.Body.Position.X > Body.Position.X)
                {
                    Sprite.Effects = SpriteEffects.FlipHorizontally;
                }
                else if (playerMob.Body.Position.X < Body.Position.X)
                {
                    Sprite.Effects = SpriteEffects.None;
                }
            }

            if (Body.Velocity.X > 0f)
            {
                Sprite.Effects = SpriteEffects.FlipHorizontally;
            }
            else if (Body.Velocity.X < 0f)
            {
                Sprite.Effects = SpriteEffects.None;
            }
        }
示例#9
0
        public static Level GenerateLevel(LD44Game game, int width, int height, ChunkSet chunkSet, bool sky, string background, Random random)
        {
            ChunkSides[,] chunkSides = new ChunkSides[width, height];

            if (width > 1)
            {
                chunkSides[0, height - 1].Right = SideStatus.Open;
                chunkSides[1, height - 1].Left  = SideStatus.Open;
            }
            if (height > 1)
            {
                chunkSides[0, height - 1].Top    = SideStatus.Closed;
                chunkSides[0, height - 2].Bottom = SideStatus.Closed;
            }

            if (width > 1)
            {
                chunkSides[width - 1, 0].Left  = SideStatus.Open;
                chunkSides[width - 2, 0].Right = SideStatus.Open;
            }
            if (height > 1)
            {
                chunkSides[width - 1, 0].Bottom = SideStatus.Closed;
                chunkSides[width - 1, 1].Top    = SideStatus.Closed;
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (x == 0)
                    {
                        chunkSides[x, y].Left = SideStatus.Closed;
                    }
                    if (y == 0)
                    {
                        chunkSides[x, y].Top = sky ? SideStatus.Edge : SideStatus.Closed;
                    }
                    if (x == width - 1)
                    {
                        chunkSides[x, y].Right = SideStatus.Closed;
                    }
                    if (y == height - 1)
                    {
                        chunkSides[x, y].Bottom = SideStatus.Closed;
                    }
                }
            }

            if (width > 1)
            {
                Tunnel(chunkSides, 1, 0, random);

                while (TunnelUncertainChunk(chunkSides, random))
                {
                    ;
                }
            }

            int cx = 1;
            int cy = height - 1;

            while (cx < width - 2 || cy > 0)
            {
                if (cx < width - 2 && cy > 0)
                {
                    if (_random.Next(3) == 0)
                    {
                        chunkSides[cx, cy].Top        = SideStatus.Open;
                        chunkSides[cx, cy - 1].Bottom = SideStatus.Open;
                        cy--;
                    }
                    else
                    {
                        chunkSides[cx, cy].Right    = SideStatus.Open;
                        chunkSides[cx + 1, cy].Left = SideStatus.Open;
                        cx++;
                    }
                }
                else if (cx < width - 2)
                {
                    chunkSides[cx, cy].Right    = SideStatus.Open;
                    chunkSides[cx + 1, cy].Left = SideStatus.Open;
                    cx++;
                }
                else
                {
                    chunkSides[cx, cy].Top        = SideStatus.Open;
                    chunkSides[cx, cy - 1].Bottom = SideStatus.Open;
                    cy--;
                }
            }

            var level = new Level(chunkSet.Width * width, chunkSet.Height * height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Chunk chunk = chunkSet.Get(chunkSides[x, y], random);

                    for (int y2 = 0; y2 < chunkSet.Height; y2++)
                    {
                        for (int x2 = 0; x2 < chunkSet.Width; x2++)
                        {
                            InitializeTile(game, level, x * chunkSet.Width + x2, y * chunkSet.Height + y2, chunk[x2, y2]);
                        }
                    }
                }
            }

            int fullHeight = height * chunkSet.Height;
            int fullWidth  = width * chunkSet.Width;

            for (int y = 0; y < fullHeight; y++)
            {
                for (int x = 0; x < fullWidth; x++)
                {
                    Tile tile = level.GetTile(x, y);

                    if (tile.TileType != TileType.Solid ||
                        (tile.FrontSprite.Texture != "rock" &&
                         tile.FrontSprite.Texture != "leaf" &&
                         tile.FrontSprite.Texture != "marble"))
                    {
                        continue;
                    }

                    if (y == 0 || level.GetTile(x, y - 1).TileType == TileType.Solid)
                    {
                        if (y == fullHeight - 1 || level.GetTile(x, y + 1).TileType == TileType.Solid)
                        {
                            tile.FrontSprite.Texture += "_center";
                        }
                        else
                        {
                            tile.FrontSprite.Texture += "_bottom";
                        }
                    }
                    else
                    {
                        tile.FrontSprite.Texture += "_top";
                    }
                }
            }

            level.Background.Texture = background;

            return(level);
        }
示例#10
0
        private static void InitializeTile(LD44Game game, Level level, int x, int y, ChunkTile tileType)
        {
            Tile tile = level.GetTile(x, y);

            switch (tileType)
            {
            case ChunkTile.Rock: {
                tile.FrontSprite.Texture = "rock";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.Leaf: {
                tile.FrontSprite.Texture = "leaf";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.Marble: {
                tile.FrontSprite.Texture = "marble";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.Roof: {
                tile.FrontSprite.Texture = "roof";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.HouseWall: {
                tile.FrontSprite.Texture = "house_wall";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.HouseWindow: {
                tile.FrontSprite.Texture = "house_window";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.RockWall: {
                tile.BackSprite.Texture = "rock_wall";
                break;
            }

            case ChunkTile.Sapling: {
                tile.BackSprite.Texture = "sapling";
                break;
            }

            case ChunkTile.Bat: {
                var bat = new BatMob {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["bat_flying"], 0.5f)
                    {
                        IsLooping = true
                    }
                };
                bat.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(bat);
                break;
            }

            case ChunkTile.Player: {
                level.Entrance = new Vector2(x + 0.5f, y + 0.5f);
                break;
            }

            case ChunkTile.Door: {
                tile.BackSprite.Texture = "rock_wall";

                var door = new Interactable {
                    Position = new Vector2(x, y) + new Vector2(0.5f),
                    Region   = new RectangleF(0f, 0f, 1f, 1f),

                    InteractableType = InteractableType.Door,

                    Destination = game.TunnelTemplate
                };
                door.Sprite.Texture = "door";
                door.Sprite.Origin  = new Vector2(0.5f);
                level.Interactables.Add(door);
                break;
            }

            case ChunkTile.Greeter: {
                var talker = new Interactable {
                    Position = new Vector2(x, y) + new Vector2(0.5f),
                    Region   = new RectangleF(0f, 0f, 1f, 1f),

                    InteractableType = InteractableType.Message,

                    Message = "Hohohohoho, you dare enter the domain of Volgax uninvited? You fool!"
                };
                talker.Animation = new AnimationState <Sprite>(game.SpriteAnimations["trader_idle"], 0.5f)
                {
                    IsLooping = true
                };
                talker.Sprite.Texture = "trader";
                talker.Sprite.Origin  = new Vector2(0.5f);
                level.Interactables.Add(talker);
                break;
            }

            case ChunkTile.Spikes: {
                var spikes = new SpikesMob();
                spikes.Body.Ghost    = true;
                spikes.Body.Position = new Vector2(x, y + 6f / 16f) + new Vector2(0.5f);
                level.Mobs.Add(spikes);
                break;
            }

            case ChunkTile.Spot: {
                level.Spots.Add(new Point(x, y));
                break;
            }

            case ChunkTile.Monkey: {
                var monkey = new MonkeyMob(_random)
                {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["monkey_idle"], 0.5f)
                    {
                        IsLooping = true
                    }
                };
                monkey.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(monkey);
                break;
            }

            case ChunkTile.EliteBat: {
                var bat = new EliteBatMob {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["elite_bat_flying"], 0.5f)
                    {
                        IsLooping = true
                    }
                };
                bat.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(bat);
                break;
            }

            case ChunkTile.Gem: {
                var gem = new GemMob {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["gem_idle"], 3f)
                    {
                        IsLooping = true
                    }
                };
                gem.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(gem);
                break;
            }

            case ChunkTile.Angel: {
                var angel = new Interactable {
                    Position = new Vector2(x, y) + new Vector2(0.5f),
                    Region   = new RectangleF(0f, 0f, 1f, 1f),

                    InteractableType = InteractableType.Blessing,

                    Message = "Please, accept my blessing."
                };
                angel.Animation = new AnimationState <Sprite>(game.SpriteAnimations["angel_idle"], 10f)
                {
                    IsLooping = true
                };
                angel.Sprite.Texture = "angel";
                angel.Sprite.Origin  = new Vector2(0.5f, 0.75f);
                level.Interactables.Add(angel);
                break;
            }

            case ChunkTile.Waterfall: {
                tile.FrontSprite.Texture = "waterfall";
                tile.FrontAnimation      = new AnimationState <Sprite>(game.SpriteAnimations["waterfall"], 0.1f)
                {
                    IsLooping = true
                };
                break;
            }

            case ChunkTile.Villager: {
                var villager = new VillagerMob {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["villager_idle"], 0.5f)
                    {
                        IsLooping = true
                    }
                };
                villager.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(villager);
                break;
            }

            case ChunkTile.Entrance: {
                level.Entrances.Add(new Point(x, y));
                break;
            }

            case ChunkTile.Exit: {
                level.Exits.Add(new Point(x, y));
                break;
            }

            case ChunkTile.Valgox: {
                var valgox = new Interactable {
                    Position = new Vector2(x, y) + new Vector2(0.5f),
                    Region   = new RectangleF(0f, 0f, 1f, 1f),

                    InteractableType = InteractableType.Valgox,

                    Message = "Oi, you! Get off my tower right now or I'll smite you!"
                };
                valgox.Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_idle"], 0.5f)
                {
                    IsLooping = true
                };
                valgox.Sprite.Texture = "valgox";
                valgox.Sprite.Origin  = new Vector2(0.5f, 0.85f);
                level.Interactables.Add(valgox);
                break;
            }

            case ChunkTile.Curse: {
                var curse = new CurseMob();
                curse.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(curse);
                break;
            }
            }
        }
示例#11
0
 public static Level GenerateLevel(LD44Game game, LevelTemplate template, Random random)
 {
     return(GenerateLevel(game, template.Width, template.Height, template.Chunks, template.Sky, template.Background, random));
 }
示例#12
0
        public void Update(LD44Game game, Level level, float delta)
        {
            PlayerMob playerMob = level.Mobs.OfType <PlayerMob>().First();

            if (!_sighted)
            {
                if (_sentryTimer <= 0f)
                {
                    _sentryTimer = 3f + _random.Next(6);
                    if (_random.Next(8) == 0)
                    {
                        _sentryTimer += 5f;
                    }

                    Sprite.Effects = Sprite.Effects == SpriteEffects.None ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
                }
                else
                {
                    _sentryTimer -= delta;
                }
            }

            var sight = new RectangleF(Body.Position.X, Body.Position.Y - 1.5f, 10f, 3f);

            if (!FacingRight)
            {
                sight.X -= sight.Width;
            }

            RectangleF playerRegion = playerMob.Body.Bounds;

            playerRegion.X = playerMob.Body.Position.X - playerMob.Body.Bounds.Width / 2f;
            playerRegion.Y = playerMob.Body.Position.Y - playerMob.Body.Bounds.Height / 2f;

            float distance = Vector2.Distance(Body.Position, playerMob.Body.Position);

            if (_sighted && distance > 10f)
            {
                _sighted = false;
            }

            if (!_sighted && (sight.Intersects(playerRegion) || distance < 1.5f))
            {
                _sighted = true;

                _state      = State.Waiting;
                _stateTimer = 1f;
            }

            if (_sighted)
            {
                switch (_state)
                {
                case State.Waiting: {
                    Body.Velocity = new Vector2(0f, Body.Velocity.Y);
                    if (playerMob.Body.Position.X > Body.Position.X)
                    {
                        Sprite.Effects = SpriteEffects.FlipHorizontally;
                    }
                    else if (playerMob.Body.Position.X < Body.Position.X)
                    {
                        Sprite.Effects = SpriteEffects.None;
                    }

                    _stateTimer -= delta;
                    if (_stateTimer <= 0f)
                    {
                        if (playerMob.Body.Position.Y + 0.5f < Body.Position.Y)
                        {
                            _state = State.Leaping;
                        }
                        else
                        {
                            if (_random.Next(4) == 0)
                            {
                                _state = State.Leaping;
                            }
                            else
                            {
                                _state = State.Running;
                            }
                        }

                        if (_state == State.Running)
                        {
                            _stateTimer = 3f;
                        }
                        else
                        {
                            if (playerMob.Body.Position.X > Body.Position.X)
                            {
                                Body.Velocity = new Vector2(8f, Body.Velocity.Y);
                            }
                            else if (playerMob.Body.Position.X < Body.Position.X)
                            {
                                Body.Velocity = new Vector2(-8f, Body.Velocity.Y);
                            }
                            Body.Velocity -= new Vector2(0f, 13f);
                            _state         = State.Leaping;
                        }
                    }
                    break;
                }

                case State.Running: {
                    if (playerMob.Body.Position.X - 0.75f > Body.Position.X)
                    {
                        Body.Velocity  = new Vector2(6f, Body.Velocity.Y);
                        Sprite.Effects = SpriteEffects.FlipHorizontally;
                    }
                    else if (playerMob.Body.Position.X + 0.75f < Body.Position.X)
                    {
                        Body.Velocity  = new Vector2(-6f, Body.Velocity.Y);
                        Sprite.Effects = SpriteEffects.None;
                    }

                    _stateTimer -= delta;
                    if (_stateTimer <= 0f)
                    {
                        _state      = State.Waiting;
                        _stateTimer = 1f;
                    }
                    break;
                }

                case State.Leaping: {
                    if (Body.Contact.Y > 0f)
                    {
                        _state      = State.Waiting;
                        _stateTimer = 1f;
                    }
                    break;
                }
                }
            }
        }
示例#13
0
 public RestartScreen(LD44Game game)
 {
     _game = game;
 }
示例#14
0
 public WinScreen(LD44Game game)
 {
     _game = game;
 }