public override void Update(float elapsed, Camera camera, Player player, Map map)
 {
     //			y += yDir * elapsed * FALL_SPEED;
     //			x += xDir * elapsed * MOVE_SPEED;
     base.Update (elapsed, camera, player, map);
     //rect = new Rectangle (new Point ((int)x, (int)y), new Size (WIDTH, HEIGHT + 1));
 }
        public override void Update(float elapsed, Camera camera, Player player, Map map)
        {
            base.Update (elapsed, camera, player, map);
            if (!dead) {
                tileDirRelSprites = new List<TileDirectionRelSprite> ();
                ApplyCamera (camera);
                x += xDir * MOVE_SPEED * elapsed;
                y += yDir * FALL_SPEED * elapsed;
                if (jumping) {
                    if (yDir >= 0) {
                        jumping = false;
                        falling = true;
                    } else {
                        yDir += FALL_SPEED;
                    }
                } else if (falling) {
                    if (yDir < FALL_CAP)
                        yDir += FALL_SPEED;
                }
                gun.Update (elapsed, camera);
                if (xDir != 0) {
                    gun.left = xDir < 0;

                }
                if (gun.left) {
                    gun.x = x - gun.width;
                } else if (!gun.left) {
                    gun.x = x + width;
                }
                gun.y = y + height / 3;
            }
        }
 public override void Update(float elapsed, Camera camera, Player player, Map map)
 {
     base.Update (elapsed, camera, player, map);
     if (!dead) {
         DoAI (camera, player,map);
     }
 }
Esempio n. 4
0
        public void Update(GameTime gameTime, Map gameMap)
        {
            MoveHorizontal(faceDir);

            // Move rectangle to enemy's location
            collRect.X = (int)Position.X - (collRect.Width / 2);
            collRect.Y = (int)Position.Y - collRect.Height;

            // Apply inertia to X speed
            Speed.X = MathHelper.Lerp(Speed.X, 0f, INERTIA);
            // Clamp X floating point value
            if ((Speed.X > 0f && Speed.X < 0.1f) || (Speed.X < 0f && Speed.X > -0.1f)) Speed.X = 0f;
            // Apply gravity to Y speed
            Speed.Y += Map.GRAVITY;

            // Check Collisions
            CheckCollisions(gameMap);

            // Check platform edges
            CheckPlatform(gameMap);

            // Apply speed to position
            Position += Speed;

            // Clamp X position to map boundaries
            if (Position.X < 0)
            {
                Position.X = 0;
                Speed.X = 0;
                faceDir = 1;
            }
            if (Position.X > Map.MAP_WIDTH * Map.TILE_WIDTH)
            {
                Position.X = Map.MAP_WIDTH * Map.TILE_WIDTH;
                Speed.X = 0;
                faceDir = -1;
            }

            // If we're not jumping...
            if (Speed.X != 0f)
            {
                // If we're moving left or right, animate!
                // Increment frame time counter by elapsed game frame time (ms)
                currentFrameTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (currentFrameTime >= FRAME_TIME)
                {
                    // If current animation frame time is reached, reset current frame time to 0 and increment current frame number
                    currentFrameTime = 0;
                    currentFrame++;
                    // If we're at the end of the animation sequence, loop back to first frame
                    if (currentFrame >= WALK_FRAMES + FIRST_WALK_FRAME) currentFrame = FIRST_WALK_FRAME;
                }
            }
        }
        public void Update(GameTime dt)
        {
            _currentMap.Update(dt, _player);

            if (_currentMap.Completed)
            {
                int index = _maps.FindIndex(x => x == _currentMap);
                _currentMap = (Map)_maps[++index].Clone();
                _player.Respawn(new Vector2(200, 200));
            }
        }
        public void LoadMaps(GraphicsDevice gd, params string[] mapFiles)
        {
            foreach (string mapFile in mapFiles)
            {
                var m = new Map();
                m.Load(_contentManager, mapFile, gd);
                _maps.Add(m);
            }

            _currentMap = _maps.First();
        }
Esempio n. 7
0
        public static Map Load(string fn, ContentManager content)
        {
            Map newMap;
            string mapText;
            Texture2D tilesTex;

            mapText = File.ReadAllText(Path.Combine(content.RootDirectory, fn));
            tilesTex = content.Load<Texture2D>("tiles");
            newMap = new Map(mapText, tilesTex);

            return newMap;
        }
Esempio n. 8
0
        public override void Update()
        {
            base.Update ();
            if (Engine.Scene != null && !initialized) {
                Map map = new Map(50, 20);

                Debug.Log (Core.playerManager.players.Count);
                Hero hero = new Hero();
                hero.Position.x = 1 * Config.GRID;
                hero.Position.y = 1 * Config.GRID;
                Engine.Scene.Add(hero);

                initialized = true;
            }
        }
 public virtual void Update(float elapsed, Camera camera, Player player, Map map)
 {
     rect = new Rectangle (new Point ((int)x, (int)y), new Size (width, height));
     if (health <= 0) {
         dead = true;
     }
     if (dead) {
         if (system == null) {
             ParticleOptions ops = (new EffectDie (colour, (KillableSprite)this)).template.Clone();
             ops.xPosRange = new Vector (new Point ((int)x, (int)x + width));
             ops.yPosRange = new Vector (new Point ((int)y, (int)y + height));
             system = new ParticleSystem (ops);
         }
         system.Update (elapsed, camera);
         return;
     }
 }
