From f39bbd8bc87da72cec6cb0d145ccc240c89e79a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Tue, 8 Mar 2016 18:07:21 +0100 Subject: [PATCH] =?UTF-8?q?H=C3=A9ritage=20de=20Ball=20depuis=20Object=20e?= =?UTF-8?q?t=20nettoyage=20de=20ball.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ball.cpp | 47 ++++------------------------------------------- ball.hpp | 32 +++++++++++--------------------- 2 files changed, 15 insertions(+), 64 deletions(-) diff --git a/ball.cpp b/ball.cpp index fe4143e..1c1126c 100644 --- a/ball.cpp +++ b/ball.cpp @@ -1,52 +1,13 @@ #include "ball.hpp" -#include "engine.hpp" - -// TODO réécrire cette classe Ball::Ball() { - if (!texture.loadFromFile("res/balle.png")) { - std::cerr << "Failed to load texture" << std::endl; - } - - velocity.x = velocity.y = 0; - position.x = 150; position.y = 150; - - sprite.setOrigin(12, 12); - sprite.setTexture(texture); + // TODO: implémenter cette fonction } -void Ball::update(float delta) { - int verticalPos = std::ceil(position.y); - - // gravity - velocity.y += Engine::GRAVITY * delta; - - // jump - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && verticalPos >= 150) { - velocity.y = -Engine::JUMP; - } - - // go left/right - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { - velocity.x -= Engine::MOVE; - } - - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { - velocity.x += Engine::MOVE; - } - - if (verticalPos > 150) { - position.y = 150; - velocity.y = -.3f * std::abs(velocity.y); - } - - velocity.x *= .95f; - position += velocity * delta; +void Ball::update(sf::Vector2f forces, float delta) { + // TODO: implémenter cette fonction } void Ball::draw(sf::RenderWindow& window) { - sprite.setPosition(position + sf::Vector2f(0, -12)); - sprite.rotate(velocity.x / 10); - - window.draw(sprite); + // TODO: implémenter cette fonction } diff --git a/ball.hpp b/ball.hpp index 25e6d46..4155280 100644 --- a/ball.hpp +++ b/ball.hpp @@ -1,38 +1,28 @@ #ifndef PTF_BALL_HPP #define PTF_BALL_HPP +#include "object.hpp" #include #include -class Ball { +class Ball : public Object { protected: - sf::Vector2f position; sf::Vector2f velocity; float mass; - int charge; public: Ball(); - void update(float delta); + /** + * Mise à jour de la position de la balle en fonction des forces + * qui lui sont appliquées + */ + void update(sf::Vector2f forces, float delta); + + /** + * Dessine la balle dans la fenêtre donnée + */ void draw(sf::RenderWindow& window); - - // getters et setters - sf::Vector2f getPosition() { - return position; - } - - sf::Vector2f getVelocity() { - return velocity; - } - - float getMass() { - return mass; - } - - int getCharge() { - return charge; - } }; #endif