Exemplo n.º 1
0
        public void draw()
        {
            Vector2 healthBar = new Vector2(lineBatch.getView().Center.X, 20) - Vector2.UnitX * HEALTH_BAR_WIDTH / 2;
            lineBatch.setMatrix(0, healthBar);

            float percentHealth = health / MAX_HEALTH;
            int healthWidth = (int)(percentHealth * HEALTH_BAR_WIDTH);

            lineBatch.setColor(Color.Green);
            lineBatch.fillRectangle(new Rectangle(0, 0, healthWidth, HEALTH_BAR_HEIGHT));

            lineBatch.setColor(Color.Red);
            lineBatch.fillRectangle(new Rectangle(healthWidth, 0, HEALTH_BAR_WIDTH - healthWidth, HEALTH_BAR_HEIGHT));

            lineBatch.setColor(Color.Orange);
            lineBatch.drawRectangle(new Rectangle(0, 0, HEALTH_BAR_WIDTH, HEALTH_BAR_HEIGHT));
            lineBatch.drawLine(Vector2.UnitX * healthWidth, new Vector2(healthWidth, HEALTH_BAR_HEIGHT));

            lineBatch.setMatrix(0, position);
            lineBatch.setColor(PLAYER_COLOR);

            lineBatch.drawCircle(head - Vector2.UnitY * HEAD_RADIUS, HEAD_RADIUS);
            lineBatch.drawLine(head, waist);

            float angle = (float)Math.Sin(moveValue / 5) / 5;

            lineBatch.setMatrix(angle, position + waist, waist);
            lineBatch.drawLine(waist, rightKnee);
            lineBatch.drawLine(rightKnee, rightFoot);

            lineBatch.setMatrix(-angle, position + waist, waist);
            lineBatch.drawLine(waist, leftKnee);
            lineBatch.drawLine(leftKnee, leftFoot);

            lineBatch.setMatrix(0, Vector2.Zero);
            MatrixTransformer matrixTransformer = new MatrixTransformer(bow.angle, bow.position, Bow.bowRotationOrigin);
            lineBatch.drawLine(position + shoulder, matrixTransformer.applyMatrix(Bow.bowOrigin));

            bow.draw();
        }
Exemplo n.º 2
0
        public void update(GameTime gameTime, Vector2 position)
        {
            this.position = position;

            MouseState mouseState = Mouse.GetState();
            angle = (float)Math.Atan2(mouseState.Y - position.Y, mouseState.X - (position.X + lineBatch.getView().Left));

            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                MatrixTransformer matrixTransformer = new MatrixTransformer(angle, position, bowRotationOrigin);
                //Calculate where the origin of the bow is using the matrix
                //Set the back of the arrow to the middle of the string of the bow and subtract the arrow power
                Vector2 arrowPosition = matrixTransformer.applyMatrix(bowOrigin + Vector2.UnitX * (Arrow.ARROW_LENGTH - BOW_WIDTH - arrowPower));

                if (!mousePressed)
                {
                    if (timer.update(gameTime)) //Nested so that it wont change tempArrow when we press the mouse but we havent delayed
                    {
                        tempArrow = new Arrow(lineBatch, arrowPosition, angle);
                        mousePressed = true;
                    }
                }
                else
                {
                    tempArrow.position = arrowPosition;
                    tempArrow.angle = angle;
                    arrowPower += tempArrow.speed < Arrow.MAX_SPEED ? 1 : 0;
                    tempArrow.speed = arrowPower;
                }
            }
            else if (mouseState.LeftButton == ButtonState.Released)
            {
                mousePressed = false;
                if (tempArrow != null)
                {
                    tempArrow.speed = tempArrow.speed == 0 ? 1 : tempArrow.speed;
                    arrows.Add(tempArrow);
                    tempArrow = null;
                    arrowPower = 0;
                }
            }

            List<Arrow> removeArrows = new List<Arrow>();

            foreach (Arrow arrow in arrows)
            {
                arrow.update(gameTime);
                if (arrow.position.Y >= lineBatch.getView().Bottom) //If it went below the screen
                    removeArrows.Add(arrow);
            }
            foreach (Arrow arrow in removeArrows)
                arrows.Remove(arrow);
        }
Exemplo n.º 3
0
        public void draw()
        {
            float legAngle = (float)Math.Sin(moveValue);

            Vector2 newBody = body * scale;

            MatrixTransformer matrixTransformer = new MatrixTransformer(legAngle, Vector2.Zero, -body);
            Vector2 newRightKnee = matrixTransformer.applyMatrix(rightKnee * scale);
            Vector2 newRightFoot = matrixTransformer.applyMatrix(rightFoot * scale);

            matrixTransformer.setMatrix(-legAngle, Vector2.Zero, -body);
            Vector2 newLeftKnee = matrixTransformer.applyMatrix(leftKnee * scale);
            Vector2 newLeftFoot = matrixTransformer.applyMatrix(leftFoot * scale);

            lineBatch.setMatrix(0, position + level.offset);
            lineBatch.setColor(color);

            lineBatch.drawLine(body, newRightKnee);
            lineBatch.drawLine(newRightKnee, newRightFoot);
            lineBatch.drawLine(body, newLeftKnee);
            lineBatch.drawLine(newLeftKnee, newLeftFoot);
        }