Esempio n. 1
0
        public void Draw(SpriteBatch spriteBatch, EntitySprite player)
        {
            if (heal)                                                                                                      // if they were healing it
            {
                spriteBatch.Draw(texture, new Vector2(player.POSRect.X, player.POSRect.Y - rectangle.Height), Color.Pink); //draws the pink sword of healing

                if (cooldown <= 0)                                                                                         // if the cooldown is < 0
                {
                    heal = false;                                                                                          // sets heal to false
                }
            }
            switch (swinging)  // this is the switch to determine if they are swinging or not
            {
            case Swinging.Not: //if their not it doesnt draw
            {
                break;
            }

            case Swinging.Is:    //if it is it draws the sword
            {
                spriteBatch.Draw(texture, Position, null, Color.White, rotation, spriteOrigin, 1f, SpriteEffects.None, 0);
                break;
            }
            }
        }
Esempio n. 2
0
        public bool swinged;                                                            //this is a bool to check if they swung named swinged
        public Weapon(Texture2D newTexture, Rectangle newRectangle, EntitySprite Owner) ////this creates the sword using just a texture and rectangle
        {
            owner    = Owner;
            Position = new Vector2(newRectangle.X, newRectangle.Y);//it sets the position using the rectangles position

            texture      = newTexture;
            rectangle    = newRectangle;
            spriteOrigin = new Vector2(rectangle.Width / 2, rectangle.Height);// and the origin is the center of the width of thw sword but the bottom of the height, that wat it rotats from the handle, not the center
        }
Esempio n. 3
0
        public void Update(GameTime gameTime, EntitySprite Player, int width, int height, Rectangle rectangle) // this is used for updateting the camera and takes in the playersprite so it cantrack the player
        {
            centre = new Vector2(Player.Position.X, Player.Position.Y);                                        // this is the centre of the camera and will always be at the players position

            float left   = centre.X - rectangle.Width / 2;
            float top    = centre.Y - rectangle.Height * 2 / 3;
            float right  = centre.X + rectangle.Width / 2;
            float bottom = centre.Y + rectangle.Height / 3;

            if (left <= 0)
            {
                centrer.X = rectangle.Width / 2;
            }
            else if (right >= width)
            {
                centrer.X = width - rectangle.Width / 2;
            }
            else
            {
                centrer.X = centre.X;// it just follows the characters x
            }
            if (top <= 0)
            {
                centrer.Y = rectangle.Height * 2 / 3;
            }
            else if (bottom >= height)
            {
                centrer.Y = height - rectangle.Height / 3;
            }
            else
            {
                centrer.Y = centre.Y;                                                                  // and y
            }
            transform =                                                                                // this is the camera transformation matrix, i watched a 3 hour lecture and vaguely understand whats going on here
                        Matrix.CreateTranslation(new Vector3(-centrer.X, -centrer.Y, 0)) *             //so it creates a matrix translation using the inverse of the center(because cameras take in light upsidedown or something like that) then it multiplies it by the next line
                        Matrix.CreateScale(new Vector3(0.75f, 0.75f, 0)) *                             //this creates a scale for the transormation. This scale is 0.75times the size of the actual game it then multiplies it by the next line
                        Matrix.CreateTranslation(new Vector3(view.Width / 2, view.Height * 2 / 3, 0)); //this creates the translation so it can follow the player but not in the top left but rather in the centre of the viewport
        }
Esempio n. 4
0
        public void update(MouseState mouse, Viewport view, EntitySprite player, BinaryWriter writer, MemoryStream writeStream, TcpClient client) //this is the update method
        {
            if (mouse.X < view.Width / 2 && swinged == false)                                                                                     //if the mouse if on the left side of the screen it sets swung to left
            {
                SWUNG = swung.left;
            }
            else if (mouse.X >= view.Width / 2 && swinged == false)//if its on the right and they havent swung it sets it to right
            {
                SWUNG = swung.right;
            }
            if (mouse.RightButton == ButtonState.Pressed && ((PlayerStats)player).mana >= 20 && cooldown <= 0) //if they rightclick and it isnt on cooldown and they have enough mana
            {
                ((PlayerStats)player).mana   = -20;                                                            //it takes the mana
                ((PlayerStats)player).health = ((PlayerStats)player).intelligence;                             //and heals them
                cooldown             = 100;                                                                    //and puts the spell on CD
                heal                 = true;                                                                   //and makes the heal bool true
                writeStream.Position = 0;
                writer.Write((byte)Protocol.weaponCreated);
                writer.Write((byte)2);
                SendData(GetDataFromMemoryStream(writeStream), client);
            }
            else if (cooldown > 0)                           // the the cooldown is greater than 0
            {
                cooldown--;                                  //it reduces the cooldown
            }
            switch (swinging)                                // the switch to see if their swinging
            {
            case Swinging.Not:                               //if their not
            {
                rotation = 0;                                // it removes the rotation from the sword

                if (mouse.LeftButton == ButtonState.Pressed) // when they left click
                {
                    swinging = Swinging.Is;                  // it changes state to swinging
                }
                break;
            }

            case Swinging.Is:    //if they are swinging
            {
                if (timer == 0)
                {
                    writeStream.Position = 0;
                    writer.Write((byte)Protocol.weaponCreated);
                    if (mouse.X < view.Width / 2)
                    {
                        writer.Write((byte)0);
                    }
                    else
                    {
                        writer.Write((byte)1);
                    }
                    SendData(GetDataFromMemoryStream(writeStream), client);
                }
                swing();                                                   //it swings
                timer++;                                                   // and adds to the time
                if (timer > interval - ((PlayerStats)player).aSpeed / .98) // if the timer has been running for longer than the interval - aspeed
                {
                    timer    = 0;                                          //it sets the timer to 0
                    swinging = Swinging.Not;                               //and it sets swinging to not
                    swinged  = false;                                      //and swinged to false to reset all the stuff
                }
                break;
            }
            }
        }