コード例 #1
0
ファイル: Root.cs プロジェクト: SongSing/touhou-roguelike
        /// <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();
            }

            AKS.Update();

            if (AKS.IsKeyDown(Keys.RightAlt) && AKS.WasJustPressed(Keys.Enter))
            {
                this.graphics.ToggleFullScreen();
            }

            if (AKS.WasJustPressed(Keys.R))
            {
                this.gameScene.Reset();
            }

            DebugInfo.Clear();
            double frameRate = this.smartFramerate.Framerate;

            if (double.IsInfinity(frameRate))
            {
                frameRate = 0;
            }

            DebugInfo.Add("FPS: " + Math.Round(frameRate).ToString());

            DebugInfo.Add("Memory: " + GC.GetTotalMemory(false) / 1024);

            this.gameScene.Update(gameTime);

            base.Update(gameTime);
        }
コード例 #2
0
ファイル: Root.cs プロジェクト: SongSing/touhou-roguelike
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            AKS.WatchKey(Keys.RightAlt);
            AKS.WatchKey(Keys.Enter);
            AKS.WatchKey(Keys.R);

            AKS.WatchKey(KeyDefs.Up);
            AKS.WatchKey(KeyDefs.Down);
            AKS.WatchKey(KeyDefs.Left);
            AKS.WatchKey(KeyDefs.Right);
            AKS.WatchKey(KeyDefs.Shoot);
            AKS.WatchKey(KeyDefs.Bomb);

            base.Initialize();
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: SongSing/touhou-roguelike
        protected override void InternalUpdate(GameTime gameTime)
        {
            base.InternalUpdate(gameTime);

            // update position //

            float mod = this.IsFocused ? this.focusMod : 1;

            Vector2 translation = new Vector2(AKS.Axis(Root.KeyDefs.Left, Root.KeyDefs.Right), AKS.Axis(Root.KeyDefs.Up, Root.KeyDefs.Down));

            translation *= this.speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds * mod;

            this.Position += translation;

            this.Position = this.Position.Clamped(new Vector2(hitboxR), GameScene.GameArea.ToVector2() - new Vector2(hitboxR));

            if (this.Position.X >= GameScene.GameArea.X / 2)
            {
                this.SpriteEffects = SpriteEffects.None;
            }
            else
            {
                this.SpriteEffects = SpriteEffects.FlipHorizontally;
            }

            /*if (translation.X < 0)
             * {
             *  if (translation.Y <= 0)
             *  {
             *      this.SpriteEffects = SpriteEffects.FlipHorizontally;
             *  }
             *  else
             *  {
             *      this.SpriteEffects = SpriteEffects.None;
             *  }
             * }
             * else if (translation.X > 0)
             * {
             *  if (translation.Y > 0)
             *  {
             *      this.SpriteEffects = SpriteEffects.FlipHorizontally;
             *  }
             *  else
             *  {
             *      this.SpriteEffects = SpriteEffects.None;
             *  }
             * }*/
            //Log.Print(this.AbsoluteRoundedPosition.ToString() + "\n");

            // update shooting stuff //

            float shootMod = AKS.IsKeyDown(Root.KeyDefs.Focus) ? 0.1f : 1;

            if (this.canShoot)
            {
                if (AKS.IsKeyDown(Root.KeyDefs.Shoot))
                {
                    this.Shoot(0 * shootMod);
                    this.Shoot(-20 * shootMod);
                    this.Shoot(20 * shootMod);
                    this.Shoot(-40 * shootMod);
                    this.Shoot(40 * shootMod);
                    this.canShoot     = false;
                    this.shootCounter = 0;
                }
            }
            else
            {
                this.shootCounter += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (this.shootCounter >= this.shootCooldown)
                {
                    this.canShoot     = true;
                    this.shootCounter = 0;
                }
            }

            this.BulletPool.Update(gameTime);
        }