6 Replies
im new to coding
isn't sfml c++?
yeah am i in the wrong place
🙂 someone may be able to answer you anyway but there's also $cpp
We're partnered with Together C & C++, check them out here: https://discord.gg/vnyVmAE
#include <SFML/Graphics.hpp>
class Disappear : public sf::RectangleShape {
public:
Disappear() {
setFillColor(sf::Color::Green);
}
void update(float deltaTime, sf::RectangleShape& player) {
if (getGlobalBounds().intersects(player.getGlobalBounds())) {
setFillColor(sf::Color::Red);
// Check if player stands on platform for 3 seconds
standingTime += deltaTime;
if (standingTime >= 3.0f) {
// Destroy the platform (remove it from the game)
destroy();
}
} else {
// Reset standing time if not on the platform
standingTime = 0.0f;
setFillColor(sf::Color::Green);
}
}
void destroy() {
// Your logic to destroy or remove the platform goes here
// For example: removeFromGame();
}
private:
float standingTime = 0.0f;
};
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Disappearing Platform");
sf::RectangleShape player(sf::Vector2f(50, 50));
player.setFillColor(sf::Color::Blue);
player.setPosition(375, 500);
Disappear platform;
platform.setSize(sf::Vector2f(200, 20));
platform.setPosition(300, 400);
sf::Clock clock;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
float deltaTime = clock.restart().asSeconds();
// Update the platform and check for player collisions
platform.update(deltaTime, player);
window.clear();
window.draw(player);
window.draw(platform);
window.display();
}
return 0;
}
Sfml is C++