Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 public SlugMessage(Int32 id, Vector2f position, Vector2f velocity, Int32 g_id)
 {
     Id = id;
     Position = position;
     Velocity = velocity;
     G_id = g_id;
 }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
 public BoundingBox(Vector2f bottomLeft, Vector2f topRight)
 {
     Top = topRight.Y;
     Bottom = bottomLeft.Y;
     Left = bottomLeft.X;
     Right = topRight.X;
 }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
 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;
         }
     }
 }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 12
0
 public bool Contains(Vector2f _point)
 {
     return _point.X > Left && _point.X < Right &&
         _point.Y > Bottom && _point.Y < Top;
 }
Exemplo n.º 13
0
 public void Receive(GangsterMessage _message)
 {
     position = _message.Position;
     id = _message.Id;
 }
Exemplo n.º 14
0
 public ResizeableBox(UserInput keyboard, Vector2f size, Camera camera)
     : base(keyboard, size, camera)
 {
     keyboard.MouseDown += MouseDownHandler;
     keyboard.MouseUp += MouseUpHandler;
 }
Exemplo n.º 15
0
 public ColourTextBox(UserInput input, Vector2f size, Camera camera)
     : base(input, size, camera)
 {
 }
Exemplo n.º 16
0
 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);
 }
Exemplo n.º 17
0
 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);
 }
Exemplo n.º 18
0
 public Target()
 {
     Size = new Vector2f(radius*2, radius*2);
 }
Exemplo n.º 19
0
        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();
        }
Exemplo n.º 20
0
 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;
 }
Exemplo n.º 21
0
 public PointDescription(String name, Vector2f point)
 {
     this.name = name;
     this.point = point;
 }
Exemplo n.º 22
0
 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;
 }
Exemplo n.º 23
0
 public GangsterMessage(Int32 _id, Vector2f _pos)
 {
     Id = _id;
     Position = _pos;
 }
Exemplo n.º 24
0
 public Vector2f Snap(Vector2f snap)
 {
     return (this / snap).Round().ToF() * snap;
 }
Exemplo n.º 25
0
 public bool Equals(Vector2f _other)
 {
     return X == _other.X && Y == _other.Y;
 }
Exemplo n.º 26
0
 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);
 }
Exemplo n.º 27
0
        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;
        }
Exemplo n.º 28
0
 public Slug(Magnum _magnum)
 {
     m_magnum = _magnum;
     Size = new Vector2f(m_magnum.Size)/2f;
     weight = m_magnum.health;
 }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
 public MoveableTextBox(UserInput input, Vector2f size, Camera camera)
     : base(input, size, camera)
 {
 }