2021-11-30 21:29:18 -06:00
|
|
|
#include "level.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "gameobject.h"
|
2022-02-06 10:14:57 -06:00
|
|
|
#include "resources.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-08-26 09:19:17 -05:00
|
|
|
#include "stb_ds.h"
|
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
void save_level(char name[MAXNAME])
|
|
|
|
{
|
2022-08-15 23:46:06 -05:00
|
|
|
FILE *lfile = res_open(name, "wb+");
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
if (!lfile) return;
|
|
|
|
|
|
|
|
|
2022-08-26 09:19:17 -05:00
|
|
|
int objs = arrlen(gameobjects);
|
2021-11-30 21:29:18 -06:00
|
|
|
fwrite(&objs, sizeof(objs), 1, lfile);
|
|
|
|
|
2022-08-26 09:19:17 -05:00
|
|
|
for (int i = 0; i < objs; i++)
|
|
|
|
gameobject_save(&gameobjects[i], lfile);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
fclose(lfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void load_level(char name[MAXNAME])
|
|
|
|
{
|
2023-01-12 17:41:54 -06:00
|
|
|
/*
|
2022-08-15 23:46:06 -05:00
|
|
|
FILE *lfile = fopen(name, "rb");
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
if (!lfile) return;
|
|
|
|
|
2022-08-26 09:19:17 -05:00
|
|
|
new_level();
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
int objs;
|
|
|
|
fread(&objs, sizeof(objs), 1, lfile);
|
|
|
|
|
2022-08-26 09:19:17 -05:00
|
|
|
arraddn(gameobjects, objs);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
for (int i = 0; i < objs; i++) {
|
2022-11-19 17:13:57 -06:00
|
|
|
struct gameobject *go = &gameobjects[i];
|
|
|
|
fread(go, sizeof(struct gameobject), 1, lfile);
|
2022-08-26 09:19:17 -05:00
|
|
|
go->components = NULL;
|
2021-11-30 21:29:18 -06:00
|
|
|
gameobject_init(go, lfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(lfile);
|
2023-01-12 17:41:54 -06:00
|
|
|
*/
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void new_level()
|
|
|
|
{
|
2022-08-26 09:19:17 -05:00
|
|
|
for (int i = 0; i < arrlen(gameobjects); i++)
|
|
|
|
gameobject_delete(i);
|
|
|
|
|
|
|
|
arrfree(gameobjects);
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|