public bool isPointinDirection(System.Drawing.Point point) { var ret = false; Vector2 relPos = new Vector2((point.X / (float)Fledermaus.MyApplication.GameWindow.Width) * 2.0f - 1.0f, ((point.Y / (float)Fledermaus.MyApplication.GameWindow.Height) * 2.0f - 1.0f) * -1); var left = Scale * (Data.Position.X + ((LightRay)Data).RayDirection.X - Width / 2.0f); var right = Scale * (Data.Position.X + ((LightRay)Data).RayDirection.X + Width / 2.0f); var top = Scale * (Data.Position.Y + ((LightRay)Data).RayDirection.Y + Height / 2); var bottm = Scale * (Data.Position.Y + ((LightRay)Data).RayDirection.Y - Height / 2); // Skalierung left *= BasicGraphics.GetXScale(); right *= BasicGraphics.GetXScale(); if (relPos.X > left && relPos.X < right) { if (relPos.Y < top && relPos.Y > bottm) { ret = true; } } return(ret); }
//public override void Draw(); public override bool isPointInScreen(System.Drawing.Point point) { var ret = false; Vector2 relPos = new Vector2((point.X / (float)Fledermaus.MyApplication.GameWindow.Width) * 2.0f - 1.0f, ((point.Y / (float)Fledermaus.MyApplication.GameWindow.Height) * 2.0f - 1.0f) * -1); Width = -1 * Data.RelativeBounds.Min(x => x.X) + Data.RelativeBounds.Max(x => x.X); Height = -1 * Data.RelativeBounds.Min(x => x.Y) + Data.RelativeBounds.Max(x => x.Y); var left = Scale * (Data.Position.X - Width / 2.0f); var right = Scale * (Data.Position.X + Width / 2.0f); var top = Scale * (Data.Position.Y + Height / 2); var bottm = Scale * (Data.Position.Y - Height / 2); // Skalierung left *= BasicGraphics.GetXScale(); right *= BasicGraphics.GetXScale(); if (relPos.X > left && relPos.X < right) { if (relPos.Y < top && relPos.Y > bottm) { ret = true; } } return(ret); }
public override void Draw() { mainMenuDrawer.DrawMainMenu(menuItemXPaddings); if (switchFrameCount > 0) { BasicGraphics.SetColor4(0, 0, 0, switchFrameCount / 105.0f); BasicGraphics.DrawSquare(new OpenTK.Vector2(-2, 2), new OpenTK.Vector2(2, -2)); } }
public override void Draw() { base.Draw(); DrawTitle("Highscores"); DrawTimeStrings(); BasicGraphics.SetColor(BasicGraphics.Colors.DefaultText); BasicGraphics.DrawText(GetCurrentLevel(), new Vector2(-0.1f, 0.1f), 0.08f); }
protected void DrawSquare(Vector2 position, List <Vector2> bounds) { /* GL.Begin(PrimitiveType.Quads); * foreach (var bound in bounds) * GL.Vertex2(Scale*(position.X + bound.X), Scale*( position.Y + bound.Y)); * GL.End();*/ if (bounds.Count == 0) { return; } var x_small = 0.0f; var x_large = 0.0f; var y_small = 0.0f; var y_large = 0.0f; foreach (var bound in bounds) { if (bound.X < x_small) { x_small = bound.X; } else if (bound.X > x_large) { x_large = bound.X; } if (bound.Y < y_small) { y_small = bound.Y; } else if (bound.Y > y_large) { y_large = bound.Y; } } var modi = 1.0f; for (int i = 0; i < bounds.Count - 1; i++) { Vector2 point1 = new Vector2(Scale * (position.X + modi * bounds[i].X), Scale * (position.Y + modi * bounds[i].Y)); Vector2 point2 = new Vector2(Scale * (position.X + modi * bounds[i + 1].X), Scale * (position.Y + modi * bounds[i + 1].Y)); BasicGraphics.DrawOpenGLLine(point1, point2); } Vector2 point1a = new Vector2(Scale * (position.X + modi * bounds[bounds.Count - 1].X), Scale * (position.Y + modi * bounds[bounds.Count - 1].Y)); Vector2 point1b = new Vector2(Scale * (position.X + modi * bounds[0].X), Scale * (position.Y + modi * bounds[0].Y)); BasicGraphics.DrawOpenGLLine(point1a, point1b); }
/// <summary> /// /// </summary> /// <param name="device">图形设备</param> /// <param name="contentMgr">素材管理者</param> /// <param name="contentPath">引擎所需资源路径</param> public RenderEngine(GraphicsDevice device, ContentManager contentMgr, string contentPath) { if (device == null) { throw new NullReferenceException(); } this.contentPath = contentPath; this.device = device; this.coordinMgr = new CoordinMgr(); this.spriteMgr = new SpriteMgr(this); this.basicGraphics = new BasicGraphics(this); this.fontMgr = new FontMgr(this, contentMgr); Log.Initialize(); }
public override void Draw() { /* if (isSelected) * GL.Color3(0.0f, 1.0f, 0.0f); * else * GL.Color3(1.0f, 0.0f, 0.0f); * * GL.Begin(PrimitiveType.Quads); * GL.Vertex2(-Width / 2, Position-(Height/2)); * GL.Vertex2( Width / 2, Position - (Height / 2)); * GL.Vertex2( Width / 2, Position + (Height / 2)); * GL.Vertex2(-Width / 2, Position + (Height / 2)); * GL.End(); */ // GL.Clear(ClearBufferMask.ColorBufferBit); //color is multiplied with texture color white == no change // GL.Color3(Color.White); BasicGraphics.Colors color; if (!isEnabled && isSelected) { color = BasicGraphics.Colors.SelectedDisabledText; } else if (!isEnabled && !isSelected) { color = BasicGraphics.Colors.DisabledText; } else if (isEnabled && isSelected) { color = BasicGraphics.Colors.SelectedText; } else { color = BasicGraphics.Colors.ButtonText; } BasicGraphics.SetColor(color); //Vector2 position = new Vector2(Position.X - (Width / 2), Position.Y - (Height / 2)); Vector2 position = new Vector2(Position.X, Position.Y); BasicGraphics.DrawText(Text, position, 0.08f); }
private void DrawTimeString(TimeString timeString, float y) { float time = timeString.Time; string text = timeString.Context + ": " + (time < 0 ? "/" : Util.GetTimeString(time)); if (timeString.IsNewRecord) { BasicGraphics.SetColor(BasicGraphics.Colors.SpecialText); } else { BasicGraphics.SetColor(BasicGraphics.Colors.DefaultText); } BasicGraphics.DrawText(text, new Vector2(-0.8f, y), 0.08f); }
public override void Draw() { base.Draw(); DrawTitle("how to play"); float x = -0.8f; float y = 0.4f; foreach (string line in lines) { BasicGraphics.SetColor(BasicGraphics.Colors.DefaultText); BasicGraphics.DrawText(line, new Vector2(x, y), 0.08f); y -= (line.Length < 1 ? 0.05f : 0.1f); } }
public override void Draw() { if (DrawBackground) { BasicGraphics.DrawDefaultBackground(); } if (DrawTitleImage) { BasicGraphics.DrawRectangularTexture(Textures.Instance.TitleTexture, new Vector2(-0.2f, 0.8f), new Vector2(1.4f, 0.0f)); } setInitPositionOfButtons(); base.Draw(); foreach (var mb in menuButtons) { mb.Draw(); } }
public override void ProcessMouseMove(MouseMoveEventArgs e) { if (EditMode == EditMode.Edit) { if (playerVisual != null) { if (this.PlayerVisual.isPointInScreen(e.Position)) { this.PlayerVisual.IsSelected = true; //SelectedGameObject = PlayerVisual; } else { this.PlayerVisual.IsSelected = false; if (exitVisual.isPointInScreen(e.Position)) { exitVisual.IsSelected = true; //SelectedGameObject = PlayerVisual; } else { exitVisual.IsSelected = false; } foreach (var lightRay in lightRayVisuals) { if (lightRay.isPointInScreen(e.Position)) { lightRay.IsSelected = true; //SelectedGameObject = lightRay; } else if (lightRay.isPointinDirection(e.Position)) { lightRay.IsDirectionSelected = true; //SelectedGameObject = lightRay; } else { lightRay.IsSelected = false; lightRay.IsDirectionSelected = false; //lightRay.IsDirectionSelected = false; } } foreach (var obstacle in ObstacleVisuals) { if (obstacle.isPointInScreen(e.Position) || obstacle.isPointinBound(e.Position)) { //obstacle.IsSelected = true; if (obstacle.isPointInScreen(e.Position)) { obstacle.IsSelected = true; } else { obstacle.IsSelected = false; } if (obstacle.isPointinBound(e.Position)) { obstacle.IsBoundSelected = true; } else { obstacle.IsBoundSelected = false; } } else { obstacle.IsSelected = false; obstacle.IsBoundSelected = false; } } foreach (var mirrorV in mirrorVisuals) { if (mirrorV.isPointInScreen(e.Position)) { mirrorV.IsSelected = true; } else { mirrorV.IsSelected = false; } if (mirrorV.isPointInMirrorPosition(e.Position)) { mirrorV.IsMirrorPositionSelected = true; } else { mirrorV.IsMirrorPositionSelected = false; } if (mirrorV.isPointInMirrorRotation(e.Position)) { mirrorV.IsMirrorRotationSelected = true; } else { mirrorV.IsMirrorRotationSelected = false; } if (mirrorV.isPointInMirrorMaxRotation(e.Position)) { mirrorV.IsMirrorMaxRotationSelected = true; } else { mirrorV.IsMirrorMaxRotationSelected = false; } if (mirrorV.isPointInMirrorMinRotation(e.Position)) { mirrorV.IsMirrorMinRotationSelected = true; } else { mirrorV.IsMirrorMinRotationSelected = false; } if (mirrorV.isPointInRailStart(e.Position)) { mirrorV.IsRailStartSelected = true; } else { mirrorV.IsRailStartSelected = false; } } } } } else if (EditMode == EditMode.Position) { Vector2 relPos = new Vector2(((e.Position.X / (float)Fledermaus.MyApplication.GameWindow.Width) * 2.0f - 1.0f) / BasicGraphics.GetXScale(), ((e.Position.Y / (float)Fledermaus.MyApplication.GameWindow.Height) * 2.0f - 1.0f) * -1); if (relPos.X > 1.0f) { relPos = new Vector2(1.0f, relPos.Y); } else if (relPos.X < -1.0f) { relPos = new Vector2(-1.0f, relPos.Y); } if (selectedGameObject.GetType().Equals(typeof(PlayerVisual))) { selectedGameObject.Data.Position = relPos; } if (selectedGameObject.GetType().Equals(typeof(ExitVisual))) { var absTop = (-relPos + new Vector2(.0f, 1.0f)).Length; var absBot = (-relPos + new Vector2(.0f, -1.0f)).Length; var absRight = (-relPos + new Vector2(1.0f, .0f)).Length; var absLeft = (-relPos + new Vector2(-1.0f, .0f)).Length; var highest = new List <float>() { absBot, absLeft, absRight, absTop }.Min(); if (highest == absTop) { selectedGameObject.Data.Position = new Vector2(relPos.X, 1.0f - selectedGameObject.Data.RelativeBounds[0].Y);//relPos; exitVisual.IsHorizontal = true; } else if (highest == absBot) { selectedGameObject.Data.Position = new Vector2(relPos.X, -1.0f + selectedGameObject.Data.RelativeBounds[0].Y);//relPos; exitVisual.IsHorizontal = true; } else if (highest == absLeft) { selectedGameObject.Data.Position = new Vector2(-1.0f + selectedGameObject.Data.RelativeBounds[0].X, relPos.Y);//relPos; exitVisual.IsHorizontal = false; } else if (highest == absRight) { selectedGameObject.Data.Position = new Vector2(1.0f - selectedGameObject.Data.RelativeBounds[0].X, relPos.Y);//relPos; exitVisual.IsHorizontal = false; } } else if (selectedGameObject.GetType().Equals(typeof(LightRayVisual))) { if (((LightRayVisual)selectedGameObject).IsDirectionSelected) { ((LightRay)selectedGameObject.Data).RayDirection = relPos - ((LightRay)selectedGameObject.Data).Position; } else { selectedGameObject.Data.Position = relPos; } } else if (selectedGameObject.GetType().Equals(typeof(ObstacleVisual))) { if (((ObstacleVisual)selectedGameObject).IsBoundSelected) { var scale = (relPos - selectedGameObject.Data.Position).Length / selectedGameObject.Data.RelativeBounds[0].Length; for (int i = 0; i < selectedGameObject.Data.RelativeBounds.Count; i++) { selectedGameObject.Data.RelativeBounds[i] *= scale; } } else { selectedGameObject.Data.Position = relPos; } } else if (selectedGameObject.GetType().Equals(typeof(MirrorVisual))) { if (((MirrorVisual)selectedGameObject).IsMirrorPositionSelected) { var railStart = (((Mirror)selectedGameObject.Data).Position + ((Mirror)selectedGameObject.Data).RailStart); if (selectedGameObject.isPointInScreen(e.Position)) { var re = relPos - selectedGameObject.Data.Position; var relPosMirror = .0f; if (Math.Abs(selectedGameObject.Data.RelativeBounds[0].X) >= Math.Abs(selectedGameObject.Data.RelativeBounds[0].Y)) { relPosMirror = (Math.Abs(selectedGameObject.Data.RelativeBounds[0].X) + re.X) / (-((Mirror)selectedGameObject.Data).RailStart + ((Mirror)selectedGameObject.Data).RailEnd).Length; } else { if (((Mirror)selectedGameObject.Data).RailStart.Y < ((Mirror)selectedGameObject.Data).RailEnd.Y) { relPosMirror = (Math.Abs(selectedGameObject.Data.RelativeBounds[0].Y) + re.Y) / (-((Mirror)selectedGameObject.Data).RailStart + ((Mirror)selectedGameObject.Data).RailEnd).Length; } else { relPosMirror = (Math.Abs(selectedGameObject.Data.RelativeBounds[0].Y) - re.Y) / (-((Mirror)selectedGameObject.Data).RailStart + ((Mirror)selectedGameObject.Data).RailEnd).Length; } } ((Mirror)selectedGameObject.Data).StartingRelativePosition = relPosMirror; } } else if (((MirrorVisual)selectedGameObject).IsMirrorRotationSelected) { var dir = (-(((Mirror)selectedGameObject.Data).RailStart) + ((Mirror)selectedGameObject.Data).RailEnd); var mirPos = ((Mirror)selectedGameObject.Data).RailStart + dir * ((Mirror)selectedGameObject.Data).StartingRelativePosition; //RailStartDir var u = mirPos + ((Mirror)selectedGameObject.Data).RailStart; //RelPosDir var v = relPos - (selectedGameObject.Data.Position + mirPos); var dot = Vector2.Dot(Vector2.Normalize(u), Vector2.Normalize(v)); //var len = u.Length * v.Length; float angle = (float)(float)(Math.Acos(dot /*/ len*/)); var v3 = new Vector3(v.X, v.Y, .0f); var u3 = new Vector3(u.X, u.Y, .0f); //point below Raildirection if (Vector3.Cross(v3, u3).Z < 0) { angle = -1 * angle; } if (angle < ((Mirror)selectedGameObject.Data).MaxRotation && angle > ((Mirror)selectedGameObject.Data).MinRotation) { ((Mirror)selectedGameObject.Data).InitAngle = angle; } } else if (((MirrorVisual)selectedGameObject).IsMirrorMaxRotationSelected) { var dir = (-(((Mirror)selectedGameObject.Data).RailStart) + ((Mirror)selectedGameObject.Data).RailEnd); var mirPos = ((Mirror)selectedGameObject.Data).RailStart + dir * ((Mirror)selectedGameObject.Data).StartingRelativePosition; //RailStartDir var u = -1 * (mirPos + ((Mirror)selectedGameObject.Data).RailStart); //RelPosDir var v = relPos - (selectedGameObject.Data.Position + mirPos); var dot = Vector2.Dot(Vector2.Normalize(u), Vector2.Normalize(v)); //var len = u.Length * v.Length; float angle = (float)(float)(Math.Acos(dot /*/ len*/)); var v3 = new Vector3(v.X, v.Y, .0f); var u3 = new Vector3(u.X, u.Y, .0f); //point below Raildirection if (Vector3.Cross(v3, u3).Z < 0) { angle = -1 * angle; } // if (angle < ((Mirror)selectedGameObject.Data).MaxRotation && angle > ((Mirror)selectedGameObject.Data).MinRotation) if (angle < Math.PI && /*angle>0 && */ angle > ((Mirror)selectedGameObject.Data).MinRotation) { ((Mirror)selectedGameObject.Data).MaxRotation = angle; if (((Mirror)selectedGameObject.Data).InitAngle > angle) { ((Mirror)selectedGameObject.Data).InitAngle = angle; } } } else if (((MirrorVisual)selectedGameObject).IsMirrorMinRotationSelected) { var dir = (-(((Mirror)selectedGameObject.Data).RailStart) + ((Mirror)selectedGameObject.Data).RailEnd); var mirPos = ((Mirror)selectedGameObject.Data).RailStart + dir * ((Mirror)selectedGameObject.Data).StartingRelativePosition; //RailStartDir var u = -1 * (mirPos + ((Mirror)selectedGameObject.Data).RailStart); //RelPosDir var v = relPos - (selectedGameObject.Data.Position + mirPos); var dot = Vector2.Dot(Vector2.Normalize(u), Vector2.Normalize(v)); //var len = u.Length * v.Length; float angle = (float)(float)(Math.Acos(dot /*/ len*/)); var v3 = new Vector3(v.X, v.Y, .0f); var u3 = new Vector3(u.X, u.Y, .0f); //point below Raildirection if (Vector3.Cross(v3, u3).Z < 0) { angle = -1 * angle; } // if (angle < ((Mirror)selectedGameObject.Data).MaxRotation && angle > ((Mirror)selectedGameObject.Data).MinRotation) if (angle < Math.PI && angle < ((Mirror)selectedGameObject.Data).MaxRotation) { ((Mirror)selectedGameObject.Data).MinRotation = angle; if (((Mirror)selectedGameObject.Data).InitAngle < angle) { ((Mirror)selectedGameObject.Data).InitAngle = angle; } } } else if (((MirrorVisual)selectedGameObject).IsRailStartSelected) { var rs = relPos - selectedGameObject.Data.Position; if (Math.Abs(selectedGameObject.Data.Position.X + rs.X) < 1.0f && Math.Abs(selectedGameObject.Data.Position.Y + rs.X) < 1.0f && Math.Abs(selectedGameObject.Data.Position.X - rs.X) < 1.0f && Math.Abs(selectedGameObject.Data.Position.Y - rs.X) < 1.0f) { ((Mirror)selectedGameObject.Data).RailStart = rs; ((Mirror)selectedGameObject.Data).RailEnd = -rs; } } else { if (relPos.X + (selectedGameObject.Data.RelativeBounds.Min(b => b.X)) > -1.0f && relPos.X + (selectedGameObject.Data.RelativeBounds.Max(b => b.X)) < 1.0f && relPos.Y + (selectedGameObject.Data.RelativeBounds.Min(b => b.Y)) > -1.0f && relPos.Y + (selectedGameObject.Data.RelativeBounds.Max(b => b.Y)) < 1.0f) { selectedGameObject.Data.Position = relPos; } } } } }
protected void DrawTitle(string title) { BasicGraphics.SetColor(BasicGraphics.Colors.HeaderText); BasicGraphics.DrawText(title, new Vector2(-0.76f, 0.6f), 0.15f); }