#include "GameFuntion.h"
#include "Entity.h"
#include "EntityManager.h"
static bool init(const char* title,int w,int h);
static void clean();
static void update();
static void render();
static void handleEvents();
static bool running();
static void quit();
static GameFuntion* pthis = NULL;
GameFuntion* GameInstance()
{
static GameFuntion game;
if (!pthis)
{
pthis = &game;
pthis->init = init;
pthis->clean = clean;
pthis->update = update;
pthis->render = render;
pthis->handleEvents = handleEvents;
pthis->running = running;
pthis->quit = quit;
}
return pthis;
}
Entity* player1;
Entity* player2;
bool init(const char* title,int w,int h)
{
if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
SDL_Log("SDL Init");
pthis->window = SDL_CreateWindow(title,SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,w,h,SDL_WINDOW_SHOWN);
if (pthis->window)
{
SDL_Log("Window Created");
}
pthis->renderer = SDL_CreateRenderer(pthis->window,-1,0);
if(pthis->renderer)
{
SDL_Log("Renderer Created");
}
pthis->isRunning = true;
}
else
{
pthis->isRunning = false;
}
EntityManager* em = GetEntityManager(); //新增
player1 = em->addEntity(GetEntity()); //改动,原:player1 = GetEntity();
player2 = em->addEntity(GetEntity());
return pthis->isRunning;
}
void clean()
{
GetEntityManager()->clean(); //新增
//Cast(player1)->clean();
//Cast(player2)->clean();
SDL_DestroyRenderer(pthis->renderer);
SDL_DestroyWindow(pthis->window);
SDL_Quit();
SDL_Log("SDL Clean");
}
int cnt = 0;
void update()
{
cnt++;
GetEntityManager()->update();
//Cast(player1)->update();
//Cast(player2)->update();
}
void render()
{
//SDL_Log("cnt:%d",cnt);
GetEntityManager()->render();
//Cast(player1)->render();
//Cast(player2)->render();
}
void handleEvents()
{
if(SDL_PollEvent(&pthis->events))
{
if(pthis->events.type == SDL_QUIT)
{
quit();
}
}
}
bool running(){return pthis->isRunning;}
static void quit(){pthis->isRunning = false;}
没有合适的资源?快使用搜索试试~ 我知道了~
C语言+ECS游戏框架Class3
共9个文件
h:4个
c:4个
dll:1个
需积分: 1 0 下载量 176 浏览量
2023-04-15
09:41:15
上传
评论
收藏 784KB ZIP 举报
温馨提示
使用纯C语言和ECS游戏框架写的小游戏,Class3 源码
资源推荐
资源详情
资源评论
收起资源包目录
Class3.zip (9个子文件)
Class3
GameFuntion.c 2KB
EntityManager.c 2KB
Config.h 794B
GameFuntion.h 531B
mian.c 618B
EntityManager.h 448B
Entity.h 279B
Entity.c 700B
SDL2.dll 2.39MB
共 9 条
- 1
资源评论
GBEDC
- 粉丝: 115
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功