Fixe de la fonctionnalité de UpdateEverySecond

This commit is contained in:
Fife 2016-06-11 14:31:10 +01:00
parent 5d6eb24143
commit f0332b5a15
21 changed files with 102 additions and 53 deletions

0
.gitignore vendored
View File

View File

@ -23,7 +23,7 @@
}
#define rand_int(M) (rand() % (M))
#define rand_int_ab(m, M) ((rand() % ((M) - (m)) + (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)

View File

@ -1 +0,0 @@
Rework

View File

@ -10,7 +10,7 @@
#ifndef CENGINE_ENGINE_HPP
#define CENGINE_ENGINE_HPP
#include "..\Rework\CEngine.hpp"
#include "..\C-Engine\CEngine.hpp"
class Engine
{
@ -54,6 +54,10 @@ class Engine
void MoveObject( Object * v , int destination = -2 );
bool WaitOneSecond();
void ExecuteScriptSecond();
private:
bool execute;
@ -71,6 +75,8 @@ class Engine
int currentLevel;
int time;
};
#endif

View File

@ -10,7 +10,7 @@
#ifndef CENGINE_LEVEL_HPP
#define CENGINE_LEVEL_HPP
#include "..\Rework\CEngine.hpp"
#include "..\C-Engine\CEngine.hpp"
class Level
{

View File

@ -10,7 +10,7 @@
#ifndef CENGINE_OBJECT_HPP
#define CENGINE_OBJECT_HPP
#include "..\Rework\CEngine.hpp"
#include "..\C-Engine\CEngine.hpp"
class Object
{
@ -45,11 +45,10 @@ class Object
bool GetCollisionTag( char * v , int x = 0 , int y = 0 );
bool IsOnScreen();
bool Collision(int id , Level * l = NULL);
private:
bool Collision(int id);
Transform * OTransform;
Render * ORender;
RigidBody * ORigidBody;

View File

@ -10,7 +10,7 @@
#ifndef CENGINE_ANIMATION_HPP
#define CENGINE_ANIMATION_HPP
#include "..\Rework\CEngine.hpp"
#include "..\C-Engine\CEngine.hpp"
class Animation
{

View File

@ -10,7 +10,7 @@
#ifndef CENGINE_RENDER_HPP
#define CENGINE_RENDER_HPP
#include "..\Rework\CEngine.hpp"
#include "..\C-Engine\CEngine.hpp"
class Render
{

View File

@ -10,7 +10,7 @@
#ifndef CENGINE_RIGIDBODY_HPP
#define CENGINE_RIGIDBODY_HPP
#include "..\Rework\CEngine.hpp"
#include "..\C-Engine\CEngine.hpp"
class RigidBody
{

View File

@ -10,7 +10,7 @@
#ifndef CENGINE_SCRIPT_HPP
#define CENGINE_SCRIPT_HPP
#include "..\Rework\CEngine.hpp"
#include "..\C-Engine\CEngine.hpp"
class Script
{

View File

@ -10,7 +10,7 @@
#ifndef CENGINE_SPRITE_HPP
#define CENGINE_SPRITE_HPP
#include "..\Rework\CEngine.hpp"
#include "..\C-Engine\CEngine.hpp"
class Sprite
{

View File

@ -10,7 +10,7 @@
#ifndef CENGINE_TRANSFORM_HPP
#define CENGINE_TRANSFORM_HPP
#include "..\Rework\CEngine.hpp"
#include "..\C-Engine\CEngine.hpp"
class Transform
{

View File

@ -7,21 +7,7 @@
/* */
/* ************************************************************************** */
/*
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;
}
*/
#include "..\Rework\include\Engine.hpp"
#include "..\C-Engine\include\Engine.hpp"
Engine::Engine()
{
@ -42,6 +28,7 @@ Engine::Engine()
tabLevel = NULL;
nbLevel = 0;
currentLevel = 0;
time = 0;
}
void Engine::StartGame()
@ -200,6 +187,11 @@ int Engine::GetNbObject()
void Engine::ExecuteScript()
{
if(WaitOneSecond())
{
ExecuteScriptSecond();
}
if(tabLevel && currentLevel != -1)
{
for( int i = 0 ; i < GetCurrentLevel()->GetNbObject() ; i++ )
@ -299,7 +291,7 @@ void Engine::MiddleScreen(int x , int y , bool fixe)
if(screen.min.y < 0)
{
screen.min.y = 0;
screen.max.y = 63;
screen.max.y = 64;
}
if(tabLevel && currentLevel != -1)
@ -393,3 +385,35 @@ void Engine::MoveObject(Object * v , int destination)
AddObject( v , destination );
}
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::ExecuteScriptSecond()
{
if(tabLevel && currentLevel != -1)
{
for( int i = 0 ; i < GetCurrentLevel()->GetNbObject() ; i++ )
{
if( GetCurrentLevel()->GetListeObject()[i]->GetEnable())
if(GetCurrentLevel()->GetListeObject()[i]->GetScript())
GetCurrentLevel()->GetListeObject()[i]->GetScript()->UpdateEverySecond();
}
}
else
{
for( int i = 0 ; i < nbobject ; i++ )
{
if( listeObject[i]->GetEnable())
if(listeObject[i]->GetScript())
listeObject[i]->GetScript()->UpdateEverySecond();
}
}
}

View File

@ -7,7 +7,7 @@
/* */
/* ************************************************************************** */
#include "..\Rework\include\Level.hpp"
#include "..\C-Engine\include\Level.hpp"
Level::Level()
{

View File

@ -7,7 +7,7 @@
/* */
/* ************************************************************************** */
#include "..\Rework\include\Object.hpp"
#include "..\C-Engine\include\Object.hpp"
Object::Object()
@ -107,13 +107,29 @@ bool Object::IsOnScreen()
Object * Object::GetObjectCollisionTag( char* v, int x , int y)
{
for( int i = 0; i < Conteneur->GetNbObject(); i++ )
if(Conteneur->GetCurrentLevel())
{
if(Conteneur->GetListeObject()[i] != this)
for( int i = 0; i < Conteneur->GetCurrentLevel()->GetNbObject(); i++ )
{
if(!strcmp(Conteneur->GetListeObject()[i]->tag , v) && Conteneur->GetListeObject()[i]->enable)
if(Conteneur->GetCurrentLevel()->GetListeObject()[i] != this)
{
if(Collision(i))return Conteneur->GetListeObject()[i];
if(!strcmp(Conteneur->GetCurrentLevel()->GetListeObject()[i]->tag , v) && Conteneur->GetCurrentLevel()->GetListeObject()[i]->enable)
{
if(Collision(i , Conteneur->GetCurrentLevel()))return Conteneur->GetCurrentLevel()->GetListeObject()[i];
}
}
}
}
else
{
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];
}
}
}
}
@ -129,12 +145,17 @@ bool Object::GetCollisionTag(char* v , int x , int y)
return false;
}
bool Object::Collision(int id)
bool Object::Collision(int id , Level * l)
{
Object * buffer;
if(l)buffer = Conteneur->GetCurrentLevel()->GetListeObject()[id];
else buffer = Conteneur->GetListeObject()[id];
int widht1 = ORender->GetSizeX();
int height1 = ORender->GetSizeY();
int widht2 = Conteneur->GetListeObject()[id]->ORender->GetSizeX();
int height2 = Conteneur->GetListeObject()[id]->ORender->GetSizeY();
int widht2 = buffer->ORender->GetSizeX();
int height2 = buffer->ORender->GetSizeY();
if(ORigidBody)
{
@ -145,19 +166,19 @@ bool Object::Collision(int id)
}
}
if(Conteneur->GetListeObject()[id]->ORigidBody)
if(buffer->ORigidBody)
{
if(Conteneur->GetListeObject()[id]->ORigidBody->GetStat())
if(buffer->ORigidBody->GetStat())
{
widht2 = Conteneur->GetListeObject()[id]->ORigidBody->GetWidht();
height2 = Conteneur->GetListeObject()[id]->ORigidBody->GetHeight();
widht2 = buffer->ORigidBody->GetWidht();
height2 = buffer->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())
if( (( buffer->OTransform->GetX() + buffer->ORender->GetBlitX() >= OTransform->GetX() + ORender->GetBlitX() + widht1)
|| (buffer->OTransform->GetX() + buffer->ORender->GetBlitX() + widht2 <= OTransform->GetX() + ORender->GetBlitX())
|| (buffer->OTransform->GetY() + buffer->ORender->GetBlitY()>= OTransform->GetY() + ORender->GetBlitY() + height1)
|| (buffer->OTransform->GetY() + buffer->ORender->GetBlitY() + height2 <= OTransform->GetY() + ORender->GetBlitY())
) == false )return true;
return false;

View File

@ -7,7 +7,7 @@
/* */
/* ************************************************************************** */
#include "..\Rework\include\Object\Animation.hpp"
#include "..\C-Engine\include\Object\Animation.hpp"
Animation::Animation()
{

View File

@ -7,7 +7,7 @@
/* */
/* ************************************************************************** */
#include "..\Rework\include\Object\Render.hpp"
#include "..\C-Engine\include\Object\Render.hpp"
Render::Render(Object * Pointeur)
{

View File

@ -7,7 +7,7 @@
/* */
/* ************************************************************************** */
#include "..\Rework\include\Object\RigidBody.hpp"
#include "..\C-Engine\include\Object\RigidBody.hpp"
RigidBody::RigidBody(Object * Pointeur)
{
@ -173,7 +173,7 @@ int RigidBody::CollisionDecor( int x , int y)
xmin = x / m->tileWidth;
ymin = (hm - y - sizey ) / m->tileHeight;
xmax = (x + sizex - 1) / m->tileWidth;
ymax = (hm - y -1) / m->tileHeight;
ymax = (hm - y - 1) / m->tileHeight;
for( i = xmin ; i <= xmax ; i++ )
{

View File

@ -7,7 +7,7 @@
/* */
/* ************************************************************************** */
#include "..\Rework\include\Object\Script.hpp"
#include "..\C-Engine\include\Object\Script.hpp"
Script::Script()
{

View File

@ -7,7 +7,7 @@
/* */
/* ************************************************************************** */
#include "..\Rework\include\Object\Sprite.hpp"
#include "..\C-Engine\include\Object\Sprite.hpp"
Sprite::Sprite()
{

View File

@ -7,7 +7,7 @@
/* */
/* ************************************************************************** */
#include "..\Rework\include\Object\Transform.hpp"
#include "..\C-Engine\include\Object\Transform.hpp"
Transform::Transform(Object * Pointeur)
{