public DialogueScreen(M_Rectangle screenView) { this.screenView = screenView; dialogue = GetDialogue().GetEnumerator(); dialogue.MoveNext(); box = new DialogueBox(screenView, dialogue.Current, textColor); }
public Button(M_Rectangle _rect, Action <Button> _onClick) { this.rect = _rect; this.onClick = _onClick; backColor = Color.Black; }
public TuningScreen(float height, int index) { if (instance != null) { throw new Exception(); } instance = this; this.height = height; screenView = new M_Rectangle(0, 0, G.ResX, G.ResY); screenMatrix = Matrix.CreateScale(G.ResY / 1080f * 4f); screenMatrixInverse = Matrix.Invert(screenMatrix); screenView.Transform(screenMatrixInverse); stateMachine = new UpdrawEnumerator(StateMachine()); playerPos = screenView.BottomLeft + new Vector2(225, 0); friendPos = screenView.BottomLeft + new Vector2(350, 0); friendPos.X -= index * 25f; if (index >= 2) { offsets[0].X = -10000; } if (index >= 3) { offsets[1].X = -10000; } }
static M_Rectangle GetScreenView() { M_Rectangle rect = new M_Rectangle(0, 0, G.ResX, G.ResY); rect.Transform(screenMatrix); return(rect); }
public Btn_Texture(M_Rectangle _rect, Action <Btn_Texture> _onClick, Texture2D _tex) : base(_rect, f => _onClick((Btn_Texture)f)) { tex = _tex; texPos = _rect.GetCenter() - tex.GetSize() / 2f; }
public Race(List <Entity> entities, bool[,] street) { this.Entities = entities; this.street = street; width = street.GetLength(0); height = street.GetLength(1); tiles = new Tile[width, height]; player = entities.Find(f => f is Player) as Player; friend = entities.Find(f => f is Friend) as Friend; PlayerCar playerCar = entities.Find(f => f is PlayerCar) as PlayerCar; player.Pos = playerCar.Pos; for (int i = 0; i < entities.Count; i++) { OnAfterAddEntity(entities[i]); } if (instance != null) { throw new Exception(); } instance = this; camera = new Camera() { moveSpeed = 0.1f, }; #if DEBUG camera.zoomControl = true; #endif camera.zoom = camera.targetZoom = G.ResY / 1080f * 4f; camera.targetPos = player.Pos; camera.JumpToTarget(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { tiles[x, y] = new Tile() { indexX = 3, indexY = 2 }; } } UpdateTiles(0, width, 0, height); screenMatrixInverse = Matrix.Invert(screenMatrix); screenView = new M_Rectangle(0, 0, G.ResX, G.ResY); screenView.Transform(screenMatrixInverse); gameState = new UpdrawEnumerator(GetRaceEnumerable(Ingame.instance.level)); }
private void DrawRect(SpriteBatch spriteBatch, M_Rectangle rect, Color color) { Vector2 p1 = Vector2.Transform(rect.pos, viewTransform()); Vector2 p2 = Vector2.Transform(rect.BottomRight, viewTransform()); M_Rectangle newRect = new M_Rectangle(p1, p2 - p1); DrawM.Sprite.DrawRectCross(spriteBatch, newRect, color, 2, 16, 2, 1); }
public Btn_Text(M_Rectangle _rect, Action <Btn_Text> _onClick, SpriteFont _font, string _text) : base(_rect, f => _onClick((Btn_Text)f)) { font = _font; text = _text; anchor = _rect.GetCenterAnchor(); }
//int textureBorder; public G_B_Sprite(M_Rectangle area, Sprite sprite, Action <G_Button> PressLeft = null, bool stayPressed = false, float depth = 0f) { this.posL = area.pos; this.size = area.size; this.sprite = sprite; this.PressLeft = PressLeft; this.stayPressed = stayPressed; this.depth = depth; }
public G_Enum(M_Rectangle area, Action <object> ValueChanged = null, float depth = 0f) { this.posL = area.pos; this.size = area.size; this.depth = depth; Initialize(); this.ValueChanged += ValueChanged; }
public G_Plane(M_Rectangle area, float depth = 0f) { this.posL = area.pos; this.size = area.size; this.depth = depth; guis = new List <GuiElement>(); areaColor = color; }
private void BtnPressLeft(G_Button obj) { if (btn.pressed) { //action SetCatchUpdate(Update); rectOld = (M_Rectangle)rect.Clone(); } }
public G_Color(M_Rectangle area, Action <object> ColorChanged = null, Color?color = null, float depth = 0f) { this.posL = area.pos; this.size = area.size; this.color = color; this.depth = depth; Initialize(); this.ValueChanged += ColorChanged; }
public G_B_Text(M_Rectangle area, string text, Action <G_Button> Press = null, bool stayPressed = false, SpriteFont font = null, Color?colorText = null, float depth = 0f) { this.posL = area.pos; this.size = area.size; this.text = text; this.PressLeft = Press; this.stayPressed = stayPressed; this.font = font ?? GuiElement.fontStd; this.colorText = colorText ?? Color.Black; this.depth = depth; }
public G_TextBox(M_Rectangle area, Action <object> ValueChanged = null, KeyCollection keyCollection = null, int maxLength = -1, float depth = 0f) { Initialize(); this.posL = area.pos; this.size = area.size; this.ValueChanged = ValueChanged; this.keyCollection = keyCollection; this.maxLength = maxLength; this.depth = depth; }
public override void SetValue(object value, Type type) { if (value == null) { rect = new M_Rectangle(0, 0, 0, 0); } else { rect = (M_Rectangle)value; } txt.text = MyConverter.ToString(rect); }
private void UpdateView() { //Vector2 p1 = pos - new Vector2(resX, resY) / 2f / zoom; //Vector2 p2 = pos + new Vector2(resX, resY) / 2f / zoom; //float scale = 0.5f; float border = 0;//256 M_Polygon poly = new M_Polygon(Vector2.Zero, new List <Vector2>() { new Vector2(-border, -border), new Vector2(resX + border, -border), new Vector2(resX + border, resY + border), new Vector2(-border, resY + border) }); poly.Transform(Matrix.Invert(matrix)); float minX = poly.vertices[0].X; float maxX = poly.vertices[0].X; float minY = poly.vertices[0].Y; float maxY = poly.vertices[0].Y; for (int i = 1; i < poly.vertices.Count; i++) { if (poly.vertices[i].X < minX) { minX = poly.vertices[i].X; } if (poly.vertices[i].X > maxX) { maxX = poly.vertices[i].X; } if (poly.vertices[i].Y < minY) { minY = poly.vertices[i].Y; } if (poly.vertices[i].Y > maxY) { maxY = poly.vertices[i].Y; } } //minX = Math.Max(0, minX); //minY = Math.Max(0, minY); //maxX = Math.Min(mapW - 1, maxX); //maxY = Math.Min(mapH - 1, maxY); view = new M_Rectangle(minX, minY, maxX - minX, maxY - minY); //view = new M_Rectangle(p1, p2 - p1); }
private void PressRight() { //if (btn.pressed) { rect = new M_Rectangle(0, 0, 0, 0); txt.text = MyConverter.ToString(rect); btn.pressed = false; if (ValueChanged != null) { ValueChanged(rect); } } }
private void TextChanged(object text) { M_Rectangle newRect; if (MyConverter.TryParse <M_Rectangle>((string)text, out newRect)) { rect = newRect; if (ValueChanged != null) { ValueChanged(rect); } } txt.text = MyConverter.ToString(rect); }
public G_NumBox(M_Rectangle area, Action <object> ValueChanged = null, decimal increment = 1, decimal?min = null, decimal?max = null, int decimalPlaces = 0, bool modulo = true, float depth = 0f) { this.posL = area.pos; this.size = area.size; this.increment = increment; this.min = min; this.max = max; this.decimalPlaces = decimalPlaces; this.modulo = modulo; this.depth = depth; Initialize(); this.ValueChanged += ValueChanged; }
public House(M_Rectangle rect) : base(null, rect) { baseRect = Mask as M_Rectangle; basePoly = rect.ToPolygon(); for (int i = 0; i < basePoly.vertices.Count; i++) { basePoly.vertices[i] += basePoly.pos; } basePoly.pos = Vector2.Zero; drawPolies = new M_Polygon[3]; for (int i = 0; i < drawPolies.Length; i++) { drawPolies[i] = new M_Rectangle(0, 0, 0, 0).ToPolygon(); } shading[0] = Colors.brightnessTop; }
public DialogueBox(M_Rectangle viewInScreenSpace, string text, Color?textColor = null) { this.viewInScreenSpace = viewInScreenSpace.CloneRectangle(); this.viewInScreenSpace.Enlarge(-8f); this.textColor = textColor ?? Color.White; Vector2 textSize = CropText(text); textSize += boxBorder * 2f; box = new M_Rectangle(0, 0, textSize.X, textSize.Y); boxInner = new M_Rectangle(0, 0, textSize.X - cornerRadius, textSize.Y - cornerRadius); boxInnerToDraw = new M_Rectangle(0, 0, textSize.X, textSize.Y); boxInnerToDraw.Enlarge(-cornerRadius); corner = DrawM.Sprite.CreateCircleTexture(cornerRadius, Color.White); }
internal void EachWall(M_Rectangle onRect, Action <int, int> action) { int x1 = Math.Max((int)onRect.Left, 0); int y1 = Math.Max((int)onRect.Top, 0); int x2 = Math.Min((int)onRect.Right + 1, width); int y2 = Math.Min((int)onRect.Bottom + 1, height); for (int y = y1; y < y2; y++) { for (int x = x1; x < x2; x++) { if (map[x, y]) { action(x, y); } } } }
public override void Draw(SpriteBatch spriteBatch) { if (visible) { Color color; if (hover) { if (pressed) { color = colorHoverPressed; } else { color = colorHover; } } else { if (pressed) { color = colorPressed; } else { color = colorNormal; } } M_Rectangle area = GetRectangle(); DrawM.Sprite.DrawRectangle(spriteBatch, area, color, depth); if (pressed && KeyString.Record) { KeyString.Draw(spriteBatch, font, posG + new Vector2(SPACE, size.Y / 2f), colorText, depth + 0.01f, true, replaceChar); } else { spriteBatch.DrawString(font, drawText, posG + new Vector2(SPACE, (int)Math.Round((size.Y - font.MeasureString(drawText).Y) / 2f)), colorText, 0f, Vector2.Zero, 1f, SpriteEffects.None, depth + 0.01f); } DrawEnd(spriteBatch); } }
public G_RectangleViewGrid(M_Rectangle area, Func <Matrix> getViewTransform, Func <Vector2> getCustomGrid, Action <object> ValueChanged = null, M_Rectangle rect = null, float depth = 0f, bool positiveSize = true) { if (rect == null) { rect = new M_Rectangle(0, 0, 0, 0); } this.posL = area.pos; this.size = area.size; this.rect = rect; this.depth = depth; this.viewTransform = getViewTransform; this.customGrid = getCustomGrid; this.positiveSize = positiveSize; Initialize(); this.ValueChanged = ValueChanged; }
private void SetCameraInBoundary() { if (centered) { UpdateMatrix(); float width = resX / zoom; float height = resY / zoom; M_Rectangle myView = new M_Rectangle(pos - new Vector2(width, height) / 2f, new Vector2(width, height)); float w = myView.size.X / 2f * boundaryFactor; float h = myView.size.Y / 2f * boundaryFactor; w = Math.Min(w, roomBoundary.size.X / 2f); h = Math.Min(h, roomBoundary.size.Y / 2f); if (pos.X - w < roomBoundary.Left) { pos.X = roomBoundary.Left + w; } if (pos.X + w > roomBoundary.Right) { pos.X = roomBoundary.Right - w; } if (pos.Y - h < roomBoundary.Top) { pos.Y = roomBoundary.Top + h; } if (pos.Y + h > roomBoundary.Bottom) { pos.Y = roomBoundary.Bottom - h; } targetPos = pos; } }
internal void Move(Vector2 velocity) { if (velocity != Vector2.Zero) { #region Move loop Vector2 move = velocity; float newMoveDir = 0;//in which direction the last collision was directed float t = 0; while (true) { if (move.Length() < 0.001f) { break; } M_Rectangle rect = new M_Rectangle(pos, Vector2.Zero); rect.Enlarge(RADIUS + 1); rect.Expand(move); CollisionResult cr = new CollisionResult(); env.EachWall(rect, (x, y) => { CollisionResult cr2 = mask.DistToPolygon(new M_Rectangle(x, y, 1, 1).ToPolygon(), move); cr.AddCollisionResult(cr2, move); }); if (!cr.distance.HasValue || t + cr.distance.Value >= 1) { if (t > 1) { t = 1; } pos += move * (1 - t); break; } #region step move //move to nearest dist pos += move * cr.distance.Value; t += cr.distance.Value; Vector2 lastMoveN = new Vector2(-move.Y, move.X); Vector2 tangent = new Vector2(-cr.axisCol.Y, cr.axisCol.X); if (COLLISIONSPEEDWASTE) { move = Vector2.Dot(velocity, tangent) * tangent; } else { float moveLength = move.Length(); move = Vector2.Dot(velocity, tangent) * tangent; if (move != Vector2.Zero) { move = Vector2.Normalize(move) * moveLength; } } if (newMoveDir == 0) { newMoveDir = Vector2.Dot(lastMoveN, move); } else if (Math.Sign(newMoveDir) != Math.Sign(Vector2.Dot(lastMoveN, move))) { //sackgasse move = Vector2.Zero; } if (move.Length() < SPEED * 0.1f) { move = Vector2.Zero; } #endregion } #endregion } }
public void UpdateEnd(int resX, int resY) { //Vector3 move = Vector3.Zero; //if (Input.a.down) // move.X++; //if (Input.d.down) // move.X--; //if (Input.w.down) // move.Z++; //if (Input.s.down) // move.Z--; //if (Input.space.down) // move.Y++; //if (Input.leftShift.down) // move.Y--; //if (move != Vector3.Zero) //{ // move.Normalize(); // move *= moveSpeed; // if (Input.leftControl.down) // move /= 10f; // Vector2 moveXZ = new Vector2(move.X, move.Z); // moveXZ = Vector2.Transform(moveXZ, Matrix.CreateRotationZ(yaw)); // move = new Vector3(moveXZ.X, move.Y, moveXZ.Y); // pos += move; //} //view *= Matrix.CreateRotationY(0.01f); //Vector2 mbPos = Mouse.GetState().Position.ToVector2(); //if (mbPos != Input.mbPos) //{ // Console.WriteLine("y"); //} Vector2 mouseMove = Input.mbPos - mbPosPast;// new Vector2(resX, resY) / 2f; mouseMove *= mouseSensitivity; //view *= Matrix.CreateFromYawPitchRoll(mouseMove.X, mouseMove.Y, 0); //pos += new Vector3(mouseMove.X, 0, mouseMove.Y); mouseMoveSave += (mouseMove - mouseMoveSave) * 0.5f; yaw += mouseMoveSave.X; pitch += mouseMoveSave.Y; if (Math.Abs(pitch) > MathHelper.PiOver2 - 0.1f) { pitch = Math.Sign(pitch) * (MathHelper.PiOver2 - 0.1f); } mbPosPast = Input.mbPos; if (mouseMove != Vector2.Zero) { int border = 10; M_Rectangle rect = new M_Rectangle(border, border, resX - border * 2, resY - border * 2); if (!rect.ColVector(Input.mbPos)) { CenterMouse(); } //Console.WriteLine("x"); } else { } //Console.WriteLine("m"); UpdateView(); }
void MonoMethods.Draw(SpriteBatch spriteBatch) { float wScale = (float)graphics.PreferredBackBufferWidth / Width; float hScale = (float)graphics.PreferredBackBufferHeight / Height; float scale = Math.Min(wScale, hScale); if (Input.mbWheel != 0) { cameraZoom -= Math.Sign(Input.mbWheel); if (cameraZoom < 1) { cameraZoom = 1f; } } scale *= cameraZoom; float realW = graphics.PreferredBackBufferWidth / scale; float realH = graphics.PreferredBackBufferHeight / scale; if (firstPlayerView) { if (cameraOrientation == 99) { cameraOrientation = -bots[0].orientation - MathHelper.PiOver2; } else { cameraOrientation += (-bots[0].orientation - MathHelper.PiOver2 - cameraOrientation) * 0.1f;// 04f; } matrix = Matrix.CreateTranslation(new Vector3(-bots[0].positionV, 0f)) * Matrix.CreateRotationZ(cameraOrientation) * Matrix.CreateTranslation(new Vector3(new Vector2(realW, realH) / 2f, 0)) * Matrix.CreateScale(scale); } else { Vector2 shift = Vector2.Zero;// new Vector2(realW, realH) / 2f;// - new Vector2(width, height) / 2f; if (hScale > wScale) { shift.Y += (realH - Height) * 0.5f; } else if (wScale > hScale) { shift.X += (realW - Width) * 0.5f; } matrix = Matrix.CreateTranslation(new Vector3(shift, 0)) * Matrix.CreateScale(scale); } //DrawM.basicEffect.SetWorldAndInvTransp(matrix); DrawM.basicEffect.World = matrix; DrawM.scale = scale; spriteBatch.GraphicsDevice.Clear(new Color(128, 128, 128)); //spriteBatch.GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, matrix); Drawer.depth = new DepthLayer(0f); DrawM.Vertex.DrawRectangle(new M_Rectangle(0, 0, Width, Height), Color.CornflowerBlue); for (int i = 0; i < goals.Count; i++) { if (i + 1 < goals.Count) { DrawM.Vertex.DrawLine(goals[i], goals[i + 1], Color.DeepSkyBlue, 0.2f); } DrawGoal(i, goals[i], 1f); } void DrawGoal(int i, Vector2 pos, float opaque) { DrawM.Vertex.DrawCircleOutline(pos, goalRadius, Color.DeepSkyBlue, 8f); float angle = 0f; float fov = MathHelper.TwoPi / bots.Length; for (int j = 0; j < bots.Length; j++) { Color color = bots[j].goalIndex > i ? Color.Transparent : bots[j].goalIndex == i ? bots[j].GetInternalColor() : Color.DeepSkyBlue; DrawM.Vertex.DrawCone(pos, goalRadius, angle, fov, color * opaque, color * opaque, 8f); angle += fov; } //DrawM.Vertex.DrawCircle(goals[i], GOALRADIUS, Color.Lime, 16f); //font.Draw(i.ToString(), Anchor.Center(goals[i]), Color.Black, new Vector2(0.2f)); } if (firstPlayerView && bots[0].goalIndex < goals.Count) { // if goal is outside of screen, show it at the border of the screen M_Rectangle rect = new M_Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); Vector2 center = new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight) / 2f; M_Polygon poly = rect.ToPolygon(); //rect.pos -= rect.size / 2f; Matrix invert = Matrix.Invert(matrix); poly.Transform(invert); center = Vector2.Transform(center, invert); Vector2 onScreenGoalPos = goals[bots[0].goalIndex];// Vector2.Transform(goals[bots[0].goalIndex], matrix); //DrawM.Vertex.DrawRectangle(rect, Color.Red * 0.5f); if (!poly.ColVector(onScreenGoalPos)) { Vector2 dir = onScreenGoalPos - center; var cr = poly.DistToVector(onScreenGoalPos, dir); onScreenGoalPos -= dir * cr.distance.Value;// + Vector2.Normalize(dir) * 3f; //if (onScreenGoalPos.X < rect.Left) // onScreenGoalPos.X = rect.Left; //if (onScreenGoalPos.X > rect.Right) // onScreenGoalPos.X = rect.Right; //if (onScreenGoalPos.Y < rect.Top) // onScreenGoalPos.Y = rect.Top; //if (onScreenGoalPos.Y > rect.Bottom) // onScreenGoalPos.Y = rect.Bottom; DrawGoal(bots[0].goalIndex, onScreenGoalPos, 0.5f); } //camera //bots[0].goalIndex } string text; for (int i = 0; i < bots.Length; i++) { if (bots[i].Alive) { bots[i].mask.Draw(bots[i].GetInternalColor()); bots[i].Draw(); } } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp); for (int i = 0; i < goals.Count; i++) { Vector2 pos = Vector2.Transform(goals[i], matrix); font.Draw((i + 1).ToString(), Anchor.Center(pos), Color.Black); } text = ""; text += "time: " + Math.Floor(frame / 60f) + " s\n"; if (gameEnd) { for (int i = 0; i < bots.Length; i++) { text += "______________________\n"; text += "Bot " + i + "\n"; //text += "Health: " + bots[i].health + "\n"; text += "Time: " + bots[i].frameTime + "\n"; /*text += "Kills: " + bots[i].kills + "\n"; * text += "Damage Dealt: " + bots[i].damageDealt + "\n";*/ } } spriteBatch.DrawString(font, text, new Vector2(16, 16), Color.White); spriteBatch.End(); }
private void Move() { if (velocity != Vector2.Zero) { #region Move loop float t = 0; while (true) { if (velocity.Length() < 0.001f) { break; } M_Rectangle rect = new M_Rectangle(pos, Vector2.Zero); rect.Enlarge(RADIUS + 1); rect.Expand(velocity); EnvShooter.Bot botHit = null; CollisionResult cr = new CollisionResult(); env.EachWall(rect, (x, y) => { CollisionResult cr2 = mask.DistToPolygon(new M_Rectangle(x, y, 1, 1).ToPolygon(), velocity); cr.AddCollisionResult(cr2, velocity); }); for (int i = 0; i < env.bots.Length; i++) { if (env.bots[i].Alive) { CollisionResult cr2 = mask.DistToCircle(env.bots[i].mask, velocity); if (cr.AddCollisionResult(cr2, velocity)) { botHit = env.bots[i]; } } } if (!cr.distance.HasValue || t + cr.distance.Value >= 1) { if (t > 1) { t = 1; } pos += velocity * (1 - t); break; } #region step velocity //velocity to nearest dist pos += velocity * cr.distance.Value; t += cr.distance.Value; Vector2 lastMoveN = new Vector2(-velocity.Y, velocity.X); Vector2 tangent = new Vector2(-cr.axisCol.Y, cr.axisCol.X); velocity = Vector2.Dot(velocity, tangent) * tangent - Vector2.Dot(velocity, cr.axisCol) * cr.axisCol; if (botHit != null) { if (id != -1) { float damage = velocity.Length() * DAMAGE; botHit.health -= damage; if (botHit.Id != id) { env.bots[id].damageDealt += damage; } else { env.bots[id].damageDealt -= damage; } if (botHit.health < 0) { botHit.health = 0; if (botHit.Id != id) { env.bots[id].kills++; } else { env.bots[id].kills--; } } } } #endregion } #endregion } }