Ejemplo n.º 1
0
 public override void Update(Level currentLevel)
 {
     if (Alive)
     {
         Move(MovementDirection, 0.1f);
     }
     base.Update(currentLevel);
 }
Ejemplo n.º 2
0
 public void Fall(Level level)
 {
     if (Alive)
     {
         //gravity
         Vector2 originalPosition = Position;
         Velocity.Y += 0.3f;
         var verticalVelocity = new Vector2(0, Velocity.Y);
         Position += verticalVelocity;
         GameObject intersects = IntersectsWithAny(level.GameObjects);
         if (intersects != null)
         {
             Position = originalPosition;
             //object is below this
             if (intersects.Position.Y > Position.Y)
                 ReachedBottom();
         }
     }
 }
Ejemplo n.º 3
0
        private void LoadLevel(string levelname)
        {
            #if DEBUG
            if (levelname == "")
            {
                _logWindow.AddMessage("No levelname passed, loading empty level and enabling noclip");
                Level level = new Level();
                level.StartZone = new GameObject(new Vector2(0, 416), Vector2.Zero, _startZoneTexture,
                                                 GameObject.ObjectType.StartZone);
                level.FinishZone = new GameObject(new Vector2(64, 416), Vector2.Zero, _finishZoneTexture,
                                                  GameObject.ObjectType.FinishZone);
                _currentLevel = level;
                _noclip = true;
                _camera.LockToPlayingArea = !_noclip;
            }
            else
            #endif
                _currentLevel = LoadLevelFromFile(levelname);

            _currentLevel.Name = levelname;

            _player = new Player(_currentLevel.StartZone.Position, new Vector2(0, 5), _heroTexture);
            _currentLevel.GameObjects.Add(_player);
            _camera.LockToObject(_player);
        }
Ejemplo n.º 4
0
 internal Level LoadLevelFromFile(string filename)
 {
     var level = new Level();
     using(var sr = new StreamReader(filename))
     {
         while (!sr.EndOfStream)
         {
             string s = sr.ReadLine();
             if (s != null && (s.StartsWith("//") || s == ""))
                 continue;
             if (s != null)
             {
                 string[] split = s.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
                 if (split[2] == "startzone")
                 {
                     Texture2D sprite = _startZoneTexture;
                     var startZone = new GameObject(
                         new Vector2(float.Parse(split[0]), float.Parse(split[1])), Vector2.Zero, sprite,
                         GameObject.ObjectType.StartZone);
                     level.StartZone = startZone;
                 }
                 else if (split[2] == "finishzone")
                 {
                     Texture2D sprite = _finishZoneTexture;
                     var finishZone = new GameObject(
                         new Vector2(float.Parse(split[0]), float.Parse(split[1])), Vector2.Zero, sprite,
                         GameObject.ObjectType.FinishZone);
                     level.FinishZone = finishZone;
                 }
                 else if(split[2] == "enemy")
                 {
                     Texture2D sprite = _enemyTexture;
                     var enemy = new Enemy(new Vector2(float.Parse(split[0]), float.Parse(split[1])), Vector2.Zero,
                                             sprite);
                     level.GameObjects.Add(enemy);
                 }
                 else
                 {
                     var sprite = Content.Load<Texture2D>(split[2]);
                     sprite.Name = split[2];
                     var gameObject = new GameObject(
                         new Vector2(float.Parse(split[0]), float.Parse(split[1])),
                         new Vector2(0, 0), sprite, GameObject.ObjectType.Block);
                     level.GameObjects.Add(gameObject);
                 }
             }
         }
     }
     return level;
     //X,Y,spritename
     //first line = X
     //second line = Y
     //third line = spritename
 }
Ejemplo n.º 5
0
 public virtual void Update(Level currentLevel)
 {
 }
Ejemplo n.º 6
0
        public override void Update(Level currentLevel)
        {
            if (Alive)
            {
                Vector2 lastPosition = Position;
                if (Velocity.Y > 0)
                    Position += new Vector2(Velocity.X, 0);
                else
                    Position += Velocity;
                Velocity.X *= 0.75f;
                if (Velocity.Y < 0)
                    Velocity.Y *= 0.90f;

                if (IntersectsWithAny(currentLevel.GameObjects) != null)
                {
                    Position = lastPosition;
                    Velocity = new Vector2(0, Velocity.Y);
                    HitWall();
                }
                Fall(currentLevel);
                if(Position.Y > 800)
                {
                    //below visible screen
                    Die();
                }
            }
            else
            {
                if (Position.Y < -5000)
                    Velocity = Vector2.Zero;
                Position += Velocity;
            }
        }
Ejemplo n.º 7
0
 public bool HasFinished(Level currentLevel)
 {
     if (IntersectsWith(currentLevel.FinishZone))
         return true;
     return false;
 }