Browse Source

Import animation experiment

DricomDragon 4 years ago
parent
commit
2cbdae34a2

BIN
animation/Anim Lanceur/lanceur_1.bmp


BIN
animation/Anim Lanceur/lanceur_2.bmp


BIN
animation/Anim Lanceur/lanceur_3.bmp


BIN
animation/Anim Lanceur/lanceur_4.bmp


BIN
animation/Anim Lanceur/lanceur_5.bmp


BIN
animation/Anim Lanceur/lanceur_6.bmp


BIN
animation/Anim Lanceur/lanceur_7.bmp


BIN
animation/Anim Lanceur/lanceur_8.bmp


+ 44 - 0
animation/Anim Roue/AnimaRoue.cpp

@@ -0,0 +1,44 @@
+#include "AnimaRoue.h"
+
+AnimaRoue::AnimaRoue()
+:Anim_Boucle(100)
+{
+    std::cout << "Construction d'anim de roue appelée." << std::endl;
+    //Insertion des images à m_bande
+    char compteur('0');//'0'=48
+    std::string nomFichier("Anim Roue/roue_p.bmp");//p étant le caractère à remplacer
+    for (int i(0); i<4; i++)
+    {
+        compteur=48+i;//48='0'
+        nomFichier[15]=compteur;
+        m_bande.push_back(0);
+        m_bande[i]=SDL_LoadBMP(nomFichier.c_str());
+        std::cout << m_bande[i] << std::endl;
+    }
+
+}///Constructeur
+
+AnimaRoue::~AnimaRoue()
+{
+    //à enlever
+    if (m_bande.empty())
+        std::cout << "Destructeur parent automatique." << std::endl;
+    else
+        std::cout << "Destructeur parent manuel requis." << std::endl;
+    while (!m_bande.empty())
+    {
+        if (m_bande.back()!=0)
+            SDL_FreeSurface(m_bande.back());
+        m_bande.pop_back();
+    }
+    //Anim_Boucle::~Anim_Boucle();
+}///Destructeur
+
+void AnimaRoue::coller(SDL_Surface* support, int x, int y, bool centrer)
+{
+    Anim_Boucle::coller(support, x, y, centrer);
+}
+
+
+
+

+ 35 - 0
animation/Anim Roue/AnimaRoue.h

@@ -0,0 +1,35 @@
+#ifndef ANIMAROUE_H_INCLUDED
+#define ANIMAROUE_H_INCLUDED
+
+#include <iostream>
+#include <SDL.h>
+
+#include "../Animations/Anim_Boucle.h"
+
+///Développeur: Jovian Hersemeule
+///Dernière mise à jour le: 20/01/2014
+///Objet: quelques petits debug par ci par là...
+///Prochain objectif: mettre en fonction et tester objet
+
+/*
+==L'objet AnimaRoue==
+    +Argument
+        VOID
+    +Descriptif:
+        Permet de créer une animation d'une roue qui tourne. Hérite de Anim_Boucle.
+[Fonctions]
+FONCTIONS HERITEES: play; stop; pause; coller
+*/
+
+class AnimaRoue : public Anim_Boucle
+{
+    public:
+    AnimaRoue();
+    virtual ~AnimaRoue();
+    virtual void coller(SDL_Surface* support, int x, int y, bool centrer=0);
+
+    protected:
+    /*Aucun attribut supplémentaire requis.*/
+};
+
+#endif // ANIMAROUE_H_INCLUDED

BIN
animation/Anim Roue/roue_0.bmp


BIN
animation/Anim Roue/roue_1.bmp


BIN
animation/Anim Roue/roue_2.bmp


BIN
animation/Anim Roue/roue_3.bmp


+ 3 - 0
animation/Animations/Anim_AllerRetour.cpp

@@ -0,0 +1,3 @@
+#include "Anim_AllerRetour.h"
+
+

+ 34 - 0
animation/Animations/Anim_AllerRetour.h

@@ -0,0 +1,34 @@
+#ifndef ANIM_ALLERRETOUR_H_INCLUDED
+#define ANIM_ALLERRETOUR_H_INCLUDED
+
+#include "Animation.h"
+
+///Développeur: Jovian Hersemeule
+///Dernière mise à jour le: 03/08/2013
+///Objet: create cpp
+
+/*
+==L'objet ==
+    +Arguments:
+        VOID
+    +Descriptif:
+        Permet de créer une animation, comme
+[Fonctions]
+FONCTIONS HERITEES: play; stop; pause
+
+-coller:
+    +Arguments:
+        -Pointeur sur une SDL_Surface.
+    +Renvoi:
+        VOID
+    +Descriptif:
+        Permet de coller sur une surface l'image active, si l'anim est en cours.
+
+*/
+
+class Anim_AllerRetour : public Animation
+{
+
+};
+
+#endif // ANIM_ALLERRETOUR_H_INCLUDED

