//-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 public PlayerJumpToState()
 {
     destination				= Vector2F.Zero;
     destinationZPosition	= 0.0f;
     jumpDuration			= 26;
     endAction				= null;
 }
Esempio n. 2
0
 //-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 public ViewControl()
 {
     this.viewSize		= GameSettings.VIEW_SIZE;
     this.panSpeed		= GameSettings.VIEW_PAN_SPEED;
     this.position		= Vector2F.Zero;
     this.shakeOffset	= Vector2F.Zero;
 }
Esempio n. 3
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public Unit()
        {
            EnablePhysics();

            isKnockbackable			= true;
            isDamageable			= true;
            isPassable				= false;

            knockbackSpeed			= GameSettings.UNIT_KNOCKBACK_SPEED;
            knockbackDuration		= GameSettings.UNIT_KNOCKBACK_DURATION;
            hurtInvincibleDuration	= GameSettings.UNIT_HURT_INVINCIBLE_DURATION;
            hurtFlickerDuration		= GameSettings.UNIT_HURT_FLICKER_DURATION;

            knockbackTimer			= 0;
            hurtFlickerTimer		= 0;
            invincibleTimer			= 0;
            knockbackVelocity		= Vector2F.Zero;
            tools					= new HashSet<UnitTool>();

            syncAnimationWithDirection = false;
            direction		= Directions.Right;
            health			= 1;
            healthMax		= 1;
            direction		= Directions.Right;
            centerOffset	= new Point2I(8, 8);
        }
 public override void OnSwingTilePeak(int angle, Vector2F hitPoint)
 {
     if ((angle == Directions.ToAngle(SwingDirection)
         || !limitTilesToDirection) && player.IsOnGround)
     {
         CutTilesAtPoint(hitPoint);
     }
 }
Esempio n. 5
0
 //-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 public EventTile()
 {
     roomControl		= null;
     eventData		= null;
     position		= Vector2F.Zero;
     size			= Point2I.One;
     properties		= new Properties();
     collisionBox	= new Rectangle2I(0, 0, 16, 16);
 }
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------
        public override void Initialize()
        {
            base.Initialize();

            // Find the center position of the hole tile.
            Point2I location = RoomControl.GetTileLocation(position);
            holeCenterPosition = (Vector2F) location + new Vector2F(0.5f, 0.5f);
            holeCenterPosition *= GameSettings.TILE_SIZE;
        }
Esempio n. 7
0
        //========= CONSTRUCTORS =========
        /** <summary> Constructs the default control. </summary> */
        public AnalogStick()
        {
            this.directions			= new InputControl[4];
            this.disabledState		= DisableState.Enabled;
            this.position			= Vector2F.Zero;
            this.deadZone			= 0.28;
            this.directionDeadZone	= new Vector2F(0.83f, 0.83f);

            for (int i = 0; i < 4; i++)
            this.directions[i] = new InputControl();
        }
Esempio n. 8
0
 /** <summary> Constructs a line with the specified position and size. </summary> */
 public Line2F(float x, float y, float width, float height, bool asSize)
 {
     if (!asSize) {
     this.End1	= new Vector2F(x, y);
     this.End2	= new Vector2F(x + width, y + height);
     }
     else {
     this.End1	= new Vector2F(x, y);
     this.End2	= new Vector2F(width, height);
     }
 }
Esempio n. 9
0
 /** <summary> Constructs a line with the specified position and size. </summary> */
 public Line2F(Vector2F point, float width, float height, bool asSize)
 {
     if (!asSize) {
     this.End1	= point;
     this.End2	= point + new Vector2F(width, height);
     }
     else {
     this.End1	= point;
     this.End2	= new Vector2F(width, height);
     }
 }
Esempio n. 10
0
 public DamageInfo(int amount, Vector2F sourcePosition)
 {
     this.amount				= amount;
     this.hasSource			= true;
     this.sourcePosition		= sourcePosition;
     this.applyKnockBack		= true;
     this.knockbackDuration	= -1;
     this.flicker			= true;
     this.flickerDuration	= GameSettings.MONSTER_HURT_FLICKER_DURATION;
     this.invincibleDuration	= -1;
 }
