omi-eikyo/src/g_object.c

130 lines
2.5 KiB
C

// Copyright © 2017 Project Golan, all rights reserved.
// See COPYING for more information.
#include "g_object.h"
#include "g_stage.h"
#include <Doominati.h>
#include <stdio.h>
// Extern Functions ----------------------------------------------------------|
//
// G_Object_AnimGet
//
G_anima const *G_Object_AnimGet(unsigned id, unsigned ofs)
{
return (G_anima const *)DGE_Object_MemberGet(unsigned, id, ofs);
}
//
// G_Object_AnimSet
//
void G_Object_AnimSet(unsigned id, unsigned ofs, G_anima const *an)
{
DGE_Object_MemberSet(unsigned, id, ofs, (unsigned)an);
}
//
// G_RenderThinker_Animate
//
void G_RenderThinker_Animate(unsigned id)
{
G_rthnk th = {id};
if(th.ftime > 0)
th.ftime = th.ftime - 1;
else if(th.ftime == 0 && th.curanim)
{
if(th.frame < th.curanim->count)
{
G_frame const *const fr = &th.curanim->frame[th.frame];
th.sprite = fr->sprite;
th.ftime = fr->time;
th.frame = th.frame + 1;
}
else
th.sprite = 0;
}
}
//
// G_RenderThinker_AnimSet
//
void G_RenderThinker_AnimSet(unsigned id, G_anima const *anim)
{
G_rthnk th = {id};
if(anim && th.curanim != anim)
{
th.curanim = anim;
th.frame = 0;
th.ftime = 0;
}
}
//
// G_RenderThinker_AnimSetForced
//
void G_RenderThinker_AnimSetForced(unsigned id, G_anima const *anim)
{
G_rthnk th = {id};
th.curanim = anim;
th.frame = 0;
th.ftime = 0;
}
//
// G_Entity_Create
//
void G_Entity_Create(G_mfdat *info)
{
G_entty const *type = G_ObjDef_GetType(info->ent.name);
G_entit ent = {DGE_Entity_Create(type ? type->ext : 0)};
ent.x = info->ent.x;
ent.y = info->ent.y;
ent.z = info->ent.z;
ent.gravity = 1;
ent.mass = 1;
ent.friction = 0.875ulr;
if(type) {
G_ObjDef_setupEntity(type, ent);
G_ObjDef_createTask (type, ent.id);
}
}
//
// G_Sector_Create
//
void G_Sector_Create(G_mfdat *info)
{
DGE_Sector sec = {DGE_Sector_Create(4, 0)};
DGE_Object_RefAdd(sec.id);
sec.friction = 0.9lr;
sec.gz = -2;
sec.zl = info->sec.f;
sec.zu = info->sec.c;
fixed xl = info->sec.x , yl = info->sec.y;
fixed xu = info->sec.w + xl, yu = info->sec.h + yl;
DGE_Sector_PointSet(sec.id, 0, (DGE_Point2){xl, yl});
DGE_Sector_PointSet(sec.id, 1, (DGE_Point2){xl, yu});
DGE_Sector_PointSet(sec.id, 2, (DGE_Point2){xu, yu});
DGE_Sector_PointSet(sec.id, 3, (DGE_Point2){xu, yl});
DGE_Sector_CalcBounds(sec.id);
DGE_Sector_Block(sec.id);
}
// EOF