Can someone help me with my code?

Currently I'm stuck at one point, I'm trying to write something like this:


class Rectangle : public Movable {

private:

sf::RectangleShape rs;

public:

Rectangle() {}

};

class Circle : public Movable {

private:

sf::CircleShape cs;

public:

Circle() {}

};

//CLASS THAT WILL GIVE ABILITY TO MOVE ALL TYPES OF MOVABLE CLASSES.
class Movable {

public:

void move(float, float);

};

All I ask is if someone can write me a code with class that will enable all classes (rectangle, circle) to have ability to move their RectangleShape/CircleShape. And by the time I will learn how and why. I tried with virtual functions but it doesn't do what I want (or maybe idk how to use it). I would be so pleasant if someone could help me with this problem.
I created a very simple program for you, that lets you move around a circle using WASD.
I recommend you check out this playlist on youtube. It helped me get started well with SFML, and taught me all the basics -
https://www.youtube.com/playlist?list=PLHJE4y54mpC5j_x90UkuoMZOdmmL9-_rg


Otherwise there are plenty of other videos if you search for it, and if you google too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <SFML/Graphics.hpp>


int main()
{
	sf::RenderWindow window(sf::VideoMode(900, 600), "SFML works!");
	sf::CircleShape shape(50.f);
	
	shape.setFillColor(sf::Color::Green);

	int shapeSpeed = 400;
	sf::Clock gameTime;

	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();
		}

		float delta = gameTime.restart().asSeconds(); // Google what delta means. Its
                // Basically the time it takes to through everything in the program. To go an entire round.
		
		window.clear();

		if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
		{
			shape.move(shapeSpeed * delta, 0.0f);
		}
		else if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
		{
			shape.move(-shapeSpeed * delta, 0.0f);
		}
		else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
		{
			shape.move(0.0f, shapeSpeed * delta);
		}
		else if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
		{
			shape.move(0.0f, -shapeSpeed * delta);
		}
		window.draw(shape);
		window.display();
	}

	return 0;
}

Topic archived. No new replies allowed.