コード例 #1
0
        // Take a normalized vector and return the direction it's facing.
        // There's a quite of lot of operations here I'm sure it could be made more efficent.
        private Direction VectorToDirection(Vector direction)
        {
            Vector up = new Vector(0, 1, 0);
            Vector down = new Vector(0, -1, 0);
            Vector left = new Vector(-1, 0, 0);
            Vector right = new Vector(1, 0, 0);

            double upDiff = Math.Acos(direction.DotProduct(up));
            double downDiff = Math.Acos(direction.DotProduct(down));
            double leftDiff = Math.Acos(direction.DotProduct(left));
            double rightDiff = Math.Acos(direction.DotProduct(right));

            double smallest = Math.Min(Math.Min(upDiff, downDiff), Math.Min(leftDiff, rightDiff));

            // yes there's a precidence if they're the same value, it doesn't matter
            if (smallest == upDiff)
            {
                return Direction.Up;
            }
            else if (smallest == downDiff)
            {
                return Direction.Down;
            }
            else if (smallest == leftDiff)
            {
                return Direction.Left;
            }
            else
            {
                return Direction.Right;
            }
        }
コード例 #2
0
ファイル: Matrix.cs プロジェクト: iq110/csharpgameprogramming
 public Matrix(Vector x, Vector y, Vector z, Vector o)
 {
     _m11 = x.X; _m12 = x.Y; _m13 = x.Z;
     _m21 = y.X; _m22 = y.Y; _m23 = y.Z;
     _m31 = z.X; _m32 = z.Y; _m33 = z.Z;
     _m41 = o.X; _m42 = o.Y; _m43 = o.Z;
 }
コード例 #3
0
        public Vector NextMove(Vector currentPosition, double elapsedTime)
        {
            _elapsedTime += elapsedTime;
            var prng = new Random();
            double ranTime = (double) prng.Next(5, 25)/10;

            if (currentPosition.X > 600) _lastMove = new Vector(-1, 0, 0);
            else if (currentPosition.X < -600) _lastMove = new Vector(1, 0, 0);
            else if (currentPosition.Y > 370) _lastMove = new Vector(0, -1, 0);
            else if (currentPosition.Y < -370) _lastMove = new Vector(0, 1, 0);

            else if (_elapsedTime > ranTime)
            {
                _elapsedTime = 0;
                int ranNum = prng.Next(0, 3);

                switch (ranNum)
                {
                    case 0:
                        _lastMove = new Vector(0, 1, 0);
                        break;
                    case 1:
                        _lastMove = new Vector(1, 0, 0);
                        break;
                    case 2:
                        _lastMove = new Vector(0, -1, 0);
                        break;
                    case 3:
                        _lastMove = new Vector(-1, 0, 0);
                        break;
                }
            }
            return _lastMove;
        }
コード例 #4
0
ファイル: Tile.cs プロジェクト: Drahkir/AnotherCastle
 public Tile(string tileName, Texture texture, TileCollision tileCollision, Vector position)
 {
     TileName = tileName;
     TileCollision = tileCollision;
     Sprite.Texture = texture;
     Sprite.SetPosition(position);
 }
コード例 #5
0
ファイル: Ship.cs プロジェクト: hallgeirl/Hiage
 public Ship(Vector pos, Game game, ParticleEngine particleEngine, Arena arena)
 {
     position = pos;
     gameref = game;
     particles = particleEngine;
     arenaref = arena;
 }
コード例 #6
0
 public void AddExplosion(Vector position)
 {
     var explosion = new AnimatedSprite {Texture = _textureManager.Get("explosion")};
     explosion.SetAnimation(4, 4);
     explosion.SetPosition(position);
     _effects.Add(explosion);
 }
コード例 #7
0
ファイル: Text.cs プロジェクト: iq110/csharpgameprogramming
        private void CreateText(double x, double y, double maxWidth)
        {
            _bitmapText.Clear();
            double currentX = 0;
            double currentY = 0;

            string[] words = _text.Split(' ');

            foreach (string word in words)
            {
                Vector nextWordLength = _font.MeasureFont(word);

                if (maxWidth != -1 &&
                    (currentX + nextWordLength.X) > maxWidth)
                {
                    currentX = 0;
                    currentY += nextWordLength.Y;
                }

                string wordWithSpace = word + " "; // add the space character that was removed.

                foreach (char c in wordWithSpace)
                {
                    CharacterSprite sprite = _font.CreateSprite(c);
                    float xOffset = ((float)sprite.Data.XOffset) / 2;
                    float yOffset = (((float)sprite.Data.Height) * 0.5f) + ((float)sprite.Data.YOffset);
                    sprite.Sprite.SetPosition(x + currentX + xOffset, y - currentY - yOffset);
                    currentX += sprite.Data.XAdvance;
                    _bitmapText.Add(sprite);
                }
            }
            _dimensions = _font.MeasureFont(_text, _maxWidth);
            _dimensions.Y = currentY;
            SetColor(_color);
        }
