Beispiel #1
0
 public Background() :
     base(TextureLibrary.GetTexture("SpaceBackground"), new Rectangle())
 {
     mySecondTexture  = TextureLibrary.GetTexture("SpaceBackground");
     mySecondPosition = new Vector2(0, mySecondTexture.Height);
     mySpeed          = 100;
 }
Beispiel #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            player = Content.Load <Texture2D>("player");

            rockTexture = Content.Load <Texture2D>("rock");
            TextureLibrary.LoadTexture(Content, "bullet");
            TextureLibrary.LoadTexture(Content, "background");
            TextureLibrary.LoadTexture(Content, "background2");
            background1 = Content.Load <Texture2D>("background");
            background2 = Content.Load <Texture2D>("background2");
        }
Beispiel #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            enemy.Update();
            // TODO: Add your update logic here
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            attackTimer += deltaTime;
            float pixelsToMove = speed * deltaTime;

            dir = new Vector2();
            backgroundManager.Update(deltaTime);
            MouseState mouseState = Mouse.GetState();

            dirToLook = mouseState.Position.ToVector2() - playerPos;



            KeyboardState keyPress = Keyboard.GetState();

            if (alive)
            {
            }
            if (mouseState.LeftButton == ButtonState.Pressed && attackTimer >= attackSpeed)
            {
                Debug.Print("Yo");
                attackTimer = 0;
                bullets.Add(new Bullet(dirToLook, bulletSpeed, TextureLibrary.GetTexture("bullet"), playerPos, bulletDamage));
            }
            for (int i = 0; i < bullets.Count; i++)
            {
                bullets[i].Update(deltaTime);
            }
            if (keyPress.IsKeyDown(Keys.D))
            {
                dir = new Vector2(1, 0);
            }
            if (keyPress.IsKeyDown(Keys.A))
            {
                dir = new Vector2(-1, 0);
            }
            if (keyPress.IsKeyDown(Keys.W))
            {
                dir.Y = -1;
            }
            if (keyPress.IsKeyDown(Keys.S))
            {
                dir.Y = 1;
            }
            if (dir != Vector2.Zero)
            {
                dir.Normalize();
                playerPos          += (dir * pixelsToMove);
                playerRect.Location = (playerPos - playerOffset * scale).ToPoint();
            }



            rotation = (float)Math.Atan2(dirToLook.Y, dirToLook.X);

            base.Update(gameTime);
        }