#include "GameFuntion.h"
#include "Entity.h"
#include "EntityManager.h"
#include "TransfromComponent.h"
#include "SpriteComponent.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->addComponent(0); //添加变换组件
player1->addComponent(1); //添加精灵组件----(贴图) //新增
player2 = em->addEntity(GetEntity());
return pthis->isRunning;
}
void clean()
{
// Cast(player1)->clean();
// Cast(player2)->clean();
GetEntityManager()->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);
// Cast(player1)->render();
// Cast(player2)->render();
SDL_SetRenderDrawColor(pthis->renderer,230,231,232,255);
SDL_RenderClear(pthis->renderer);
GetEntityManager()->render();
SDL_RenderPresent(pthis->renderer);
}
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游戏框架Class4-2
共17个文件
c:7个
h:7个
taget:1个
需积分: 0 0 下载量 137 浏览量
2023-04-25
22:26:01
上传
评论
收藏 311KB ZIP 举报
温馨提示
使用纯C语言和ECS游戏框架写的小游戏,Class4第二节 源码
资源推荐
资源详情
资源评论
收起资源包目录
Class4-2.zip (17个子文件)
Class4-2
makefile 213B
GameFuntion.c 3KB
EntityManager.c 2KB
Component.h 1KB
Component.c 24B
SpriteComponent.h 314B
mario.bmp 907KB
Config.h 805B
GameFuntion.h 531B
TransfromComponent.c 568B
EntityManager.h 448B
TransfromComponent.h 295B
taget 66KB
Entity.h 553B
Entity.c 2KB
SpriteComponent.c 891B
main.c 618B
共 17 条
- 1
资源评论
GBEDC
- 粉丝: 115
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功