Esempio n. 11
0
        //-----------------------------------------------------------------------------
        // Static methods
        //-----------------------------------------------------------------------------
        public static bool Intersecting(CollisionModel model,
										Vector2F modelPosition,
										Rectangle2F box,
										Vector2F boxPosition)
        {
            Rectangle2F boxTranslated = Rectangle2F.Translate(box, boxPosition - modelPosition);
            for (int i = 0; i < model.boxes.Count; i++) {
                Rectangle2F modelBox = model.boxes[i];
                if (boxTranslated.Intersects(modelBox))
                    return true;
            }
            return false;
        }
Esempio n. 12
0
 //-----------------------------------------------------------------------------
 // Constructors
 //-----------------------------------------------------------------------------
 public Entity()
 {
     roomControl		= null;
     isAlive			= false;
     isInRoom		= false;
     isInitialized	= false;
     position		= Vector2F.Zero;
     zPosition		= 0.0f;
     physics			= new PhysicsComponent(this);
     graphics		= new GraphicsComponent(this);
     originOffset	= Point2I.Zero;
     centerOffset	= Point2I.Zero;
     actionAlignDistance = 5;
 }
 //-----------------------------------------------------------------------------
 // Constructor
 //-----------------------------------------------------------------------------
 public TileGraphicsComponent(Tile tile)
 {
     this.tile						= tile;
     this.animationPlayer			= new AnimationPlayer();
     this.isVisible					= true;
     this.depthLayer					= DepthLayer.TileLayer1;
     this.imageVariant				= 0;
     this.raisedDrawOffset			= Point2I.Zero;
     this.drawOffset					= Point2I.Zero;
     this.syncPlaybackWithRoomTicks	= true;
     this.isAnimatedWhenPaused		= false;
     this.absoluteDrawPosition		= Vector2F.Zero;
     this.useAbsoluteDrawPosition	= false;
 }
Esempio n. 14
0
        private TileDataInstance tileData; // The tile data used to create this tile.

        #endregion Fields

        #region Constructors

        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        // Use CreateTile() instead of this constructor.
        protected Tile()
        {
            location		= Point2I.Zero;
            layer			= 0;
            offset			= Point2I.Zero;
            size			= Point2I.One;
            flags			= TileFlags.Default;
            customSprite	= new SpriteAnimation();
            spriteAsObject	= new SpriteAnimation();
            isMoving		= false;
            pushDelay		= 20;
            properties		= new Properties();
            properties.PropertyObject = this;
            tileData		= null;
        }
Esempio n. 15
0
        private Entity transformedEntity; // The entity this entity has transformed into (bomb -> explosion)

        #endregion Fields

        #region Constructors

        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        public Entity()
        {
            entityIndex			= -1;
            roomControl			= null;
            isAlive				= false;
            isInRoom			= false;
            isInitialized		= false;
            transformedEntity	= null;
            soundBounce			= null;
            position			= Vector2F.Zero;
            zPosition			= 0.0f;
            previousPosition	= Vector2F.Zero;
            previousZPosition	= 0.0f;
            physics				= new PhysicsComponent(this);
            graphics			= new GraphicsComponent(this);
            centerOffset		= Point2I.Zero;
            actionAlignDistance	= 5;
        }
Esempio n. 16
0
        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        // Constructs a 2D graphics object containing the sprite batch.
        public Graphics2D(SpriteBatch spriteBatch)
        {
            // Containment
            this.spriteBatch			= spriteBatch;
            this.preivousRenderTargets	= new Stack<RenderTargetBinding[]>();

            // Drawing Settings
            this.translation			= Vector2F.Zero;
            this.useTranslation			= true;
            this.useIntPrecision		= false;

            // Vector Graphics
            this.white1x1				= new Texture2D(spriteBatch.GraphicsDevice, 1, 1);
            this.white2x2				= new Texture2D(spriteBatch.GraphicsDevice, 2, 2);
            this.white1x1.SetData(new Color[] { Color.White });
            this.white2x2.SetData(new Color[] { Color.White, Color.White, Color.White, Color.White });

            this.drawingColor			= XnaColor.White;
        }
