2021-11-30 21:29:18 -06:00
|
|
|
#ifndef GAMEOBJECT_H
|
|
|
|
#define GAMEOBJECT_H
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "2dphysics.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
#include "config.h"
|
2022-01-21 11:26:22 -06:00
|
|
|
#include <chipmunk/chipmunk.h>
|
2023-05-12 13:22:05 -05:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
2023-05-27 07:01:17 -05:00
|
|
|
#include "quickjs/quickjs.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct shader;
|
2022-11-17 16:48:20 -06:00
|
|
|
struct sprite;
|
2021-11-30 21:29:18 -06:00
|
|
|
struct component;
|
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct gameobject {
|
2023-05-12 13:22:05 -05:00
|
|
|
cpBodyType bodytype;
|
|
|
|
int next;
|
|
|
|
float scale;
|
|
|
|
float mass;
|
|
|
|
float f; /* friction */
|
|
|
|
float e; /* elasticity */
|
|
|
|
int flipx; /* 1 or -1 */
|
|
|
|
int flipy;
|
|
|
|
int sensor;
|
|
|
|
unsigned int layer;
|
|
|
|
cpShapeFilter filter;
|
|
|
|
cpBody *body; /* NULL if this object is dead */
|
|
|
|
int id;
|
|
|
|
struct phys_cbs cbs;
|
|
|
|
struct shape_cb *shape_cbs;
|
2023-05-27 07:01:17 -05:00
|
|
|
JSValue ref;
|
2021-11-30 21:29:18 -06:00
|
|
|
};
|
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
extern struct gameobject *gameobjects;
|
2022-08-26 09:19:17 -05:00
|
|
|
|
2022-12-22 16:58:06 -06:00
|
|
|
int MakeGameobject();
|
2023-01-04 18:09:42 -06:00
|
|
|
void gameobject_apply(struct gameobject *go);
|
2021-11-30 21:29:18 -06:00
|
|
|
void gameobject_delete(int id);
|
2023-01-13 08:05:36 -06:00
|
|
|
void gameobjects_cleanup();
|
2023-02-17 13:15:56 -06:00
|
|
|
|
|
|
|
void gameobject_set_sensor(int id, int sensor);
|
2022-12-19 18:15:38 -06:00
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct gameobject *get_gameobject_from_id(int id);
|
2023-01-12 17:41:54 -06:00
|
|
|
struct gameobject *id2go(int id);
|
2022-12-19 18:15:38 -06:00
|
|
|
int id_from_gameobject(struct gameobject *go);
|
2023-02-19 11:16:35 -06:00
|
|
|
int go2id(struct gameobject *go);
|
2023-02-05 17:42:36 -06:00
|
|
|
int body2id(cpBody *body);
|
2023-02-13 08:30:35 -06:00
|
|
|
cpBody *id2body(int id);
|
2023-02-19 11:16:35 -06:00
|
|
|
int shape2gameobject(cpShape *shape);
|
2022-12-19 18:15:38 -06:00
|
|
|
|
2023-02-02 17:52:15 -06:00
|
|
|
void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go);
|
|
|
|
|
|
|
|
/* Tries a few methods to select a gameobject; if none is selected returns -1 */
|
|
|
|
int pos2gameobject(cpVect pos);
|
|
|
|
|
2022-12-26 20:57:45 -06:00
|
|
|
void gameobject_move(struct gameobject *go, cpVect vec);
|
2022-11-19 17:13:57 -06:00
|
|
|
void gameobject_rotate(struct gameobject *go, float as);
|
2022-12-19 18:15:38 -06:00
|
|
|
void gameobject_setangle(struct gameobject *go, float angle);
|
2022-12-26 20:57:45 -06:00
|
|
|
void gameobject_setpos(struct gameobject *go, cpVect vec);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-12-21 19:24:59 -06:00
|
|
|
void gameobject_draw_debugs();
|
2023-03-17 10:25:35 -05:00
|
|
|
void gameobject_draw_debug(int go);
|
2022-12-21 19:24:59 -06:00
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
void object_gui(struct gameobject *go);
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-12-22 16:58:06 -06:00
|
|
|
void gameobject_saveall();
|
|
|
|
void gameobject_loadall();
|
|
|
|
int gameobjects_saved();
|
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
#endif
|