コード例 #8
0
        public void Move(Vector amount)
        {
            amount *= Speed;

            if (Math.Abs(amount.X) > Math.Abs(amount.Y))
            {
                if (amount.X > 0)
                {
                    MoveRight();
                }
                else
                {
                    MoveLeft();
                }
            }

            else
            {
                if (amount.Y > 0)
                {
                    MoveUp();
                }
                else
                {
                    MoveDown();
                }
            }

            Sprite.SetPosition(Sprite.GetPosition() + amount);
        }
コード例 #9
0
ファイル: Enemy.cs プロジェクト: Drahkir/AnotherCastle
 /// <summary>
 ///     Constructs an enemy given the texture and AI (IEnemyBrain)
 /// </summary>
 /// <param name="texture">The texture for the enemy</param>
 /// <param name="enemyBrain">The AI for the enemy</param>
 /// <param name="position">The spawn point for this enemy</param>
 public Enemy(Texture texture, IEnemyBrain enemyBrain, Vector position)
 {
     _enemyBrain = enemyBrain;
     Sprite.Texture = texture;
     Sprite.SetPosition(position);
     RestartShootCountDown();
 }
コード例 #10
0
ファイル: RectangleExtensions.cs プロジェクト: Drahkir/Engine
        /// <summary>
        ///     Calculates the signed depth of intersection between two rectangles.
        /// </summary>
        /// <returns>
        ///     The amount of overlap between two intersecting rectangles. These
        ///     depth values can be negative depending on which wides the rectangles
        ///     intersect. This allows callers to determine the correct direction
        ///     to push objects in order to resolve collisions.
        ///     If the rectangles are not intersecting, Vector2.Zero is returned.
        /// </returns>
        public static Vector GetIntersectionDepth(this RectangleF rectA, RectangleF rectB)
        {
            // Calculate half sizes.
            double halfWidthA = rectA.Width/2.0f;
            double halfHeightA = rectA.Height/2.0f;
            double halfWidthB = rectB.Width/2.0f;
            double halfHeightB = rectB.Height/2.0f;

            // Calculate centers.
            var centerA = new Vector(rectA.Left + halfWidthA, rectA.Top + halfHeightA, 0);
            var centerB = new Vector(rectB.Left + halfWidthB, rectB.Top + halfHeightB, 0);

            // Calculate current and minimum-non-intersecting distances between centers.
            double distanceX = centerA.X - centerB.X;
            double distanceY = centerA.Y - centerB.Y;
            double minDistanceX = halfWidthA + halfWidthB;
            double minDistanceY = halfHeightA + halfHeightB;

            // If we are not intersecting at all, return (0, 0).
            if (Math.Abs(distanceX) >= minDistanceX || Math.Abs(distanceY) >= minDistanceY)
                return Vector.Zero;

            // Calculate and return intersection depths.
            double depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
            double depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
            return new Vector(depthX, depthY, 0);
        }
コード例 #11
0
ファイル: ParticleEngine.cs プロジェクト: hallgeirl/Hiage
 //Spawn a new particle
 public void SpawnParticle(int timeToLive, Vector position, Vector velocity, Vector accelleration, double red, double green, double blue, double alpha, bool gradualFade, int size)
 {
     if (particles.Count < maxParticles)
     {
         particles.Add(new Particle(texture, timeToLive, position, velocity, accelleration, red, green, blue, alpha, gradualFade, size));
     }
 }
コード例 #12
0
ファイル: Level.cs プロジェクト: iq110/csharpgameprogramming
        public void Update(double elapsedTime)
        {
            // Get controls and apply to player character
            double _x = _input.Controller.LeftControlStick.X;
            double _y = _input.Controller.LeftControlStick.Y * -1;
            Vector controlInput = new Vector(_x, _y, 0);

            if (Math.Abs(controlInput.Length()) < 0.0001)
            {
                // If the input is very small, then the player may not be using 
                // a controller;, they might be using the keyboard.
                if (_input.Keyboard.IsKeyHeld(Keys.Left))
                {
                    controlInput.X = -1;
                }

                if (_input.Keyboard.IsKeyHeld(Keys.Right))
                {
                    controlInput.X = 1;
                }

                if (_input.Keyboard.IsKeyHeld(Keys.Up))
                {
                    controlInput.Y = 1;
                }

                if (_input.Keyboard.IsKeyHeld(Keys.Down))
                {
                    controlInput.Y = -1;
                }
            }

            _playerCharacter.Move(controlInput * elapsedTime);

        }
