示例#1
0
        protected override void Update(GameTime gameTime)
        {
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            spawnTimer += deltaTime;

            if (spawnTimer >= 2)
            {
                Enemy tempEnemy = new Enemy(TextureLibrary.GetTexture("enemy"), new Vector2(Randomizer.GetRandom(Window.ClientBounds.Width), -TextureLibrary.GetTexture("enemy").Height), 300, new Vector2(0.3f, 0.3f), 0, Color.White, 100);
                enemies.Add(tempEnemy);
                spawnTimer = 0;
            }

            player.Update(deltaTime, Keyboard.GetState(), Mouse.GetState(), Window.ClientBounds.Size);
            enemy.Update(gameTime, player, Window.ClientBounds.Height);

            for (int i = 0; i < enemies.Count; i++)
            {
                enemies[i].Update(gameTime, player, Window.ClientBounds.Height);

                if (enemies[i].GetIsAlive() == false || enemies[i].GetPosition().Y >= Window.ClientBounds.Height)
                {
                    enemies.RemoveAt(i);
                    i--;
                }
            }

            BulletManager.Update(deltaTime, player, enemies);
            base.Update(gameTime);
        }
示例#2
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            TextureLibrary.Init(Content);
        }
示例#3
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);



            triangleTexture = Content.Load <Texture2D>("triangle");

            TextureLibrary.LoadTexture("triangle");

            TextureLibrary.LoadTexture("bullet");

            TextureLibrary.LoadTexture("enemy");
        }
示例#4
0
        public void Update(float deltaTime, KeyboardState keyboardState, MouseState mouseState, Point windowSize)
        {
            if (alive)
            {
                //float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
                //KeyboardState keyboardState = Keyboard.GetState();
                //moveDir = new Vector2();
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    //moveDir.X = 1;
                    position.X += speed * deltaTime;
                }
                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    //moveDir.X = -1;
                    position.X -= speed * deltaTime;
                }

                rectangle.Location = position.ToPoint();
                rectangle.Offset(-offset);
                //if (moveDir != Vector2.Zero)
                //{
                //    moveDir.Normalize();

                //    position += moveDir * speed * deltaTime;
                //}

                attackTimer += deltaTime;
                if (attackTimer <= attackSpeed)
                {
                    attackTimer += deltaTime;
                }

                if (mouseState.LeftButton == ButtonState.Pressed && attackTimer >= attackSpeed)
                {
                    Vector2 bulletDir = mouseState.Position.ToVector2() - position;
                    BulletManager.AddBullet(TextureLibrary.GetTexture("triangle"), position, bulletDir, 400, new Vector2(0.05f, 0.05f), Owner.Player, Color.White);
                    attackTimer = 0;
                }

                if (health <= 0)
                {
                    alive = false;
                }
            }
            else
            {
                playerColor = Color.Black;
            }
        }
示例#5
0
        protected override void Initialize()
        {
            base.Initialize();
            Randomizer.Init();

            player  = new Player(triangleTexture, new Vector2(0, 400), 500, new Vector2(0.1f, 0.1f), 0, Color.White, 100, 1);
            enemy   = new Enemy(TextureLibrary.GetTexture("enemy"), new Vector2(Randomizer.GetRandom(Window.ClientBounds.Width), -TextureLibrary.GetTexture("enemy").Height), 300, new Vector2(0.3f, 0.3f), 0, Color.White, 100);
            enemies = new List <Enemy>();

            IsMouseVisible    = true;
            speed             = 300;
            triangleRectangle = triangleTexture.Bounds;

            BulletManager.SetWindowsize(Window.ClientBounds.Size);
        }