Skip to content

Commit

Permalink
Merge pull request #7 from lucas-zimerman/feat/objectcore-all-variable
Browse files Browse the repository at this point in the history
Feat: replace Object parameters fixed by variables
  • Loading branch information
lucas-zimerman authored Aug 17, 2021
2 parents 95cdbeb + 7978320 commit 8cbde59
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 123 deletions.
44 changes: 36 additions & 8 deletions MT2D/ObjectCore/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,42 @@ void Object_Render(Object *obj) {
//Decrement the frame counter
//Check if the frame tic has expired, if yes select the next frame
//Render the frame
Sprite_Render_on_Window(obj->State[obj->ActualState]->Sprites[obj->ActualFrame],DISPLAY_WINDOW1, obj->SpacePosition.X, obj->SpacePosition.Y);
Sprite_Render_on_Window(
obj->State[obj->ActualState]->Sprites[obj->ActualFrame],
DISPLAY_WINDOW1,
*(int*)obj->User_Vars[Object_PosX_Var_Index].Data,
*(int*)obj->User_Vars[Object_PosY_Var_Index].Data
);
}
}

void Object_Add_Variable(Object* object, MT2D_VAR* variable)
{
object->User_Vars_Count++;
object->User_Vars = (MT2D_VAR*)realloc(object->User_Vars, (object->User_Vars_Count + 1) * sizeof(MT2D_VAR));
object->User_Vars[object->User_Vars_Count - 1] = *variable;
}

void Object_Add_Variables(Object* object, MT2D_VAR* variables, int total)
{
int newSize = object->User_Vars_Count + total;
object->User_Vars_Count;
object->User_Vars = (MT2D_VAR*)realloc(object->User_Vars, (newSize + 1) * sizeof(MT2D_VAR));
for (int i = 0; object->User_Vars_Count < newSize; i++, object->User_Vars_Count++)
{
object->User_Vars[object->User_Vars_Count] = variables[i];
}
object->User_Vars_Count = newSize;

}

Object *Object_Create(bool Solid, bool RenderOnly, int sizeX, int sizeY, int PosX, int PosY,ObjectState **_States, int States_Count ) {
Object *Obj;
MT2D_VAR* ref;
Obj = (Object*)malloc(sizeof(Object));

Obj->Solid = Solid;
Obj->RenderOnly = RenderOnly;
Obj->Size.X = sizeX;
Obj->Size.Y = sizeY;
Obj->SpacePosition.X = PosX;
Obj->SpacePosition.Y = PosY;
Obj->ActualFrame = 0;
Obj->ActualFrameWait = _States[0]->WaitSprites[0];
Obj->ActualState = 0;
Expand All @@ -46,10 +68,16 @@ Object *Object_Create(bool Solid, bool RenderOnly, int sizeX, int sizeY, int Pos
Obj->Enabled = true;
Obj->CanDelete = false;
Obj->MyScene = 0;
Obj->Aceleration.X = 0;
Obj->Aceleration.Y = 0;

Obj->User_Vars = (MT2D_VAR*)malloc(sizeof(MT2D_VAR));
Obj->User_Vars_Count = 0;
Obj->User_Vars = 0;
// ref = ;
Object_Add_Variable(Obj, MT2D_Object_Create_Var_Int("Pos_X", PosX));
Object_Add_Variable(Obj, MT2D_Object_Create_Var_Int("Pos_Y", PosY));
Object_Add_Variable(Obj, MT2D_Object_Create_Var_Int("Size_X", sizeX));
Object_Add_Variable(Obj, MT2D_Object_Create_Var_Int("Size_Y", sizeY));
Object_Add_Variable(Obj, MT2D_Object_Create_Var_Int("Acel_X", 0));
Object_Add_Variable(Obj, MT2D_Object_Create_Var_Int("Acel_Y", 0));
return Obj;
}

Expand Down
28 changes: 25 additions & 3 deletions MT2D/ObjectCore/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
#include "../ObjectCore/Vars.h"
#endif

#define Object_PosX_Var_Index 0
#define Object_PosY_Var_Index 1
#define Object_SizeX_Var_Index 2
#define Object_SizeY_Var_Index 3
#define Object_AcelX_Var_Index 4
#define Object_AcelY_Var_Index 5
#define Object_First_User_Var_Index 6

struct ObjectState;
struct ObjectScene;

struct Object{
bool RenderOnly;
bool Solid;
Coord SpacePosition;
Coord Size;
Coord Aceleration;
Object *Target;
ObjectScene *MyScene;
ObjectState **State; /*The first state is the initial state where the object is going to be initiated*/
Expand Down Expand Up @@ -52,4 +57,21 @@ void ObjectScene_Add(ObjectScene *Scene, Object *New);
void ObjectScene_Render(ObjectScene *Scene);
void ObjectScene_Goto_NextSteps(ObjectScene *Scene);
void Object_Delete(Object *Me, bool deleteStates);
void Object_Add_Variable(Object* object, MT2D_VAR* variable);
void Object_Add_Variables(Object* object, MT2D_VAR* variables, int total);

#define ObjectPosXRef(object) ((int*)((Object*)object)->User_Vars[Object_PosX_Var_Index].Data)
#define ObjectPosYRef(object) ((int*)((Object*)object)->User_Vars[Object_PosY_Var_Index].Data)
#define ObjectAcelXRef(object) ((int*)((Object*)object)->User_Vars[Object_AcelX_Var_Index].Data)
#define ObjectAcelYRef(object) ((int*)((Object*)object)->User_Vars[Object_AcelY_Var_Index].Data)
#define ObjectSizeXRef(object) ((int*)((Object*)object)->User_Vars[Object_SizeX_Var_Index].Data)
#define ObjectSizeYRef(object) ((int*)((Object*)object)->User_Vars[Object_SizeY_Var_Index].Data)

#define ObjectPosX(object) (*(int*)(((Object*)object)->User_Vars[Object_PosX_Var_Index].Data))
#define ObjectPosY(object) (*(int*)((Object*)object)->User_Vars[Object_PosY_Var_Index].Data)
#define ObjectAcelX(object) (*(int*)((Object*)object)->User_Vars[Object_AcelX_Var_Index].Data)
#define ObjectAcelY(object) (*(int*)((Object*)object)->User_Vars[Object_AcelY_Var_Index].Data)
#define ObjectSizeX(object) (*(int*)((Object*)object)->User_Vars[Object_SizeX_Var_Index].Data)
#define ObjectSizeY(object) (*(int*)((Object*)object)->User_Vars[Object_SizeY_Var_Index].Data)

#endif
Loading

0 comments on commit 8cbde59

Please sign in to comment.