Création d'une nouvelle branche

This commit is contained in:
Fife 2016-06-09 16:07:38 +01:00
parent dee665cc2e
commit 07ae63f741
24 changed files with 3868 additions and 0 deletions

0
.gitignore vendored Normal file
View File

91
CEngine.hpp Normal file
View File

@ -0,0 +1,91 @@
/* ************************************************************************** */
/* _____ */
/* CEngine.hpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#ifndef CENGINE_HPP
#define CENGINE_HPP
extern "C" // Ajout des librairies externes au C-Engine
{
#include <fxlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "otherlib/input.h"
#include "otherlib/MonochromeLib.h"
#include "otherlib/FonctionC.h"
}
#define rand_int(M) (rand() % (M))
#define rand_int_ab(m, M) ((rand() % ((M) - (m)) + (m))
#define abs(A) ((A) > 0 ? (A) : -(A))
#define sgn(A) ((A) > 0 ? 1 : -1)
#define deg2rad(V) ((V) * 3.1415 / 180)
#define rad2deg(V) ((V) * 180 / 3.1415)
//#define CE_ALL
#define CE_BASIC
//#define CE_RPG
//#define CE_PLATEFORME
//#define CE_NETWORK
#ifdef CE_ALL
#define CE_BASIC
#define CE_RPG
#define CE_PLATEFORME
#define CE_NETWORK
#endif
#ifdef CE_BASIC
class Engine;
class Object;
class Transform;
class RigidBody;
class Render;
class Animation;
class Sprite;
class Script;
struct MassData
{
float mass;
float inv_mass;
};
struct Vec2
{
double x;
double y;
};
struct Body
{
Transform * transform;
MassData mass_data;
Vec2 velocity;
Vec2 acceleration;
Vec2 force;
};
#include "include\Engine.hpp"
#include "include\Object.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
#endif /* CENGINE_HPP */

