public override void Update(float elapsedTime) { Vector2f movement = new Vector2f(0, 0); switch(m_Id) { case 0: movement.Y += m_Velocity; movement.X += m_Velocity; if (Sprite.Position.Y > Game.WindowWidth) Sprite.Position = new Vector2f(-Game.WindowWidth, -Game.WindowHeight); if (Sprite.Position.X > Game.WindowWidth) Sprite.Position = new Vector2f(-Game.WindowWidth, -Game.WindowHeight); break; case 1: movement.Y += m_Velocity; movement.X -= m_Velocity; if (Sprite.Position.Y > Game.WindowWidth) Sprite.Position = new Vector2f(-Game.WindowWidth, -Game.WindowHeight); if (Sprite.Position.X < 0) Sprite.Position = new Vector2f(Game.WindowWidth + Sprite.GetGlobalBounds().Width - 200, 0 - Sprite.GetGlobalBounds().Height); break; } Sprite.Position += movement * elapsedTime; }
/// <summary> /// Updates the positions of the widgets in the layout. /// </summary> protected override void updatePositions() { Vector2f pos = new Vector2f(0f,0f); if (Alignment == HorizontalAlignment.Left) foreach (Widget widget in Widgets) { if (widget.Visible) { widget.Position = pos; pos.Y += widget.Size.Y; } } else if (Alignment == HorizontalAlignment.Center) foreach (Widget widget in Widgets) { if (widget.Visible) { pos.X = (Size.X - widget.Size.X) / 2; widget.Position = pos; pos.Y += widget.Size.Y; } } else if (Alignment == HorizontalAlignment.Right) foreach (Widget widget in Widgets) { if (widget.Visible) { pos.X = Size.X - widget.Size.X; widget.Position = pos; pos.Y += widget.Size.Y; } } }
public virtual Particle AddParticle(Vector2f position, Vector2f initialVelocity, Vector2f gravity, float lifeTime, Color color) { var particle = new Particle(position, initialVelocity, gravity, this, lifeTime, color); AddParticle(particle); return particle; }
private void SetNewState(VelocityComponentState state) { if (_lastState != null) _previousState = _lastState; _lastState = state; Velocity = new Vector2f(state.VelocityX, state.VelocityY); }
public override void Draw(RenderTarget rt) { Vector2f actualPosition = Position + (Selected ? new Vector2f(0, -12.0f - 5.0f * GetSelectedIndex()) : new Vector2f()); // Draw card Sprite sprite = new Sprite(Assets.LoadTexture(Info.Type == CardType.White ? "CardWhite.png" : "CardBlack.png")); Size = new Vector2f(sprite.GetGlobalBounds().Width, sprite.GetGlobalBounds().Height); sprite.Position = actualPosition; sprite.Scale = Scale; rt.Draw(sprite); // Draw text Text text = GameUtility.Wrap(Info.Value, Assets.LoadFont("arialbd.ttf"), (uint)Math.Floor(24.0f * Scale.X), Math.Floor(207.0f * Scale.X)); text.Color = Info.Type == CardType.White ? Color.Black : Color.White; text.Position = actualPosition + new Vector2f(16.0f * Scale.X, 10.0f * Scale.Y); text.Round(); rt.Draw(text); // Draw decorations if (Info.PickCount > 1) { Sprite pickMultiple = new Sprite(Assets.LoadTexture(Info.PickCount == 2 ? "PickTwo.png" : "PickThree.png")) { Position = actualPosition + new Vector2f((241.0f - 56.0f - 10.0f - 4.0f) * Scale.X, (320.0f - 10.0f - 20.0f) * Scale.Y), Scale = Scale }; rt.Draw(pickMultiple); } }
public Tile(Color color, Vector2f position, bool walkable, Vector2f size) { shape = new RectangleShape(size); shape.FillColor = color; shape.Position = position; Walkable = walkable; }
public Camera(View view) { View = new View(view); Position = View.Size / 2; originalSize = View.Size; ActualPosition = Position; }
/// <summary> /// Initializes a new instance of the <c>LightWeightPolylineVertex</c> class. /// </summary> /// <param name="location">Lightweight polyline <see cref="SharpDxf.Vector2f">vertex</see> coordinates.</param> public LightWeightPolylineVertex(Vector2f location) { this.location = location; this.bulge = 0.0f; this.beginThickness = 0.0f; this.endThickness = 0.0f; }
/// <summary> /// Initializes a new instance of the <c>LightWeightPolylineVertex</c> class. /// </summary> /// <param name="x">X coordinate.</param> /// <param name="y">Y coordinate.</param> public LightWeightPolylineVertex(float x, float y) { this.location = new Vector2f(x, y); this.bulge = 0.0f; this.beginThickness = 0.0f; this.endThickness = 0.0f; }
public override void Update() { base.Update(); Pos = MouseManager.Pos; if (Pos.X < 640 && (Base.X > 558 || Base.Y < 62 || Base.X < 82 || Base.Y > 540) && !_disabled && SpawnButton.Selected!=null) { Rotation = (float)Angle.AngleBetween(Base, Pos); if (_visible == false && MouseManager.LeftDown) { Base = Pos; } if (_visible && !MouseManager.LeftDown) { SpawnButton.Selected.Throw(this); } _visible = MouseManager.LeftDown; } else { if (Pos.X > 640 && MouseManager.LeftDown) { _disabled = true; } _visible = false; } if (MouseManager.LeftDown == false) { _disabled = false; } if (Pos.X < 640 && (Base.X > 558 || Base.Y < 62 || Base.X < 82 || Base.Y > 540) && !_disabled && SpawnButton.Selected != null) return; _visible = false; Base = new Vector2f(559, 10); }
/// <summary> /// Initializes a new instance of the <c>LightWeightPolylineVertex</c> class. /// </summary> public LightWeightPolylineVertex() { this.location = Vector2f.Zero; this.bulge = 0.0f; this.beginThickness = 0.0f; this.endThickness = 0.0f; }
public Thrower(Vector2f pos, World parent, bool add = true) : base(Rsc.Tex("rsc/Throw.png"), pos, parent, add) { Origin = new Vector2f(32, 1); _visible = false; Col.A = 100; }
public override void Draw() { if (!_visible) return; var d = new Vector2f(Math.Abs(Base.X - Pos.X), Math.Abs(Base.Y - Pos.Y)); var sx = Pos.X < Base.X ? 1 : -1; var sy = Pos.Y < Base.Y ? 1 : -1; var worker = new Vector2f(Pos.X, Pos.Y); var err = d.X - d.Y; while (!(worker.X == Base.X && worker.Y == Base.Y)) { Parent.Parent.Window.Draw(new Sprite(Rsc.Tex("rsc/ThrowLine.png")) { Position = worker, Rotation = Rotation + 90, Origin = new Vector2f(2.5f, 2.5f), Color = new Color(255,255,255,100) }); var e2 = 2*err; if (e2 > -d.Y) { err -= d.Y; worker.X += sx; } if (!(e2 < d.X)) continue; err += d.X; worker.Y += sy; } base.Draw(); }
public InGame(IEnumerable<Player> players) { ChatBacklog = new List<string>(); Input.Text = InputText; chatValue = ""; // Add every player from lobby foreach (Player p in players) Entities.Add(p); // Set local player position first LocalPlayer.Position = new Vector2f(GameOptions.Width / 2.0f - 128.0f - 8.0f, GameOptions.Height - 194.0f - 8.0f - 64.0f); // Add everyone else Vector2f otherPosition = new Vector2f(GameOptions.Width / 2.0f - ((128.0f + 32.0f) * (Players.Count - 2)) / 2.0f - 128.0f - 8.0f, 100.0f + 32.0f + 8.0f); foreach (Player p in Players.Where(p => !p.IsLocalPlayer)) { p.Position = otherPosition; otherPosition += new Vector2f(128.0f + 32.0f, 0.0f); } // Play match start sound string startSoundFilename = "Start" + new Random().Next(5).ToString("G") + ".wav"; Timer.NextFrame(() => Assets.PlaySound(startSoundFilename)); }
public HighscoreList(Vector2f position) { Text = new Text(); Text.Font = Game.Assets.Fonts["PixelPlay"]; Text.CharacterSize = 30; Text.Position = position; }
public HealthBar() : base(Color.Red) { Position = new Vector2f(180, 525); Size = new Vector2f(180, 20); CurrentValue = 100; }
public Vector2f MeasureString(TextString str) { Vector2f size = new Vector2f(0f,0f); Vector2f curLineSize = new Vector2f(0f, 0f); foreach (KeyValuePair<TextStyle, string> s in str.FormatedText) { if (s.Key == TextStyle.EndLine) { size.Y += curLineSize.Y; size.X = curLineSize.X > size.X ? curLineSize.X : size.X; curLineSize = new Vector2f(0f, 0f); } else { Text textSlope = new Text(s.Value, Font, str.CharacterSize); Text.Styles textStyle = Text.Styles.Regular; if ((s.Key & TextStyle.Bold) != 0) textStyle |= Text.Styles.Bold; if( (s.Key & TextStyle.Italic) != 0) textStyle |= Text.Styles.Italic; textSlope.Style = textStyle; FloatRect localBounds = textSlope.GetLocalBounds(); Vector2f ssize = new Vector2f(localBounds.Width,localBounds.Height); curLineSize.X += (int)ssize.X; curLineSize.Y = (int)ssize.Y > curLineSize.Y ? (int)ssize.Y : curLineSize.Y; } } size.X = curLineSize.X > size.X ? curLineSize.X : size.X; size.Y += curLineSize.Y; return size; }
public static bool CircleCircleCollision(Vector2f circle1Center, float circle1Radius, Vector2f circle2Center, float circle2Radius) { float radius = circle1Radius + circle2Radius; float deltaX = circle1Center.X - circle2Center.X; float deltaY = circle1Center.Y - circle2Center.Y; return (deltaX * deltaX) + (deltaY * deltaY) <= (radius * radius); }
/// <summary>Checks collision between Circle and Rotated Rectangle.</summary> /// <param name="rectAngle">In Degrees.</param> public static bool CircleRectangleCollision(Vector2f circleCenter, float circleRadius, RectangleShape rect, float rectAngle = 0, Vector2f rectOffset = default(Vector2f)) { Vector2f rectPos = new Vector2f(rect.Position.X + rectOffset.X, rect.Position.Y + rectOffset.Y); Vector2f rectCenter = new Vector2f(rectPos.X + (rect.Size.X / 2), rectPos.Y + (rect.Size.Y / 2)); // Rotate circle's center point back Vector2f unrotatedCircle = new Vector2f(); unrotatedCircle.X = (float)Math.Cos(rectAngle) * (circleCenter.X - rectCenter.X) - (float)Math.Sin(rectAngle) * (circleCenter.Y - rectCenter.Y) + rectCenter.X; unrotatedCircle.Y = (float)Math.Sin(rectAngle) * (circleCenter.X - rectCenter.X) + (float)Math.Cos(rectAngle) * (circleCenter.Y - rectCenter.Y) + rectCenter.Y; // Closest point in the rectangle to the center of circle rotated backwards(unrotated) Vector2f closest = new Vector2f(); // Find the unrotated closest x point from center of unrotated circle if (unrotatedCircle.X < rectPos.X) closest.X = rectPos.X; else if (unrotatedCircle.X > rectPos.X + rect.Size.X) closest.X = rectPos.X + rect.Size.X; else closest.X = unrotatedCircle.X; // Find the unrotated closest y point from center of unrotated circle if (unrotatedCircle.Y < rectPos.Y) closest.Y = rectPos.Y; else if (unrotatedCircle.Y > rectPos.Y + rect.Size.Y) closest.Y = rectPos.Y + rect.Size.Y; else closest.Y = unrotatedCircle.Y; // Determine collision return Distance(unrotatedCircle, closest) < circleRadius; }
public ClientPlayer(Deathmatch dm) : base(dm) { this.model = MainGame.Char2Model; Pos = new Vector2f(10, 10); Speed = 2f; MaxJumps = 2; JumpsLeft = MaxJumps; Alive = true; Health = 100; Texture = Content.GetTexture(model.idleFile); deathTimer = 0; Killer = this; idle = new Animation(Content.GetTexture(model.idleFile), 4, 120, 1); running = new Animation(Content.GetTexture(model.runFile), 6, 60, 2); backpedal = new Animation(Content.GetTexture(model.runFile), 6, 60, 2, false); jumpUp = new Animation(Content.GetTexture(model.jumpUpFile), 1, 60, 0); jumpDown = new Animation(Content.GetTexture(model.jumpDownFile), 3, 60, -5); animation = idle; weapons = new List<Weapon>() { new Revolver(this), null, null, null, }; respawnTimer = respawnLength * 60; weapon = weapons[0]; }
// Bresenham line algorithm private void DrawLine(Vector2f p0, Vector2f p1, Texture2D tx, Color c, int offset = 0) { int x0 = (int)p0.x; int y0 = (int)p0.y; int x1 = (int)p1.x; int y1 = (int)p1.y; int dx = Mathf.Abs(x1-x0); int dy = Mathf.Abs(y1-y0); int sx = x0 < x1 ? 1 : -1; int sy = y0 < y1 ? 1 : -1; int err = dx-dy; while (true) { tx.SetPixel(x0+offset,y0+offset,c); if (x0 == x1 && y0 == y1) break; int e2 = 2*err; if (e2 > -dy) { err -= dy; x0 += sx; } if (e2 < dx) { err += dx; y0 += sy; } } }
static void Initialize() { Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + Environment.CurrentDirectory + "\\libs"); dtClock = new Stopwatch(); textFps = new Text("0", new Font(new FileStream("assets\\fonts\\arial.ttf", FileMode.Open, FileAccess.Read))); window = new RenderWindow(new VideoMode(1280, 768), "Test", Styles.Default); window.SetFramerateLimit(60); window.SetTitle("NATE"); tiles = new TileManager("assets\\tilemaps\\rpgtiles.png", 32); iMap = new MapInterface(); //map = new Map(new Vector2i(32, 32), ((int)tiles.image.Size.X / tiles.tileSize) * ((int)tiles.image.Size.Y / tiles.tileSize), true); -- for random //map = new Map(new Vector2i(32, 32), ((int)tiles.image.Size.X / tiles.tileSize) * ((int)tiles.image.Size.Y / tiles.tileSize), false); -- blank map = iMap.ReadMap("map1.ntm"); scaling = new Vector2f(2, 2); textureCollection = new Texture[(tiles.image.Size.X / tiles.tileSize) * (tiles.image.Size.Y / tiles.tileSize)]; camera = new Camera(); camera.speed = 1000; window.Closed += (s, a) => window.Close(); window.KeyPressed += (s, a) => { if (a.Code == Keyboard.Key.Z) { iMap.WriteMap("map0.ntm", map); } }; window.MouseWheelMoved += (s, a) => { scaling.X += a.Delta * 0.075f; scaling.Y += a.Delta * 0.075f; }; dtClock.Start(); for (int i = 0; i < (tiles.image.Size.X / tiles.tileSize) * (tiles.image.Size.Y / tiles.tileSize); i++) { textureCollection[i] = tiles.GetTile(i); textureCollection[i].Smooth = false; } }
public void AddTile(float x, float y) { Vector2f pos = new Vector2f (x, y); CollisionTiles.Add (pos, new Tile (pos, true)); CollisionTiles [pos].ChangeSprite (DAO.GetSprite (Element.Tile5)); }
public virtual Projectile SpawnProjectile(Vector2f pos, float direction, float offset, Vector2f? targetPos = null) { Projectile proj = new Projectile(Game, GetProjectileModel(), this); // Position and Velocity proj.SetPosition(pos); proj.Rotate(direction); float angle = offset == 0 ? (float)Utils.ToRadians(direction) : (float)Utils.ToRadians(direction + offset); proj.Velocity = new Vector2f((float)Math.Cos(angle) * ProjectileSpeed, (float)Math.Sin(angle) * ProjectileSpeed); // Stats proj.Damage = Damage; proj.SetLifeSpan(ProjectileLifeSpan); if (targetPos.HasValue) proj.SetTargetPosition(targetPos.Value); if (ProjectileRotateSpeed != 0) { proj.RotateSpeed = ProjectileRotateSpeed*(Utils.RandomInt() == 1 ? 1 : -1); proj.Rotate(Utils.RandomInt(0, 359)); } Game.Layer_Other.AddChild(proj); return proj; }
public void SetFrame(int newFrame, bool resetTime) { if (Animation != null) { // calculate new vertex positions and texture coordinates var rect = Animation.Frames[newFrame]; var texCoordA = new Vector2f(0, 0); var texCoordB = new Vector2f(0, rect.Height); var texCoordC = new Vector2f(rect.Width, rect.Height); var texCoordD = new Vector2f(rect.Width, 0); var left = rect.Left + 0.0001f; var right = left + rect.Width; float top = rect.Top; var bottom = top + rect.Height; _vertices[0] = new Vertex(texCoordA, new Vector2f(left, top)); _vertices[1] = new Vertex(texCoordB, new Vector2f(left, bottom)); _vertices[2] = new Vertex(texCoordC, new Vector2f(right, bottom)); _vertices[3] = new Vertex(texCoordD, new Vector2f(right, top)); } if (resetTime) { _currentTime = Time.Zero; } }
internal static IntRect getRectOfFrame(short mFrame, int framesPerRow, Vector2f frameSize) { int rowNum = mFrame / framesPerRow; int colNum = mFrame % framesPerRow; return new IntRect((int)(colNum * frameSize.X), (int)(rowNum * frameSize.Y), (int)frameSize.X, (int)frameSize.Y); }
public virtual void Fire(Vector2f pos, float direction, Vector2f? targetPos = null) { if (!CanShoot) return; SpawnProjectiles(pos, direction, targetPos); }
public override void Draw(RenderManager renderMgr, Camera camera) { int xStart = (int)((camera.Center.X - camera.Size.X * 0.5f) / TileWidth); int xEnd = (int)(1 + (camera.Center.X + camera.Size.X * 0.5f) / TileWidth); var yStart = (int)((camera.Center.Y - camera.Size.Y * 0.5f) / TileHeight); var yEnd = (int)(1 + (camera.Center.Y + camera.Size.Y * 0.5f) / TileHeight); ; if (xStart < 0) xStart = 0; if (xEnd > MapWidth - 1) xEnd = MapWidth - 1; if (yStart < 0) yStart = 0; if (yEnd > MapHeight - 1) yEnd = MapHeight - 1; for (var i = xStart; i < xEnd; i++) { for (var j = yStart; j < yEnd; j++) { if (Tiles[i, j].Texture == null) continue; var position = new Vector2f( TileWidth * i + TileWidth * 0.5f, TileHeight * j + TileHeight * 0.5f); renderMgr.DrawSprite(Tiles[i, j].Texture, Tiles[i, j].SubImageRect, position + WorldPosition, TileWidth, TileHeight, false, false, Tint, ZIndex); } } }
public Circle(float radius) : base((float)Math.PI * radius * radius) { circle = new CircleShape(radius); circle.FillColor = Color.Green; Origin = new Vector2f(1, 1).Unit() * radius; }
public ParticleSystem(Sprite particleSprite, Vector2f position) { MaximumParticleCount = 200; //TODO start with sane defaults Acceleration = new Vector2f(); AccelerationVariance = 0f; ColorRange = new SS14.Shared.Utility.Range<Vector4f>(Vector4f.UnitX * 255, Vector4f.Zero); ColorVariance = 0f; EmissionOffset = new Vector2f(); EmissionRadiusRange = new SS14.Shared.Utility.Range<float>(0f, 0f); Emit = false; EmitRate = 1; EmitterPosition = position; Lifetime = 1.0f; LifetimeVariance = 0f; ParticleSprite = particleSprite; RadialAcceleration = 0f; RadialAccelerationVariance = 0f; RadialVelocity = 0f; RadialVelocityVariance = 0f; SizeRange = new SS14.Shared.Utility.Range<float>(1, 0); SizeVariance = 0.1f; SpinVelocity = new SS14.Shared.Utility.Range<float>(0f, 0f); SpinVelocityVariance = 0f; TangentialAcceleration = 0; TangentialAccelerationVariance = 0; TangentialVelocity = 0; TangentialVelocityVariance = 0; Velocity = new Vector2f(); VelocityVariance = 0; }
public override Vector2f GetNextPoint(Vector2f position, Vector2f speed) { return(position + speed); }
public TerrainTile(Vector2f[] apexes, Vector2f center, Texture texture, Vector2i tileSize) : base(texture, tileSize) { Apexes = apexes; Center = center; }
public static float Magnitude(this Vector2f v) { return((float)Math.Sqrt(v.X * v.X + v.Y * v.Y)); }
public static Vector2f Normalize(this Vector2f v) { var mag = v.Magnitude(); return(mag < 0.000001 ? new Vector2f() : new Vector2f(v.X / mag, v.Y / mag)); }
public static float SquaredMagnitude(this Vector2f v) { return(v.X * v.X + v.Y * v.Y); }
public HitboxComponent() { Size = new Vector2f(); Offset = new Vector2f(); }
public extern Sprite(AtlasRegion region, Vector2f size, int zOrder, string name = "");
//get vector lenght public static float GetDistance(Vector2f vec) { return((float)Math.Sqrt(vec.X * vec.X + vec.Y * vec.Y)); }
public void SetSpriteCenter(string sprite, Vector2f center) { SetSpriteCenter(sprites[sprite], center); }
public abstract Vector2f GetNextPoint(Vector2f position, Vector2f speed);
public static bool CheckCollisionPointTriangle(Vector2f point, Vector2f p1, Vector2f p2, Vector2f p3) { bool collision = false; float alpha = ((p2.y - p3.y) * (point.x - p3.x) + (p3.x - p2.x) * (point.y - p3.y)) / ((p2.y - p3.y) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.y - p3.y)); float beta = ((p3.y - p1.y) * (point.x - p3.x) + (p1.x - p3.x) * (point.y - p3.y)) / ((p2.y - p3.y) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.y - p3.y)); float gamma = (1.0f - alpha - beta); if ((alpha > 0) && (beta > 0) & (gamma > 0)) { collision = true; } return(collision); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Loads the widget /// </summary> /// /// <param name="configFileFilename">Filename of the config file. /// The config file must contain a Button section with the needed information.</param> /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public Button(string configFileFilename) { m_LoadedConfigFile = Global.ResourcePath + configFileFilename; // Parse the config file ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "Button"); // Find the folder that contains the config file string configFileFolder = m_LoadedConfigFile.Substring(0, m_LoadedConfigFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1); // Loop over all properties for (int i = 0; i < configFile.Properties.Count; ++i) { if (configFile.Properties[i] == "separatehoverimage") { m_SeparateHoverImage = configFile.ReadBool(i); } else if (configFile.Properties[i] == "textcolor") { m_Text.Color = configFile.ReadColor(i); } else if (configFile.Properties[i] == "normalimage") { configFile.ReadTexture(i, configFileFolder, m_TextureNormal_M); m_SplitImage = false; } else if (configFile.Properties[i] == "hoverimage") { configFile.ReadTexture(i, configFileFolder, m_TextureHover_M); } else if (configFile.Properties[i] == "downimage") { configFile.ReadTexture(i, configFileFolder, m_TextureDown_M); } else if (configFile.Properties[i] == "focusedimage") { configFile.ReadTexture(i, configFileFolder, m_TextureFocused_M); } else if (configFile.Properties[i] == "normalimage_l") { configFile.ReadTexture(i, configFileFolder, m_TextureNormal_L); } else if (configFile.Properties[i] == "normalimage_m") { configFile.ReadTexture(i, configFileFolder, m_TextureNormal_M); m_SplitImage = true; } else if (configFile.Properties[i] == "normalimage_r") { configFile.ReadTexture(i, configFileFolder, m_TextureNormal_R); } else if (configFile.Properties[i] == "hoverimage_l") { configFile.ReadTexture(i, configFileFolder, m_TextureHover_L); } else if (configFile.Properties[i] == "hoverimage_m") { configFile.ReadTexture(i, configFileFolder, m_TextureHover_M); } else if (configFile.Properties[i] == "hoverimage_r") { configFile.ReadTexture(i, configFileFolder, m_TextureHover_R); } else if (configFile.Properties[i] == "downimage_l") { configFile.ReadTexture(i, configFileFolder, m_TextureDown_L); } else if (configFile.Properties[i] == "downimage_m") { configFile.ReadTexture(i, configFileFolder, m_TextureDown_M); } else if (configFile.Properties[i] == "downimage_r") { configFile.ReadTexture(i, configFileFolder, m_TextureDown_R); } else if (configFile.Properties[i] == "focusedimage_l") { configFile.ReadTexture(i, configFileFolder, m_TextureFocused_L); } else if (configFile.Properties[i] == "focusedimage_m") { configFile.ReadTexture(i, configFileFolder, m_TextureFocused_M); } else if (configFile.Properties[i] == "focusedimage_r") { configFile.ReadTexture(i, configFileFolder, m_TextureFocused_R); } else { Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i] + "' in section Button in " + m_LoadedConfigFile + "."); } } // Check if the image is split if (m_SplitImage) { // Make sure the required textures were loaded if ((m_TextureNormal_L.texture != null) && (m_TextureNormal_M.texture != null) && (m_TextureNormal_R.texture != null)) { Size = new Vector2f(m_TextureNormal_L.Size.X + m_TextureNormal_M.Size.X + m_TextureNormal_R.Size.X, m_TextureNormal_M.Size.Y); m_TextureNormal_M.texture.texture.Repeated = true; } else { throw new Exception("Not all needed images were loaded for the button. Is the Button section in " + m_LoadedConfigFile + " complete?"); } // Check if optional textures were loaded if ((m_TextureFocused_L.texture != null) && (m_TextureFocused_M.texture != null) && (m_TextureFocused_R.texture != null)) { m_AllowFocus = true; m_WidgetPhase |= (byte)WidgetPhase.Focused; m_TextureFocused_M.texture.texture.Repeated = true; } if ((m_TextureHover_L.texture != null) && (m_TextureHover_M.texture != null) && (m_TextureHover_R.texture != null)) { m_WidgetPhase |= (byte)WidgetPhase.Hover; m_TextureHover_M.texture.texture.Repeated = true; } if ((m_TextureDown_L.texture != null) && (m_TextureDown_M.texture != null) && (m_TextureDown_R.texture != null)) { m_WidgetPhase |= (byte)WidgetPhase.MouseDown; m_TextureDown_M.texture.texture.Repeated = true; } } else // The image isn't split { // Make sure the required texture was loaded if (m_TextureNormal_M.texture != null) { Size = new Vector2f(m_TextureNormal_M.Size.X, m_TextureNormal_M.Size.Y); } else { throw new Exception("NormalImage property wasn't loaded. Is the Button section in " + m_LoadedConfigFile + " complete?"); } // Check if optional textures were loaded if (m_TextureFocused_M.texture != null) { m_AllowFocus = true; m_WidgetPhase |= (byte)WidgetPhase.Focused; } if (m_TextureHover_M.texture != null) { m_WidgetPhase |= (byte)WidgetPhase.Hover; } if (m_TextureDown_M.texture != null) { m_WidgetPhase |= (byte)WidgetPhase.MouseDown; } } }
private List <Vector2f> PopulateNewDomainPoints3(CJStarDomain entity) { List <Vector2f> pointsToReturn = new List <Vector2f>(); for (int i = 0; i < entity.Domain.Count; i++) { StarEntity currentStarEntity = entity.Domain[i]; StarEntity nextStarEntity = entity.Domain[(i + 1) % entity.Domain.Count]; pointsToReturn.Add(currentStarEntity.Position); if (entity.DomainLinks.TryGetValue(currentStarEntity, out StarLinkEntity currentLink) && currentLink is CurvedStarLinkEntity) { int sign = currentLink.StarFrom == currentStarEntity ? 1 : -1; float radiusLink = (currentLink as CurvedStarLinkEntity).Radius * sign; Vector2f currentToNextNorm = nextStarEntity.Position - currentStarEntity.Position; float lenCurrentToNext = currentToNextNorm.Len(); currentToNextNorm = currentToNextNorm / lenCurrentToNext; float angleToRotate = (float)Math.Acos(lenCurrentToNext / (2 * radiusLink)); Vector2f currentToCenter = currentToNextNorm.Rotate(angleToRotate) * radiusLink; Vector2f centerPoint = currentStarEntity.Position + currentToCenter; Vector2f newPoint = centerPoint + (-currentToCenter).Rotate(Math.Sign(radiusLink) * sign * (Math.PI / 2 - angleToRotate)); pointsToReturn.Add(newPoint); } else { Vector2f firstPoint; if (i == 0) { firstPoint = entity.Domain[entity.Domain.Count - 1].Position; } else { firstPoint = entity.Domain[i - 1].Position; } Vector2f secondPoint = entity.Domain[i].Position; Vector2f thirdPoint = entity.Domain[(i + 1) % entity.Domain.Count].Position; Vector2f fourthPoint = entity.Domain[(i + 2) % entity.Domain.Count].Position; Vector2f normVector1 = secondPoint - firstPoint; normVector1 = normVector1 / normVector1.Len(); Vector2f normVector2 = thirdPoint - secondPoint; normVector2 = normVector2 / normVector2.Len(); Vector2f normVector3 = fourthPoint - thirdPoint; normVector3 = normVector3 / normVector3.Len(); float distX1 = normVector1.X != 0 ? (secondPoint.X - firstPoint.X) / normVector1.X : (secondPoint.Y - firstPoint.Y) / normVector1.Y; float distX2 = normVector2.X != 0 ? distX1 + (thirdPoint.X - secondPoint.X) / normVector2.X : distX1 + (thirdPoint.Y - secondPoint.Y) / normVector2.Y; float distX3 = normVector3.X != 0 ? distX2 + (fourthPoint.X - thirdPoint.X) / normVector3.X : distX2 + (fourthPoint.Y - thirdPoint.Y) / normVector3.Y; Vector2f firstPointX = new Vector2f(0, firstPoint.X); Vector2f secondPointX = new Vector2f(distX1, secondPoint.X); Vector2f thirdPointX = new Vector2f(distX2, thirdPoint.X); Vector2f fourthPointX = new Vector2f(distX3, fourthPoint.X); float x = (distX2 + distX1) / 2; float newPointX = this.CubicInterpolate(x, firstPointX, secondPointX, thirdPointX, fourthPointX); Vector2f firstPointY = new Vector2f(0, firstPoint.Y); Vector2f secondPointY = new Vector2f(distX1, secondPoint.Y); Vector2f thirdPointY = new Vector2f(distX2, thirdPoint.Y); Vector2f fourthPointY = new Vector2f(distX3, fourthPoint.Y); float newPointY = this.CubicInterpolate(x, firstPointY, secondPointY, thirdPointY, fourthPointY); pointsToReturn.Add(new Vector2f(newPointX, newPointY)); } } return(pointsToReturn); }
public virtual void Render(Vector2f topLeft, Vector2f bottomRight) { //Render slaves beneath IEnumerable <SpriteComponent> renderablesBeneath = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth < DrawDepth select c; foreach (SpriteComponent component in renderablesBeneath.ToList()) { component.Render(topLeft, bottomRight); } //Render this sprite if (!visible) { return; } if (currentBaseSprite == null) { return; } Sprite spriteToRender = GetActiveDirectionalSprite(); Vector2f renderPos = CluwneLib.WorldToScreen(Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position); var bounds = spriteToRender.GetLocalBounds(); SetSpriteCenter(spriteToRender, renderPos); if (Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position.X + bounds.Left + bounds.Width < topLeft.X || Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position.X > bottomRight.X || Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position.Y + bounds.Top + bounds.Height < topLeft.Y || Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position.Y > bottomRight.Y) { return; } spriteToRender.Scale = new Vector2f(HorizontalFlip ? -1 : 1, 1); spriteToRender.Draw(); //Render slaves above IEnumerable <SpriteComponent> renderablesAbove = from SpriteComponent c in slaves //FIXTHIS orderby c.DrawDepth ascending where c.DrawDepth >= DrawDepth select c; foreach (SpriteComponent component in renderablesAbove.ToList()) { component.Render(topLeft, bottomRight); } //Draw AABB var aabb = AABB; if (CluwneLib.Debug.DebugColliders) { CluwneLib.drawRectangle((int)(renderPos.X - aabb.Width / 2), (int)(renderPos.Y - aabb.Height / 2), aabb.Width, aabb.Height, new SFML.Graphics.Color(0, 255, 0)); } }
private float QuadraticInterpolate(float x, Vector2f point0, Vector2f point1, Vector2f point2) { return(point0.Y * ((x - point1.X) * (x - point2.X)) / ((point0.X - point1.X) * (point0.X - point2.X)) + point1.Y * ((x - point0.X) * (x - point2.X)) / ((point1.X - point0.X) * (point1.X - point2.X)) + point2.Y * ((x - point0.X) * (x - point1.X)) / ((point2.X - point0.X) * (point2.X - point1.X))); }
private bool IsPointInsideDomain(Vector2f coordinate) { bool result = false; Vector2f origin = new Vector2f(-100000, -100000); float minDist = int.MaxValue; int nbIntersect = 0; for (int i = 0; i < this.domainPoints.Count; i++) { Vector2f point1 = this.domainPoints[i]; Vector2f point2; if (i == this.domainPoints.Count - 1) { point2 = this.domainPoints[0]; } else { point2 = this.domainPoints[i + 1]; } float num1 = point1.X * point2.Y - point1.Y * point2.X; float num2 = origin.X * coordinate.Y - origin.Y * coordinate.X; float denum = (point1.X - point2.X) * (origin.Y - coordinate.Y) - (point1.Y - point2.Y) * (origin.X - coordinate.X); if (denum != 0) { float intersecX = (num1 * (origin.X - coordinate.X) - num2 * (point1.X - point2.X)) / denum; float intersecY = (num1 * (origin.Y - coordinate.Y) - num2 * (point1.Y - point2.Y)) / denum; Vector2f intersect = new Vector2f(intersecX, intersecY); if (intersect != point2 && (intersect - point1).Dot(intersect - point2) < 0 && (intersect - origin).Dot(intersect - coordinate) < 0) { nbIntersect++; } } Vector2f firstVector = coordinate - point1; Vector2f normalizedEdge = (point2 - point1).Normalize(); //vec2 vector = vector - normalizedEdge * dot(normalizedEdge, vector); //vec3 crossVector = cross(vec3(firstVector, 0), vec3(normalizedEdge, 0)); //vec3 crossVector2 = cross(vec3(vector2, 0), vec3(-normalizedEdge, 0)); Vector2f secondVector = coordinate - point2; if (normalizedEdge.Dot(firstVector) * normalizedEdge.Dot(secondVector) < 0) { float crossLen = Math.Abs(firstVector.CrossZ(normalizedEdge)); if (crossLen < minDist) { minDist = crossLen; } } float lenToPoint = firstVector.Len(); if (lenToPoint < minDist) { minDist = lenToPoint; } } if (this.isFilled) { if (nbIntersect % 2 == 1) { result = true; } } if (minDist < MARGIN_DOMAIN / 2) { result = true; } return(result); }
public Bullet(Vector2f position, Vector2f vector) { Position = position; this.vector = vector; }
private float CubicInterpolate(float x, Vector2f point0, Vector2f point1, Vector2f point2, Vector2f point3) { return(point0.Y * ((x - point1.X) * (x - point2.X) * (x - point3.X)) / ((point0.X - point1.X) * (point0.X - point2.X) * (point0.X - point3.X)) + point1.Y * ((x - point0.X) * (x - point2.X) * (x - point3.X)) / ((point1.X - point0.X) * (point1.X - point2.X) * (point1.X - point3.X)) + point2.Y * ((x - point0.X) * (x - point1.X) * (x - point3.X)) / ((point2.X - point0.X) * (point2.X - point1.X) * (point2.X - point3.X)) + point3.Y * ((x - point0.X) * (x - point1.X) * (x - point2.X)) / ((point3.X - point0.X) * (point3.X - point1.X) * (point3.X - point2.X))); }
public RoundShape(Vector2f center, float radius) { Center = center; Radius = radius; }
public void Update2(float speed, Vector2f sPos, float Rad, bool rotX = false, bool rotY = false) { pos = new Vector2f(rotX ? sPos.X + MathF.Cos(tick * speed / 100) * Rad : sPos.X, rotY ? sPos.Y + MathF.Sin(tick * speed / 100) * Rad: sPos.Y); shape.Position = pos; tick++; }
private void RenderToCanvas() { for (int y = 0, i = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++, i++) { TmxLayerTile tsTile = background_tiles.Tiles[i]; if (tsTile.Gid > 1) { try { Tile tile = tileset[tsTile.Gid - 1]; /* * float rotation = 0f; * if (tile.Orientation == TileOrientation.Rotate90CW) * rotation = 90f; * if (tile.Orientation == TileOrientation.Rotate180CCW) * rotation = 180f; * if (tile.Orientation == TileOrientation.Rotate270CCW) * rotation = -90f; */ Vector2f scale = new Vector2f(1f, 1f); float rotation = 0f; if (tsTile.HorizontalFlip) { scale.X *= -1f; } if (tsTile.VerticalFlip) { scale.Y *= -1f; } if (tsTile.DiagonalFlip) { rotation = -90f; } sprites[x, y].TextureRect = new IntRect(tile.Left, tile.Top, tileset.TileWidth, tileset.TileHeight); sprites[x, y].Origin = new Vector2f(tileset.TileWidth / 2f, tileset.TileHeight / 2f); sprites[x, y].Rotation = rotation; sprites[x, y].Scale = scale; canvas.Draw(sprites[x, y]); } catch (Exception) { //Console.WriteLine($"Position: [{x}; {y}] - {tsTile.Gid - 1}"); } } tsTile = behind_tiles.Tiles[i]; if (tsTile.Gid > 1) { try { Tile tile = tileset[tsTile.Gid - 1]; /* * float rotation = 0f; * if (tile.Orientation == TileOrientation.Rotate90CW) * rotation = 90f; * if (tile.Orientation == TileOrientation.Rotate180CCW) * rotation = 180f; * if (tile.Orientation == TileOrientation.Rotate270CCW) * rotation = -90f; */ Vector2f scale = new Vector2f(1f, 1f); float rotation = 0f; if (tsTile.HorizontalFlip) { scale.X *= -1f; } if (tsTile.VerticalFlip) { scale.Y *= -1f; } if (tsTile.DiagonalFlip) { rotation = -90f; } sprites[x, y].TextureRect = new IntRect(tile.Left, tile.Top, tileset.TileWidth, tileset.TileHeight); sprites[x, y].Origin = new Vector2f(tileset.TileWidth / 2f, tileset.TileHeight / 2f); sprites[x, y].Rotation = rotation; sprites[x, y].Scale = scale; canvas.Draw(sprites[x, y]); } catch (Exception) { //Console.WriteLine($"Position: [{x}; {y}] - {tsTile.Gid - 1}"); } } tsTile = play_tiles.Tiles[i]; if (tsTile.Gid > 1) { try { Tile tile = tileset[tsTile.Gid - 1]; /* * float rotation = 0f; * if (tile.Orientation == TileOrientation.Rotate90CW) * rotation = 90f; * if (tile.Orientation == TileOrientation.Rotate180CCW) * rotation = 180f; * if (tile.Orientation == TileOrientation.Rotate270CCW) * rotation = -90f; */ Vector2f scale = new Vector2f(1f, 1f); float rotation = 0f; if (tsTile.HorizontalFlip) { scale.X *= -1f; } if (tsTile.VerticalFlip) { scale.Y *= -1f; } if (tsTile.DiagonalFlip) { rotation = -90f; } sprites[x, y].TextureRect = new IntRect(tile.Left, tile.Top, tileset.TileWidth, tileset.TileHeight); sprites[x, y].Origin = new Vector2f(tileset.TileWidth / 2f, tileset.TileHeight / 2f); sprites[x, y].Rotation = rotation; sprites[x, y].Scale = scale; canvas.Draw(sprites[x, y]); objectCanvas.Draw(sprites[x, y]); } catch (Exception) { //Console.WriteLine($"Position: [{x}; {y}] - {tsTile.Gid - 1}"); } } tsTile = roof_tiles.Tiles[i]; if (tsTile.Gid > 1) { try { Tile tile = tileset[tsTile.Gid - 1]; /* * float rotation = 0f; * if (tile.Orientation == TileOrientation.Rotate90CW) * rotation = 90f; * if (tile.Orientation == TileOrientation.Rotate180CCW) * rotation = 180f; * if (tile.Orientation == TileOrientation.Rotate270CCW) * rotation = -90f; */ Vector2f scale = new Vector2f(1f, 1f); float rotation = 0f; if (tsTile.HorizontalFlip) { scale.X *= -1f; } if (tsTile.VerticalFlip) { scale.Y *= -1f; } if (tsTile.DiagonalFlip) //🛹 { rotation = -90f; } sprites[x, y].TextureRect = new IntRect(tile.Left, tile.Top, tileset.TileWidth, tileset.TileHeight); sprites[x, y].Origin = new Vector2f(tileset.TileWidth / 2f, tileset.TileHeight / 2f); sprites[x, y].Rotation = rotation; sprites[x, y].Scale = scale; roofCanvas.Draw(sprites[x, y]); } catch (Exception) { //Console.WriteLine($"Position: [{x}; {y}] - {tsTile.Gid - 1}"); } } } } canvas.Display(); objectCanvas.Display(); roofCanvas.Display(); }
protected Enemy(Vector2f position, Vector2f size, Texture texture, int health, uint scoreAdded, string type, string moveSoundName) : base(position, size, texture, health) { ScoreAdded = scoreAdded; Type = type; MoveSoundName = moveSoundName; }
void OnMouseMoved(object sender, MouseMoveEventArgs e) { // Il est possible d'obtenir les coordonnées de la souris avec e.X et e.Y positionDuBloc = new Vector2f(e.X, e.Y); }
public static fTextGameObject CreateUnityTextMeshGO( string sName, string sText, Colorf textColor, float fTextHeight, BoxPosition textOrigin = BoxPosition.Center, float fOffsetZ = -0.1f) { GameObject textGO = new GameObject(sName); TextMesh tm = textGO.AddComponent <TextMesh>(); tm.text = sText; tm.color = textColor; tm.fontSize = 50; tm.offsetZ = fOffsetZ; tm.alignment = TextAlignment.Left; // ignore material changes when we add to GameObjectSet textGO.AddComponent <IgnoreMaterialChanges>(); // use our textmesh material instead MaterialUtil.SetTextMeshDefaultMaterial(tm); Vector2f size = UnityUtil.EstimateTextMeshDimensions(tm); float fScaleH = fTextHeight / size.y; tm.transform.localScale = new Vector3(fScaleH, fScaleH, fScaleH); float fTextWidth = fScaleH * size.x; // by default text origin is top-left if (textOrigin == BoxPosition.Center) { tm.transform.Translate(-fTextWidth / 2.0f, fTextHeight / 2.0f, 0); } else if (textOrigin == BoxPosition.BottomLeft) { tm.transform.Translate(0, fTextHeight, 0); } else if (textOrigin == BoxPosition.TopRight) { tm.transform.Translate(-fTextWidth, 0, 0); } else if (textOrigin == BoxPosition.BottomRight) { tm.transform.Translate(-fTextWidth, fTextHeight, 0); } else if (textOrigin == BoxPosition.CenterLeft) { tm.transform.Translate(0, fTextHeight / 2.0f, 0); } else if (textOrigin == BoxPosition.CenterRight) { tm.transform.Translate(-fTextWidth, fTextHeight / 2.0f, 0); } else if (textOrigin == BoxPosition.CenterTop) { tm.transform.Translate(-fTextWidth / 2.0f, 0, 0); } else if (textOrigin == BoxPosition.CenterBottom) { tm.transform.Translate(-fTextWidth / 2.0f, fTextHeight, 0); } textGO.GetComponent <Renderer>().material.renderQueue = SceneGraphConfig.TextRendererQueue; return(new fTextGameObject(textGO, new fText(tm, TextType.UnityTextMesh), new Vector2f(fTextWidth, fTextHeight))); }
public void ResetPosition(Vector2f newPosition) { this.Position = newPosition; _additionalSpeed = 0; }
private void CreateEdgeColliders() { var sides = this.CreateTileSides(this.TilemapData); // todo: right now, all colliders are straight lines. they dont have to be. // todo>> make one collider for each closed shape. thus the amount of colliders is reduced greatly while (sides.Count > 0) { TileSide startSide = sides.First(); sides.Remove(startSide); Vector2f min = startSide.Min; Vector2f max = startSide.Max; TileSide previous = startSide.Previous; while (sides.Contains(previous)) { sides.Remove(previous); min = previous.Min; previous = previous.Previous; } TileSide next = startSide.Next; while (sides.Contains(next)) { sides.Remove(next); max = next.Max; next = next.Next; } this.Add <EdgeCollider2D>().points = new Vector2[] { min, max }; } #region !! TODO !! This is the optimized version (combines the colliders) which doesn't work with Unity 4.3, BUT it should work with Unity 4.5 (there is a bug with EdgeColliders and Physics2D.OverlapArea which broke crate collisions!!) /* * // create segments * HashSet<Segment2Di> segments = new HashSet<Segment2Di>(); * Dictionary<Vector2i, HashSet<Segment2Di>> pointToSegment = new Dictionary<Vector2i, HashSet<Segment2Di>>(); * while (sides.Count > 0) * { * TileSide startSide = sides.First(); * sides.Remove(startSide); * * Vector2i min = startSide.MinIndex; * Vector2i max = startSide.MaxIndex; * * TileSide previous = startSide.Previous; * while (sides.Contains(previous)) * { * sides.Remove(previous); * min = previous.MinIndex; * previous = previous.Previous; * } * * TileSide next = startSide.Next; * while (sides.Contains(next)) * { * sides.Remove(next); * max = next.MaxIndex; * next = next.Next; * } * * Segment2Di segment = new Segment2Di(min, max); * segments.Add(segment); * * pointToSegment.GetOrAddDefault(min).Add(segment); * pointToSegment.GetOrAddDefault(max).Add(segment); * } * * // FlaiDebug.LogWarning("S: " + string.Join(", ", segments.ToArray().Select(p => p.ToString()).ToArray())); * // combine segments and create edge colliders * while (segments.Count > 0) * { * Segment2Di current = segments.First(); * FlaiDebug.Log(current); * segments.Remove(current); * pointToSegment[current.Start].Remove(current); * pointToSegment[current.End].Remove(current); * * List<Vector2> points = new List<Vector2>() { current.Start * Tile.Size, current.End * Tile.Size }; * while (pointToSegment[current.End].Count != 0) * { * Segment2Di newSegment = pointToSegment[current.End].FirstOrDefault(segments.Contains); * if (newSegment == default(Segment2Di)) * { * break; * } * * segments.Remove(newSegment); * segments.Remove(newSegment.Flipped); * if (newSegment.End == current.End) * { * newSegment = newSegment.Flipped; * } * * FlaiDebug.Log(newSegment); * pointToSegment[newSegment.Start].Remove(newSegment); * pointToSegment[newSegment.End].Remove(newSegment); * points.Add(newSegment.End * Tile.Size); * current = newSegment; * } * * this.Add<EdgeCollider2D>().points = points.ToArray(); * } */ #endregion }
public CircleObject(float size) : base(size) { this.Origin = new Vector2f(this.Position.X + this.Radius, this.Position.Y + this.Radius); _direction = new Vector2f(-1, 0); }
public void ShowMapMultiplayer() { if (!_window.IsOpen) { _context.Close = true; } _window.Clear(); //_window.Draw(_backgroundMultiplayer); //view player 1 View view1 = new View(new Vector2f(Settings.XResolution / 2, Settings.YResolution / 2), new Vector2f(Settings.XResolution, Settings.YResolution)); view1.Viewport = new FloatRect(0.25f, 0f, 0.5f, 0.5f); view1.Size = new Vector2f(Settings.XResolution, Settings.YResolution); _window.SetView(view1); Vector2f PositionScreen1 = new Vector2f(400, 300); // Background Player 1 _window.Draw(_background); // Load map foreach (KeyValuePair <SFML.System.Vector2f, Sprite> s in _spritesDisplayed) { s.Value.GetSprite.Position = s.Key; s.Value.GetSprite.Position -= _moveTheMapOf; _window.Draw(s.Value.GetSprite); } // Lifebar _hpBar.TextureRect = new IntRect(0, 0, (int)(_lifebarTexture.Size.X * _context.GetGame.GetPlayer.GetLife.PerCent), (int)_lifebarTexture.Size.Y); // HP Text Text hp = new Text(Convert.ToString(_context.GetGame.GetPlayer.GetLife.CurrentPoint), _context.GetFont, 28); hp.Position = new SFML.System.Vector2f(_lifebarTexture.Size.X / 2 - hp.GetGlobalBounds().Width / 2, _lifebarTexture.Size.Y / 2 - hp.GetGlobalBounds().Height / 2 - 5); _window.Draw(_hpBar); _window.Draw(hp); // Player if (_context.GetGame.GetPlayer.IsAlive) { _context.GetGame.GetPlayer.GetPlayerSprite.GetSprite.Position = new SFML.System.Vector2f(_context.GetGame.GetPlayer.Position.X * 128, _window.Size.Y + _context.GetGame.GetPlayer.Position.Y * -128 - 65); _window.Draw(_context.GetGame.GetPlayer.GetPlayerSprite.GetSprite); } // Monsters foreach (Monster m in _context.GetGame.GetMonsters) { //Orientation if (m.Orientation == "right" && m.GetMonsterSprite.GetSprite.Scale != new SFML.System.Vector2f(1.0f, 1.0f)) //Right { m.GetMonsterSprite.GetSprite.Origin = new SFML.System.Vector2f(0, 0); m.GetMonsterSprite.GetSprite.Scale = new SFML.System.Vector2f(1.0f, 1.0f); } else if (m.Orientation == "left" && m.GetMonsterSprite.GetSprite.Scale != new SFML.System.Vector2f(-1.0f, 1.0f))//Left { m.GetMonsterSprite.GetSprite.Origin = new SFML.System.Vector2f(m.GetMonsterSprite.GetSprite.Texture.Size.X / 2, 0); m.GetMonsterSprite.GetSprite.Scale = new SFML.System.Vector2f(-1.0f, 1.0f); } m.GetMonsterSprite.GetSprite.Position = new SFML.System.Vector2f(m.Position.X * 128, _window.Size.Y + m.Position.Y * -128 - 40); m.GetMonsterSprite.GetSprite.Position -= _moveTheMapOf; _window.Draw(m.GetMonsterSprite.GetSprite); } // Boss if (_context.GetGame.GetBoss != null) { _context.GetGame.GetBoss.GetBossSprite.GetSprite.Position = new SFML.System.Vector2f(_context.GetGame.GetBoss.Position.X * 128 - 150, _window.Size.Y + _context.GetGame.GetBoss.Position.Y * -128 - 205); _context.GetGame.GetBoss.GetBossSprite.GetSprite.Position -= _moveTheMapOf; _window.Draw(_context.GetGame.GetBoss.GetBossSprite.GetSprite); } //view player 2 View view2 = new View(new Vector2f(Settings.XResolution / 2, Settings.YResolution / 2), new Vector2f(Settings.XResolution, Settings.YResolution)); view2.Viewport = new FloatRect(0.25f, 0.5f, 0.5f, 0.5f); view2.Size = new Vector2f(Settings.XResolution, Settings.YResolution); Vector2f PositionScreen2 = new Vector2f(400, 300); _window.SetView(view2); // Background Player 2 _window.Draw(_background); // Load map foreach (KeyValuePair <SFML.System.Vector2f, Sprite> s in _spritesDisplayed2) { s.Value.GetSprite2.Position = s.Key; s.Value.GetSprite2.Position -= _moveTheMapOf2; _window.Draw(s.Value.GetSprite2); } // Lifebar _hpBar.TextureRect = new IntRect(0, 0, (int)(_lifebarTexture.Size.X * _context2.GetGame2.GetPlayer2.GetLife2.PerCent2), (int)_lifebarTexture.Size.Y); // HP Text Text hp2 = new Text(Convert.ToString(_context2.GetGame2.GetPlayer2.GetLife2.CurrentPoint2), _context.GetFont, 28); hp2.Position = new SFML.System.Vector2f(_lifebarTexture.Size.X / 2 - hp.GetGlobalBounds().Width / 2, _lifebarTexture.Size.Y / 2 - hp.GetGlobalBounds().Height / 2 - 5); _window.Draw(_hpBar); _window.Draw(hp2); // Player if (_context2.GetGame2.GetPlayer2.IsAlive2) { _context2.GetGame2.GetPlayer2.GetPlayerSprite2.GetSprite2.Position = new SFML.System.Vector2f(_context2.GetGame2.GetPlayer2.Position2.X2 * 128, _window.Size.Y + _context2.GetGame2.GetPlayer2.Position2.Y2 * -128 - 65); _window.Draw(_context2.GetGame2.GetPlayer2.GetPlayerSprite2.GetSprite2); } // Monsters foreach (Monster m in _context2.GetGame2.GetMonsters2) { //Orientation if (m.Orientation2 == "right" && m.GetMonsterSprite2.GetSprite2.Scale != new SFML.System.Vector2f(1.0f, 1.0f)) //Right { m.GetMonsterSprite2.GetSprite2.Origin = new SFML.System.Vector2f(0, 0); m.GetMonsterSprite2.GetSprite2.Scale = new SFML.System.Vector2f(1.0f, 1.0f); } else if (m.Orientation2 == "left" && m.GetMonsterSprite2.GetSprite2.Scale != new SFML.System.Vector2f(-1.0f, 1.0f))//Left { m.GetMonsterSprite2.GetSprite2.Origin = new SFML.System.Vector2f(m.GetMonsterSprite2.GetSprite2.Texture.Size.X / 2, 0); m.GetMonsterSprite2.GetSprite2.Scale = new SFML.System.Vector2f(-1.0f, 1.0f); } m.GetMonsterSprite2.GetSprite2.Position = new SFML.System.Vector2f(m.Position2.X2 * 128, _window.Size.Y + m.Position2.Y2 * -128 - 40); m.GetMonsterSprite2.GetSprite2.Position -= _moveTheMapOf2; _window.Draw(m.GetMonsterSprite2.GetSprite2); } // Boss if (_context2.GetGame2.GetBoss2 != null) { _context2.GetGame2.GetBoss2.GetBossSprite2.GetSprite2.Position = new SFML.System.Vector2f(_context2.GetGame2.GetBoss2.Position2.X2 * 128 - 150, _window.Size.Y + _context2.GetGame2.GetBoss2.Position2.Y2 * -128 - 205); _context2.GetGame2.GetBoss2.GetBossSprite2.GetSprite2.Position -= _moveTheMapOf2; _window.Draw(_context2.GetGame2.GetBoss2.GetBossSprite2.GetSprite2); } // Display _window.Display(); }
public static Vector2f Vector2f(Vector2f min, Vector2f max, System.Random random = null) { return(min + new Vector2f(Float(max.x - min.x, random), Float(max.y - min.y, random))); }
public void Update(double elapsedTime) { _oldPosition = this.Position; this.Position += _direction * (_speed + _additionalSpeed) * (float)elapsedTime; }