Esempio n. 17
0
 public static int NearestFromVector(Vector2F vector)
 {
     // Cheap algorithm for turning a vector into an axis-aligned direction.
     if (vector.X > 0) {
         if (vector.X >= Math.Abs(vector.Y))
             return Directions.Right;
         else if (vector.Y < 0)
             return Directions.Up;
         else
             return Directions.Down;
     }
     else {
         if (-vector.X >= Math.Abs(vector.Y))
             return Directions.Left;
         else if (vector.Y < 0)
             return Directions.Up;
         else
             return Directions.Down;
     }
 }
        //-----------------------------------------------------------------------------
        // Overridden Methods
        //-----------------------------------------------------------------------------
        public override void OnBegin(MonsterState previousState)
        {
            monster.IsPassable = true;

            if (galeEffect != null) {
                monster.SetPositionByCenter(galeEffect.Position);
                galeEffect.DestroyAndTransform(monster);
                galeEffect = null;
            }

            timer			= 0;
            isRising		= false;
            galeZPosition	= monster.ZPosition;
            monsterPosition	= monster.Position;

            monster.Physics.Velocity = Vector2F.Zero;
            monster.Graphics.PauseAnimation();
            monster.DisablePhysics();

            galeAnimationPlayer.Play(GameData.ANIM_EFFECT_SEED_GALE);
        }
Esempio n. 19
0
        private float zVelocity; // Z-Velocity in pixels per frame.

        #endregion Fields

        #region Constructors

        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------
        // By default, physics are disabled.
        public PhysicsComponent(Entity entity)
        {
            this.isEnabled			= false;
            this.flags				= PhysicsFlags.None;
            this.entity				= entity;
            this.velocity			= Vector2F.Zero;
            this.zVelocity			= 0.0f;
            this.gravity			= GameSettings.DEFAULT_GRAVITY;
            this.maxFallSpeed		= GameSettings.DEFAULT_MAX_FALL_SPEED;
            this.collisionBox		= new Rectangle2F(-4, -10, 8, 9);		// TEMPORARY: this is the player collision box.
            this.softCollisionBox	= new Rectangle2F(-6, -14, 12, 13);	// TEMPORARY: this is the player collision box.
            this.topTileFlags		= TileFlags.None;
            this.allTileFlags		= TileFlags.None;
            this.isColliding		= false;
            this.autoDodgeDistance	= 6;

            this.hasLanded			= false;

            this.collisionInfo = new CollisionInfo[Directions.Count];
            for (int i = 0; i < Directions.Count; i++)
                collisionInfo[i].Clear();
        }
Esempio n. 20
0
 /** <summary> Constructs a copy of the specified point. </summary> */
 public Point2I(Vector2F v)
 {
     this.X = (int)v.X;
     this.Y = (int)v.Y;
 }
Esempio n. 21
0
        //========== COLLISION ===========

        /** <summary> Returns true if the specified vector is colliding with this line. </summary> */
        public bool Colliding(Vector2F point)
        {
            return(IsPointOnLine(point));
        }
Esempio n. 22
0
 // Return the top-most ladder the player is colliding with when placed at the given position.
 private Tile GetHighestLadder(Player player, Vector2F position)
 {
     Rectangle2F pollLadderBox = player.Movement.ClimbCollisionBox;
     pollLadderBox.Point += position;
     Tile highestLadder = null;
     foreach (Tile tile in RoomControl.TileManager.GetTilesTouching(pollLadderBox)) {
         if (tile.IsLadder && (highestLadder == null || tile.Bounds.Top < highestLadder.Bounds.Top))
             highestLadder = tile;
     }
     return highestLadder;
 }
Esempio n. 23
0
 /** <summary> Returns a nonnegative random vector less than or equal to the specified maximum. </summary> */
 public static Vector2F NextVector(Vector2F maxPoint)
 {
     return(new Vector2F((float)random.NextDouble(), (float)random.NextDouble()) * maxPoint);
 }
