コード例 #1
0
ファイル: Game1.cs プロジェクト: spaghettikotze/CockroachKing
        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            //graphics.PreferredBackBufferWidth = 960;
            //graphics.PreferredBackBufferHeight = 540;
            resolution = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            graphics.ApplyChanges();
            scale = new Vector2(resolution.X / 1920, resolution.Y / 1080);

            keyboard = new KeyboardListener();
            mouse    = new MouseListener();
            Console.OpenStandardOutput();
            base.Initialize();
        }
コード例 #2
0
        /*public static bool Collided(GameObject a, GameObject b)
         * {
         *  bool collision = false;
         *
         *  int i = 0;
         *  int j = 0;
         *  float dist2 = 0;
         *  float r2 = 0;
         *  while (i < a.Collider.Count)
         *  {
         *      while (j < b.Collider.Count)
         *      {
         *          dist2 = Vector2.DistanceSquared(a.Collider[i].Position, b.Collider[j].Position);
         *          r2 = (a.Collider[i].Radius + b.Collider[j].Radius) * (a.Collider[i].Radius + b.Collider[j].Radius);
         *          if (dist2 < r2)
         *          {
         *              collision = true;
         *              break;
         *          }
         *          j++;
         *      }
         *      if (collision)
         *          break;
         *      i++;
         *  }
         *
         *  return collision;
         * }*/

        /*public static void CollisionHandler(List<GameObject> objects, GameTime gameTime)
         * {
         *  for (int i = 0; i < objects.Count; i++)
         *  {
         *      GameObject currentObject = objects[i];
         *      double deltaTime = gameTime.TotalGameTime.TotalSeconds - currentObject.LastCollisionTime;
         *      for (int j = 0; j < objects.Count; j++)
         *      {
         *          GameObject otherObject = objects[j];
         *          if (currentObject == otherObject || (deltaTime < 2 && otherObject == currentObject.LastCollisionObject))
         *              continue;
         *          if (Collided(currentObject, otherObject))
         *          {
         *
         *              if (currentObject is Projectile)
         *              {
         *                  Projectile currentProjectile = (Projectile)currentObject;
         *                  if (otherObject == currentProjectile.Owner || otherObject is Projectile)
         *                      continue;
         *                  otherObject.Hit(currentProjectile.Power);
         *                  currentProjectile.Impact = true;
         *              }
         *              else if (!(otherObject is Projectile))
         *              {
         *                  otherObject.Hit(otherObject.Hitpoints / 2);
         *                  currentObject.Hit(currentObject.Hitpoints / 2);
         *              }
         *
         *              otherObject.LastCollisionObject = currentObject;
         *              currentObject.LastCollisionObject = otherObject;
         *
         *          }
         *
         *      }
         *  }
         * }*/

        public static void PlayerHandler(Player player, MouseListener mouse, KeyboardListener keyboard)
        {
            float xAcc = 10f;
            float yAcc = 10f;

            player.Velocity     = new Vector2();
            player.Acceleration = new Vector2();

            if (keyboard.KeyPressed(Keys.Left) || keyboard.KeyPressed(Keys.A))
            {
                player.Acceleration = new Vector2(-xAcc, player.Acceleration.Y);
            }
            if (keyboard.KeyPressed(Keys.Right) || keyboard.KeyPressed(Keys.D))
            {
                player.Acceleration = new Vector2(xAcc, player.Acceleration.Y);
            }

            /*if (keyboard.KeyPressed(Keys.Down) || keyboard.KeyPressed(Keys.S))
             *  player.Acceleration = new Vector2(player.Acceleration.X, yAcc);*/
            /*if (keyboard.KeyPressed(Keys.Up) || keyboard.KeyPressed(Keys.W))
            *   player.Acceleration = new Vector2(player.Acceleration.X, -yAcc);*/
        }