コード例 #1
0
ファイル: Invader.cs プロジェクト: kenpower/XNA4
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            //position += velocity;

            world =Matrix.CreateScale(radius)*Matrix.CreateTranslation(position) ;

            //            if (DateTime.Now.Subtract(timeOfBirth).TotalMilliseconds > 2000)
            //            {
            //                alive = false;
            //            }
            int i=random.Next()%40;
            if (i == 0 && bullets.Count<40)
            {
                Bullet b = new Bullet(theGame);
                b.Initialize(bulletModel, Vector3.Backward, position);
                bullets.Add(b);
            }

            base.Update(gameTime);
        }
コード例 #2
0
ファイル: Ship.cs プロジェクト: kenpower/XNA4
        public void Update(GameTime gt)
        {
            KeyboardState ks = Keyboard.GetState();

            if(ks.IsKeyDown(Keys.Up)){
                yaw+=maxYawSpeed;
            }
            if(ks.IsKeyDown(Keys.Down)){
                yaw-=maxYawSpeed;
            }

            if (ks.IsKeyDown(Keys.Right))
            {
                position.X += maxHorzSpeed;
            }
            if (ks.IsKeyDown(Keys.Left))
            {
                position.X -= maxHorzSpeed;

            }

            Matrix rot=Matrix.CreateRotationY(yaw);
            direction = Vector3.Transform(Vector3.Forward, rot);

            //only spawn bullet if its been 100ms since last bullet was made
            if (ks.IsKeyDown(Keys.Space)
                &&
                DateTime.Now.Subtract(timeOfLastBullet).TotalMilliseconds
                > 100)
            {
                Bullet b = new Bullet(game);
                b.Initialize(bulletModel,direction,position);
                bullets.Add(b);
                timeOfLastBullet = DateTime.Now;
            }
            world = Matrix.CreateRotationY(yaw) * Matrix.CreateTranslation(position) ;

            foreach (Bullet b in bullets)
            {
                  b.Update(gt);
            }
            bullets.RemoveAll(Bullet.IsDead);

            long millsSinceLastDeath = (long)DateTime.Now.Subtract(timeOfLastDeath).TotalMilliseconds;
            if (millsSinceLastDeath < 3000)
            {//flicker for 3 seconds after death
                spawning = true;
                long tenthsSinceLastDeath = millsSinceLastDeath / 100;
                visible=true;
                if (tenthsSinceLastDeath % 2 == 0)
                {
                    visible = false;
                }
            }
            else
            {
                spawning = false;
                visible = true;

            }
        }