Esempio n. 24
0
 /** <summary> Returns the scalar projection on this vector and another. </summary> */
 public float ScalarProjection(Vector2F v)
 {
     return (Length * GMath.Cos(Direction - v.Direction));
 }
Esempio n. 25
0
 /** <summary> Returns the projection of this vector on another. </summary> */
 public Vector2F ProjectionOn(Vector2F v)
 {
     return new Vector2F(ScalarProjection(v), v.Direction);
 }
Esempio n. 26
0
 /** <summary> Returns the distance between this vector to another. </summary> */
 public float DistanceTo(Vector2F v)
 {
     return (v - this).Length;
 }
Esempio n. 27
0
        //-----------------------------------------------------------------------------
        // Static methods
        //-----------------------------------------------------------------------------

        public static bool Intersecting(CollisionModel model,
                                        Vector2F modelPosition,
                                        Rectangle2F box)
        {
            return(Intersecting(model, modelPosition, box, Vector2F.Zero));
        }
Esempio n. 28
0
 /** <summary> Constructs a copy of the specified line. </summary> */
 public Line2F(Line2F l)
 {
     this.End1 = l.End1;
     this.End2 = l.End2;
 }
Esempio n. 29
0
        //========= CONSTRUCTORS =========

        /** <summary> Constructs a line with the specified endpoints. </summary> */
        public Line2F(float x1, float y1, float x2, float y2)
        {
            this.End1 = new Vector2F(x1, y1);
            this.End2 = new Vector2F(x2, y2);
        }
Esempio n. 30
0
 /** <summary> Constructs a line with the specified endpoints. </summary> */
 public Line2F(Vector2F end1, Vector2F end2)
 {
     this.End1 = end1;
     this.End2 = end2;
 }
Esempio n. 31
0
 /** <summary> Returns the dot product of this vector with another. </summary> */
 public float Dot(Vector2F v)
 {
     return ((X * v.X) + (Y * v.Y));
 }
Esempio n. 32
0
 /** <summary> Constructs a line with the specified endpoints. </summary> */
 public Line2F(float x1, float y1, Vector2F end2)
 {
     this.End1 = new Vector2F(x1, y1);
     this.End2 = end2;
 }
Esempio n. 33
0
 /** <summary> Returns the rejection of this vector on another. </summary> */
 public Vector2F RejectionOn(Vector2F v)
 {
     return (this - ProjectionOn(v));
 }
 private bool CanLandAtPosition(Vector2F position)
 {
     foreach (Tile tile in player.Physics.GetTilesMeeting(position, CollisionBoxType.Hard)) {
         if (tile.IsSolid && tile.CollisionStyle == CollisionStyle.Rectangular && !(tile is TileColorBarrier) && !tile.IsBreakable) {
             return false;
         }
     }
     return true;
 }
Esempio n. 35
0
 /** <summary> Constructs a copy of the specified vector. </summary> */
 public Vector2F(Vector2F v)
 {
     this.X	= v.X;
     this.Y	= v.Y;
 }
Esempio n. 36
0
 /** <summary> Constructs a line with the specified size. </summary> */
 public Line2F(Vector2F size)
 {
     this.End1 = Vector2F.Zero;
     this.End2 = size;
 }
Esempio n. 37
0
 //-----------------------------------------------------------------------------
 // Circular Collisions
 //-----------------------------------------------------------------------------
 private void ResolveCircularCollision(Entity entity, Tile tile, Vector2F modelPos, CollisionModel model)
 {
     for (int i = 0; i < model.BoxCount; i++) {
         Rectangle2F box = model.Boxes[i];
         box.Point += modelPos;
         ResolveCircularCollision(entity, tile, box);
     }
 }
Esempio n. 38
0
 /** <summary> Constructs a line with the specified endpoints. </summary> */
 public Line2F(Vector2F end1, float x2, float y2)
 {
     this.End1 = end1;
     this.End2 = new Vector2F(x2, y2);
 }