View File

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* _____ */
/* Animation.hpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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

View File

@ -0,0 +1,62 @@
/* ************************************************************************** */
/* _____ */
/* Render.hpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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

View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* _____ */
/* RigidBody.hpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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

View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* _____ */
/* Script.hpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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

View File

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* _____ */
/* Sprite.hpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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

View File

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* _____ */
/* Transform.hpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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

57
include/Engine.hpp Normal file
View File

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* _____ */
/* Engine.hpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#ifndef CENGINE_ENGINE_HPP
#define CENGINE_ENGINE_HPP
#include "..\Rework\CEngine.hpp"
class Engine
{
public:
Engine(); //Constructeur
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 AddObject( Object * v); //Ajout un objet au moteur
void DelObject( Object * v); //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
void ExecuteScript();
void AppliedForce();
void Draw();
void UpdateRelativePosition();
private:
bool execute;
int fpswish;
bool fps;
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
};
#endif

64
include/Object.hpp Normal file
View File

@ -0,0 +1,64 @@
/* ************************************************************************** */
/* _____ */
/* Object.hpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#ifndef CENGINE_OBJECT_HPP
#define CENGINE_OBJECT_HPP
#include "..\Rework\CEngine.hpp"
class Object
{
public:
Object(); //Constructeur
~Object();
void AffectEngine(Engine * EV);
void AffectTag(char * v);
void Enable();
void Disable();
void AddRigidBody(); //Ajout un RigidBody
//Accesseur
Engine * GetEngine();
Transform * GetTransform();
RigidBody * GetRigidBody();
Render * GetRender();
Script * GetScript();
char * GetTag();
bool GetEnable();
//Fonction pour les scripts
Object * GetObjectCollisionTag( char* v , int x = 0 , int y = 0);
bool GetCollisionTag( char * v , int x = 0 , int y = 0 );
bool IsOnScreen();
private:
bool Collision(int id);
Transform * OTransform;
Render * ORender;
RigidBody * ORigidBody;
Script * OScript;
Engine * Conteneur;
char * tag;
bool enable;
};
#endif

92
otherlib/FonctionC.c Normal file
View File

@ -0,0 +1,92 @@
#include "MonochromeLib.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "FonctionC.h"
PrintV(int x, int y, int v)
{
char txt[10];
sprintf(txt,"%d",v);
PrintMini(x,y,txt,0);
}
void setFps(int fpsWish)
{
static unsigned int fps = 0, fps_count = 0; // "static" permet de garder les valeurs en mémoire entre les différents appels
do
{
fps = RTC_getTicks(); // on enregistre les ticks
Sleep(1); // permet d'économiser de la batterie
}
while(fps < fps_count + fpsWish); // tant que ceux-ci ne se sont pas suffisamment écoulés
fps_count = RTC_getTicks(); // on met à jour les dernières valeurs
}
int getDelay( int ms)
{
static int time=0;
if(RTC_getTicks() - time > (ms / 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 1;
}
return 0;
}
int getFps()
{
// variables utilisées (en static, pour pouvoir garder en mémoire les valeurs)
static int disp_fps=0, fps=1, time=0;
if(RTC_getTicks() - time > 128) // si il s'est écoulé une seconde complète
{
disp_fps = fps; // alors on récupère le nombre de FPS
fps = 0; // on remet à 0 le compteur
time = RTC_getTicks(); // et on se rappelle du nombre de ticks de la dernière seconde écoulée
}
fps++; // on monte la valeur des FPS
return disp_fps;
}
int rand_int(int max)
{
return rand() % max;
}
int rand_int_ab(int min, int max)
{
return rand() % (max - min) + min;
}
static int SysCallCode[] = {0xD201422B,0x60F20000,0x80010070};
static int (*SysCall)( int R4, int R5, int R6, int R7, int FNo ) = (void*)&SysCallCode;
int RTC_getTicks(void)
{
return (*SysCall)(0, 0, 0, 0, 0x3B); // on déclare la fonction voulue selon son numéro (ici 0x3B)
}
float ABS( float v)
{
if(v < 0) return -v;
return v;
}
double degretorad(float v)
{
return v * 3.1415 / 180;
}
double radtodegre(float v)
{
return v * 180 / 3.1415;
}

11
otherlib/FonctionC.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef FONCTIONC
#define FONCTIONC
int PrintV(int x, int y, int v);
int getFps();
void setFps(int fpsWish);
int getDelay( int ms);
int RTC_getTicks(void);
#endif // FONCTIONC

1559
otherlib/MonochromeLib.c Normal file

File diff suppressed because it is too large Load Diff

167
otherlib/MonochromeLib.h Normal file
View File

@ -0,0 +1,167 @@
/*************************************************************/
/** MonochromeLib - monochrome graphic library for fx-9860G **/
/** MonochromeLib is free software **/
/** **/
/** @author Pierre "PierrotLL" Le Gall **/
/** @contact legallpierre89@gmail.com **/
/** **/
/** @file MonochromeLib.h **/
/** Include header for MonochromeLib **/
/** **/
/** @date 11-22-2011 **/
/*************************************************************/
#ifndef MONOCHROMELIB
#define MONOCHROMELIB
/****************************************************/
/** uncomment #define of functions you want to use **/
/****************************************************/
#define ML_ALL //Auto define all functions
// #define ML_CLEAR_VRAM
// #define ML_CLEAR_SCREEN
// #define ML_DISPLAY_VRAM
// #define ML_SET_CONTRAST
// #define ML_GET_CONTRAST
// #define ML_PIXEL
// #define ML_POINT
// #define ML_PIXEL_TEST
// #define ML_LINE
// #define ML_HORIZONTAL_LINE
// #define ML_VERTICAL_LINE
// #define ML_RECTANGLE
// #define ML_POLYGON
// #define ML_FILLED_POLYGON
// #define ML_CIRCLE
// #define ML_FILLED_CIRCLE
// #define ML_ELLIPSE
// #define ML_ELLIPSE_IN_RECT
// #define ML_FILLED_ELLIPSE
// #define ML_FILLED_ELLIPSE_IN_RECT
// #define ML_HORIZONTAL_SCROLL
// #define ML_VERTICAL_SCROLL
// #define ML_BMP_OR
// #define ML_BMP_AND
// #define ML_BMP_XOR
// #define ML_BMP_OR_CL
// #define ML_BMP_AND_CL
// #define ML_BMP_XOR_CL
// #define ML_BMP_8_OR
// #define ML_BMP_8_AND
// #define ML_BMP_8_XOR
// #define ML_BMP_8_OR_CL
// #define ML_BMP_8_AND_CL
// #define ML_BMP_8_XOR_CL
// #define ML_BMP_16_OR
// #define ML_BMP_16_AND
// #define ML_BMP_16_XOR
// #define ML_BMP_16_OR_CL
// #define ML_BMP_16_AND_CL
// #define ML_BMP_16_XOR_CL
// #define ML_BMP_OR_ZOOM
// #define ML_BMP_AND_ZOOM
// #define ML_BMP_XOR_ZOOM
// #define ML_BMP_OR_ROTATE
// #define ML_BMP_AND_ROTATE
// #define ML_BMP_XOR_ROTATE
/**************************/
/** Functions prototypes **/
/**************************/
#ifdef __cplusplus
extern "C" {
#endif
#define ML_SCREEN_WIDTH 128
#define ML_SCREEN_HEIGHT 64
#define ML_CONTRAST_MIN 130
#define ML_CONTRAST_NORMAL 168
#define ML_CONTRAST_MAX 190
typedef enum {ML_TRANSPARENT=-1, ML_WHITE, ML_BLACK, ML_XOR, ML_CHECKER} ML_Color;
char* ML_vram_adress();
void ML_clear_vram();
void ML_clear_screen();
void ML_display_vram();
void ML_set_contrast(unsigned char contrast);
unsigned char ML_get_contrast();
void ML_pixel(int x, int y, ML_Color color);
void ML_point(int x, int y, int width, ML_Color color);
ML_Color ML_pixel_test(int x, int y);
void ML_line(int x1, int y1, int x2, int y2, ML_Color color);
void ML_horizontal_line(int y, int x1, int x2, ML_Color color);
void ML_vertical_line(int x, int y1, int y2, ML_Color color);
void ML_rectangle(int x1, int y1, int x2, int y2, int border_width, ML_Color border_color, ML_Color fill_color);
void ML_polygon(const int *x, const int *y, int nb_vertices, ML_Color color);
void ML_filled_polygon(const int *x, const int *y, int nb_vertices, ML_Color color);
void ML_circle(int x, int y, int radius, ML_Color color);
void ML_filled_circle(int x, int y, int radius, ML_Color color);
void ML_ellipse(int x, int y, int radius1, int radius2, ML_Color color);
void ML_ellipse_in_rect(int x1, int y1, int x2, int y2, ML_Color color);
void ML_filled_ellipse(int x, int y, int radius1, int radius2, ML_Color color);
void ML_filled_ellipse_in_rect(int x, int y, int radius1, int radius2, ML_Color color);
void ML_horizontal_scroll(int scroll);
void ML_vertical_scroll(int scroll);
void ML_bmp_or(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_and(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_xor(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_or_cl(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_and_cl(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_xor_cl(const unsigned char *bmp, int x, int y, int width, int height);
void ML_bmp_8_or(const unsigned char *bmp, int x, int y);
void ML_bmp_8_and(const unsigned char *bmp, int x, int y);
void ML_bmp_8_xor(const unsigned char *bmp, int x, int y);
void ML_bmp_8_or_cl(const unsigned char *bmp, int x, int y);
void ML_bmp_8_and_cl(const unsigned char *bmp, int x, int y);
void ML_bmp_8_xor_cl(const unsigned char *bmp, int x, int y);
void ML_bmp_16_or(const unsigned short *bmp, int x, int y);
void ML_bmp_16_and(const unsigned short *bmp, int x, int y);
void ML_bmp_16_xor(const unsigned short *bmp, int x, int y);
void ML_bmp_16_or_cl(const unsigned short *bmp, int x, int y);
void ML_bmp_16_and_cl(const unsigned short *bmp, int x, int y);
void ML_bmp_16_xor_cl(const unsigned short *bmp, int x, int y);
void ML_bmp_or_zoom(const unsigned char *bmp, int x, int y, int width, int height, float zoom_w, float zoom_h);
void ML_bmp_and_zoom(const unsigned char *bmp, int x, int y, int width, int height, float zoom_w, float zoom_h);
void ML_bmp_xor_zoom(const unsigned char *bmp, int x, int y, int width, int height, float zoom_w, float zoom_h);
void ML_bmp_or_rotate(const unsigned char *bmp, int x, int y, int width, int height, int angle);
void ML_bmp_and_rotate(const unsigned char *bmp, int x, int y, int width, int height, int angle);
void ML_bmp_xor_rotate(const unsigned char *bmp, int x, int y, int width, int height, int angle);
#ifdef __cplusplus
}
#endif
#endif //MONOCHROMELIB

233
otherlib/input.c Normal file
View File

@ -0,0 +1,233 @@
/****************************************************************************/
/* */
/* Input */
/* */
/* Par NineStars V2 */
/****************************************************************************/
#include "input.h"
static int SysCallCode[] = {0xD201422B,0x60F20000,0x80010070};
static int (*SysCall)( int R4, int R5, int R6, int R7, int FNo ) = (void*)&SysCallCode;
unsigned char last_key[54] = {0};
unsigned char current_key[54] = {0};
void input_update()
{
int i;
for (i=0; i<54; i++)
{
last_key[i] = current_key[i];
if (key_down(i+25))
{
if (current_key[i] < 255)
{
current_key[i] ++;
}
} else {
current_key[i] = 0;
}
}
}
int input_any_key()
{
int i;
for (i=0; i<54; i++)
{
if (current_key[i] > 0)
{
return 1;
}
}
return 0;
}
int input_press(char key)
{
key -= 25;
return current_key[key];
}
int input_trigger(char key)
{
key -= 25;
return (current_key[key] == 1);
}
int input_release(char key)
{
key -= 25;
return (last_key[key] && !current_key[key]);
}
int input_hold_short(char key)
{
key -= 25;
return current_key[key] > 7;
}
int input_hold_long(char key)
{
key -= 25;
return current_key[key] > 14;
}
int input_repeat(char key)
{
key -= 25;
if (current_key[key] == 1)
{
return 1;
}
if (current_key[key] == 8)
{
current_key[key] = 6;
return 1;
}
return 0;
}
int input_repeat_short(char key)
{
key -= 25;
if (current_key[key] == 1)
{
return 1;
}
if (current_key[key] == 5)
{
current_key[key] = 3;
return 1;
}
return 0;
}
int input_dir4()
{
if (current_key[K_DOWN-25]) return 2;
if (current_key[K_LEFT-25]) return 4;
if (current_key[K_RIGHT-25]) return 6;
if (current_key[K_UP-25]) return 8;
return 0;
}
int input_dir8()
{
if (current_key[K_LEFT-25] && current_key[K_DOWN-25]) return 1;
if (current_key[K_DOWN-25] && current_key[K_RIGHT-25]) return 3;
if (current_key[K_LEFT-25] && current_key[K_UP-25]) return 7;
if (current_key[K_RIGHT-25] && current_key[K_UP-25]) return 9;
if (current_key[K_DOWN-25]) return 2;
if (current_key[K_LEFT-25]) return 4;
if (current_key[K_RIGHT-25]) return 6;
if (current_key[K_UP-25]) return 8;
return 0;
}
#define SCA 0xD201D002
#define SCB 0x422B0009
#define SCE 0x80010070
typedef int(*sc_i2cp2sip) (char*, char*, short int*, short int*);
typedef int(*sc_iv) (void);
typedef int(*sc_4i) (int, int, int);
const unsigned int sc003b[] = {SCA, SCB, SCE, 0x3B};
const unsigned int sc0015[] = {SCA, SCB, SCE, 0x15};
const unsigned int sc0248[] = {SCA, SCB, SCE, 0x248};
#define RTC_GetTicks (*(sc_iv)sc003b)
#define PutKey (*(sc_4i)sc0248)
#define GlibGetOSVersionInfo (*(sc_i2cp2sip)sc0015)
int OSVersionAsInt(void)
{
unsigned char mainversion;
unsigned char minorversion;
unsigned short release;
unsigned short build;
GlibGetOSVersionInfo( &mainversion, &minorversion, &release, &build );
return ( ( mainversion << 24 ) & 0xFF000000 ) | ( ( minorversion << 16 ) & 0x00FF0000 ) | ( release & 0x0000FFFF );
}
#define isOS2 (OSVersionAsInt() >= 0x02020000)
#define OS2(x,y) ((OSVersionAsInt() >= 0x02020000)?y:x)
void key_inject(int keycode)
{
(*SysCall)(keycode, 0, 0, 0, 0x248);
}
static void delay()
{
unsigned char i;
for(i=0 ; i<5 ; i++);
}
unsigned char CheckKeyRow(unsigned char code)
{
unsigned char result=0;
short*PORTB_CTRL=(void*)0xA4000102;
short*PORTM_CTRL=(void*)0xA4000118;
char*PORTB=(void*)0xA4000122;
char*PORTM=(void*)0xA4000138;
char*PORTA=(void*)0xA4000120;
short smask;
char cmask;
unsigned char column, row;
column = code>>4;
row = code &0x0F;
smask = 0x0003 << (( row %8)*2);
cmask = ~( 1 << ( row %8) );
if(row <8)
{
*PORTB_CTRL = 0xAAAA ^ smask;
*PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x00AA;
delay();
*PORTB = cmask;
*PORTM = (*PORTM & 0xF0 ) | 0x0F;
}
else
{
*PORTB_CTRL = 0xAAAA;
*PORTM_CTRL = ((*PORTM_CTRL & 0xFF00 ) | 0x00AA) ^ smask;
delay();
*PORTB = 0xFF;
*PORTM = (*PORTM & 0xF0 ) | cmask;
}
delay();
result = (~(*PORTA))>>column & 1;
delay();
*PORTB_CTRL = 0xAAAA;
*PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x00AA;
delay();
*PORTB_CTRL = 0x5555;
*PORTM_CTRL = (*PORTM_CTRL & 0xFF00 ) | 0x0055;
delay();
return result;
}
unsigned char key_down(unsigned char code)
{
unsigned short key[8];
const unsigned short* keyboardregister = (unsigned short*)0xA44B0000;
if(isOS2)
{
unsigned char row = code%10;
memcpy(&key, keyboardregister, sizeof(unsigned short) << 3);
return (0 != (key[row >> 1] & 1 << code / 10 - 1 + ((row & 1) << 3)));
}
else
{
return CheckKeyRow((code % 10) + ((code / 10 - 1) << 4));
}
}

108
otherlib/input.h Normal file
View File

@ -0,0 +1,108 @@
/****************************************************************************/
/* */
/* Input */
/* */
/* Par NineStars V2 */
/****************************************************************************/
#ifndef DEF_INPUT
#define DEF_INPUT
// input_update : mets à jour le clavier, il faut appeler cette méthode une fois par frame
void input_update();
// input_press : renvoie 1 si la touche key est pressée, 0 sinon
int input_press(char key);
// input_trigger : renvoie 1 au moment où key est pressée, 0 sinon
int input_trigger(char key);
// input_release : renvoie 1 au moment où key est relachée, 0 sinon
int input_release(char key);
// input_hold_short : renvoie 1 si la touche a été pressée un court instant, 0 sinon
int input_hold_short(char key);
// input_hold_long : renvoie 1 si la touche a été pressée un long instant, 0 sinon
int input_hold_long(char key);
// input_repeat : renvoie 1 quand la touche est pressée, puis des 1 à intervalle régulier
int input_repeat(char key);
// input_reapeat_short : renvoie 1 quand la touche est pressée, puis des 1 à intervalle régulier courts
int input_repeat_short(char key);
// input_dir4 : renvoie un nombre donnant la direction des touches fléchées suivant l'ordre du pavé numérique
// sans prendre en compte les diagonales, 0 si aucune direction
int input_dir4();
// input_dir8 : renvoie un nombre donnant la direction des touches fléchées suivant l'ordre du pavé numérique
// en prenant en compte les diagonales, 0 si aucune direction
int input_dir8();
int input_any_key();
void key_inject(int keycode);
unsigned char key_down(unsigned char code);
/***************/
/** Key codes **/
/***************/
#define K_0 71
#define K_1 72
#define K_2 62
#define K_3 52
#define K_4 73
#define K_5 63
#define K_6 53
#define K_7 74
#define K_8 64
#define K_9 54
#define K_DP 61
#define K_EXP 51
#define K_PMINUS 41
#define K_PLUS 42
#define K_MINUS 32
#define K_MULT 43
#define K_DIV 33
#define K_FRAC 75
#define K_LPAR 55
#define K_RPAR 45
#define K_COMMA 35
#define K_STORE 25
#define K_XTT 76
#define K_LOG 66
#define K_LN 56
#define K_SIN 46
#define K_COS 36
#define K_TAN 26
#define K_SQUARE 67
#define K_POW 57
#define K_EXE 31
#define K_DEL 44
#define K_AC 32
#define K_FD 65
#define K_EXIT 47
#define K_SHIFT 78
#define K_ALPHA 77
#define K_OPTN 68
#define K_VARS 58
#define K_UP 28
#define K_DOWN 37
#define K_LEFT 38
#define K_RIGHT 27
#define K_F1 79
#define K_F2 69
#define K_F3 59
#define K_F4 49
#define K_F5 39
#define K_F6 29
#define K_MENU 48
#endif

View File

@ -0,0 +1,118 @@
/* ************************************************************************** */
/* _____ */
/* Animation.cpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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;
}

146
src/Components/Render.cpp Normal file
View File

@ -0,0 +1,146 @@
/* ************************************************************************** */
/* _____ */
/* Render.cpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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;
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( iterateur >= nb_anim) iterateur = 0;
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);
}
}

View File

@ -0,0 +1,216 @@
/* ************************************************************************** */
/* _____ */
/* RigidBody.cpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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;
}
}

57
src/Components/Script.cpp Normal file
View File

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* _____ */
/* Script.cpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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;
}

226
src/Components/Sprite.cpp Normal file
View File

@ -0,0 +1,226 @@
/* ************************************************************************** */
/* _____ */
/* Sprite.cpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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;
}

View File

@ -0,0 +1,66 @@
/* ************************************************************************** */
/* _____ */
/* Transform.cpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#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;
}

196
src/Engine.cpp Normal file
View File

@ -0,0 +1,196 @@
/* ************************************************************************** */
/* _____ */
/* Engine.cpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#include "..\Rework\include\Engine.hpp"
Engine::Engine()
{
execute = true;
fps = false;
fpswish = 4;
listeObject = NULL;
nbobject = 0;
}
void Engine::StartGame()
{
InitGame();
while(execute)
{
ML_clear_vram();
input_update();
ExecuteScript();
AppliedForce();
UpdateRelativePosition();
Draw();
setFps(fpswish);
ML_display_vram();
}
DelAllObject();
}
void Engine::InitGame()
{
execute = true;
srand(RTC_getTicks());
for( int i = 0 ; i < nbobject ; i++ )
{
if(listeObject[i]->GetScript() && listeObject[i]->GetEnable())listeObject[i]->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)
{
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)
{
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()
{
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()
{
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());
}
/*
bool Engine::WaitOneSecond()
{
if(RTC_getTicks() - time > 128) // 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;
}
*/
void Engine::UpdateRelativePosition()
{
for( int i = 0 ; i < nbobject; i++ )
{
if(listeObject[i]->GetEnable())
listeObject[i]->GetTransform()->SetRelativeXY( listeObject[i]->GetTransform()->GetX() , listeObject[i]->GetTransform()->GetY() );
}
}

162
src/Object.cpp Normal file
View File

@ -0,0 +1,162 @@
/* ************************************************************************** */
/* _____ */
/* Object.cpp | ___| _ ____ ___ */
/* Project : C-Engine | |_ | | | __| / _ \ */
/* | _| | | | |= | __/ */
/* By: Fife <wasabifife@gmail.com> |_| |_| |_| \___| */
/* */
/* */
/* ************************************************************************** */
#include "..\Rework\include\Object.hpp"
Object::Object()
{
OTransform = new Transform(this);
ORender = new Render(this);
tag = new char[20];
enable = true;
ORigidBody = NULL;
OScript = NULL;
Conteneur = NULL;
}
Object::~Object()
{
delete OTransform;
delete ORender;
delete ORigidBody;
delete OScript;
delete []tag;
}
void Object::AffectEngine(Engine * EV)
{
Conteneur = EV;
}
void Object::AffectTag(char * v)
{
strcpy( tag , v );//Copie v dans tag.
}
void Object::Enable()
{
enable = true;
}
void Object::Disable()
{
enable = false;
}
void Object::AddRigidBody()
{
ORigidBody = new RigidBody(this);
}
Engine * Object::GetEngine()
{
return Conteneur;
}
Transform * Object::GetTransform()
{
return OTransform;
}
RigidBody * Object::GetRigidBody()
{
return ORigidBody;
}
Render * Object::GetRender()
{
return ORender;
}
Script * Object::GetScript()
{
return OScript;
}
char * Object::GetTag()
{
return tag;
}
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;
}
Object * Object::GetObjectCollisionTag( char* v, int x , int y)
{
for( int i = 0; i < Conteneur->GetNbObject(); i++ )
{
if(Conteneur->GetListeObject()[i] != this)
{
if(!strcmp(Conteneur->GetListeObject()[i]->tag , v) && Conteneur->GetListeObject()[i]->enable)
{
if(Collision(i))return Conteneur->GetListeObject()[i];
}
}
}
return NULL;
}
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(ORigidBody->GetStat())
{
widht1 = ORigidBody->GetWidht();
height1 = 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;
}