Пример #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            map_level = 0;
            attributes = new List<List<string>>();
            contents = new List<List<string>>();
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>("GameFont");
            // TODO: use this.Content to load your game content here
            player = new Player();
            player.LoadContent(Content, inputManager);

            enemies = new List<Enemy>();
            enemies.Add(new Enemy());

            foreach(Enemy e in enemies)
            {
                e.LoadContent(Content, inputManager);
            }

            map = new Map();
            maps.Add("Load/Map.cme");
            maps.Add("Load/Map1.cme");
            maps.Add("Load/Map2.cme");
            map.LoadContent(Content, maps[0]);

            collision = new Collision();
            collisions.Add("Load/Collision.cme");
            collisions.Add("Load/Collision1.cme");
            collisions.Add("Load/Collision2.cme");
            collision.LoadContent(Content, collisions[0]);

            splashBackground = Content.Load<Texture2D>(@"menu");
            gameOver = Content.Load<Texture2D>(@"gameover");
        }
Пример #2
0
        public override void Update(GameTime gameTime, InputManager inputManager, Collision col)
        {
            if (((inputManager.KeyDown(Keys.D) && !inputManager.KeyDown(Keys.W, Keys.A, Keys.S)) ||
                (inputManager.KeyDown(Keys.D) && currentDirection == direction.right))
                && position.X <= (GameConstants.windowWidth - player_img.Width / moveAnimation.Frames.X))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 3);
                position.X += GameConstants.moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                currentDirection = direction.right;
            }
            else if (((inputManager.KeyDown(Keys.A) && !inputManager.KeyDown(Keys.W, Keys.D, Keys.S)) ||
                inputManager.KeyDown(Keys.A) && currentDirection == direction.left)
                && position.X > 0)
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 2);
                position.X -= GameConstants.moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                currentDirection = direction.left;
            }
            else if (((inputManager.KeyDown(Keys.W) && !inputManager.KeyDown(Keys.D, Keys.A, Keys.S)) ||
                inputManager.KeyDown(Keys.W) && currentDirection == direction.up)
                && position.Y > 0)
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
                position.Y -= GameConstants.moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                currentDirection = direction.up;
            }
            else if (((inputManager.KeyDown(Keys.S) && !inputManager.KeyDown(Keys.W, Keys.A, Keys.D)) ||
                inputManager.KeyDown(Keys.S) && currentDirection == direction.down)
                && position.Y <= (GameConstants.windowHeight - player_img.Height/moveAnimation.Frames.Y))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0);
                position.Y += GameConstants.moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                currentDirection = direction.down;
            }

            for (int i = 0; i < col.collisionMap.Count; i++)
            {
                for (int j = 0; j < col.collisionMap[i].Count; j++)
                {
                    if (col.collisionMap[i][j] == "x")
                    {
                        if (position.X + moveAnimation.FrameWidth - 15 < j * GameConstants.tileWidth ||
                            position.X + 15 > j * GameConstants.tileWidth + GameConstants.tileWidth ||
                            position.Y + moveAnimation.FrameHeight - 10 < i * GameConstants.tileHeight ||
                            position.Y + 25 > i * GameConstants.tileHeight + GameConstants.tileHeight)
                        {
                            // no collision
                        }
                        else
                        {
                            position = moveAnimation.Position;
                        }
                    }
                }
            }
            moveAnimation.Position = position;
            moveAnimation.Update(gameTime);

            if (inputManager.KeyDown(Keys.P))
            {
                if (shoot_cd <= 0)
                {
                    Bullet b = new Bullet();
                    b.Position = new Vector2((this.position.X + 12), (this.position.Y + 8));

                    if (currentDirection == direction.up)
                        b.Direction = Bullet.direction.up;
                    else if (currentDirection == direction.down)
                        b.Direction = Bullet.direction.down;
                    else if (currentDirection == direction.left)
                        b.Direction = Bullet.direction.left;
                    else if (currentDirection == direction.right)
                        b.Direction = Bullet.direction.right;

                    bulletLoad.Add(b);
                    shoot_sound.Play(sound_volume, 0f, 0f);
                    shoot_cd = GameConstants.cooldown;
                    LostHealth(10);
                }
            }

            foreach (Bullet b in bulletLoad)
            {
                float x = b.BulletPosX;
                float y = b.BulletPosY;
                switch (b.Direction)
                {
                    case Bullet.direction.right:
                        x += GameConstants.shotSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        b.BulletPosX = x;
                        break;
                    case Bullet.direction.left:
                        x -= GameConstants.shotSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        b.BulletPosX = x;
                        break;
                    case Bullet.direction.up:
                        y -= GameConstants.shotSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        b.BulletPosY = y;
                        break;
                    case Bullet.direction.down:
                        y += GameConstants.shotSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                        b.BulletPosY = y;
                        break;
                }

            }

            try
            {
                foreach (Bullet b in bulletLoad)
                {
                    if (b.BulletPosX > GameConstants.windowWidth ||
                        b.BulletPosX <= 0 ||
                        b.BulletPosY > GameConstants.windowHeight ||
                        b.BulletPosY <= 0)
                    {
                        bulletLoad.Remove(b);
                    }
                }
            }
            catch (InvalidOperationException e)
            {
            }

            if (shoot_cd <= 0)
                shoot_cd = 0;
            else if (shoot_cd > 0)
                shoot_cd -= GameConstants.cooldown * (float)gameTime.ElapsedGameTime.TotalSeconds;
        }
Пример #3
0
 public virtual void Update(GameTime gameTime, InputManager input, Collision col)
 {
 }