Esempio n. 10
0
        private void CheckPlatform(Map gameMap)
        {
            Vector2 checkPos;

            // Left
            if (Speed.X < 0)
            {
                checkPos.X = collRect.Left - (Map.TILE_WIDTH/2);
                checkPos.Y = collRect.Bottom + (Map.TILE_HEIGHT / 2);
                if (gameMap.GetTileAt(checkPos) == 0)
                {
                    faceDir = 1;
                }
            }

            // Right
            if (Speed.X > 0)
            {
                checkPos.X = collRect.Right + (Map.TILE_WIDTH/2);
                checkPos.Y = collRect.Bottom + (Map.TILE_HEIGHT / 2);
                if (gameMap.GetTileAt(checkPos) == 0)
                {
                    faceDir = -1;
                }
            }
        }
Esempio n. 11
0
        private void CheckCollisions(Map gameMap)
        {
            Vector2 checkPos;

            // First, check collsions downwards
            if (Speed.Y > 0)
            {
                checkPos.Y = collRect.Bottom + Speed.Y;
                for (checkPos.X = collRect.Left + 4; checkPos.X <= collRect.Right - 4; checkPos.X += collRect.Width / 8)
                    if (gameMap.GetTileAt(checkPos) > 0)
                    {
                        Speed.Y = 0;
                    }
            }

            //  Up
            if (Speed.Y < 0)
            {
                checkPos.Y = collRect.Top + Speed.Y;
                for (checkPos.X = collRect.Left + 4; checkPos.X <= collRect.Right - 4; checkPos.X += collRect.Width / 8)
                    if (gameMap.GetTileAt(checkPos) > 0)
                    {
                        Speed.Y = 0;
                    }
            }

            // Left
            if (Speed.X < 0)
            {
                checkPos.X = collRect.Left + Speed.X;
                for (checkPos.Y = collRect.Top + 4; checkPos.Y <= collRect.Bottom - 4; checkPos.Y += collRect.Height / 8)
                    if (gameMap.GetTileAt(checkPos) > 0)
                    {
                        Speed.X = 0;
                        faceDir = 1;
                    }
            }

            // Right
            if (Speed.X > 0)
            {
                checkPos.X = collRect.Right + Speed.X;
                for (checkPos.Y = collRect.Top + 4; checkPos.Y <= collRect.Bottom - 4; checkPos.Y += collRect.Height / 8)
                    if (gameMap.GetTileAt(checkPos) > 0)
                    {
                        Speed.X = 0;
                        faceDir = -1;
                    }
            }
        }
Esempio n. 12
0
        public void Update(GameTime gameTime, Map gameMap)
        {
            // Move rectangle to player's location
            collRect.X = (int)Position.X - (collRect.Width / 2);
            collRect.Y = (int)Position.Y - collRect.Height;

            // Apply inertia to X speed
            Speed.X = MathHelper.Lerp(Speed.X, 0f,INERTIA);
            // Clamp X floating point value
            if ((Speed.X > 0f && Speed.X < 0.1f) || (Speed.X < 0f && Speed.X > -0.1f)) Speed.X = 0f;
            // Apply gravity to Y speed
            Speed.Y += Map.GRAVITY;

            // Check Collisions
            CheckCollisions(gameMap);

            // Apply speed to position
            Position += Speed;

            // Clamp X position to map boundaries
            if (Position.X < 0)
            {
                Position.X = 0;
                Speed.X = 0;
            }
            if (Position.X > Map.MAP_WIDTH * Map.TILE_WIDTH)
            {
                Position.X = Map.MAP_WIDTH * Map.TILE_WIDTH;
                Speed.X = 0;
            }

            // Temporary!
            //if (Position.Y > 720)
            //{
            //    Position.Y = 720;
            //    Speed.Y = 0;
            //    isJumping = false;
            //}

            // Animation
            if (!isJumping)
            {
                // If we're not jumping...
                if (Speed.X != 0f)
                {
                    // If we're moving left or right, animate!
                    // Increment frame time counter by elapsed game frame time (ms)
                    currentFrameTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (currentFrameTime >= FRAME_TIME)
                    {
                        // If current animation frame time is reached, reset current frame time to 0 and increment current frame number
                        currentFrameTime = 0;
                        currentFrame++;
                        // If we're at the end of the animation sequence, loop back to first frame
                        if (currentFrame >= WALK_FRAMES + FIRST_WALK_FRAME) currentFrame = FIRST_WALK_FRAME;
                    }
                }
                else
                {
                    // If we're not moving, display the idle frame
                    currentFrame = IDLE_FRAME;
                }
            }
            else
            {
                // Jumping, so display the jump frame
                currentFrame = JUMP_FRAME;
            }
        }
 public virtual void DoAI(Camera camera, Player player, Map map)
 {
     if (player.rect.IntersectsWith (rect)) {
         player.dead = true;
     }
 }
Esempio n. 14
0
 public void Update(GameTime gameTime, Map gameMap)
 {
     // Update all enemies
     foreach (Enemy e in Enemies) e.Update(gameTime, gameMap);
 }