Esempio n. 39
0
 // Returns true if the entity would be clipping if it were placed at the given position.
 private bool IsCollidingAt(Entity entity, Vector2F position, bool onlyStatic, int clipDirection = -1, float clipDistance = 0.0f)
 {
     Rectangle2F entityBox = entity.Physics.CollisionBox;
     entityBox.Point += position;
     if (entity.Physics.CollideWithRoomEdge && !((Rectangle2F) roomControl.RoomBounds).Contains(entityBox))
         return true;
     foreach (CollisionCheck check in GetCollisions(entity, entityBox)) {
         if (onlyStatic && IsSolidObjectDynamic(check.SolidObject))
             continue;
         float allowedClipAmount = GetAllowedEdgeClipAmount(entity, check.SolidObject);
         Rectangle2F insetSolidBox = check.SolidBox.Inflated(-allowedClipAmount, -allowedClipAmount);
         if (clipDirection >= 0)
             insetSolidBox.ExtendEdge(Directions.Reverse(clipDirection), allowedClipAmount - clipDistance);
         if (entityBox.Intersects(insetSolidBox))
             return true;
     }
     return false;
 }
Esempio n. 40
0
        //=========== CONTAINS ===========

        /** <summary> Returns true if the specified vector is inside this line. </summary> */
        public bool Contains(Vector2F point)
        {
            return(false);
        }
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------
        public override void OnBegin(PlayerState previousState)
        {
            // TODO: player.passable = true;
            player.IsStateControlled		= true;
            player.AutoRoomTransition		= true;
            player.Movement.IsStrafing		= true;
            player.Physics.CollideWithWorld = false;
            player.Graphics.PlayAnimation(GameData.ANIM_PLAYER_JUMP);

            // The player can hold his sword while ledge jumping.
            isHoldingSword = (previousState == player.HoldSwordState);

            if (isHoldingSword) {
                isHoldingSword = true;
                player.Graphics.PlayAnimation(GameData.ANIM_PLAYER_DEFAULT);
            }
            else {
                player.Direction = direction;
            }

            // Find the landing position, calculating the move distance in pixels.
            Vector2F pos = player.Position + Directions.ToVector(direction);
            int distance = 0;
            while (!CanLandAtPosition(pos)) {
                distance += 1;
                pos += Directions.ToVector(direction);
            }

            if (!player.RoomControl.RoomBounds.Contains(pos)) {
                // Fake jumping by using the xy-velocity instead of the z-velocity.
                hasRoomChanged = false;
                velocity = new Vector2F(0.0f, -1.0f);
                player.Physics.ZVelocity = 0;
                ledgeExtendsToNextRoom = true;
            }
            else {
                // Small ledge distances have special jump speeds.
                float jumpSpeed = 1.5f;
                if (distance >= 28)
                    jumpSpeed = 2.0f;
                else if (distance >= 20)
                    jumpSpeed = 1.75f;

                // Calculate the movement speed based on jump speed, knowing
                // they should take the same amount of time to perform.
                float jumpTime = (2.0f * jumpSpeed) / GameSettings.DEFAULT_GRAVITY;
                float speed    = distance / jumpTime;//  GMath.Clamp((float) distance / jumpTime, 0.7f, 2.5f);//5.0f);

                // For larger ledges, calculate the speed so that both
                // the movement speed and the jump speed equal eachother.
                if (speed > 1.5f) {
                    speed = GMath.Sqrt(0.5f * distance * GameSettings.DEFAULT_GRAVITY);
                    jumpSpeed = speed;
                }

                velocity = Directions.ToVector(direction) * speed;
                player.Physics.ZVelocity = jumpSpeed;
                ledgeExtendsToNextRoom = false;
            }

            player.Physics.Velocity = velocity;
            player.Position += velocity;
            AudioSystem.PlaySound(GameData.SOUND_PLAYER_JUMP);
        }
Esempio n. 42
0
 /** <summary> Constructs a line with the specified size. </summary> */
 public Line2F(float width, float height)
 {
     this.End1 = Vector2F.Zero;
     this.End2 = new Vector2F(width, height);
 }