+ 43 - 0
animation/Animations/Anim_Boucle.cpp

@@ -0,0 +1,43 @@
+#include "Anim_Boucle.h"
+
+
+Anim_Boucle::Anim_Boucle(Uint32 tempsFrequence)
+:Animation(tempsFrequence)
+{
+    std::cout << "Construction de boucle appelée." << std::endl;
+}///Constructeur
+
+Anim_Boucle::~Anim_Boucle()
+{
+    //à enlever
+    while (!m_bande.empty())
+    {
+        if (m_bande.back()!=0)
+            SDL_FreeSurface(m_bande.back());
+        m_bande.pop_back();
+    }
+}///Destructeur
+
+void Anim_Boucle::coller(SDL_Surface* support, int x, int y, bool centrer)
+{
+    //[1] Détérmination de l'image active
+    SDL_Surface* imageActive;
+    imageActive=m_bande[((SDL_GetTicks()-m_tempsDepart)/m_tempsFrequence)%m_bande.size()];
+
+    //[2] Cadrage de l'image
+    SDL_Rect position;
+    if (centrer)
+    {
+        position.x=x-imageActive->w/2;
+        position.y=y-imageActive->h/2;
+    }
+    else
+    {
+        position.x=x;
+        position.y=y;
+    }
+
+    //[3] Collage de l'image active
+    SDL_BlitSurface(imageActive, 0, support, &position);
+
+}///coller

+ 41 - 0
animation/Animations/Anim_Boucle.h

@@ -0,0 +1,41 @@
+#ifndef ANIM_BOUCLE_H_INCLUDED
+#define ANIM_BOUCLE_H_INCLUDED
+
+#include "Animation.h"
+
+///Développeur: Jovian Hersemeule
+///Dernière mise à jour le: 21/08/2013
+///Objet: debug primaire, chgmt calcul
+
+/*
+==L'objet Anim_Boucle==
+    +Argument
+        VOID
+    +Descriptif:
+        Permet de créer une animation durable qui boucle: le fumée d'une usine,
+        un bonhomme qui court, une roue qui tourne, etc...
+        Une animation de ce genre hérite de cette classe.
+[Fonctions]
+FONCTIONS HERITEES: play; stop; pause
+
+-coller:
+    +Arguments:
+        -Pointeur sur une SDL_Surface.
+    +Renvoi:
+        VOID
+    +Descriptif:
+        Permet de coller sur une surface l'image active, si l'anim est en cours.
+*/
+
+class Anim_Boucle : public Animation
+{
+    public:
+    Anim_Boucle(Uint32 tempsFrequence);
+    virtual ~Anim_Boucle();
+    virtual void coller(SDL_Surface* support, int x, int y, bool centrer=0);
+
+    protected:
+    /*Aucun attribut supplémentaire requis.*/
+};
+
+#endif // ANIM_BOUCLE_H_INCLUDED

+ 4 - 0
animation/Animations/Anim_Ephemere.cpp

@@ -0,0 +1,4 @@
+#include "Anim_Ephemere.h"
+
+
+

+ 35 - 0
animation/Animations/Anim_Ephemere.h

@@ -0,0 +1,35 @@
+#ifndef ANIM_EPHEMERE_H_INCLUDED
+#define ANIM_EPHEMERE_H_INCLUDED
+
+#include "Animation.h"
+
+///Développeur: Jovian Hersemeule
+///Dernière mise à jour le: 03/08/2013
+///Objet: mise au point header, create cpp
+
+/*
+==L'objet Anim_Ephemere==
+    +Arguments:
+        VOID
+    +Descriptif:
+        Permet de créer un effet éphèmere par une animation, comme une explosion ou un impact.
+        Lorque l'animation est finie, la fonction end() renvoie vrai, et faux lorsqu'elle tourne encore.
+        Une anim de ce genre hérite de cette classe.
+[Fonctions]
+
+*/
+
+class Anim_Ephemere : public Animation
+{
+    public:
+    Anim_Ephemere(Uint32 tempsFrequence);
+    virtual ~Anim_Ephemere();
+    virtual void coller(SDL_Surface* support, int x, int y, bool centrer=0);
+    bool end();
+
+    protected:
+    bool m_estFini;
+
+};
+
+#endif // ANIM_EPHEMERE_H_INCLUDED

+ 33 - 0
animation/Animations/Animation.cpp

@@ -0,0 +1,33 @@
+#include "Animation.h"
+
+
+Animation::Animation(Uint32 tempsFrequence)
+:m_tempsFrequence(tempsFrequence),m_tempsDepart(0),m_imageActive(0)
+{
+
+}///Animation()
+
+Animation::~Animation()
+{
+    while (!m_bande.empty())
+    {
+        if (m_bande.back()!=0)
+            SDL_FreeSurface(m_bande.back());
+        m_bande.pop_back();
+    }
+}///~Animation()
+
+void Animation::play()
+{
+    m_tempsDepart=SDL_GetTicks();
+}///play()
+
+void Animation::pause()
+{
+    //Set pause --'
+}///pause()
+
+void Animation::stop()
+{
+    //Stop ! *0*
+}///stop()