コード例 #13
0
ファイル: BasicGroundEnemy.cs プロジェクト: hallgeirl/Hiage
        //Character attributes
        public BasicGroundEnemy(Game game, Vector position, Vector velocity, Dictionary<string, Sprite> sprites, string defaultSprite, IController controller, //GameObject attributes
		               WorldPhysics worldPhysics, ObjectPhysics objectPhysics, Dictionary<string, BoundingPolygon> boundingPolygons,	//PhysicalObject attributes
		               double runSpeed, double maxSpeed)
            : base(game, position, velocity, sprites, defaultSprite, controller, worldPhysics, objectPhysics, boundingPolygons, runSpeed, maxSpeed)
        {
            Stompable = true;
        }
コード例 #14
0
ファイル: EditorModel.cs プロジェクト: hallgeirl/Hiage
 public EditorModel()
 {
     Running = true;
     MousePosition = new Vector();
     Objects = new List<MapObject>();
     ExtraProperties = new Dictionary<string, string>();
 }
コード例 #15
0
ファイル: TestState.cs プロジェクト: hallgeirl/Hiage
 public CollidableObject(double x, double y, Vector v)
 {
     position = new Vector(x, y);
     velocity = v;
     LastVelocity = new Vector(0,0);
     BoundingBox = new BoundingBox(position.X-width/2, position.Y+height/2, position.X+width/2, position.Y-height/2);
 }
コード例 #16
0
ファイル: Block.cs プロジェクト: harvPrentiss/Subway-Tetris
 public Block(TextureManager manager, string blockType)
 {
     _sprite.Texture = manager.Get(blockType);
     DropSpeed = 30.0;
     Direction = new Vector(0, -1, 0);
     KeepAlive = true;
     _moveDistance = _sprite.GetWidth();
 }
コード例 #17
0
ファイル: VerticalMenu.cs プロジェクト: beamery/bTris
 public VerticalMenu(double x, double y, Input.Input input, Color unfocused, Color focused)
 {
     this.input = input;
     position = new Vector(x, y, 0);
     Spacing = 50;
     SetUnfocusedColor(unfocused);
     SetFocusColor(focused);
 }
コード例 #18
0
ファイル: Block.cs プロジェクト: harvPrentiss/Subway-Tetris
 public Block(Texture texture)
 {
     _sprite.Texture = texture;
     DropSpeed = 30.0;
     Direction = new Vector(0, -1, 0);
     KeepAlive = true;
     _moveDistance = _sprite.GetWidth();
 }
コード例 #19
0
ファイル: Bullet.cs プロジェクト: iq110/csharpgameprogramming
        public Bullet(Texture bulletTexture)
        {
            _sprite.Texture = bulletTexture;

            // Some default values
            Dead = false;
            Direction = new Vector(1, 0, 0);
            Speed = 512;// pixels per second
        }
コード例 #20
0
ファイル: PhysicalObject.cs プロジェクト: hallgeirl/Hiage
        public PhysicalObject(Game game, Vector position, Vector velocity, Dictionary<string, Sprite> sprites, string defaultSprite, IController controller, 
		                       WorldPhysics worldPhysics, ObjectPhysics objectPhysics, Dictionary<string, BoundingPolygon> boundingPolygons)
            : base(game, position, velocity, sprites, defaultSprite, controller, boundingPolygons)
        {
            this.worldPhysics = worldPhysics;
            this.objectPhysics = objectPhysics;
            this.friction = objectPhysics.Friction*worldPhysics.GroundFrictionFactor;
            inAirTimer.Start();
        }
コード例 #21
0
ファイル: Character.cs プロジェクト: hallgeirl/Hiage
        //Just pass on the constructor stuff to base
        public Character(Game game, Vector position, Vector velocity, Dictionary<string, Sprite> sprites, string defaultSprite, IController controller, 
		                 WorldPhysics worldPhysics, ObjectPhysics objectPhysics, Dictionary<string, BoundingPolygon> boundingPolygons,
		                 double runSpeed, double maxSpeed)
            : base(game, position, velocity, sprites, defaultSprite, controller, worldPhysics, objectPhysics, boundingPolygons)
        {
            CurrentSprite.PlayAnimation("stand", true);
            MaxSpeed = maxSpeed;
            RunSpeed = runSpeed;
        }
