Permalink
Browse files

upgraded entities

  • Loading branch information...
1 parent 994a396 commit 0dd1ae3d8d05b49c0993b2893bba8cdfef39d93e @niksaak committed Feb 20, 2013
Showing with 65 additions and 7 deletions.
  1. +45 −0 src/entities/entity.c
  2. +20 −7 src/entities/entity.h
View
@@ -9,6 +9,8 @@ static Entity* alloc_entity()
return malloc(sizeof(Entity));
}
+// particles:
+
Entity* mkentity_particle(cpSpace* space, cpVect position, cpVect impulse)
{
Entity* ent = alloc_entity();
@@ -28,6 +30,28 @@ Entity* mkentity_particle(cpSpace* space, cpVect position, cpVect impulse)
return ent;
}
+Entity* ent_emit_particle(Entity* ent, cpVect offset, cpVect impulse)
+{
+ cpSpace* space;
+ cpBody* body;
+
+ space = cpBodyGetSpace(ent->body);
+ body = ent->body;
+
+ return mkentity_particle(space,
+ cpBodyLocal2World(body, offset),
+ cpvadd(cpBodyGetVel(body), impulse));
+}
+
+Entity*
+ent_emit_particlea(Entity* ent, cpVect offset, cpFloat angle, cpFloat impulse)
+{
+ return ent_emit_particle(ent, offset,
+ cpvmult(cpvforangle(angle), impulse));
+}
+
+// blocks:
+
Entity* mkentity_block(cpSpace* space, cpVect position,
cpFloat width, cpFloat height, cpFloat mass, cpVect velocity)
{
@@ -48,6 +72,8 @@ Entity* mkentity_block(cpSpace* space, cpVect position,
return ent;
}
+// rings:
+
Entity* mkentity_ring(cpSpace* space, cpVect position,
cpFloat radius, cpFloat mass, cpVect velocity)
{
@@ -68,6 +94,25 @@ Entity* mkentity_ring(cpSpace* space, cpVect position,
return ent;
}
+Entity* mkentity_shaped(cpSpace* space, cpVect position,
+ int vertc, cpVect* vertv, cpFloat mass, cpVect velocity)
+{
+ Entity* ent = alloc_entity();
+
+ ent->kind = AWKWARDKIND;
+ ent->color = 0xffffffff;
+ ent->body = cpBodyNew(mass, cpMomentForPoly(mass, vertc, vertv, cpvzero));
+ ent->shape = cpPolyShapeNew(ent->body, vertc, vertv, cpvzero);
+ cpSpaceAddBody(space, ent->body);
+ cpSpaceAddShape(space, ent->shape);
+ cpBodySetPos(ent->body, position);
+ cpSpaceReindexShapesForBody(space, ent->body);
+ cpBodySetUserData(ent->body, ent);
+ cpShapeSetUserData(ent->shape, ent);
+
+ return ent;
+}
+
void delentity(Entity* e)
{
if(e != NULL) {
View
@@ -8,7 +8,8 @@
typedef enum EntityKind {
PARTICLEKIND,
BLOCKKIND,
- RINGKIND
+ RINGKIND,
+ AWKWARDKIND
} EntityKind;
typedef struct Entity {
@@ -19,13 +20,25 @@ typedef struct Entity {
cpShape* shape;
} Entity;
-extern Entity* mkentity_particle(cpSpace* space, cpVect position,
- cpVect impulse);
+extern Entity*
+mkentity_particle(cpSpace* space, cpVect position, cpVect impulse);
-extern Entity* mkentity_block(cpSpace* space, cpVect position,
- cpFloat width, cpFloat height, cpFloat mass, cpVect velocity);
+extern Entity*
+ent_emit_particle(Entity* ent, cpVect offset, cpVect impulse);
-extern Entity* mkentity_ring(cpSpace* space, cpVect position,
- cpFloat radius, cpFloat mass, cpVect velocity);
+extern Entity*
+ent_emit_particlea(Entity* ent, cpVect offset, cpFloat angle, cpFloat velocity);
+
+extern Entity*
+mkentity_block(cpSpace* space, cpVect position,
+ cpFloat width, cpFloat height, cpFloat mass, cpVect velocity);
+
+extern Entity*
+mkentity_ring(cpSpace* space, cpVect position,
+ cpFloat radius, cpFloat mass, cpVect velocity);
+
+extern Entity*
+mkentity_shaped(cpSpace* space, cpVect position,
+ int vertc, cpVect* vertv, cpFloat mass, cpVect velocity);
extern void delentity(Entity* entity);

0 comments on commit 0dd1ae3

Please sign in to comment.