+ 75 - 0
animation/Animations/Animation.h

@@ -0,0 +1,75 @@
+#ifndef ANIMATION_H_INCLUDED
+#define ANIMATION_H_INCLUDED
+
+#include <SDL.h>
+#include <iostream>
+#include <vector>
+
+///Développeur: Jovian Hersemeule
+///Dernière mise à jour le: 13/08/2013
+///Objet: remplissage du cpp, débuggage primaire: nombreux points à ameliorer
+
+/*
+==L'objet Animation (classe abstraite)==
+    +Arguments:
+        VOID
+    +Descriptif:
+        Permet de créer un effet d'animation à partir d'une succession d'image. Classe abstraite,
+        cette classe ne peut produire d'objet mais sert à l'heritage à tous les types d'animation.
+[Fonctions]
+-play:
+    +Arguments:
+        VOID
+    +Renvoi:
+        VOID
+    +Descriptif:
+        Permet de lancer la succession des images, ou de la relancer. Rafraichi l'attribut m_tempsDepart.
+
+-pause:
+    +Arguments:
+        VOID
+    +Renvoi:
+        VOID
+    +Descriptif:
+        Permet de stopper l'animation sur l'image active.
+
+-stop:
+    +Arguments:
+        VOID
+    +Renvoi:
+        VOID
+    +Descriptif:
+        Permet d'arrêter l'animation et de la réenclencher au début.
+
+-coller:
+    +Arguments:
+        -Pointeur sur une SDL_Surface.
+        -Coordonnée d'abscisse.
+        -Coordonnée en ordonnée.
+        -Bool de calibrage: vrai pour centrer, faux pour rectanguler
+    +Renvoi:
+        VOID
+    +Descriptif:
+        Permet de coller sur une surface l'image active. Contient les calculs de sélection d'image.
+
+*/
+
+class Animation
+{
+    public:
+    Animation(Uint32 tempsFrequence);
+    virtual ~Animation();
+    void play();
+    void pause();
+    void stop();
+    virtual void coller(SDL_Surface* support, int x, int y, bool centrer=0)=0;//Virtuelle pure
+
+    protected:
+    std::vector<SDL_Surface*> m_bande;
+    const Uint32 m_tempsFrequence;//Tps en ms entre chq img
+    Uint32 m_tempsDepart;//"heure" en ms du départ de l'anim
+    Uint16 m_imageActive;
+
+};
+
+#endif // ANIMATION_H_INCLUDED

+ 70 - 0
animation/main.cpp

@@ -0,0 +1,70 @@
+#include <iostream>
+#include <SDL.h>
+
+#include "Anim Roue/AnimaRoue.h"
+
+int main ( int argc, char** argv )
+{
+    /// [1] Démarrage
+    // [1.1] Démarrages SDL
+    if ( SDL_Init( SDL_INIT_VIDEO ) < 0)
+    {
+        std::cout << "Impossible d'initialiser la SDL: " << SDL_GetError() << std::endl;
+        return 1;
+    }
+
+    // [1.2] Préparation de fermeture
+    atexit(SDL_Quit);
+
+    // [1.3] Para-fenêtre
+    SDL_WM_SetCaption("Test animations", 0);
+
+    /// [2] Préparation des composants
+    // [2.1] Préparation de la fenêtre
+    SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16,
+                                           SDL_HWSURFACE|SDL_DOUBLEBUF);
+    if ( !screen )
+    {
+        std::cout << "Unable to set 640x480 video: " << SDL_GetError() << std::endl;
+        return 1;
+    }
+
+    // [2.2] Préparation
+    AnimaRoue maRoue;
+
+    /// [3] Boucle principale
+    bool done = false;
+    while (!done)
+    {
+        // [3.1] Gestion évènements
+        SDL_Event event;
+        while (SDL_PollEvent(&event))
+        {
+            switch (event.type)
+            {
+            case SDL_QUIT:
+                done = true;
+                break;
+            case SDL_KEYDOWN:
+                if (event.key.keysym.sym == SDLK_ESCAPE)
+                    done = true;
+                break;
+            } // end switch event type
+        } // end of message processing
+
+        // [3.2] Calculs
+
+        // [3.3] Dessin des composants
+        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 255));
+
+        maRoue.coller(screen, 20, 40);
+
+        SDL_Flip(screen);
+    } //fin bcl principale
+
+    ///[4] Destruction des composants
+
+
+    std::cout << "Aucune erreur détectée." << std::endl;
+    return 0;
+}