public Vector2f FindOffset() { LastOffset = ViewOffset; Vector2f centre; if (CameraSubject != null) { centre = CameraSubject.Position; } else if (CurrentScreen != null) { centre = CurrentScreen.Bounds.Centre.Clone(); } else { centre = Game.ScreenCentre; } ViewOffset = Game.ScreenSize*0.5f - centre; if (CurrentScreen == null) return ViewOffset; Bounds = CurrentScreen.Bounds.Clone; Bounds.Right -= Game.Width; //Bounds.Left += Game.Width/2; Bounds.Top -= Game.Height; //Bounds.Bottom += Game.Height/2; ViewOffset *= -1; ViewOffset.Clamp(Bounds); ViewOffset *= -1; return ViewOffset; }
public SlugMessage(Int32 id, Vector2f position, Vector2f velocity, Int32 g_id) { Id = id; Position = position; Velocity = velocity; G_id = g_id; }
public void Draw() { Gl.glPushMatrix(); Gl.glTranslatef(Position.X+radius, Position.Y+radius, 0); float outSize = radius; float inSize = radius/2; Gl.glBegin(Gl.GL_TRIANGLE_FAN); Gl.glColor3f(1,1,1); for (float i = 0 ; i < Math.PI*2 ; i += (float)Math.PI/4) { var v = new Vector2f((float)Math.Sin(i), (float)Math.Cos(i)); v *= outSize; Gl.glVertex2f(v.X,v.Y); } Gl.glEnd(); Gl.glBegin(Gl.GL_TRIANGLE_FAN); Gl.glColor3f(1,0,0); for (float i = 0 ; i < Math.PI*2 ; i += (float)Math.PI/4) { var v = new Vector2f((float)Math.Sin(i), (float)Math.Cos(i)); v *= inSize; Gl.glVertex2f(v.X,v.Y); } Gl.glEnd(); Gl.glPopMatrix(); }
public BoundingBox(Vector2f bottomLeft, Vector2f topRight) { Top = topRight.Y; Bottom = bottomLeft.Y; Left = bottomLeft.X; Right = topRight.X; }
public void MouseDownHandler(Sdl.SDL_MouseButtonEvent button) { if (button.button == Sdl.SDL_BUTTON_LEFT) { grabPos = m_keyboard.MousePos - Position; grab = Bounds.Contains(m_keyboard.MousePos); } }
public TextBox(UserInput input, Vector2f size, Camera camera) : base(input, size, camera) { Contents = new Text(""); if (camera != null) Contents.SetHUD(camera); m_keyboard.KeyDown += AddLetter; }
protected ResizeableBox NewBox(Vector2f pos, Vector2f size, Colour colour) { ResizeableBox box = new ResizeableBox(m_keyboard, size, null); box.Position = pos; box.backgroundColour = colour; items.Add(box); return box; }
public GuiItem(UserInput keyboard, Vector2f size, Camera camera) { m_keyboard = keyboard; m_keyboard.MouseDown += MouseClicked; Size = size; backgroundColour = new Colour(1,0.4f,0.4f,0.5f); foregroundColour = new Colour(1,1,1,1); Hidden = false; if (camera != null) SetHUD(camera); Layer = Layer.Normal; Priority = Priority.Front; displayList = Gl.glGenLists(1); Gl.glNewList(1, Gl.GL_COMPILE); ConstantDraw(); Gl.glEndList(); }
public void MouseDownHandler(Sdl.SDL_MouseButtonEvent button) { if (button.button == Sdl.SDL_BUTTON_LEFT) { grabPos = m_keyboard.MousePos - Position; if (MouseOnLeft ()) { leftGrab = true; } if (MouseOnRight ()) { rightGrab = true; } if (MouseOnBottom()) { bottomGrab = true; } if (MouseOnTop()) { topGrab = true; } if (MouseInMiddle()) { middleGrab = true; } } }
protected override void Control(float _delta, IEnumerable<Bumped> _bumps) { if (_bumps.Contains(Bumped.Left)) { m_direction = Vector2f.Right; } else if (_bumps.Contains(Bumped.Right)) { m_direction = Vector2f.Left; } if (m_direction.Equals(Vector2f.Left)) { GoLeft(); } else if (m_direction.Equals(Vector2f.Right)) { GoRight(); } var gangsters = m_provider.GetAllGangsters(); Gangster closeGangster = gangsters.First(); float distance = float.MaxValue; foreach (var gangster in gangsters) { if (gangster == this) continue; float thisDistance = (gangster.Position - Position).LengthSquared(); if (thisDistance < distance) { distance = thisDistance; closeGangster = gangster; } } fireCounter -= _delta; float angleToGangster = (closeGangster.Position - Position).Angle(); if (distance < distToEnemySquared && closeGangster.Position.Y >= Position.Y && (closeGangster.Position.X - Position.X) * Math.Sign(m_direction.X) > 0) { m_aim = (closeGangster.Position + m_aim)/2; m_magnum.AimAt(m_aim); if (fireCounter <= 0 ) { m_magnum.Shoot(); fireCounter = timeToFire; } } else { m_magnum.AimAt(Position + m_direction); } }
protected IEnumerable<Bumped> TryMove(Vector2f _move) { List<Bumped> bumps = new List<Bumped>(); if (m_tiles == null) return bumps; int collision; m_position.Y += _move.Y; collision = m_tiles.IsCollision(m_position, Size); if (collision == TileMap.BLOCK) { if (_move.Y > 0) { m_position.Y = (float)Math.Floor(m_position.Y + Size.Y) - (Size.Y + pushAway); bumps.Add(Bumped.Top); } else if (_move.Y < 0) { m_position.Y = ((int)(m_position.Y + 1)) + pushAway; bumps.Add(Bumped.Bottom); } } else if (collision == TileMap.FLOOR) { if (_move.Y < 0) { m_position.Y = ((int)(m_position.Y + 1)) + pushAway; bumps.Add(Bumped.Bottom); } } m_position.X += _move.X; collision = m_tiles.IsCollision(m_position, Size); if (collision == TileMap.BLOCK) { if (_move.X > 0) { m_position.X = (float)Math.Floor(m_position.X + Size.X) - (Size.X + pushAway); bumps.Add(Bumped.Right); } else if (_move.X < 0) { m_position.X = ((int)(m_position.X + 1)) + pushAway; bumps.Add(Bumped.Left); } } return bumps; }
public bool Contains(Vector2f _point) { return _point.X > Left && _point.X < Right && _point.Y > Bottom && _point.Y < Top; }
public void Receive(GangsterMessage _message) { position = _message.Position; id = _message.Id; }
public ResizeableBox(UserInput keyboard, Vector2f size, Camera camera) : base(keyboard, size, camera) { keyboard.MouseDown += MouseDownHandler; keyboard.MouseUp += MouseUpHandler; }
public ColourTextBox(UserInput input, Vector2f size, Camera camera) : base(input, size, camera) { }
public void Cap(Vector2f max) { if (Math.Abs(X) > max.X) X = max.X * Math.Sign(X); if (Math.Abs(Y) > max.Y) Y = max.Y * Math.Sign(Y); }
public override void Update(float _delta) { if (middleGrab) { Position = m_keyboard.MousePos - grabPos; if (MoveAction != null) MoveAction(Bounds); } if (rightGrab) { Size.X = m_keyboard.MousePos.X - Position.X; if (ResizeAction != null) ResizeAction(Bounds); } if (leftGrab) { float oldx = Position.X; Position = new Vector2f(m_keyboard.MousePos.X, Position.Y); Size.X += oldx - Position.X; if (ResizeAction != null) ResizeAction(Bounds); } if (bottomGrab) { float oldy = Position.Y; Position = new Vector2f(Position.X, m_keyboard.MousePos.Y); Size.Y += oldy - Position.Y; if (ResizeAction != null) ResizeAction(Bounds); } if (topGrab) { Size.Y = m_keyboard.MousePos.Y - Position.Y; if (ResizeAction != null) ResizeAction(Bounds); } base.Update (_delta); }
public Target() { Size = new Vector2f(radius*2, radius*2); }
public static void Init() { s_sprite = new Sprite(s_tmpBmp); s_totalSize = new Vector2f(s_sprite.Bitmap.Size.Width, s_sprite.Bitmap.Size.Height)/Tile.Size; Vector2f worldPosition = new Vector2f(0,0); Vector2f pixelPosition = new Vector2f(0,0); Vector2f previousPixelPosition = new Vector2f(0,0); Vector2f pixelSize = new Vector2f(0,0); Vector2f worldSize = new Vector2f(0,0); foreach (char character in characters) { previousPixelPosition = pixelPosition.Clone(); pixelPosition = RenderCharacter (character, pixelPosition, out pixelSize); if (pixelPosition.X >= s_sprite.Bitmap.Size.Width) { pixelPosition.Y += pixelSize.Y; pixelPosition.X = 0; previousPixelPosition = pixelPosition.Clone(); pixelPosition = RenderCharacter(character, pixelPosition, out pixelSize); } worldSize = pixelSize / Tile.Size; worldPosition = previousPixelPosition / Tile.Size; s_characters[character] = new Character() { Size = worldSize.Clone(), Position = worldPosition.Clone(), Char = character }; } s_sprite.ReloadBitmap(); }
private MoveablePoint makePoint(String title, Vector2f point) { var mPoint = new MoveablePoint(m_keyboard, null); mPoint.backgroundColour = new Colour(1,0.2f,0.8f,1); mPoint.CentreOn(point); mPoint.SetLabel(title); items.Add(mPoint); return mPoint; }
public PointDescription(String name, Vector2f point) { this.name = name; this.point = point; }
public void Clamp(Vector2f min, Vector2f max) { if (X < min.X) X = min.X; else if (X > max.X) X = max.X; if (Y < min.Y) Y = min.Y; else if (Y > max.Y) Y = max.Y; }
public GangsterMessage(Int32 _id, Vector2f _pos) { Id = _id; Position = _pos; }
public Vector2f Snap(Vector2f snap) { return (this / snap).Round().ToF() * snap; }
public bool Equals(Vector2f _other) { return X == _other.X && Y == _other.Y; }
public void Ensure(Vector2f min) { if (Math.Abs(X) > min.X) X = min.X * Math.Sign(X); if (Math.Abs(Y) > min.Y) Y = min.Y * Math.Sign(Y); }
private static Vector2f RenderCharacter(char character, Vector2f pixelPosition, out Vector2f size) { var graphics = Graphics.FromImage(s_sprite.Bitmap); graphics.DrawString( character.ToString(), s_font, Brushes.White, new PointF(pixelPosition.X, pixelPosition.Y)); SizeF psize = graphics.MeasureString(character.ToString(), s_font); size = new Vector2f(psize.Width, psize.Height); pixelPosition.X += size.X; return pixelPosition; }
public Slug(Magnum _magnum) { m_magnum = _magnum; Size = new Vector2f(m_magnum.Size)/2f; weight = m_magnum.health; }
public void Update(float _delta) { m_speed += m_acceleration*_delta; float tmpMaxSpeed; tmpMaxSpeed = maxSpeed; //collisions bumps = TryMove(m_speed*_delta); if (bumps.Contains(Bumped.Left)) { if (!onWallLeft) { HitWallLeft(); } onWallLeft = true; m_speed.X = 0; if (m_speed.Y < 0) { tmpMaxSpeed = wallSlideSpeed; } } else { onWallLeft = false; } if (bumps.Contains(Bumped.Right)) { if (!onWallRight) { HitWallRight(); } onWallRight = true; m_speed.X = 0; if (m_speed.Y < 0) { tmpMaxSpeed = wallSlideSpeed; } } else { onWallRight = false; } if (onWallLeft || onWallRight) { wallTimeCount -= _delta; } else { wallTimeCount = wallTime; } if (bumps.Contains(Bumped.Bottom)) { m_speed.Y = 0; if (!onFloor) { HitFloor(); } onFloor = true; } else { onFloor = false; } if (bumps.Contains(Bumped.Top)) { m_speed.Y = 0; } //PrintBumps(bumps); if (TryInjure()) { Die(); } if (Position.Y < -10) { Die(); } m_speed.Cap(tmpMaxSpeed); if (onFloor) { m_speed.Cap(new Vector2f(maxFloorSpeed, maxYSpeed)); } else { m_speed.Cap(new Vector2f(maxXSpeed, maxYSpeed)); } //physics if (doPhysics) { m_acceleration.Y = -gravity; if (onFloor) { m_acceleration.X = -m_speed.X * friction; groundTimeCount -= _delta; } else { m_acceleration.X = -m_speed.X * friction * airFrictionMultiplier; groundTimeCount = groundTime; } } //Console.WriteLine("gt " + groundTimeCount); // Console.WriteLine("speed : " + m_speed); // Console.WriteLine("acceleration : " + m_acceleration); // Console.WriteLine("position : " + m_position); //m_time += _delta; //log.WriteLine(String.Format("{0}, {1}, {2}, {3}",m_time, m_position.CSV(), m_speed.CSV(), m_acceleration.CSV())); Control(_delta, bumps); m_magnum.Update(_delta); }
public MoveableTextBox(UserInput input, Vector2f size, Camera camera) : base(input, size, camera) { }