Exemple #1
0
Fichier : AI.cs Projet : LMY/yuPong
        public static PongMoveMovement SuggestForce(int playern, Level lvl, Ball[] balls, Pad pad)
        {
            float force_constant = 40f * pad.Mass;

            int   bestball    = -1;
            float best_deltax = float.PositiveInfinity;

            for (int i = 0; i < balls.Length; i++)
            {
                if (balls[i].Speed.X < 0 && playern == 1 || balls[i].Speed.X > 0 && playern == 0)
                {
                    if (Math.Abs(balls[i].Center.X - pad.Center.X) <= pad.Size.X * 1.002f)
                    {
                        continue;
                    }


                    float this_deltax = Math.Abs(balls[i].Center.X - pad.Center.X);

                    if (this_deltax > lvl.SizeX * 0.4f)
                    {
                        continue;
                    }

                    if (bestball < 0 || this_deltax < best_deltax)      // if first valid found or closest one
                    {
                        bestball    = i;
                        best_deltax = this_deltax;
                    }
                }
            }

            if (bestball < 0)
            {
                return(new PongMoveMovement(new Vector3(0, force_constant * -pad.Center.Y, 0)));
            }
            else
            {
                float kk = -(pad.Center.Y - balls[bestball].Center.Y);
                return(new PongMoveMovement(new Vector3(0, 2 * force_constant * kk, 0)));
            }
        }
Exemple #2
0
        public GameStateMatch(Character char1, Character char2, bool human1, bool human2, MatchType type)
        {
            matchtype = type;
            won_p1    = won_p2 = 0;

            pause = true;

            GL.Enable(EnableCap.Texture2D);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.ClearDepth(1.0f);

            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ColorMaterial(MaterialFace.FrontAndBack, ColorMaterialParameter.AmbientAndDiffuse);
            GL.Enable(EnableCap.ColorMaterial);
            GL.Enable(EnableCap.Blend);

//            GL.DepthFunc(DepthFunction.Lequal);
            GL.Enable(EnableCap.DepthTest);
//            human2 = true;


            Appearance.init();

            lvl = new Level();

            pads    = new Pad[2];
            pads[0] = new Pad(lvl, 0, Appearance.PongGenericAppearance);
            pads[1] = new Pad(lvl, 1, Appearance.PongGenericAppearance);

            balls          = new Ball[1];
            balls[0]       = new Ball();
            balls[0].Speed = Vector3.UnitX * 7;

            if (human1)
            {
                player1 = new Player(this, char1, pads[0], InputHuman.input1, char1.DefaultAppearance);
            }
            else
            {
                player1 = new Player(this, char1, pads[0], new InputAI(), char1.DefaultAppearance);
            }

            if (human2)
            {
                player2 = new Player(this, char2, pads[1], InputHuman.input2, char2.DefaultAppearance);
            }
            else
            {
                player2 = new Player(this, char2, pads[1], new InputAI(), char2.DefaultAppearance);
            }


            theEvents    = new GameEventList();
            theFieldlist = new FieldList();

            const float hbarsize = 0.85f;

            player1.Healthbar = new Healthbar(new Vector3(lvl.SizeX / 2 - hbarsize / 2 * lvl.SizeX / 2, lvl.SizeY / 2 * 1.2f, 0), false, new Vector3(lvl.SizeX / 2 * hbarsize, 0.4f, 1));
            player2.Healthbar = new Healthbar(new Vector3(-lvl.SizeX / 2 + hbarsize / 2 * lvl.SizeX / 2, lvl.SizeY / 2 * 1.2f, 0), true, new Vector3(lvl.SizeX / 2 * hbarsize, 0.4f, 1));



            GL.Enable(EnableCap.Lighting);      // Let there Be Light

            float R0 = pads[0].theAppearance.Color.R;
            float G0 = pads[0].theAppearance.Color.G;
            float B0 = pads[0].theAppearance.Color.B;

            float R1 = pads[1].theAppearance.Color.R;
            float G1 = pads[1].theAppearance.Color.G;
            float B1 = pads[1].theAppearance.Color.B;

            const float light_height = 12.5f;

            light5_ambient  = new Color4(0.6f, 0.6f, 0.6f, 1);
            light5_diffuse  = new Color4(0.6f, 0.6f, 0.6f, 1);
            light5_specular = new Color4(1.0f, 1.0f, 1.0f, 1);
            light5_pos      = new Vector4(lvl.SizeX / 4, 0, light_height, 1);
            light5_dir      = new Vector4(0, 0, -1, 0);

            light6_ambient  = new Color4(0.6f, 0.6f, 0.6f, 1);
            light6_diffuse  = new Color4(0.6f, 0.6f, 0.6f, 1);
            light6_specular = new Color4(1.0f, 1.0f, 1.0f, 1);

            light6_pos = new Vector4(-lvl.SizeX / 4, 0, light_height, 1);
            light6_dir = new Vector4(0, 0, -1, 0);

            SetAmbientLight();
            GL.Enable(EnableCap.Light5);
            GL.Enable(EnableCap.Light6);

            ResetRound();

            pause = false;
        }