예제 #1
0
파일: Player.cs 프로젝트: rokn/AbilityGame
        private void StartBasicAttack()
        {
            canWalk     = false;
            weaponIsOut = true;
            hasHit      = false;
            canAttack   = false;

            weaponPosition = Vector2.Normalize(Main.mouse.RealPosition - position);

            weaponTipPosition  = weaponPosition;
            weaponTipPosition *= (EntityHeight / 2) + weaponTexture.Width;
            weaponTipPosition += position;

            weaponPosition *= EntityHeight / 2;
            weaponPosition += position;

            weaponRotation = MathAid.FindRotation(weaponPosition, Main.mouse.RealPosition);

            float rInDegrees = MathHelper.ToDegrees(weaponRotation);

            DirectTowardsRotation(rInDegrees);

            weaponTimer = new TimeSpan(0, 0, 0, 0, weaponTime);
            attackTimer = new TimeSpan(0, 0, 0, 0, attackSpeed);

            walkingAnimation[currentDirection].ChangeAnimatingState(false);
        }
예제 #2
0
        public static bool CheckPixelPerfectCollision(Texture2D texture, Rectangle rect, Texture2D destructionTexture, Rectangle destructionnRectangle)
        {
            Rectangle intersectRect = MathAid.GetIntersectingRectangle(destructionnRectangle, rect);

            Color[] colorData = new Color[texture.Width * texture.Height];
            texture.GetData(colorData);

            Color[] destructionTextureData = new Color[destructionTexture.Width * destructionTexture.Height];
            destructionTexture.GetData(destructionTextureData);

            Point startPos1 = new Point(intersectRect.X - destructionnRectangle.X, intersectRect.Y - destructionnRectangle.Y);
            Point startPos2 = new Point(intersectRect.X - rect.X, intersectRect.Y - rect.Y);

            for (int x = 0; x < intersectRect.Width; x++)
            {
                for (int y = 0; y < intersectRect.Height; y++)
                {
                    if (destructionTextureData[(startPos1.X + x) + (startPos1.Y + y) * destructionTexture.Width].A != 0)
                    {
                        int X = startPos2.X + x;
                        int Y = startPos2.Y + y;
                        if (colorData[X + Y * texture.Width].A != 0)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
예제 #3
0
        private void Push()
        {
            if (!push)
            {
                push = true;
                pushCollision.Clear();
                pushDirection = Vector2.Normalize(Main.mouse.RealPosition - Owner.Position);
                Vector2 teleCenter = Owner.Position + pushDirection * (Owner.EntityHeight / 2);
                float   teleAngle  = MathAid.FindRotation(teleCenter, Main.mouse.RealPosition);
                pushRotation = teleAngle;
                pushStart    = Owner.Position - MathAid.AngleToVector(teleAngle + 90) * pushTexture.Height / 2;
                pushEnd      = Owner.Position - MathAid.AngleToVector(teleAngle - 90) * pushTexture.Height / 2;
                pushTime     = new TimeSpan(0, 0, 0, 0, pushMiliSeconds);
                Vector2 startToEndDirection = Vector2.Normalize(pushEnd - pushStart);

                for (int i = 0; i < pushTexture.Height; i++)
                {
                    pushCollision.Add(pushStart + startToEndDirection * i);
                }
            }
        }
예제 #4
0
        public static void Update()
        {
            if (mouse.LeftClick())
            {
                if (spriteSheetRectangle.Contains(mouse.clickRectangle))
                {
                    ChangeSelectedTile();
                }
            }
            if (mouse.LeftHeld())
            {
                if (spriteSheetRectangle.Contains(mouse.clickRectangle))
                {
                    dragging = true;
                }
            }
            if (dragging)
            {
                if (MouseIsInWorkingArea())
                {
                    dragging = false;
                }
                int x = ((int)mouse.Position.X - (int)currTileSetPosition.X) / TileSet.tileWidth;
                int y = ((int)mouse.Position.Y - (int)currTileSetPosition.Y) / TileSet.tileHeight;

                markerRect.Width  = TileSet.tileWidth * (x - currentTileX + 1);
                markerRect.Height = TileSet.tileHeight * (y - currentTileY + 1);
                if (markerRect.Width > defaultRect.Width || markerRect.Height > defaultRect.Height)
                {
                    multipleSelected = true;
                    multipleTileX    = x - currentTileX;
                    multipleTileY    = y - currentTileY;
                }
                if (mouse.LeftReleased())
                {
                    dragging = false;
                }
            }
            #region Check For Input
            if (keyboard.IsHeld(Keys.LeftControl))
            {
                if (keyboard.JustPressed(Keys.S))
                {
                    Save();
                }
            }

            if (!blocksMode)
            {
                if (Scripts.KeyIsPressed(Keys.Space))
                {
                    if (mouse.LeftHeld() || mouse.LeftClick())
                    {
                        if (MouseIsInWorkingArea())
                        {
                            ChangeTile();
                        }
                    }
                    if (mouse.RightHeld() || mouse.RightClick())
                    {
                        if (MouseIsInWorkingArea())
                        {
                            RemoveTile();
                        }
                    }
                }
                else
                {
                    if (mouse.LeftClick())
                    {
                        if (MouseIsInWorkingArea())
                        {
                            ChangeTile();
                        }
                    }
                    if (mouse.RightClick())
                    {
                        if (MouseIsInWorkingArea())
                        {
                            RemoveTile();
                        }
                    }
                }
                if (keyboard.IsHeld(Keys.LeftControl))
                {
                    if (keyboard.JustPressed(Keys.C))
                    {
                        Main.tilemap.ClearTileMap();
                    }
                }
            }
            else
            {
                foreach (Rectangle rect in rectsToRemove)
                {
                    Main.blockRects.Remove(rect);
                }

                if (keyboard.IsHeld(Keys.LeftControl))
                {
                    if (keyboard.JustPressed(Keys.C))
                    {
                        Main.blockRects.Clear();
                    }
                }
                if (MouseIsInWorkingArea())
                {
                    #region AddRects
                    if (mouse.LeftClick())
                    {
                        rectToBeAdded  = new Rectangle((int)mouse.RealPosition.X, (int)mouse.RealPosition.Y, 0, 0);
                        isDraggingRect = true;
                        if (keyboard.IsHeld(Keys.LeftShift))
                        {
                            Vector2 snappedPosition = GetSnappedMousePosition();
                            rectToBeAdded = MathAid.UpdateRectViaVector(rectToBeAdded, snappedPosition);
                        }
                    }
                    if (isDraggingRect)
                    {
                        if (keyboard.IsHeld(Keys.LeftShift))
                        {
                            Vector2 snappedPosition = GetSnappedMousePosition();
                            rectToBeAdded.Width  = (int)snappedPosition.X - rectToBeAdded.X + TileSet.tileWidth;
                            rectToBeAdded.Height = (int)snappedPosition.Y - rectToBeAdded.Y + TileSet.tileHeight;
                        }
                        else
                        {
                            rectToBeAdded.Width  = (int)mouse.RealPosition.X - rectToBeAdded.X;
                            rectToBeAdded.Height = (int)mouse.RealPosition.Y - rectToBeAdded.Y;
                        }
                        if (mouse.LeftReleased())
                        {
                            AddRect();
                        }
                    }
                    #endregion

                    #region RemoveRects
                    if (Scripts.KeyIsPressed(Keys.Space))
                    {
                        if (mouse.RightClick() || mouse.RightHeld())
                        {
                            RemoveRects();
                        }
                    }
                    else
                    {
                        if (mouse.RightClick())
                        {
                            RemoveRects();
                        }
                    }
                    #endregion
                }
                else
                {
                    if (isDraggingRect)
                    {
                        isDraggingRect = false;
                    }
                }
            }
            if (keyboard.JustPressed(Keys.B))
            {
                blocksMode = !blocksMode;
            }
            #endregion
        }
예제 #5
0
 protected void UpdateRect()
 {
     walkingRect = MathAid.UpdateRectViaVector(walkingRect, position - walkingOrigin);
     rect        = MathAid.UpdateRectViaVector(rect, position - origin);
 }
예제 #6
0
        public void DirectTowardsMouse()
        {
            float angle = MathAid.FindRotation(Position, Main.mouse.RealPosition);

            DirectTowardsRotation(MathHelper.ToDegrees(angle));
        }