diff --git a/CEngine.hpp b/CEngine.hpp index 2e40f38..651d7ac 100644 --- a/CEngine.hpp +++ b/CEngine.hpp @@ -1,10 +1,9 @@ /* ************************************************************************** */ -/* _____ */ -/* CEngine.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ +/* _____ _ __ ___ __ */ +/* CEngine.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ /* */ /* ************************************************************************** */ @@ -32,17 +31,17 @@ //#define CE_ALL #define CE_BASIC - #define CE_MAP //#define CE_RPG - //#define CE_PLATEFORME + #define CE_PLATEFORME //#define CE_NETWORK #ifdef CE_ALL + #define CE_BASIC #define CE_RPG #define CE_PLATEFORME #define CE_NETWORK - #define CE_MAP + #endif //*********Declaration**********// @@ -58,6 +57,7 @@ class Animation; class Sprite; class Script; + class Level; struct MassData { @@ -67,8 +67,8 @@ struct Vec2 { - double x; - double y; + int x; + int y; }; struct AABB @@ -87,32 +87,20 @@ }; #endif - #ifdef CE_MAP - - class Level; - class World; - - #endif - //********Include**********// #ifdef CE_BASIC + #include "include\Engine.hpp" #include "include\Object.hpp" + #include "include\Level.hpp" - #include "include\Components\Transform.hpp" //Les composants de la class Object. - #include "include\Components\RigidBody.hpp" - #include "include\Components\Render.hpp" - #include "include\Components\Animation.hpp" - #include "include\Components\Sprite.hpp" - #include "include\Components\Script.hpp" - - #endif - - #ifdef CE_MAP - - #include "include\Map\World.hpp" //Les différents composant du décor du jeu - #include "include\Map\Level.hpp" + #include "include\Object\Transform.hpp" //Les composants de la class Object. + #include "include\Object\RigidBody.hpp" + #include "include\Object\Render.hpp" + #include "include\Object\Animation.hpp" + #include "include\Object\Sprite.hpp" + #include "include\Object\Script.hpp" #endif diff --git a/include/Components/Animation.hpp b/include/Components/Animation.hpp deleted file mode 100644 index 409f401..0000000 --- a/include/Components/Animation.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Animation.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#ifndef CENGINE_ANIMATION_HPP -#define CENGINE_ANIMATION_HPP - -#include "..\Rework\CEngine.hpp" - - class Animation - { - public: - - Animation(); - Animation(Sprite & v); - Animation(Sprite * v , int nb , int nbd = 250 , bool vwaitatend = false , bool vwaittheend = false );//Constructeur - - void SetIt(int v); - - int GetSizeX(); - int GetSizeY(); - - int GetBlitX(); - int GetBlitY(); - - void DrawReverseAnim( int , int , int); - void DrawAnim( int , int , int ); - - bool WaitDelay(); - - private: - - Sprite * TabSprite; - - int iterateur; - int delay; // En ms - int time; - int nb_image; - - bool waitatend; - bool waittheend; - bool isend; - - }; - -#endif diff --git a/include/Components/Render.hpp b/include/Components/Render.hpp deleted file mode 100644 index 22bdeb6..0000000 --- a/include/Components/Render.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Render.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#ifndef CENGINE_RENDER_HPP -#define CENGINE_RENDER_HPP - -#include "..\Rework\CEngine.hpp" - - class Render - { - public: - - Render(Object * Pointeur); //Constructeur - ~Render(); - - void SetRender(Animation * v, int nb); - void SetRender(Animation & v); - - void CopieRender(Animation * v, int nb); - void CopieRender(Animation & v); - - void SetIt( int v); - int GetIt(); - - void ReverseRender(bool); - bool GetReverse(); - - void SetDirection(int); - int GetDirection(); - - int GetSizeY(); - int GetSizeX(); - - int GetBlitX(); - int GetBlitY(); - - void DrawObject(); - - - private: - - Object * Conteneur; - Animation * TabAnim; - - int nb_anim; - int iterateur; - int time; - - int direction; - bool reverse; - - bool copie; - }; - -#endif diff --git a/include/Components/RigidBody.hpp b/include/Components/RigidBody.hpp deleted file mode 100644 index 3079586..0000000 --- a/include/Components/RigidBody.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* RigidBody.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#ifndef CENGINE_RIGIDBODY_HPP -#define CENGINE_RIGIDBODY_HPP - -#include "..\Rework\CEngine.hpp" - - class RigidBody - { - public: - - RigidBody(Object * Pointeur); //Constructeur - - void SetMass(float); - void UseFixeBody( int w , int h); - void UseFlexBody(); - - void AppliedForce(); - - int Move( int x , int y); - int TryMove( int x , int y); - int CollisionDecor( int x , int y); - void Affine(int vx , int vy); - - int GetWidht(); - int GetHeight(); - bool GetStat(); - - Body * GetBody(); - - private: - - Object * Conteneur; - - Body R_body; - - bool usefixebody; - int widht; - int height; - }; - -#endif diff --git a/include/Components/Script.hpp b/include/Components/Script.hpp deleted file mode 100644 index 55e6d92..0000000 --- a/include/Components/Script.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Script.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#ifndef CENGINE_SCRIPT_HPP -#define CENGINE_SCRIPT_HPP - -#include "..\Rework\CEngine.hpp" - - class Script - { - public: - - Script(); //Constructeur - - virtual void Update(); - virtual void UpdateEverySecond(); - virtual void Start(); - - void AffectObject(Object * OV); - void AffectEngine(Engine * EV); - - Engine * GetEngine(); - Object * GetObject(); - - private: - - Object * OConteneur; - Engine * EConteneur; - - }; - -#endif diff --git a/include/Components/Sprite.hpp b/include/Components/Sprite.hpp deleted file mode 100644 index ad8f1a3..0000000 --- a/include/Components/Sprite.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Sprite.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#ifndef CENGINE_SPRITE_HPP -#define CENGINE_SPRITE_HPP - -#include "..\Rework\CEngine.hpp" - - class Sprite - { - public: - - Sprite(); - Sprite(const unsigned char * v1 , int sizex , int sizey , int bx = 0 , int by = 0 ); - Sprite(const unsigned char * v1 , const unsigned char * v2 , int sizex , int sizey , int bx = 0 , int by = 0 ); //Constructeur - - void DrawReverseSprite( int x , int y , int d ); - void DrawSprite( int x , int y , int d ); - - void CreateReverse( int brx = 0 , int bry = 0 ); - - int GetSizeY(); - int GetSizeX(); - - int GetBlitX(); - int GetBlitY(); - - private: - - const unsigned char * Beta; - const unsigned char * Alpha; - - unsigned char * ReverseBeta; - unsigned char * ReverseAlpha; - - int size_x; - int size_y; - - int b_x; - int b_y; - - int br_x; - int br_y; - - }; - -#endif diff --git a/include/Components/Transform.hpp b/include/Components/Transform.hpp deleted file mode 100644 index 597b9bb..0000000 --- a/include/Components/Transform.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Transform.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#ifndef CENGINE_TRANSFORM_HPP -#define CENGINE_TRANSFORM_HPP - -#include "..\Rework\CEngine.hpp" - - class Transform - { - public: - - Transform(Object * Pointeur); //Constructeur - - double GetX(); - double GetY(); - - double GetRelativeX(); - double GetRelativeY(); - - void SetX(double v); - void SetY(double v); - void SetXY(double vx ,double vy); - - void SetRelativeXY(double vx ,double vy); - - private: - - Object * Conteneur; - - Vec2 positionabsolu; // en pixel - Vec2 positionrelative; // en pixel - }; - -#endif diff --git a/include/Engine.hpp b/include/Engine.hpp index 072a625..b43edfa 100644 --- a/include/Engine.hpp +++ b/include/Engine.hpp @@ -1,10 +1,9 @@ /* ************************************************************************** */ -/* _____ */ -/* Engine.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ +/* _____ _ __ ___ __ */ +/* Engine.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ /* */ /* ************************************************************************** */ @@ -13,62 +12,65 @@ #include "..\Rework\CEngine.hpp" - class Engine - { - public: +class Engine +{ + public: - Engine(); //Constructeur + Engine(); //Constructeur - void StartGame(); //Lance le jeu - void InitGame(); //Initialise le jeu - void StopGame(); //Quitte le jeu + void StartGame(); //Lance le jeu + void InitGame(); //Initialise le jeu + void StopGame(); //Quitte le jeu - void ShowFps(); //Affiche les FPS à l'écran - void HideFps(); //Cache les FPS de l'écran - void SetFpsWish(int v); //Set le nombre de FPS + void ShowFps(); //Affiche les FPS à l'écran + void HideFps(); //Cache les FPS de l'écran + void SetFpsWish(int v); //Set le nombre de FPS - void AddObject( Object * v); //Ajout un objet au moteur - void DelObject( Object * v); //Supprime l'objet - void DelAllObject(); //Supprime tout les objets + void AddObject( Object * v , int level = -1); //Ajout un objet au moteur + void DelObject( Object * v , bool destroy = true); //Supprime l'objet + void DelAllObject(); //Supprime tout les objets - Object ** GetListeObject(); //Renvoie un pointeur sur le tableau d'objet - int GetNbObject(); //Renvoie le nombre d'objet liés au moteur + Object ** GetListeObject(); //Renvoie un pointeur sur le tableau d'objet + int GetNbObject(); //Renvoie le nombre d'objet liés au moteur - void ExecuteScript(); - void AppliedForce(); - void Draw(); + void ExecuteScript(); + void AppliedForce(); + void Draw(); - AABB * GetScreen(); - void MoveScreen( int x ,int y); - void MiddleScreen(int x , int y , bool fixe = true); + AABB * GetScreen(); + void MoveScreen( int x ,int y); + void MiddleScreen(int x , int y , bool fixe = true); - void UpdateRelativePosition(); + void UpdateRelativePosition(); - #ifdef CE_MAP + void SetLevel( Level ** userTabLevel , int userNbLevel); + void SetLevel( Level * userLevel); - World * GetWorld(); - void SetWorld( World * v); + void DrawLevel(); - #endif + void SetCurrentLevel( int id); + Level * GetCurrentLevel(); + Level * GetLevel(int id); - private: + void MoveObject( Object * v , int destination = -2 ); - bool execute; + private: - int fpswish; - bool fps; + bool execute; - Object ** listeObject; //Tableau d'objet utilisé dans le cas ou il n'y a pas de map. - int nbobject; //Nombre d'objet liés au moteur. nb = Nombre + int fpswish; + bool fps; - AABB screen; + Object ** listeObject; //Tableau d'objet utilisé dans le cas ou il n'y a pas de map. + int nbobject; //Nombre d'objet liés au moteur. nb = Nombre - #ifdef CE_MAP + AABB screen; - World * engineWorld; + Level ** tabLevel; + int nbLevel; - #endif + int currentLevel; - }; +}; #endif diff --git a/include/Level.hpp b/include/Level.hpp new file mode 100644 index 0000000..91dc965 --- /dev/null +++ b/include/Level.hpp @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Level.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#ifndef CENGINE_LEVEL_HPP +#define CENGINE_LEVEL_HPP + +#include "..\Rework\CEngine.hpp" + +class Level +{ + public: + + Level();//Constructeur + + void AffectEngine( Engine * v ); + Engine * GetEngine(); + + void SetMap( const unsigned char * userTileset , unsigned char * userMap , bool * userProperties, int userTileWidth , int userTileHeight , int userWorldWidth , int userWorldHeight); + + int GetIdMap( int x, int y ); + void ReplaceIdMap( int x , int y, char v ); + + void DrawMap(); + + Object ** GetListeObject(); + int GetNbObject(); + + void AddObject( Object * v); //Ajout un objet au level + bool DelObject( Object * v , bool destroy = true); //Supprime l'objet + void DelAllObject(); //Supprime tout les objets + + int tileWidth; + int tileHeight; + + int levelWidth; + int levelHeight; + + bool * solid; + + private: + + Engine * engineLink; + + unsigned char * map; + + const unsigned char * tileset; + + int tilegap; + + Object ** listeObject; + int nbObject; +}; + +#endif diff --git a/include/Map/Level.hpp b/include/Map/Level.hpp deleted file mode 100644 index 018a762..0000000 --- a/include/Map/Level.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Level.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#ifndef CENGINE_LEVEL_HPP -#define CENGINE_LEVEL_HPP - -#include "..\Rework\CEngine.hpp" - - class Level - { - public: - - Level();//Constructeur - - void AffectWorld( World * v ); - World * GetWorld(); - - void SetMap( const unsigned char * userTileset , unsigned char * userMap , bool * userProperties, int userTileWidth , int userTileHeight , int userWorldWidth , int userWorldHeight); - - int GetIdMap( int x, int y ); - void ReplaceIdMap( int x , int y, char v ); - - void DrawMap(); - - Object ** GetListeObject(); - int GetNbObject(); - - void AddObject( Object * v); //Ajout un objet au level - bool DelObject( Object * v); //Supprime l'objet - void DelAllObject(); //Supprime tout les objets - - int tileWidth; - int tileHeight; - - int levelWidth; - int levelHeight; - - private: - - World * worldLink; - - unsigned char * map; - - const unsigned char * tileset; - bool * solid; - - int tilegap; - - int xscroll,yscroll; - - Object ** listeObject; - int nbObject; - }; - -#endif diff --git a/include/Map/World.hpp b/include/Map/World.hpp deleted file mode 100644 index 14fc780..0000000 --- a/include/Map/World.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* World.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#ifndef CENGINE_WORLD_HPP -#define CENGINE_WORLD_HPP - -#include "..\Rework\CEngine.hpp" - - class World - { - public: - - World();//Constructeur - - void AffectEngine(Engine * EV); - Engine * GetEngine(); - - void SetLevel( Level ** userTabLevel , int userNbLevel); - void SetLevel( Level * userLevel); - - void DrawLevel(); - - Level * GetCurrentLevel(); - Level * GetLevel(int id); - - void AddObject( Object * v, int level = -1); //Ajout un objet au level - void DelObject( Object * v); //Supprime l'objet - void DelAllObject(); //Supprime tout les objets - - private: - - Engine * engineLink; - - Level ** tabLevel; - int nbLevel; - - int currentLevel; - - }; - -#endif diff --git a/include/Object.hpp b/include/Object.hpp index b5dfb71..73304e6 100644 --- a/include/Object.hpp +++ b/include/Object.hpp @@ -1,10 +1,9 @@ /* ************************************************************************** */ -/* _____ */ -/* Object.hpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ +/* _____ _ __ ___ __ */ +/* Object.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ /* */ /* ************************************************************************** */ @@ -13,52 +12,53 @@ #include "..\Rework\CEngine.hpp" - class Object - { - public: +class Object +{ + public: - Object(); //Constructeur - ~Object(); + Object(); //Constructeur + ~Object(); - void AffectEngine(Engine * EV); - void AffectTag(char * v); + void AffectEngine(Engine * EV); + void AffectScript(Script * SV); + void AffectTag(char * v); - void Enable(); - void Disable(); + void Enable(); + void Disable(); - void AddRigidBody(); //Ajout un RigidBody + void AddRigidBody(); //Ajout un RigidBody - //Accesseur + //Accesseur - Engine * GetEngine(); - Transform * GetTransform(); - RigidBody * GetRigidBody(); - Render * GetRender(); - Script * GetScript(); + Engine * GetEngine(); + Transform * GetTransform(); + RigidBody * GetRigidBody(); + Render * GetRender(); + Script * GetScript(); - char * GetTag(); - bool GetEnable(); + char * GetTag(); + bool GetEnable(); - //Fonction pour les scripts + //Fonction pour les scripts - Object * GetObjectCollisionTag( char* v , int x = 0 , int y = 0); - bool GetCollisionTag( char * v , int x = 0 , int y = 0 ); + Object * GetObjectCollisionTag( char* v , int x = 0 , int y = 0); + bool GetCollisionTag( char * v , int x = 0 , int y = 0 ); - bool IsOnScreen(); + bool IsOnScreen(); - private: + private: - bool Collision(int id); + bool Collision(int id); - Transform * OTransform; - Render * ORender; - RigidBody * ORigidBody; - Script * OScript; - Engine * Conteneur; + Transform * OTransform; + Render * ORender; + RigidBody * ORigidBody; + Script * OScript; + Engine * Conteneur; - char * tag; - bool enable; + char * tag; + bool enable; - }; +}; #endif diff --git a/include/Object/Animation.hpp b/include/Object/Animation.hpp new file mode 100644 index 0000000..e64bcd9 --- /dev/null +++ b/include/Object/Animation.hpp @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Animation.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#ifndef CENGINE_ANIMATION_HPP +#define CENGINE_ANIMATION_HPP + +#include "..\Rework\CEngine.hpp" + +class Animation +{ + public: + + Animation(); + Animation(Sprite & v); + Animation(Sprite * v , int nb , int nbd = 250 , bool vwaitatend = false , bool vwaittheend = false );//Constructeur + + void SetIt(int v); + + int GetSizeX(); + int GetSizeY(); + + int GetBlitX(); + int GetBlitY(); + + void DrawReverseAnim( int , int , int); + void DrawAnim( int , int , int ); + + bool WaitDelay(); + + private: + + Sprite * TabSprite; + + int iterateur; + int delay; // En ms + int time; + int nb_image; + + bool waitatend; + bool waittheend; + bool isend; + +}; + +#endif diff --git a/include/Object/Render.hpp b/include/Object/Render.hpp new file mode 100644 index 0000000..05bb44d --- /dev/null +++ b/include/Object/Render.hpp @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Render.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#ifndef CENGINE_RENDER_HPP +#define CENGINE_RENDER_HPP + +#include "..\Rework\CEngine.hpp" + +class Render +{ + public: + + Render(Object * Pointeur); //Constructeur + ~Render(); + + void SetRender(Animation * v, int nb); + void SetRender(Animation & v); + + void CopieRender(Animation * v, int nb); + void CopieRender(Animation & v); + + void SetIt( int v ); + int GetIt(); + + void ReverseRender(bool); + bool GetReverse(); + + void SetDirection(int); + int GetDirection(); + + int GetSizeY(); + int GetSizeX(); + + int GetBlitX(); + int GetBlitY(); + + void DrawObject(); + + private: + + Object * Conteneur; + Animation * TabAnim; + + int nb_anim; + int iterateur; + int time; + + int direction; + bool reverse; + + bool copie; +}; + +#endif diff --git a/include/Object/RigidBody.hpp b/include/Object/RigidBody.hpp new file mode 100644 index 0000000..d927ac8 --- /dev/null +++ b/include/Object/RigidBody.hpp @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* RigidBody.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#ifndef CENGINE_RIGIDBODY_HPP +#define CENGINE_RIGIDBODY_HPP + +#include "..\Rework\CEngine.hpp" + +class RigidBody +{ + public: + + RigidBody(Object * Pointeur); //Constructeur + + void SetMass(float); + void UseFixeBody( int w , int h); + void UseFlexBody(); + + void AppliedForce(); + + int Move( int x , int y); + int TryMove( int x , int y); + int CollisionDecor( int x , int y); + void Affine(int vx , int vy); + + int GetWidht(); + int GetHeight(); + bool GetStat(); + + Body * GetBody(); + + private: + + Object * Conteneur; + + Body R_body; + + bool usefixebody; + int widht; + int height; +}; + +#endif diff --git a/include/Object/Script.hpp b/include/Object/Script.hpp new file mode 100644 index 0000000..b704edf --- /dev/null +++ b/include/Object/Script.hpp @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Script.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#ifndef CENGINE_SCRIPT_HPP +#define CENGINE_SCRIPT_HPP + +#include "..\Rework\CEngine.hpp" + +class Script +{ + public: + + Script(); //Constructeur + + virtual void Update(); + virtual void UpdateEverySecond(); + virtual void Start(); + + void AffectObject(Object * OV); + void AffectEngine(Engine * EV); + + Engine * GetEngine(); + Object * GetObject(); + + private: + + Object * OConteneur; + Engine * EConteneur; + + }; + +#endif diff --git a/include/Object/Sprite.hpp b/include/Object/Sprite.hpp new file mode 100644 index 0000000..977f130 --- /dev/null +++ b/include/Object/Sprite.hpp @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Sprite.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#ifndef CENGINE_SPRITE_HPP +#define CENGINE_SPRITE_HPP + +#include "..\Rework\CEngine.hpp" + +class Sprite +{ + public: + + Sprite(); + Sprite(const unsigned char * v1 , int sizex , int sizey , int bx = 0 , int by = 0 ); + Sprite(const unsigned char * v1 , const unsigned char * v2 , int sizex , int sizey , int bx = 0 , int by = 0 ); //Constructeur + + void DrawReverseSprite( int x , int y , int d ); + void DrawSprite( int x , int y , int d ); + + void CreateReverse( int brx = 0 , int bry = 0 ); + + int GetSizeY(); + int GetSizeX(); + + int GetBlitX(); + int GetBlitY(); + + private: + + const unsigned char * Beta; + const unsigned char * Alpha; + + unsigned char * ReverseBeta; + unsigned char * ReverseAlpha; + + int size_x; + int size_y; + + int b_x; + int b_y; + + int br_x; + int br_y; + +}; + +#endif diff --git a/include/Object/Transform.hpp b/include/Object/Transform.hpp new file mode 100644 index 0000000..001e93f --- /dev/null +++ b/include/Object/Transform.hpp @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Transform.hpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#ifndef CENGINE_TRANSFORM_HPP +#define CENGINE_TRANSFORM_HPP + +#include "..\Rework\CEngine.hpp" + +class Transform +{ + public: + + Transform(Object * Pointeur); //Constructeur + + double GetX(); + double GetY(); + + double GetRelativeX(); + double GetRelativeY(); + + void SetX(double v); + void SetY(double v); + void SetXY(double vx ,double vy); + + void SetRelativeXY(double vx ,double vy); + + private: + + Object * Conteneur; + + Vec2 positionabsolu; // en pixel + Vec2 positionrelative; // en pixel +}; + +#endif diff --git a/src/Components/Animation.cpp b/src/Components/Animation.cpp deleted file mode 100644 index e4729cc..0000000 --- a/src/Components/Animation.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Animation.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#include "..\Rework\include\Components\Animation.hpp" - - Animation::Animation() - { - TabSprite = NULL; - - nb_image = 0; - delay = 0; - iterateur = 0; - time = 0; - - waitatend = false; - waittheend = false; - isend = false; - } - - Animation::Animation(Sprite & v) - { - TabSprite = &v; - nb_image = 1; - } - - Animation::Animation(Sprite * v , int nb , int nbd , bool vwaitatend , bool vwaittheend) - { - TabSprite = v; - nb_image = nb; - delay = nbd; - - waitatend = vwaitatend; - waittheend = vwaittheend; - } - - void Animation::SetIt(int v) - { - iterateur = v; - time = RTC_getTicks(); - isend = false; - } - - int Animation::GetSizeY() - { - return TabSprite[iterateur].GetSizeY(); - } - - int Animation::GetSizeX() - { - return TabSprite[iterateur].GetSizeX(); - } - - int Animation::GetBlitX() - { - return TabSprite[iterateur].GetBlitX(); - } - - int Animation::GetBlitY() - { - return TabSprite[iterateur].GetBlitY(); - } - - - void Animation::DrawAnim ( int x , int y , int d) - { - if( iterateur >= nb_image) iterateur = 0; - - TabSprite[ iterateur ].DrawSprite( x , y , d); - - if(WaitDelay())iterateur ++; - - if( iterateur >= nb_image) - { - isend = true; - - if(!waitatend)iterateur = 0; - else iterateur = nb_image - 1; - } - - } - - void Animation::DrawReverseAnim ( int x , int y , int d) - { - if( iterateur >= nb_image) iterateur = 0; - - TabSprite[ iterateur ].DrawReverseSprite( x , y , d); - - if(WaitDelay())iterateur ++; - - if( iterateur >= nb_image) - { - isend = true; - - if(!waitatend)iterateur = 0; - else iterateur = nb_image - 1; - } - } - - bool Animation::WaitDelay() - { - - if(RTC_getTicks() - time > (delay / 7.8125)) // si il s'est écoulé une seconde complète - { - time = RTC_getTicks(); // et on se rappelle du nombre de ticks de la dernière seconde écoulée - return true; - } - - return false; - - } - diff --git a/src/Components/Render.cpp b/src/Components/Render.cpp deleted file mode 100644 index 0c4cc07..0000000 --- a/src/Components/Render.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Render.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#include "..\Rework\include\Components\Render.hpp" - - Render::Render(Object * Pointeur) - { - Conteneur = Pointeur; - TabAnim = NULL; - nb_anim = 0; - - iterateur = 0; - - reverse = false; - direction = 0; - - copie = false; - - } - - Render::~Render() - { - if(copie)delete TabAnim; - } - - void Render::SetRender(Animation * v, int nb) - { - TabAnim = v; - nb_anim = nb; - } - - void Render::SetRender(Animation & v) - { - TabAnim = &v; - nb_anim = 1; - } - - void Render::CopieRender(Animation * v, int nb) - { - TabAnim = new Animation[nb]; - - for(int i = 0; i < nb ; i++) - { - TabAnim[i] = v[i]; - } - - nb_anim = nb; - copie = true; - } - - void Render::CopieRender(Animation & v) - { - TabAnim = new Animation; - - TabAnim[0] = v; - - nb_anim = 1; - copie = true; - } - - void Render::SetIt(int v) - { - if(iterateur != v /*&& (!TabAnim[iterateur].GetWaittheEnd() || TabAnim[iterateur].GetisEnd())*/) - { - iterateur = v; - if( iterateur >= nb_anim) iterateur = 0; - TabAnim[ iterateur].SetIt(0); - } - } - - int Render::GetIt() - { - if(TabAnim)return iterateur; - - return 0; - } - - void Render::ReverseRender(bool v) - { - reverse = v; - } - - bool Render::GetReverse() - { - return reverse; - } - - void Render::SetDirection(int v) - { - direction = v; - - if(direction > 360) direction -= 360; - if(direction < 0) direction += 360; - } - - int Render::GetDirection() - { - return direction; - } - - int Render::GetSizeY() - { - if(TabAnim)return TabAnim[iterateur].GetSizeY(); - - return 0; - } - - int Render::GetSizeX() - { - if(TabAnim)return TabAnim[iterateur].GetSizeX(); - - return 0; - } - - int Render::GetBlitX() - { - if(TabAnim)return TabAnim[iterateur].GetBlitX(); - - return 0; - } - - int Render::GetBlitY() - { - if(TabAnim)return TabAnim[iterateur].GetBlitY(); - - return 0; - } - - void Render::DrawObject() - { - if(TabAnim) - { - if(!reverse) - { - TabAnim[ iterateur ].DrawAnim( Conteneur->GetTransform()->GetRelativeX() , 64 - Conteneur->GetTransform()->GetRelativeY() - GetSizeY() , direction); - } - else - { - TabAnim[ iterateur].DrawReverseAnim( Conteneur->GetTransform()->GetRelativeX() , 64 - Conteneur->GetTransform()->GetRelativeY() - GetSizeY() , direction); - } - - } - } diff --git a/src/Components/RigiBodys.cpp b/src/Components/RigiBodys.cpp deleted file mode 100644 index e2b24e1..0000000 --- a/src/Components/RigiBodys.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* RigidBody.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#include "..\Rework\include\Components\RigidBody.hpp" - - RigidBody::RigidBody(Object * Pointeur) - { - usefixebody = false; - widht = 0; - height = 0; - - Conteneur = Pointeur; - - R_body.transform = Conteneur->GetTransform(); - - R_body.velocity.x = 0; - R_body.velocity.y = 0; - - R_body.acceleration.x = 0; - R_body.acceleration.y = 0; - - R_body.mass_data.mass = 0; - R_body.mass_data.inv_mass = 0; - } - - void RigidBody::SetMass(float v) - { - R_body.mass_data.mass = v; - - if(v) - R_body.mass_data.inv_mass = 1 / v; - else - R_body.mass_data.inv_mass = 0; - } - - void RigidBody::UseFixeBody(int w , int h) - { - usefixebody = true; - widht = w; - height = h; - } - - void RigidBody::UseFlexBody() - { - usefixebody = false; - widht = 0; - height = 0; - } - - int RigidBody::GetHeight() - { - return height; - } - - int RigidBody::GetWidht() - { - return widht; - } - - bool RigidBody::GetStat() - { - return usefixebody; - } - - Body * RigidBody::GetBody() - { - return &R_body; - } - - void RigidBody::AppliedForce() - { - if(R_body.mass_data.mass > 0) - { - R_body.acceleration.x = R_body.force.x * R_body.mass_data.inv_mass + R_body.acceleration.x; - R_body.acceleration.y = R_body.force.y * R_body.mass_data.inv_mass + R_body.acceleration.y; - - R_body.velocity.x = R_body.velocity.x + (R_body.acceleration.x * 0.1); - R_body.velocity.y = R_body.velocity.y + (R_body.acceleration.y * 0.1); - - Move(R_body.velocity.x * 0.1, R_body.velocity.y * 0.1); - - R_body.force.x = 0; - R_body.force.y = 0; - R_body.acceleration.x = 0; - R_body.acceleration.y = 0; - } - } - - int RigidBody::Move(int x,int y) - { - if (TryMove( x, y))return 1; - - Affine(x,y); - - return 0; - } - - int RigidBody::TryMove( int x ,int y) - { - /*Map * m = Conteneur->GetEngine()->GetMap(); - - if(!m) - { - int tx = R_body.transform->GetX() + x; - int ty = R_body.transform->GetY() + y; - - R_body.transform->SetXY( tx , ty); - - return 1; - } - - if (x >= m->LARGEUR_TILE|| y>= m->HAUTEUR_TILE) - { - TryMove( x / 2 , y / 2 ); - TryMove( x / 2 , y / 2 ); - return 1; - }*/ - - int tx = R_body.transform->GetX() + x; - int ty = R_body.transform->GetY() + y; - - if (!CollisionDecor( tx , ty)) - { - R_body.transform->SetXY( tx , ty); - return 1; - } - else - { - if( x )R_body.velocity.x = 0 ; - if( y )R_body.velocity.y = 0 ; - } - - return 0; - - } - - int RigidBody::CollisionDecor( int x , int y) - { - /*if(Conteneur->GetEngine()->GetMap()) - { - Map * m = Conteneur->GetEngine()->GetMap(); - - int sizex , sizey; - - if(!usefixebody) - { - sizex = Conteneur->GetRender()->GetSizeX(); - sizey = Conteneur->GetRender()->GetSizeY(); - } - else - { - sizex = widht; - sizey = height; - } - - - if ( x < 0 || ( x + sizex ) > m->nbtiles_largeur_monde * m->LARGEUR_TILE || y + sizey > m->nbtiles_hauteur_monde * m->HAUTEUR_TILE || y < 2) return 1; - - int xmin,xmax,ymin,ymax,i,j,indicetile, hm; - - hm = m->nbtiles_hauteur_monde * m->HAUTEUR_TILE; - - xmin = x / m->LARGEUR_TILE; - ymin = (hm - y - sizey ) / m->HAUTEUR_TILE; - xmax = (x + sizex - 1) / m->LARGEUR_TILE; - ymax = (hm - y -1) / m->HAUTEUR_TILE; - - for( i = xmin ; i <= xmax ; i++ ) - { - for( j = ymin ; j <= ymax ; j++ ) - { - indicetile = m->GetIdMap(i,j); - - if (m->plein[indicetile])return 1; - } - } - - }*/ - - return 0; - } - - - void RigidBody::Affine(int vx,int vy) - { - int i; - - for( i = 0 ; i < abs(vx) ; i++) - { - if ( !TryMove ( sgn(vx) , 0 ) ) - break; - } - - for( i = 0 ; i < abs(vy) ; i++) - { - if ( !TryMove ( 0 , sgn(vy) ) ) - break; - } - } - - - - - - - - - - diff --git a/src/Components/Script.cpp b/src/Components/Script.cpp deleted file mode 100644 index 7ae318b..0000000 --- a/src/Components/Script.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Script.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#include "..\Rework\include\Components\Script.hpp" - - Script::Script() - { - OConteneur = NULL; - EConteneur = NULL; - } - - void Script::Start() - { - - } - - void Script::Update() - { - - } - - void Script::UpdateEverySecond() - { - - } - - void Script::AffectObject(Object * OV) - { - OConteneur = OV; - } - - void Script::AffectEngine(Engine * EV) - { - EConteneur = EV; - } - - Object * Script::GetObject() - { - return OConteneur; - } - - Engine * Script::GetEngine() - { - if(OConteneur) return OConteneur->GetEngine(); - - return EConteneur; - } - - - diff --git a/src/Components/Sprite.cpp b/src/Components/Sprite.cpp deleted file mode 100644 index 56741d7..0000000 --- a/src/Components/Sprite.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Sprite.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#include "..\Rework\include\Components\Sprite.hpp" - - Sprite::Sprite() - { - Alpha = NULL; - Beta = NULL; - - ReverseAlpha = NULL; - ReverseBeta = NULL; - } - - Sprite::Sprite(const unsigned char * v1, int sizex, int sizey , int bx , int by) - { - Beta=v1; - size_x=sizex; - size_y=sizey; - - b_x = bx; - b_y = by; - - Alpha = NULL; - - ReverseAlpha = NULL; - ReverseBeta = NULL; - } - - Sprite::Sprite(const unsigned char * v1, const unsigned char * v2, int sizex, int sizey , int bx, int by) - { - Beta=v1; - Alpha = v2; - - size_x=sizex; - size_y=sizey; - - b_x = bx; - b_y = by; - - ReverseAlpha = NULL; - ReverseBeta = NULL; - } - - void Sprite::DrawReverseSprite( int x , int y , int d) - { - switch(d) - { - case 90: if(size_y % 2 == 0)y --; break; - case 180: if(size_y % 2 == 0)y --; if(size_x % 2 == 0)x --; break; - case 270: if(size_x % 2 == 0)x --; break; - } - - if(ReverseBeta) - { - if(ReverseAlpha) - { - ML_bmp_or_rotate((const unsigned char*) ReverseAlpha, x + br_x, y + br_y, size_x , size_y, d); // Affichage du canal alpha - ML_bmp_and_rotate((const unsigned char*) ReverseBeta, x +br_x, y +br_y, size_x , size_y, d); // Affichage du sprite en entier - } - else - { - ML_bmp_or_rotate((const unsigned char*) ReverseBeta, x +br_x , y +br_y, size_x , size_y , d); // Affichage du sprite en entier - } - - } - else - { - DrawSprite( x , y , d); - } - } - - void Sprite::DrawSprite( int x , int y , int d) - { - switch(d) - { - case 90: if(size_y % 2 == 0)y --; break; - case 180: if(size_y % 2 == 0)y --; if(size_x % 2 == 0)x --; break; - case 270: if(size_x % 2 == 0)x --; break; - } - - if(Beta) - { - if(Alpha) - { - ML_bmp_or_rotate((const unsigned char*) Alpha, x + b_x, y + b_y, size_x , size_y , d); // Affichage du canal alpha - ML_bmp_and_rotate((const unsigned char*) Beta, x +b_x, y +b_y, size_x , size_y ,d); // Affichage du sprite en entier - } - else - { - ML_bmp_or_rotate((const unsigned char*) Beta, x +b_x , y +b_y, size_x , size_y , d); // Affichage du sprite en entier - } - - } - } - - void Sprite::CreateReverse( int brx , int bry) - { - int taille, lx , decalage; - - unsigned char transit; - unsigned char out ; - - br_x = brx; - br_y = bry; - - decalage = size_x % 8; - - lx = size_x / 8 + ( decalage != 0 ); - - taille = lx * size_y; - - if(Beta) - { - ReverseBeta = (unsigned char*) malloc(sizeof(unsigned char) * taille); - - for( int i = 0 ; i < size_y ; i++ ) - for( int a = 0 ; a < lx ; a++ ) - ReverseBeta[i * lx + a] = Beta[ (i + 1) * lx - (a + 1)]; - - for(int i = 0; i < taille ; i++) - { - transit = ReverseBeta[i]; - - out = 0x0; - - if((transit & 0x80) != 0x0) out = out | 0x01; - if((transit & 0x40) != 0x0) out = out | 0x02; - if((transit & 0x20) != 0x0) out = out | 0x04; - if((transit & 0x10) != 0x0) out = out | 0x08; - if((transit & 0x08) != 0x0) out = out | 0x10; - if((transit & 0x04) != 0x0) out = out | 0x20; - if((transit & 0x02) != 0x0) out = out | 0x40; - if((transit & 0x01) != 0x0) out = out | 0x80; - - ReverseBeta[i] = out; - } - - if(decalage) - { - for(int i = 0 ; i < size_y ; i++ ) - for(int a = 0 ; a < lx ; a++ ) - { - transit = ((unsigned char)ReverseBeta[i * lx + a] >> ( decalage)); - - ReverseBeta[i * lx + a] = ((unsigned char)ReverseBeta[i * lx + a] << ( 8 - decalage)); - - if(a != 0)ReverseBeta[i * lx + a - 1] = ReverseBeta[i * lx + a - 1] | transit; - } - - } - } - - - if(Alpha) - { - ReverseAlpha = (unsigned char*) malloc(sizeof(unsigned char) * taille); - - for(int i = 0 ; i < size_y ; i++) - for(int a = 0; a < lx; a++) - ReverseAlpha[i * lx + a] = Alpha[ (i +1)*lx - (a+1)]; - - for(int i = 0; i < taille ; i++) - { - transit = ReverseAlpha[i]; - - out = 0x0; - - if((transit & 0x80) != 0x0) out = out | 0x01; - if((transit & 0x40) != 0x0) out = out | 0x02; - if((transit & 0x20) != 0x0) out = out | 0x04; - if((transit & 0x10) != 0x0) out = out | 0x08; - if((transit & 0x08) != 0x0) out = out | 0x10; - if((transit & 0x04) != 0x0) out = out | 0x20; - if((transit & 0x02) != 0x0) out = out | 0x40; - if((transit & 0x01) != 0x0) out = out | 0x80; - - ReverseAlpha[i] = out; - } - - if(decalage) - { - for(int i = 0 ; i < size_y ; i++ ) - for(int a = 0 ; a < lx ; a++ ) - { - transit = ((unsigned char)ReverseAlpha[i * lx + a] >> ( decalage)); - - ReverseAlpha[i * lx + a] = ((unsigned char)ReverseAlpha[i * lx + a] << ( 8 - decalage)); - - if(a)ReverseAlpha[i * lx + a - 1] = ReverseAlpha[i * lx + a - 1] | transit; - } - - } - - - } - - - } - - int Sprite::GetSizeY() - { - return size_y; - } - - int Sprite::GetSizeX() - { - return size_x; - } - - int Sprite::GetBlitX() - { - return b_x; - } - - int Sprite::GetBlitY() - { - return b_y; - } diff --git a/src/Components/Transforms.cpp b/src/Components/Transforms.cpp deleted file mode 100644 index 803d653..0000000 --- a/src/Components/Transforms.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Transform.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#include "..\Rework\include\Components\Transform.hpp" - - Transform::Transform(Object * Pointeur) - { - Conteneur = Pointeur; - - positionabsolu.x = 0; - positionabsolu.y = 0; - - positionrelative.x = 0; - positionrelative.y = 0; - } - - double Transform::GetX() - { - return positionabsolu.x; - } - - double Transform::GetY() - { - return positionabsolu.y; - } - - double Transform::GetRelativeX() - { - return positionrelative.x; - } - - double Transform::GetRelativeY() - { - return positionrelative.y; - } - - void Transform::SetX(double v) - { - positionabsolu.x = v; - } - - void Transform::SetY(double v) - { - positionabsolu.y = v; - } - - void Transform::SetXY(double vx ,double vy) - { - positionabsolu.x = vx; - positionabsolu.y = vy; - } - - void Transform::SetRelativeXY(double vx ,double vy) - { - positionrelative.x = vx; - positionrelative.y = vy; - } - - diff --git a/src/Engine.cpp b/src/Engine.cpp index 550563a..86392c1 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -1,10 +1,9 @@ /* ************************************************************************** */ -/* _____ */ -/* Engine.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ +/* _____ _ __ ___ __ */ +/* Engine.cpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ /* */ /* ************************************************************************** */ @@ -24,310 +23,373 @@ #include "..\Rework\include\Engine.hpp" - Engine::Engine() +Engine::Engine() +{ + execute = true; + + fps = false; + fpswish = 4; + + listeObject = NULL; + nbobject = 0; + + screen.min.x = 0; + screen.min.y = 0; + + screen.max.x = 128; + screen.max.y = 64; + + tabLevel = NULL; + nbLevel = 0; + currentLevel = 0; +} + +void Engine::StartGame() +{ + InitGame(); + + while(execute) { - execute = true; + ML_clear_vram(); + input_update(); - fps = false; - fpswish = 4; + ExecuteScript(); + AppliedForce(); + UpdateRelativePosition(); + Draw(); - listeObject = NULL; - nbobject = 0; - - screen.min.x = 0; - screen.min.y = 0; - - screen.max.x = 128; - screen.max.y = 64; - - #ifdef CE_MAP - engineWorld = NULL; - #endif + setFps(fpswish); + ML_display_vram(); } - void Engine::StartGame() + DelAllObject(); +} + +void Engine::InitGame() +{ + execute = true; + + srand(RTC_getTicks()); + + for( int i = 0 ; i < nbobject ; i++ ) { - InitGame(); - - while(execute) - { - ML_clear_vram(); - input_update(); - - ExecuteScript(); - AppliedForce(); - UpdateRelativePosition(); - Draw(); - - setFps(fpswish); - - ML_display_vram(); - } - - DelAllObject(); + if(listeObject[i]->GetScript() && listeObject[i]->GetEnable())listeObject[i]->GetScript()->Start(); } - void Engine::InitGame() + if(tabLevel) + for( int i = 0 ; i < nbLevel ; i++ ) + for( int j = 0 ; j < tabLevel[i]->GetNbObject() ; j++ ) + if(tabLevel[i]->GetListeObject()[j]->GetScript() && tabLevel[i]->GetListeObject()[j]->GetEnable())tabLevel[i]->GetListeObject()[j]->GetScript()->Start(); +} + +void Engine::StopGame() +{ + execute = false; +} + +void Engine::ShowFps() +{ + fps = true; +} + +void Engine::HideFps() +{ + fps = false; +} + +void Engine::SetFpsWish(int v) +{ + fpswish = 180 / v; +} + +void Engine::AddObject( Object * v , int level) +{ + if(level == -1 && tabLevel) { - execute = true; - - srand(RTC_getTicks()); - - for( int i = 0 ; i < nbobject ; i++ ) - { - if(listeObject[i]->GetScript() && listeObject[i]->GetEnable())listeObject[i]->GetScript()->Start(); - } + tabLevel[currentLevel]->AddObject(v); + return; } - void Engine::StopGame() + if( level < nbLevel && level >= 0 && tabLevel) { - execute = false; + tabLevel[level]->AddObject(v); + return; } - void Engine::ShowFps() + Object ** Tab = listeObject; //On créai un pointeur sur la liste actuelle d'objet + + listeObject = (Object**) malloc( sizeof(Object *) * ( nbobject + 1 ) );//On alloue l'espace nécéssaire pour le nouveau tableau + + for( int i = 0 ; i < nbobject ; i++ )//On copie les pointeurs + listeObject[i] = Tab[i]; + + listeObject[ nbobject ] = v; //Et on rajoute l'objet + v->AffectEngine(this); + + nbobject ++; + + delete Tab; +} + +void Engine::DelObject( Object * v , bool destroy ) +{ + if(tabLevel) { - fps = true; - } - - void Engine::HideFps() - { - fps = false; - } - - void Engine::SetFpsWish(int v) - { - fpswish = 180 / v; - } - - void Engine::AddObject( Object * v) - { - #ifdef CE_MAP - if(engineWorld) - { - engineWorld->AddObject(v); - return; - } - #endif - - Object ** Tab = listeObject; //On créai un pointeur sur la liste actuelle d'objet - - listeObject = (Object**) malloc( sizeof(Object *) * ( nbobject + 1 ) );//On alloue l'espace nécéssaire pour le nouveau tableau - - for( int i = 0 ; i < nbobject ; i++ )//On copie les pointeurs - listeObject[i] = Tab[i]; - - listeObject[ nbobject ] = v; //Et on rajoute l'objet - v->AffectEngine(this); - - nbobject ++; - - delete Tab; - } - - void Engine::DelObject( Object * v) - { - #ifdef CE_MAP - if(engineWorld) - { - engineWorld->DelObject(v); - return; - } - #endif - - Object ** Tab = listeObject; - int index = -1; - - if(!Tab)return; - - for( int i = 0 ; i < nbobject ; i++ ) - if(Tab[i] == v ) - index = i ; - - if(index == -1)return; - - listeObject = (Object**) malloc( sizeof(Object *) * ( nbobject - 1) ); - - for( int i = 0 ; i < index ; i++ ) - listeObject[ i ] = Tab[ i ]; - - for(int i = index + 1 ; i < nbobject ; i++ ) - listeObject[ i - 1] = Tab[ i ]; - - nbobject --; - delete v; - delete Tab; - } - - void Engine::DelAllObject() - { - #ifdef CE_MAP - if(engineWorld) - { - engineWorld->DelAllObject(); - } - #endif - - for(int i = 0 ; i < nbobject ; i++) - delete listeObject[i]; - - delete listeObject; - listeObject = NULL; - } - - Object ** Engine::GetListeObject() - { - return listeObject; - } - - int Engine::GetNbObject() - { - return nbobject; - } - - void Engine::ExecuteScript() - { - for( int i = 0 ; i < nbobject ; i++ ) - { - if( listeObject[i]->GetEnable()) - if(listeObject[i]->GetScript()) - listeObject[i]->GetScript()->Update(); - } - } - - void Engine::AppliedForce() - { - for( int i = 0 ; i < nbobject ; i++ ) - { - if( listeObject[i]->GetEnable()) - if(listeObject[i]->GetRigidBody()) - listeObject[i]->GetRigidBody()->AppliedForce(); - } - } - - void Engine::Draw() - { - - #ifdef CE_MAP - if(engineWorld) - { - engineWorld->GetCurrentLevel()->DrawMap(); - - for( int i = 0 ; i < engineWorld->GetCurrentLevel()->GetNbObject() ; i++ ) - { - if( engineWorld->GetCurrentLevel()->GetListeObject()[i]->GetEnable()) - if(engineWorld->GetCurrentLevel()->GetListeObject()[i]->GetRender()) - engineWorld->GetCurrentLevel()->GetListeObject()[i]->GetRender()->DrawObject(); - } - } - else - { - for( int i = 0 ; i < nbobject ; i++ ) - { - if( listeObject[i]->GetEnable()) - if(listeObject[i]->GetRender()) - listeObject[i]->GetRender()->DrawObject(); - } - } - #else - - for( int i = 0 ; i < nbobject ; i++ ) - { - if( listeObject[i]->GetEnable()) - if(listeObject[i]->GetRender()) - listeObject[i]->GetRender()->DrawObject(); - } - - #endif - - if(fps) PrintV(110,2,getFps()); - } - - AABB * Engine::GetScreen() - { - return &screen; - } - - void Engine::MoveScreen(int x , int y) - { - screen.min.x = x; - screen.max.x = x + 64; - screen.min.y = y; - screen.max.y = y + 128; - } - - void Engine::MiddleScreen(int x , int y , bool fixe) - { - screen.min.x = x - 32; - screen.max.x = x + 32; - screen.min.y = y - 64; - screen.max.y = y + 64; - - if(fixe) + if(!tabLevel[currentLevel]->DelObject(v , destroy )) { - if( screen.min.x < 0 ) + for(int i = 0 ; i < nbLevel ; i++ ) { - screen.min.x = 0; - screen.max.x = 128; + if(tabLevel[i]->DelObject(v , destroy ))return; } - - if(screen.min.y < 0) - { - screen.min.y = 0; - screen.max.y = 63; - } - - #ifdef CE_MAP - if(engineWorld) - { - if(screen.max.x > engineWorld->GetCurrentLevel()->levelWidth * engineWorld->GetCurrentLevel()->tileWidth) - { - screen.max.x = engineWorld->GetCurrentLevel()->levelWidth * engineWorld->GetCurrentLevel()->tileWidth; - screen.min.x = screen.max.x - 128; - } - - if(screen.max.y > engineWorld->GetCurrentLevel()->levelHeight * engineWorld->GetCurrentLevel()->tileHeight) - { - screen.max.y = engineWorld->GetCurrentLevel()->levelHeight * engineWorld->GetCurrentLevel()->tileHeight; - screen.min.y = screen.max.y - 64; - } - } - #endif // CE_MAP } } - void Engine::UpdateRelativePosition() - { - #ifdef CE_MAP - if(engineWorld) - { - for( int i = 0 ; i < engineWorld->GetCurrentLevel()->GetNbObject() ; i++ ) - { - if( engineWorld->GetCurrentLevel()->GetListeObject()[i]->GetEnable()) - engineWorld->GetCurrentLevel()->GetListeObject()[i]->GetTransform()->SetRelativeXY( engineWorld->GetCurrentLevel()->GetListeObject()[i]->GetTransform()->GetX() - screen.min.x , engineWorld->GetCurrentLevel()->GetListeObject()[i]->GetTransform()->GetY() - screen.min.y ); - } - } - #endif // CE_MAP + Object ** Tab = listeObject; + int index = -1; - for( int i = 0 ; i < nbobject; i++ ) + if(!Tab)return; + + for( int i = 0 ; i < nbobject ; i++ ) + if(Tab[i] == v ) + index = i ; + + if(index == -1)return; + + listeObject = (Object**) malloc( sizeof(Object *) * ( nbobject - 1) ); + + for( int i = 0 ; i < index ; i++ ) + listeObject[ i ] = Tab[ i ]; + + for(int i = index + 1 ; i < nbobject ; i++ ) + listeObject[ i - 1] = Tab[ i ]; + + nbobject --; + + if(destroy)delete v; + + delete Tab; +} + +void Engine::DelAllObject() +{ + if(tabLevel) + { + for(int i = 0 ; i < nbLevel ; i++ ) { - if(listeObject[i]->GetEnable()) - listeObject[i]->GetTransform()->SetRelativeXY( listeObject[i]->GetTransform()->GetX() - screen.min.x , listeObject[i]->GetTransform()->GetY() - screen.min.y ); + tabLevel[i]->DelAllObject(); } } + for(int i = 0 ; i < nbobject ; i++) + delete listeObject[i]; - #ifdef CE_MAP + delete listeObject; + listeObject = NULL; +} - World * Engine::GetWorld() +Object ** Engine::GetListeObject() +{ + return listeObject; +} + +int Engine::GetNbObject() +{ + return nbobject; +} + +void Engine::ExecuteScript() +{ + if(tabLevel && currentLevel != -1) + { + for( int i = 0 ; i < GetCurrentLevel()->GetNbObject() ; i++ ) { - return engineWorld; + if( GetCurrentLevel()->GetListeObject()[i]->GetEnable()) + if(GetCurrentLevel()->GetListeObject()[i]->GetScript()) + GetCurrentLevel()->GetListeObject()[i]->GetScript()->Update(); + } + } + else + { + for( int i = 0 ; i < nbobject ; i++ ) + { + if( listeObject[i]->GetEnable()) + if(listeObject[i]->GetScript()) + listeObject[i]->GetScript()->Update(); + } + } +} + +void Engine::AppliedForce() +{ + if(tabLevel && currentLevel != -1) + { + for( int i = 0 ; i < GetCurrentLevel()->GetNbObject() ; i++ ) + { + if( GetCurrentLevel()->GetListeObject()[i]->GetEnable()) + if(GetCurrentLevel()->GetListeObject()[i]->GetRigidBody()) + GetCurrentLevel()->GetListeObject()[i]->GetRigidBody()->AppliedForce(); + } + } + else + { + for( int i = 0 ; i < nbobject ; i++ ) + { + if( listeObject[i]->GetEnable()) + if(listeObject[i]->GetRigidBody()) + listeObject[i]->GetRigidBody()->AppliedForce(); + } + } +} + +void Engine::Draw() +{ + if(tabLevel && currentLevel != -1) + { + GetCurrentLevel()->DrawMap(); + + for( int i = 0 ; i < GetCurrentLevel()->GetNbObject() ; i++ ) + { + if( GetCurrentLevel()->GetListeObject()[i]->GetEnable()) + if(GetCurrentLevel()->GetListeObject()[i]->GetRender()) + GetCurrentLevel()->GetListeObject()[i]->GetRender()->DrawObject(); + } + } + else + { + for( int i = 0 ; i < nbobject ; i++ ) + { + if( listeObject[i]->GetEnable()) + if(listeObject[i]->GetRender()) + listeObject[i]->GetRender()->DrawObject(); + } + } + + if(fps) PrintV(110,2,getFps()); +} + +AABB * Engine::GetScreen() +{ + return &screen; +} + +void Engine::MoveScreen(int x , int y) +{ + screen.min.x = x; + screen.max.x = x + 64; + screen.min.y = y; + screen.max.y = y + 128; +} + +void Engine::MiddleScreen(int x , int y , bool fixe) +{ + screen.min.x = x - 64; + screen.max.x = x + 64; + screen.min.y = y - 32; + screen.max.y = y + 32; + + if(fixe) + { + if( screen.min.x < 0 ) + { + screen.min.x = 0; + screen.max.x = 128; } - void Engine::SetWorld( World * v) + if(screen.min.y < 0) { - engineWorld = v; - engineWorld->AffectEngine(this); + screen.min.y = 0; + screen.max.y = 63; } - #endif + if(tabLevel && currentLevel != -1) + { + if(screen.max.x > GetCurrentLevel()->levelWidth * GetCurrentLevel()->tileWidth) + { + screen.max.x = GetCurrentLevel()->levelWidth * GetCurrentLevel()->tileWidth; + screen.min.x = screen.max.x - 128; + } + + if(screen.max.y > GetCurrentLevel()->levelHeight * GetCurrentLevel()->tileHeight) + { + screen.max.y = GetCurrentLevel()->levelHeight * GetCurrentLevel()->tileHeight; + screen.min.y = screen.max.y - 64; + } + } + } +} + +void Engine::UpdateRelativePosition() +{ + if(tabLevel && currentLevel != -1) + { + for( int i = 0 ; i < GetCurrentLevel()->GetNbObject() ; i++ ) + { + if( GetCurrentLevel()->GetListeObject()[i]->GetEnable()) + GetCurrentLevel()->GetListeObject()[i]->GetTransform()->SetRelativeXY( GetCurrentLevel()->GetListeObject()[i]->GetTransform()->GetX() - screen.min.x , GetCurrentLevel()->GetListeObject()[i]->GetTransform()->GetY() - screen.min.y ); + } + } + + for( int i = 0 ; i < nbobject; i++ ) + { + if(listeObject[i]->GetEnable()) + listeObject[i]->GetTransform()->SetRelativeXY( listeObject[i]->GetTransform()->GetX() - screen.min.x , listeObject[i]->GetTransform()->GetY() - screen.min.y ); + } +} + + +void Engine::SetLevel( Level ** userTabLevel , int userNbLevel) +{ + tabLevel = userTabLevel; + nbLevel = userNbLevel; + + for(int i = 0 ; i < nbLevel ; i++ ) + tabLevel[i]->AffectEngine(this); +} + +void Engine::SetLevel( Level * userLevel) +{ + tabLevel = new Level*[1]; + tabLevel[0] = userLevel; + + nbLevel = 1; + + userLevel->AffectEngine(this); +} + +void Engine::SetCurrentLevel( int id) +{ + if( id < 0 || id >= nbLevel) + currentLevel = - 1; + else + currentLevel = id; +} + +void Engine::DrawLevel() +{ + if(tabLevel && currentLevel != -1 )tabLevel[currentLevel]->DrawMap(); +} + +Level * Engine::GetCurrentLevel() +{ + if(currentLevel != -1) + return tabLevel[currentLevel]; + else + return NULL; +} + +Level * Engine::GetLevel(int id) +{ + if(id > -1 && id < nbLevel) + return tabLevel[id]; + else + return NULL; +} + +void Engine::MoveObject(Object * v , int destination) +{ + DelObject( v , false ); + + AddObject( v , destination ); +} + diff --git a/src/Level.cpp b/src/Level.cpp new file mode 100644 index 0000000..ccddf0c --- /dev/null +++ b/src/Level.cpp @@ -0,0 +1,156 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Level.cpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#include "..\Rework\include\Level.hpp" + +Level::Level() +{ + engineLink = NULL; + listeObject = NULL; + nbObject = 0; + + tileset = NULL; + map = NULL; + solid = NULL; + + tileHeight = 0; + tileWidth = 0; + tilegap = 0; + + levelHeight = 0; + levelWidth = 0; + +} + +void Level::AffectEngine( Engine * v ) +{ + engineLink = v; +} + +Engine * Level::GetEngine() +{ + return engineLink; +} + +void Level::SetMap( const unsigned char * userTileset , unsigned char * userMap , bool * userProperties, int userTileWidth , int userTileHeight , int userWorldWidth , int userWorldHeight) +{ + + tileset = userTileset; + map = userMap; + solid = userProperties; + + tileWidth = userTileWidth; + tileHeight = userTileHeight; + + tilegap = userTileHeight / 8; + if(userTileHeight % 8)tilegap++; + + levelWidth = userWorldWidth; + levelHeight = userWorldHeight; + +} + +int Level::GetIdMap( int x , int y ) +{ + return *(map + levelWidth * y + x); +} + +void Level::ReplaceIdMap( int x , int y , char v ) +{ + *(map + levelWidth * y + x) = v; +} + +void Level::DrawMap() +{ + int dy = levelHeight * tileHeight - engineLink->GetScreen()->max.y ; + + int minx = engineLink->GetScreen()->min.x / tileWidth ; + int miny = dy / tileHeight ; + + int maxx = 128 / tileWidth + minx + 2; + int maxy = 64 / tileHeight + miny + 2; + + int xscroll = engineLink->GetScreen()->min.x ; + int yscroll = dy % tileHeight; + + for( int i = minx; i < maxx; i++) + { + for( int j = miny ; j < maxy; j++) + { + if (!(i < 0 || i >= levelWidth || j < 0 || j >= levelHeight)) + ML_bmp_or_cl( tileset + tileHeight * tilegap * GetIdMap(i,j), (i * tileWidth ) - xscroll , ((j - miny) * tileHeight) - yscroll, tileWidth , tileHeight); + } + } +} + +Object ** Level::GetListeObject() +{ + return listeObject; +} + +int Level::GetNbObject() +{ + return nbObject; +} + +void Level::AddObject( Object * v) +{ + Object ** Tab = listeObject; //On créai un pointeur sur la liste actuelle d'objet + + listeObject = (Object**) malloc( sizeof(Object *) * ( nbObject + 1 ) );//On alloue l'espace nécéssaire pour le nouveau tableau + + for( int i = 0 ; i < nbObject ; i++ )//On copie les pointeurs + listeObject[i] = Tab[i]; + + listeObject[ nbObject ] = v; //Et on rajoute l'objet + v->AffectEngine(GetEngine()); + + nbObject ++; + + delete Tab; +} + +bool Level::DelObject( Object * v , bool destroy) +{ + Object ** Tab = listeObject; + int index = -1; + + if(!Tab)return false; + + for( int i = 0 ; i < nbObject ; i++ ) + if(Tab[i] == v ) + index = i ; + + if(index == -1)return false; + + listeObject = (Object**) malloc( sizeof(Object *) * ( nbObject - 1) ); + + for( int i = 0 ; i < index ; i++ ) + listeObject[ i ] = Tab[ i ]; + + for(int i = index + 1 ; i < nbObject ; i++ ) + listeObject[ i - 1] = Tab[ i ]; + + nbObject --; + + if(destroy)delete v; + + delete Tab; + + return true; +} + +void Level::DelAllObject() +{ + for(int i = 0 ; i < nbObject ; i++) + delete listeObject[i]; + + delete listeObject; + listeObject = NULL; +} diff --git a/src/Map/Level.cpp b/src/Map/Level.cpp deleted file mode 100644 index e002575..0000000 --- a/src/Map/Level.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* Level.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#include "..\Rework\include\Map\Level.hpp" - - Level::Level() - { - worldLink = NULL; - listeObject = NULL; - nbObject = 0; - - tileset = NULL; - map = NULL; - solid = NULL; - - tileHeight = 0; - tileWidth = 0; - tilegap = 0; - - levelHeight = 0; - levelWidth = 0; - - xscroll = 0; - yscroll = 0; - } - - void Level::AffectWorld( World * v ) - { - worldLink = v; - } - - World * Level::GetWorld() - { - return worldLink; - } - - void Level::SetMap( const unsigned char * userTileset , unsigned char * userMap , bool * userProperties, int userTileWidth , int userTileHeight , int userWorldWidth , int userWorldHeight) - { - - tileset = userTileset; - map = userMap; - solid = userProperties; - - tileWidth = userTileWidth; - tileHeight = userTileHeight; - - tilegap = userTileHeight / 8; - if(userTileHeight % 8)tilegap++; - - levelWidth = userWorldWidth; - levelHeight = userWorldHeight; - - } - - int Level::GetIdMap( int x , int y ) - { - return *(map + levelWidth * y + x); - } - - void Level::ReplaceIdMap( int x , int y , char v ) - { - *(map + levelWidth * y + x) = v; - } - - void Level::DrawMap() - { - int minx,maxx,miny,maxy; - - int dy = levelHeight * tileHeight - worldLink->GetEngine()->GetScreen()->max.y ; - - minx = worldLink->GetEngine()->GetScreen()->min.x / tileWidth ; - miny = dy / tileHeight ; - - maxx = 128 / tileWidth + minx + 2; - maxy = 64 / tileHeight + miny + 2; - - xscroll = worldLink->GetEngine()->GetScreen()->min.x ; - yscroll = dy % tileHeight; - - for( int i = minx; i < maxx; i++) - { - for( int j = miny ; j < maxy; j++) - { - if (!(i < 0 || i >= levelWidth || j < 0 || j >= levelHeight)) - ML_bmp_or_cl( tileset + tileHeight * tilegap * GetIdMap(i,j), (i * tileWidth ) - xscroll , ((j - miny) * tileHeight) - yscroll, tileWidth , tileHeight); - } - } - } - - Object ** Level::GetListeObject() - { - return listeObject; - } - - int Level::GetNbObject() - { - return nbObject; - } - - void Level::AddObject( Object * v) - { - Object ** Tab = listeObject; //On créai un pointeur sur la liste actuelle d'objet - - listeObject = (Object**) malloc( sizeof(Object *) * ( nbObject + 1 ) );//On alloue l'espace nécéssaire pour le nouveau tableau - - for( int i = 0 ; i < nbObject ; i++ )//On copie les pointeurs - listeObject[i] = Tab[i]; - - listeObject[ nbObject ] = v; //Et on rajoute l'objet - v->AffectEngine(GetWorld()->GetEngine()); - - nbObject ++; - - delete Tab; - } - - bool Level::DelObject( Object * v) - { - Object ** Tab = listeObject; - int index = -1; - - if(!Tab)return false; - - for( int i = 0 ; i < nbObject ; i++ ) - if(Tab[i] == v ) - index = i ; - - if(index == -1)return false; - - listeObject = (Object**) malloc( sizeof(Object *) * ( nbObject - 1) ); - - for( int i = 0 ; i < index ; i++ ) - listeObject[ i ] = Tab[ i ]; - - for(int i = index + 1 ; i < nbObject ; i++ ) - listeObject[ i - 1] = Tab[ i ]; - - nbObject --; - delete v; - delete Tab; - - return true; - } - - void Level::DelAllObject() - { - for(int i = 0 ; i < nbObject ; i++) - delete listeObject[i]; - - delete listeObject; - listeObject = NULL; - } - - - diff --git a/src/Map/World.cpp b/src/Map/World.cpp deleted file mode 100644 index 50fcbe9..0000000 --- a/src/Map/World.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* ************************************************************************** */ -/* _____ */ -/* World.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ -/* */ -/* ************************************************************************** */ - -#include "..\Rework\include\Map\World.hpp" - - World::World() - { - tabLevel = NULL; - nbLevel = 0; - currentLevel = 0; - engineLink = NULL; - } - - void World::AffectEngine(Engine * EV) - { - engineLink = EV; - } - - Engine * World::GetEngine() - { - return engineLink; - } - - void World::SetLevel( Level ** userTabLevel , int userNbLevel) - { - tabLevel = userTabLevel; - nbLevel = userNbLevel; - - for(int i = 0 ; i < nbLevel ; i++ ) - tabLevel[i]->AffectWorld(this); - } - - void World::SetLevel( Level * userLevel) - { - tabLevel = new Level*[1]; - tabLevel[0] = userLevel; - - nbLevel = 1; - - userLevel->AffectWorld(this); - } - - void World::DrawLevel() - { - if(tabLevel)tabLevel[currentLevel]->DrawMap(); - } - - Level * World::GetCurrentLevel() - { - return tabLevel[currentLevel]; - } - - Level * World::GetLevel(int id) - { - return tabLevel[id]; - } - - void World::AddObject( Object * v, int level) - { - if(level < 0 && tabLevel)tabLevel[currentLevel]->AddObject(v); - - if( level < nbLevel && level >= 0 && tabLevel) - { - tabLevel[level]->AddObject(v); - } - } - - void World::DelObject( Object * v) - { - if(tabLevel) - { - if(!tabLevel[currentLevel]->DelObject(v)) - { - for(int i = 0 ; i < nbLevel ; i++ ) - { - if(tabLevel[i]->DelObject(v))return; - } - } - } - } - - void World::DelAllObject() - { - if(tabLevel) - { - for(int i = 0 ; i < nbLevel ; i++ ) - { - tabLevel[i]->DelAllObject(); - } - } - } diff --git a/src/Object.cpp b/src/Object.cpp index dd435b7..5c5ad5b 100644 --- a/src/Object.cpp +++ b/src/Object.cpp @@ -1,162 +1,167 @@ /* ************************************************************************** */ -/* _____ */ -/* Object.cpp | ___| _ ____ ___ */ -/* Project : C-Engine | |_ | | | __| / _ \ */ -/* | _| | | | |= | __/ */ -/* By: Fife |_| |_| |_| \___| */ -/* */ +/* _____ _ __ ___ __ */ +/* Object.cpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ /* */ /* ************************************************************************** */ #include "..\Rework\include\Object.hpp" - Object::Object() - { - OTransform = new Transform(this); - ORender = new Render(this); - tag = new char[20]; - enable = true; +Object::Object() +{ + OTransform = new Transform(this); + ORender = new Render(this); + tag = new char[20]; + enable = true; - ORigidBody = NULL; - OScript = NULL; - Conteneur = NULL; - } + ORigidBody = NULL; + OScript = NULL; + Conteneur = NULL; +} - Object::~Object() - { - delete OTransform; - delete ORender; - delete ORigidBody; - delete OScript; - delete []tag; - } +Object::~Object() +{ + delete OTransform; + delete ORender; + delete ORigidBody; + delete OScript; + delete []tag; +} - void Object::AffectEngine(Engine * EV) - { - Conteneur = EV; - } +void Object::AffectEngine(Engine * EV) +{ + Conteneur = EV; +} - void Object::AffectTag(char * v) - { - strcpy( tag , v );//Copie v dans tag. - } +void Object::AffectScript(Script * SV) +{ + OScript = SV; + OScript->AffectObject(this); +} - void Object::Enable() - { - enable = true; - } +void Object::AffectTag(char * v) +{ + strcpy( tag , v );//Copie v dans tag. +} - void Object::Disable() - { - enable = false; - } +void Object::Enable() +{ + enable = true; +} - void Object::AddRigidBody() - { - ORigidBody = new RigidBody(this); - } +void Object::Disable() +{ + enable = false; +} - Engine * Object::GetEngine() - { - return Conteneur; - } +void Object::AddRigidBody() +{ + ORigidBody = new RigidBody(this); +} - Transform * Object::GetTransform() - { - return OTransform; - } +Engine * Object::GetEngine() +{ + return Conteneur; +} - RigidBody * Object::GetRigidBody() - { - return ORigidBody; - } +Transform * Object::GetTransform() +{ + return OTransform; +} - Render * Object::GetRender() - { - return ORender; - } +RigidBody * Object::GetRigidBody() +{ + return ORigidBody; +} - Script * Object::GetScript() - { - return OScript; - } +Render * Object::GetRender() +{ + return ORender; +} - char * Object::GetTag() - { - return tag; - } +Script * Object::GetScript() +{ + return OScript; +} - bool Object::GetEnable() - { - return enable; - } +char * Object::GetTag() +{ + return tag; +} - bool Object::IsOnScreen() - { +bool Object::GetEnable() +{ + return enable; +} + +bool Object::IsOnScreen() +{ /*if(OTransform->GetX() < Conteneur->GetScreen()->max.x && OTransform->GetX() + ORender->GetSizeX() > Conteneur->GetScreen()->min.x && OTransform->GetY() < Conteneur->GetScreen()->max.y && OTransform->GetY() + ORender->GetSizeY() > Conteneur->GetScreen()->min.y ) return true; else return false;*/ - return true; - } + return true; +} - Object * Object::GetObjectCollisionTag( char* v, int x , int y) +Object * Object::GetObjectCollisionTag( char* v, int x , int y) +{ + for( int i = 0; i < Conteneur->GetNbObject(); i++ ) { - for( int i = 0; i < Conteneur->GetNbObject(); i++ ) + if(Conteneur->GetListeObject()[i] != this) { - if(Conteneur->GetListeObject()[i] != this) + if(!strcmp(Conteneur->GetListeObject()[i]->tag , v) && Conteneur->GetListeObject()[i]->enable) { - if(!strcmp(Conteneur->GetListeObject()[i]->tag , v) && Conteneur->GetListeObject()[i]->enable) - { - if(Collision(i))return Conteneur->GetListeObject()[i]; - } + if(Collision(i))return Conteneur->GetListeObject()[i]; } } - - return NULL; } + return NULL; +} - bool Object::GetCollisionTag(char* v , int x , int y) + +bool Object::GetCollisionTag(char* v , int x , int y) +{ + if(GetObjectCollisionTag(v,x,y))return true; + + return false; +} + +bool Object::Collision(int id) +{ + int widht1 = ORender->GetSizeX(); + int height1 = ORender->GetSizeY(); + int widht2 = Conteneur->GetListeObject()[id]->ORender->GetSizeX(); + int height2 = Conteneur->GetListeObject()[id]->ORender->GetSizeY(); + + if(ORigidBody) { - if(GetObjectCollisionTag(v,x,y))return true; - - return false; + if(ORigidBody->GetStat()) + { + widht1 = ORigidBody->GetWidht(); + height1 = ORigidBody->GetHeight(); + } } - bool Object::Collision(int id) + if(Conteneur->GetListeObject()[id]->ORigidBody) { - int widht1 = ORender->GetSizeX(); - int height1 = ORender->GetSizeY(); - int widht2 = Conteneur->GetListeObject()[id]->ORender->GetSizeX(); - int height2 = Conteneur->GetListeObject()[id]->ORender->GetSizeY(); - - if(ORigidBody) + if(Conteneur->GetListeObject()[id]->ORigidBody->GetStat()) { - if(ORigidBody->GetStat()) - { - widht1 = ORigidBody->GetWidht(); - height1 = ORigidBody->GetHeight(); - } + widht2 = Conteneur->GetListeObject()[id]->ORigidBody->GetWidht(); + height2 = Conteneur->GetListeObject()[id]->ORigidBody->GetHeight(); } - - if(Conteneur->GetListeObject()[id]->ORigidBody) - { - if(Conteneur->GetListeObject()[id]->ORigidBody->GetStat()) - { - widht2 = Conteneur->GetListeObject()[id]->ORigidBody->GetWidht(); - height2 = Conteneur->GetListeObject()[id]->ORigidBody->GetHeight(); - } - } - - if( (( Conteneur->GetListeObject()[id]->OTransform->GetX() + Conteneur->GetListeObject()[id]->ORender->GetBlitX() >= OTransform->GetX() + ORender->GetBlitX() + widht1) - || (Conteneur->GetListeObject()[id]->OTransform->GetX() + Conteneur->GetListeObject()[id]->ORender->GetBlitX() + widht2 <= OTransform->GetX() + ORender->GetBlitX()) - || (Conteneur->GetListeObject()[id]->OTransform->GetY() + Conteneur->GetListeObject()[id]->ORender->GetBlitY()>= OTransform->GetY() + ORender->GetBlitY() + height1) - || (Conteneur->GetListeObject()[id]->OTransform->GetY() + Conteneur->GetListeObject()[id]->ORender->GetBlitY() + height2 <= OTransform->GetY() + ORender->GetBlitY()) - ) == false )return true; - - return false; } + if( (( Conteneur->GetListeObject()[id]->OTransform->GetX() + Conteneur->GetListeObject()[id]->ORender->GetBlitX() >= OTransform->GetX() + ORender->GetBlitX() + widht1) + || (Conteneur->GetListeObject()[id]->OTransform->GetX() + Conteneur->GetListeObject()[id]->ORender->GetBlitX() + widht2 <= OTransform->GetX() + ORender->GetBlitX()) + || (Conteneur->GetListeObject()[id]->OTransform->GetY() + Conteneur->GetListeObject()[id]->ORender->GetBlitY()>= OTransform->GetY() + ORender->GetBlitY() + height1) + || (Conteneur->GetListeObject()[id]->OTransform->GetY() + Conteneur->GetListeObject()[id]->ORender->GetBlitY() + height2 <= OTransform->GetY() + ORender->GetBlitY()) + ) == false )return true; + + return false; +} + diff --git a/src/Object/Animation.cpp b/src/Object/Animation.cpp new file mode 100644 index 0000000..6cef9e4 --- /dev/null +++ b/src/Object/Animation.cpp @@ -0,0 +1,130 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Animation.cpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#include "..\Rework\include\Object\Animation.hpp" + +Animation::Animation() +{ + TabSprite = NULL; + + nb_image = 0; + delay = 0; + iterateur = 0; + time = 0; + + waitatend = false; + waittheend = false; + isend = false; +} + +Animation::Animation(Sprite & v) +{ + TabSprite = &v; + nb_image = 1; + + delay = 0; + iterateur = 0; + time = 0; + + waitatend = false; + waittheend = false; + isend = false; +} + +Animation::Animation(Sprite * v , int nb , int nbd , bool vwaitatend , bool vwaittheend) +{ + TabSprite = v; + nb_image = nb; + delay = nbd; + + waitatend = vwaitatend; + waittheend = vwaittheend; + + iterateur = 0; + time = 0; + + waitatend = false; + waittheend = false; + isend = false; +} + +void Animation::SetIt(int v) +{ + iterateur = v; + time = RTC_getTicks(); + isend = false; +} + +int Animation::GetSizeY() +{ + return TabSprite[iterateur].GetSizeY(); +} + +int Animation::GetSizeX() +{ + return TabSprite[iterateur].GetSizeX(); +} + +int Animation::GetBlitX() +{ + return TabSprite[iterateur].GetBlitX(); +} + +int Animation::GetBlitY() +{ + return TabSprite[iterateur].GetBlitY(); +} + + +void Animation::DrawAnim ( int x , int y , int d) +{ + if( iterateur >= nb_image) iterateur = 0; + + TabSprite[ iterateur ].DrawSprite( x , y , d); + + if(WaitDelay())iterateur ++; + + if( iterateur >= nb_image) + { + isend = true; + + if(!waitatend)iterateur = 0; + else iterateur = nb_image - 1; + } + +} + +void Animation::DrawReverseAnim ( int x , int y , int d) +{ + if( iterateur >= nb_image) iterateur = 0; + + TabSprite[ iterateur ].DrawReverseSprite( x , y , d); + + if(WaitDelay())iterateur ++; + + if( iterateur >= nb_image) + { + isend = true; + + if(!waitatend)iterateur = 0; + else iterateur = nb_image - 1; + } +} + +bool Animation::WaitDelay() +{ + if(RTC_getTicks() - time > (delay / 7.8125)) + { + time = RTC_getTicks(); + return true; + } + + return false; +} + diff --git a/src/Object/Render.cpp b/src/Object/Render.cpp new file mode 100644 index 0000000..069e203 --- /dev/null +++ b/src/Object/Render.cpp @@ -0,0 +1,142 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Render.cpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#include "..\Rework\include\Object\Render.hpp" + +Render::Render(Object * Pointeur) +{ + Conteneur = Pointeur; + TabAnim = NULL; + nb_anim = 0; + + iterateur = 0; + + reverse = false; + direction = 0; + + copie = false; +} + +Render::~Render() +{ + if(copie)delete TabAnim; +} + +void Render::SetRender(Animation * v, int nb) +{ + TabAnim = v; + nb_anim = nb; +} + +void Render::SetRender(Animation & v) +{ + TabAnim = &v; + nb_anim = 1; +} + +void Render::CopieRender(Animation * v, int nb) +{ + TabAnim = new Animation[nb]; + + for(int i = 0; i < nb ; i++) + { + TabAnim[i] = v[i]; + } + + nb_anim = nb; + copie = true; +} + +void Render::CopieRender(Animation & v) +{ + TabAnim = new Animation; + + TabAnim[0] = v; + + nb_anim = 1; + copie = true; +} + +void Render::SetIt(int v) +{ + if(iterateur != v /*&& (!TabAnim[iterateur].GetWaittheEnd() || TabAnim[iterateur].GetisEnd())*/) + { + iterateur = v; + if( iterateur >= nb_anim) iterateur = 0; + TabAnim[ iterateur].SetIt(0); + } +} + +int Render::GetIt() +{ + if(TabAnim)return iterateur; + return 0; +} + +void Render::ReverseRender(bool v) +{ + reverse = v; +} + +bool Render::GetReverse() +{ + return reverse; +} + +void Render::SetDirection(int v) +{ + direction = v; + + if(direction > 360) direction -= 360; + if(direction < 0) direction += 360; +} + +int Render::GetDirection() +{ + return direction; +} + +int Render::GetSizeY() +{ + if(TabAnim)return TabAnim[iterateur].GetSizeY(); + else return 0; +} + +int Render::GetSizeX() +{ + if(TabAnim)return TabAnim[iterateur].GetSizeX(); + else return 0; +} + +int Render::GetBlitX() +{ + if(TabAnim)return TabAnim[iterateur].GetBlitX(); + else return 0; +} + +int Render::GetBlitY() +{ + if(TabAnim)return TabAnim[iterateur].GetBlitY(); + else return 0; +} + +void Render::DrawObject() +{ + if(TabAnim) + { + if(!reverse) + { + TabAnim[ iterateur ].DrawAnim( Conteneur->GetTransform()->GetRelativeX() , 64 - Conteneur->GetTransform()->GetRelativeY() - GetSizeY() , direction); + } + else + { + TabAnim[ iterateur].DrawReverseAnim( Conteneur->GetTransform()->GetRelativeX() , 64 - Conteneur->GetTransform()->GetRelativeY() - GetSizeY() , direction); + } + } +} diff --git a/src/Object/RigiBodys.cpp b/src/Object/RigiBodys.cpp new file mode 100644 index 0000000..6ffbaca --- /dev/null +++ b/src/Object/RigiBodys.cpp @@ -0,0 +1,219 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* RigidBody.cpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#include "..\Rework\include\Object\RigidBody.hpp" + +RigidBody::RigidBody(Object * Pointeur) +{ + usefixebody = false; + widht = 0; + height = 0; + + Conteneur = Pointeur; + + R_body.transform = Conteneur->GetTransform(); + + R_body.velocity.x = 0; + R_body.velocity.y = 0; + + R_body.acceleration.x = 0; + R_body.acceleration.y = 0; + + R_body.mass_data.mass = 0; + R_body.mass_data.inv_mass = 0; +} + +void RigidBody::SetMass(float v) +{ + R_body.mass_data.mass = v; + + if(v) + R_body.mass_data.inv_mass = 1 / v; + else + R_body.mass_data.inv_mass = 0; +} + +void RigidBody::UseFixeBody(int w , int h) +{ + usefixebody = true; + widht = w; + height = h; +} + +void RigidBody::UseFlexBody() +{ + usefixebody = false; + widht = 0; + height = 0; +} + +int RigidBody::GetHeight() +{ + return height; +} + +int RigidBody::GetWidht() +{ + return widht; +} + +bool RigidBody::GetStat() +{ + return usefixebody; +} + +Body * RigidBody::GetBody() +{ + return &R_body; +} + +void RigidBody::AppliedForce() +{ + if(R_body.mass_data.mass > 0) + { + #ifdef CE_PLATEFORME + R_body.force.y = -10 * R_body.mass_data.mass * R_body.mass_data.mass ; + #endif // CE_PLATEFORME + + R_body.acceleration.x = R_body.force.x * R_body.mass_data.inv_mass + R_body.acceleration.x; + R_body.acceleration.y = R_body.force.y * R_body.mass_data.inv_mass + R_body.acceleration.y; + + R_body.velocity.x = R_body.velocity.x + (R_body.acceleration.x * 0.1); + R_body.velocity.y = R_body.velocity.y + (R_body.acceleration.y * 0.1); + + Move(R_body.velocity.x * 0.1, R_body.velocity.y * 0.1); + + R_body.force.x = 0; + R_body.force.y = 0; + R_body.acceleration.x = 0; + R_body.acceleration.y = 0; + } +} + +int RigidBody::Move(int x,int y) +{ + if(TryMove( x, y))return 1; + + Affine(x,y); + + return 0; +} + +int RigidBody::TryMove( int x ,int y) +{ + Level * m = Conteneur->GetEngine()->GetCurrentLevel(); + + if( m == NULL ) + { + int tx = R_body.transform->GetX() + x; + int ty = R_body.transform->GetY() + y; + + R_body.transform->SetXY( tx , ty); + + return 1; + } + + if( x >= m->tileWidth || y>= m->tileHeight ) + { + TryMove( x / 2 , y / 2 ); + TryMove( x / 2 , y / 2 ); + + return 1; + } + + int tx = R_body.transform->GetX() + x; + int ty = R_body.transform->GetY() + y; + + if(!CollisionDecor( tx , ty)) + { + R_body.transform->SetXY( tx , ty); + return 1; + } + else + { + if( x )R_body.velocity.x = 0 ; + if( y )R_body.velocity.y = 0 ; + } + + return 0; + +} + +int RigidBody::CollisionDecor( int x , int y) +{ + if(Conteneur->GetEngine()->GetCurrentLevel()) + { + Level * m = Conteneur->GetEngine()->GetCurrentLevel(); + + int sizex , sizey; + + if(!usefixebody) + { + sizex = Conteneur->GetRender()->GetSizeX(); + sizey = Conteneur->GetRender()->GetSizeY(); + } + else + { + sizex = widht; + sizey = height; + } + + if( x < 0 || ( x + sizex ) > m->levelWidth * m->tileWidth || y + sizey > m->levelHeight * m->tileHeight || y < 2) return 1; + + int xmin,xmax,ymin,ymax,i,j,indicetile, hm; + + hm = m->levelHeight * m->tileHeight; + + xmin = x / m->tileWidth; + ymin = (hm - y - sizey ) / m->tileHeight; + xmax = (x + sizex - 1) / m->tileWidth; + ymax = (hm - y -1) / m->tileHeight; + + for( i = xmin ; i <= xmax ; i++ ) + { + for( j = ymin ; j <= ymax ; j++ ) + { + indicetile = m->GetIdMap(i,j); + + if(m->solid[indicetile])return 1; + } + } + + } + + return 0; +} + + +void RigidBody::Affine(int vx,int vy) +{ + int i; + + for( i = 0 ; i < abs(vx) ; i++) + { + if( !TryMove ( sgn(vx) , 0 ) ) + break; + } + + for( i = 0 ; i < abs(vy) ; i++) + { + if( !TryMove ( 0 , sgn(vy) ) ) + break; + } +} + + + + + + + + + + diff --git a/src/Object/Script.cpp b/src/Object/Script.cpp new file mode 100644 index 0000000..8f7edb2 --- /dev/null +++ b/src/Object/Script.cpp @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Script.cpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#include "..\Rework\include\Object\Script.hpp" + +Script::Script() +{ + OConteneur = NULL; + EConteneur = NULL; +} + +void Script::Start() +{ + +} + +void Script::Update() +{ + +} + +void Script::UpdateEverySecond() +{ + +} + +void Script::AffectObject(Object * OV) +{ + OConteneur = OV; +} + +void Script::AffectEngine(Engine * EV) +{ + EConteneur = EV; +} + +Object * Script::GetObject() +{ + return OConteneur; +} + +Engine * Script::GetEngine() +{ + if(OConteneur) return OConteneur->GetEngine(); + + return EConteneur; +} + + + diff --git a/src/Object/Sprite.cpp b/src/Object/Sprite.cpp new file mode 100644 index 0000000..630b66c --- /dev/null +++ b/src/Object/Sprite.cpp @@ -0,0 +1,221 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Sprite.cpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#include "..\Rework\include\Object\Sprite.hpp" + +Sprite::Sprite() +{ + Alpha = NULL; + Beta = NULL; + + ReverseAlpha = NULL; + ReverseBeta = NULL; +} + +Sprite::Sprite(const unsigned char * v1, int sizex, int sizey , int bx , int by) +{ + Beta=v1; + size_x=sizex; + size_y=sizey; + + b_x = bx; + b_y = by; + + Alpha = NULL; + + ReverseAlpha = NULL; + ReverseBeta = NULL; +} + +Sprite::Sprite(const unsigned char * v1, const unsigned char * v2, int sizex, int sizey , int bx, int by) +{ + Beta=v1; + Alpha = v2; + + size_x=sizex; + size_y=sizey; + + b_x = bx; + b_y = by; + + ReverseAlpha = NULL; + ReverseBeta = NULL; +} + +void Sprite::DrawReverseSprite( int x , int y , int d) +{ + switch(d) + { + case 90: if(size_y % 2 == 0)y --; break; + case 180: if(size_y % 2 == 0)y --; if(size_x % 2 == 0)x --; break; + case 270: if(size_x % 2 == 0)x --; break; + } + + if(ReverseBeta) + { + if(ReverseAlpha) + { + ML_bmp_or_rotate((const unsigned char*) ReverseAlpha, x + br_x, y + br_y, size_x , size_y, d); // Affichage du canal alpha + ML_bmp_and_rotate((const unsigned char*) ReverseBeta, x +br_x, y +br_y, size_x , size_y, d); // Affichage du sprite en entier + } + else + { + ML_bmp_or_rotate((const unsigned char*) ReverseBeta, x +br_x , y +br_y, size_x , size_y , d); // Affichage du sprite en entier + } + + } + else + { + DrawSprite( x , y , d); + } +} + +void Sprite::DrawSprite( int x , int y , int d) +{ + switch(d) + { + case 90: if(size_y % 2 == 0)y --; break; + case 180: if(size_y % 2 == 0)y --; if(size_x % 2 == 0)x --; break; + case 270: if(size_x % 2 == 0)x --; break; + } + + if(Beta) + { + if(Alpha) + { + ML_bmp_or_rotate((const unsigned char*) Alpha, x + b_x, y + b_y, size_x , size_y , d); // Affichage du canal alpha + ML_bmp_and_rotate((const unsigned char*) Beta, x +b_x, y +b_y, size_x , size_y ,d); // Affichage du sprite en entier + } + else + { + ML_bmp_or_rotate((const unsigned char*) Beta, x +b_x , y +b_y, size_x , size_y , d); // Affichage du sprite en entier + } + + } +} + +void Sprite::CreateReverse( int brx , int bry) +{ + int taille, lx , decalage; + + unsigned char transit; + unsigned char out ; + + br_x = brx; + br_y = bry; + + decalage = size_x % 8; + + lx = size_x / 8 + ( decalage != 0 ); + + taille = lx * size_y; + + if(Beta) + { + ReverseBeta = (unsigned char*) malloc(sizeof(unsigned char) * taille); + + for( int i = 0 ; i < size_y ; i++ ) + for( int a = 0 ; a < lx ; a++ ) + ReverseBeta[i * lx + a] = Beta[ (i + 1) * lx - (a + 1)]; + + for(int i = 0; i < taille ; i++) + { + transit = ReverseBeta[i]; + + out = 0x0; + + if((transit & 0x80) != 0x0) out = out | 0x01; + if((transit & 0x40) != 0x0) out = out | 0x02; + if((transit & 0x20) != 0x0) out = out | 0x04; + if((transit & 0x10) != 0x0) out = out | 0x08; + if((transit & 0x08) != 0x0) out = out | 0x10; + if((transit & 0x04) != 0x0) out = out | 0x20; + if((transit & 0x02) != 0x0) out = out | 0x40; + if((transit & 0x01) != 0x0) out = out | 0x80; + + ReverseBeta[i] = out; + } + + if(decalage) + { + for(int i = 0 ; i < size_y ; i++ ) + for(int a = 0 ; a < lx ; a++ ) + { + transit = ((unsigned char)ReverseBeta[i * lx + a] >> ( decalage)); + + ReverseBeta[i * lx + a] = ((unsigned char)ReverseBeta[i * lx + a] << ( 8 - decalage)); + + if(a != 0)ReverseBeta[i * lx + a - 1] = ReverseBeta[i * lx + a - 1] | transit; + } + + } + } + + + if(Alpha) + { + ReverseAlpha = (unsigned char*) malloc(sizeof(unsigned char) * taille); + + for(int i = 0 ; i < size_y ; i++) + for(int a = 0; a < lx; a++) + ReverseAlpha[i * lx + a] = Alpha[ (i +1)*lx - (a+1)]; + + for(int i = 0; i < taille ; i++) + { + transit = ReverseAlpha[i]; + + out = 0x0; + + if((transit & 0x80) != 0x0) out = out | 0x01; + if((transit & 0x40) != 0x0) out = out | 0x02; + if((transit & 0x20) != 0x0) out = out | 0x04; + if((transit & 0x10) != 0x0) out = out | 0x08; + if((transit & 0x08) != 0x0) out = out | 0x10; + if((transit & 0x04) != 0x0) out = out | 0x20; + if((transit & 0x02) != 0x0) out = out | 0x40; + if((transit & 0x01) != 0x0) out = out | 0x80; + + ReverseAlpha[i] = out; + } + + if(decalage) + { + for(int i = 0 ; i < size_y ; i++ ) + for(int a = 0 ; a < lx ; a++ ) + { + transit = ((unsigned char)ReverseAlpha[i * lx + a] >> ( decalage)); + + ReverseAlpha[i * lx + a] = ((unsigned char)ReverseAlpha[i * lx + a] << ( 8 - decalage)); + + if(a)ReverseAlpha[i * lx + a - 1] = ReverseAlpha[i * lx + a - 1] | transit; + } + } + + } +} + +int Sprite::GetSizeY() +{ + return size_y; +} + +int Sprite::GetSizeX() +{ + return size_x; +} + +int Sprite::GetBlitX() +{ + return b_x; +} + +int Sprite::GetBlitY() +{ + return b_y; +} diff --git a/src/Object/Transforms.cpp b/src/Object/Transforms.cpp new file mode 100644 index 0000000..b20af47 --- /dev/null +++ b/src/Object/Transforms.cpp @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* _____ _ __ ___ __ */ +/* Transform.cpp | ___(_)/ _| ___ ( _ ) / /_ */ +/* Project: C-Engine | |_ | | |_ / _ \/ _ \| '_ \ */ +/* | _| | | _| __/ (_) | (_) | */ +/* Author: Fife |_| |_|_| \___|\___/ \___/ */ +/* */ +/* ************************************************************************** */ + +#include "..\Rework\include\Object\Transform.hpp" + +Transform::Transform(Object * Pointeur) +{ + Conteneur = Pointeur; + + positionabsolu.x = 0; + positionabsolu.y = 0; + + positionrelative.x = 0; + positionrelative.y = 0; +} + +double Transform::GetX() +{ + return positionabsolu.x; +} + +double Transform::GetY() +{ + return positionabsolu.y; +} + +double Transform::GetRelativeX() +{ + return positionrelative.x; +} + +double Transform::GetRelativeY() +{ + return positionrelative.y; +} + +void Transform::SetX(double v) +{ + positionabsolu.x = v; +} + +void Transform::SetY(double v) +{ + positionabsolu.y = v; +} + +void Transform::SetXY(double vx ,double vy) +{ + positionabsolu.x = vx; + positionabsolu.y = vy; +} + +void Transform::SetRelativeXY(double vx ,double vy) +{ + positionrelative.x = vx; + positionrelative.y = vy; +} + +