コード例 #22
0
ファイル: Block.cs プロジェクト: harvPrentiss/Subway-Tetris
 public Block(Texture texture, Vector scaler, Vector position)
 {
     _sprite.Texture = texture;
     DropSpeed = 30.0;
     Direction = new Vector(0, -1, 0);
     KeepAlive = true;
     _sprite.SetScale(scaler.X, scaler.Y);
     _sprite.SetPosition(position.X, position.Y);
     _moveDistance = _sprite.GetWidth();
 }
コード例 #23
0
ファイル: Missile.cs プロジェクト: Drahkir/AnotherCastle
        public Missile(Texture missileTexture, Vector direction)
        {
            Sprite.Texture = missileTexture;

            // Some default values
            Dead = false;
            Direction = direction;
            Speed = 512; // pixels per second
            Damage = 10;
        }
コード例 #24
0
ファイル: EnemyMissile.cs プロジェクト: Drahkir/AnotherCastle
        public override void OnCollision(IEntity entity, Vector amount)
        {
            if (entity.GetType() == typeof (Eyeball))
            {
                return;
            }

            Dead = true;
            //Sprite.SetColor(new Color(0, 0, 1, 1));
        }
コード例 #25
0
ファイル: Font.cs プロジェクト: beamery/bTris
 public Vector MeasureFont(string text, double maxWidth)
 {
     Vector dimensions = new Vector();
     foreach (char c in text)
     {
         CharacterData data = characterData[c];
         dimensions.X += data.XAdvance;
         dimensions.Y = Math.Max(dimensions.Y, data.Height + data.YOffset);
     }
     return dimensions;
 }
コード例 #26
0
ファイル: Player.cs プロジェクト: hallgeirl/Hiage
        public Player(Game game, Vector position, Vector velocity, Dictionary<string, Sprite> sprites, string defaultSprite, IController controller, //GameObject attributes
		               WorldPhysics worldPhysics, ObjectPhysics objectPhysics, Dictionary<string, BoundingPolygon> boundingPolygons, //PhysicalObject attributes
		               double runSpeed, double maxSpeed, 	//Character attributes
		               PlayerState state)
            : base(game, position, velocity, sprites, defaultSprite, controller, worldPhysics, objectPhysics, boundingPolygons, runSpeed, maxSpeed)
        {
            oldFriction = objectPhysics.Friction;
            PlayerState = state;

            invincibleTimer.Start();
        }
コード例 #27
0
 /// <summary>
 ///     Constructs an enemy given the texture and AI (IEnemyBrain)
 /// </summary>
 /// <param name="texture">The texture for the enemy</param>
 /// <param name="enemyBrain">The AI for the enemy</param>
 /// <param name="position">The spawn point for this enemy</param>
 public EastWestSkeleton(Texture texture, IEnemyBrain enemyBrain, Vector position)
     : base(texture, enemyBrain, position)
 {
     Health = 15;
     Damage = 10;
     Sprite.SetScale(1.8, 1.8);
     Speed = 200;
     MaxTimeToShoot = 12;
     MinTimeToShoot = 1;
     RestartShootCountDown();
 }
コード例 #28
0
ファイル: Mushroom.cs プロジェクト: hallgeirl/Hiage
        public Mushroom(Game game, 
		                    Vector position, 
		                    Dictionary<string, Sprite> sprites, string defaultSprite, 
		                    WorldPhysics worldPhysics, ObjectPhysics objectPhysics, 
		                    Dictionary<string, BoundingPolygon> polygons, 
		                    ItemType itemType)
            : base(game, position, new Vector(0,0), sprites, defaultSprite, new DumbGroundAI(), worldPhysics, objectPhysics, polygons)
        {
            CurrentSprite.PlayAnimation(Sprite.DEFAULT_ANIMATION, true);
            MushroomType = itemType;
        }
コード例 #29
0
ファイル: Spline.cs プロジェクト: Drahkir/Engine
        private Vector CalculateCatmullRom(double t, Vector p1, Vector p2, Vector p3, Vector p4)
        {
            double t2 = t*t;
            double t3 = t2*t;

            double b1 = 0.5*(-t3 + 2*t2 - t);
            double b2 = 0.5*(3*t3 - 5*t2 + 2);
            double b3 = 0.5*(-3*t3 + 4*t2 + t);
            double b4 = 0.5*(t3 - t2);

            return (p1*b1 + p2*b2 + p3*b3 + p4*b4);
        }
コード例 #30
0
        public void Move(Vector amount, bool _setPosition)
        {
            amount *= _speed;
            if (!_setPosition)
            {
                _sprite.SetPosition(_sprite.GetPosition() + amount);
            }

            else
            {
                _sprite.SetPosition(_sprite.GetPosition());
            }
        }