Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - moonyTown

Pages: [1]
1
Graphics / Re: Ball doesnt change his start position
« on: April 01, 2020, 12:20:37 am »
What do you mean by isn't linked,  isn't it enough to write something like Shot. Position = Rect. position like I did for the start position before the movement begin.

But okee I will try to implement what you wrote and post it later?

2
Graphics / Re: Ball doesnt change his start position
« on: March 31, 2020, 08:37:47 pm »
OK thanks, now I see the mistake by the movement
 Position.X - Position.X + Size.X, Position.Y - Position.Y + Size.Y)
 

But, why need the circle a rotation? I just want that the start position of the circle is always by the top of the rect.
This was my attempt but it failed.
CircleShape Shot = new CircleShape(5);
                    Shot.Position = new Vector2f(Position.X, Position.Y + Size.Y * 2 / 3);
                    ShotList.Add(Shot);
                }
           

3
Graphics / Ball doesnt change his start position
« on: March 31, 2020, 06:09:23 pm »
Hi There,

i have a problem with the rotation. My goal was to rotate a Rect and make it shoot by pressing left mouse button or space.
The rotation works but not the shoot. The ball always fly away from the same position no matter if the Rect rotate or not.

Here an example picture

https://imgur.com/CDmGOdI
https://imgur.com/60wauzO

using SFML.Graphics;
using SFML.System;
using SFML.Audio;
using SFML.Window;
using System;
using System.Collections.Generic;

namespace Pong3final
{
    class Player : RectangleShape
    {
        public float Speed;
        public float RotationMovement;
        public List<CircleShape> ShotList = new List<CircleShape>();
        float TimeSinceLastShot;

        public bool PlayerSettingMouse = false;
        public bool PlayerSettingKeyboard = true;

        public Player(Vector2f size) : base(size)
        {
            Origin = new Vector2f(Position.X + Size.X / 2, Position.Y + Size.Y * 2 / 3);

            if (PlayerSettingMouse)
                PlayerSettingKeyboard = false;

            if (PlayerSettingKeyboard)
                PlayerSettingMouse = false;
        }
        public void Rotate(float deltaTime, Window window)
        {
            if (PlayerSettingKeyboard)
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Right))
                {
                    RotationMovement += 150 * deltaTime;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Left))
                {
                    RotationMovement -= 150 * deltaTime;
                }

                Rotation = -RotationMovement;
            }

            if (PlayerSettingMouse)
            {
                Vector2i MousePosition = Mouse.GetPosition(window);

                float dx = MousePosition.X - Position.X;
                float dy = MousePosition.Y - Position.Y;

                RotationMovement = (float)(Math.Atan2(dx, dy) * (180 / Math.PI));

                Rotation = -RotationMovement;
            }
        }

        public void Shot(float deltaTime)
        {

            if (PlayerSettingKeyboard)
            {
                TimeSinceLastShot += deltaTime;

                if (Keyboard.IsKeyPressed(Keyboard.Key.Space) && TimeSinceLastShot > 0.5f)
                {
                    TimeSinceLastShot = 0;
                    CircleShape Shot = new CircleShape(5);
                    Shot.Position = new Vector2f(Position.X, Position.Y + Size.Y * 2 / 3);
                    ShotList.Add(Shot);
                }

                foreach (CircleShape shots in ShotList)
                {
                    shots.Position += new Vector2f(Position.X - Position.X + Size.X, Position.Y - Position.Y + Size.Y) * deltaTime;
                }
            }

            if (PlayerSettingMouse)
            {
                TimeSinceLastShot += deltaTime;

                if (Mouse.IsButtonPressed(Mouse.Button.Left) && TimeSinceLastShot > 0.5f)
                {
                    TimeSinceLastShot = 0;
                    CircleShape Shot = new CircleShape(5);
                    Shot.Position = new Vector2f(Position.X, Position.Y + Size.Y * 2 / 3);
                    ShotList.Add(Shot);
                }

                foreach (CircleShape shots in ShotList)
                {                  
                    shots.Position += new Vector2f(Position.X - Position.X + Size.X, Position.Y - Position.Y + Size.Y) * deltaTime;
                }
            }

        }
    }
}
[code=csharp]

Pages: [1]