private void AI(player pl) { //if ((pl.Position.X >= Centerpoint.X - 0.0500f && pl.Position.Y <= Centerpoint.Y + 0.0500f) // || (pl.Position.X <= Centerpoint.X + 0.0500f && pl.Position.Y <= Centerpoint.Y + 0.0500f) // || (pl.Position.X >= Centerpoint.X - 0.0500f && pl.Position.Y >= Centerpoint.Y - 0.0500f) // || (pl.Position.X <= Centerpoint.X + 0.0500f && pl.Position.Y >= Centerpoint.Y - 0.0500f)) //{ // if (pl.Position == Centerpoint) // { // Direction = new OpenTK.Vector2(0, 0); // } // if (pl.Position.X - Centerpoint.X > 0) // { // Direction = new OpenTK.Vector2(0.0005f, Direction.Y); // } // else if (pl.Position.X - Centerpoint.X <0) // { // Direction = new OpenTK.Vector2(-0.0005f, Direction.Y); // } // if (pl.Position.Y - Centerpoint.Y > 0) // { // Direction = new OpenTK.Vector2(Direction.X, 0.0005f); // } // else if (pl.Position.Y - Centerpoint.Y < 0) // { // Direction = new OpenTK.Vector2(Direction.X, -0.0005f); // } //} //else //{ if(counter == 1000) { a = rand.Next(0, 100); counter = 0; } if(a <= 25) { Direction = new OpenTK.Vector2(Direction.X, 50f); } else if(a > 25 && a < 50) { Direction = new OpenTK.Vector2(Direction.X, -50f); } else if(a > 50 && a < 75) { Direction = new OpenTK.Vector2(50f, Direction.Y); } else if(a > 75 && a < 100) { Direction = new OpenTK.Vector2(-50f, Direction.Y); } counter++; //} }
public void Update(player pl) { Direction = new OpenTK.Vector2(0, 0); AI(pl); base.Update(); }
//Methods //-Protected protected override void OnLoad(EventArgs e) { base.OnLoad(e); KeyDown += OnKeyDown; KeyUp += OnKeyUp; MouseDown += OnMouseButtonDown; MouseUp += OnMouseButtonUp; System.Console.WriteLine("OpenGL version: " + GL.GetString(StringName.Version)); System.Console.WriteLine("Graphics card vendor: " + GL.GetString(StringName.Vendor)); System.Console.WriteLine("Graphics card: " + GL.GetString(StringName.Renderer)); System.Console.WriteLine("Shading language version" + GL.GetString(StringName.ShadingLanguageVersion)); //System.Console.WriteLine("Extensions: " + GL.GetString(StringName.Extensions)); System.Console.WriteLine(""); Console.WriteLine("Max Vertex Vectors: " + GL.GetInteger(GetPName.MaxVertexUniformVectors).ToString()); Console.WriteLine("Max Fragment Vectors: " + GL.GetInteger(GetPName.MaxFragmentUniformVectors).ToString()); Console.WriteLine("Max Texture Units: " + GL.GetInteger(GetPName.MaxTextureUnits).ToString()); Console.WriteLine(""); Misc.Time.Init(); //Init main timers Title = "Caliginous - OpenTK"; VSync = VSyncMode.Off; GL.Enable(EnableCap.CullFace); //GL.Enable(EnableCap.DepthTest); //Greatly increases performance (at the cost of memory) but have to pay attention of the Z (i.e for text)! (Checka hur alpha funkar med detta!? http://www.opengl.org/wiki/Transparency_Sorting ) //GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.Blend); //GL.Enable(EnableCap.AlphaTest); //GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.ClearColor(Color.Black); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); projection_M4 = Matrix4.CreateOrthographic(Width, Height, -1, 1); camera_CAM = new Misc.Camera(new Vector3((Width / 2), (Height / 2), 0)); view_M4 = Matrix4.LookAt(camera_CAM.Position, new Vector3(0, 0, -1), new Vector3(0, 1, 0)); //Create VBOs vBOMain_I = Misc.VBOHandler.AddVBO(10024); #if DEBUG Misc.Misc.GLError("(Main VBO Gen)"); #endif vBOFont_I = Misc.VBOHandler.AddVBO(10024); #if DEBUG Misc.Misc.GLError("(Font VBO Gen)"); #endif vBOEvent_I = Misc.VBOHandler.AddVBO(10024); #if DEBUG Misc.Misc.GLError("(Event VBO Gen)" + Environment.NewLine); Console.WriteLine("Main VBO: " + vBOMain_I.ToString()); Console.WriteLine("Font VBO: " + vBOFont_I.ToString()); Console.WriteLine("Event VBO: " + vBOEvent_I.ToString()); Console.WriteLine(""); #endif //Create FBO(s) Misc.FBOHandler.CreateFBO(Width, Height); Misc.FBOHandler.BindScreenBuffer(); //Load shaders progID_I = Misc.ShaderHandler.CreateProgram(); #if DEBUG Misc.Misc.GLError("(Main 1)"); #endif uniformMatProj_I = Misc.ShaderHandler.GetUniformLoc(progID_I, "m4Projection"); uniformMatModV_I = Misc.ShaderHandler.GetUniformLoc(progID_I, "m4ModelView"); uniformProjView_I = Misc.ShaderHandler.GetUniformLoc(progID_I, "m4ProjView"); uniformView_I = Misc.ShaderHandler.GetUniformLoc(progID_I, "m4View"); uniformMod_I = Misc.ShaderHandler.GetUniformLoc(progID_I, "m4Model"); uniformTime_I = Misc.ShaderHandler.GetUniformLoc(progID_I, "fTime"); uniformStep_I = Misc.ShaderHandler.GetUniformLoc(progID_I, "v2Step"); //Send uniforms that wont change often GL.UniformMatrix4(uniformMatProj_I, false, ref projection_M4); view_M4 = Matrix4.CreateTranslation(-camera_CAM.Position); GL.UniformMatrix4(uniformView_I, false, ref view_M4); //GL.Uniform2(uniformStep_I, RayStep_V2); //Load font(s) and textbox Misc.FontHandler.AddFont(1, "Images/TestFont-TransparentBG.png", 100f, 0f, 0f, 26, 4, vBOFont_I, progID_I); //Font 1 - Vanlig text Misc.FontHandler.AddFont(2, "Images/TestFont-TransparentBG.png", 80f, 0f, 0f, 26, 4, vBOFont_I, progID_I); //Font 2 - Textbox text mainTextbox_TB = new Misc.TextBox(-((Width / 2)), -(Height / 2), 310f, 125f, "Images/TB-Border.png", "", Color.White, 2, vBOEvent_I, progID_I); //Init/Load EventHandler //eh = new EventEngine.EventHandler("/Events", "/Images/TB-Border.png"); kBState_KbS = new KeyboardState(); //---Init and create stuff/objects--- gameworld = new World(); player = new player(new Vector3(410, 310, 0), new Vector2(45, 45), "Images/BMongo-Trans.png"); nonpc = new npc(new Vector3(410, 420, 0), new Vector2(45, 45), "Images/xox.png"); //Lights //Misc.LightHandler.AddLight(new Vector3(player.Center), new Vector3(0.2f, 0.2f, 0.05f), 300, 10); //Used when testing shadows Misc.LightHandler.AddLight(new Vector3(player.Center), Color.Gray, 200, 0); //Used when testing shadows //Misc.LightHandler.AddLight(new Vector3(0, 0, 0), Color.White, 200, 0); //Used when testing shadows //Misc.LightHandler.AddLight(new Vector3(player.Center), Color.White, 10, 20); //Misc.LightHandler.AddLight(new Vector3(125, 250, 0), Color.Green, 100, 20); //Misc.LightHandler.AddLight(new Vector3(500, 100, 0), Color.Red, 20, 10); //Misc.LightHandler.AddLight(new Vector3(550, 100, 0), Color.Green, 20, 10); //Misc.LightHandler.ColorMapQuad = new Misc.Quad(new Vector3(-(Width / 2), -(Height / 2), 0), new Vector2(Width, Height), ""); //Fixa in så den skapas inne i LightHandler???!? //Misc.LightHandler.ShadowMapQuad = new Misc.Quad(new Vector3(-(Width / 2), -(Height / 2), 0), new Vector2(Width, Height), ""); //Fixa in så den skapas inne i LightHandler???!? Misc.LightHandler.RenderQuad = new Misc.Quad(new Vector3(-(Width / 2), -(Height / 2), 0), new Vector2(Width, Height), ""); //Fixa in så den skapas inne i LightHandler???!? }