feat(game_core): 重构游戏引擎并添加新功能
- 重构了游戏引擎的核心逻辑和架构 - 添加了新的实体组件系统(ECS) - 实现了简单的碰撞检测和响应 - 新增了地图和子弹功能 - 优化了输入处理和渲染逻辑 - 调整了游戏控制方式
This commit is contained in:
@@ -18,6 +18,43 @@ ge_render_system_init(ge_render_system_t* ctx, ge_render_t* render) {
|
||||
|
||||
#define _GE_RENDERABLE_MASK (GE_RENDERABLE_MASK | GE_COMPONENT_ACVIVE)
|
||||
|
||||
static inline void
|
||||
ge_render_system_draw_basic(
|
||||
ge_render_system_t* ctx,
|
||||
ge_render_component_t* comp,
|
||||
ge_render_pos2_t* pos) {
|
||||
Assert(comp->type < GE_RENDER_COMP_TYPE_SIZE);
|
||||
switch (comp->type) {
|
||||
case GE_RENDER_COMP_TYPE_POINT:
|
||||
ctx->render->func_draw_point(
|
||||
ctx->render,
|
||||
pos,
|
||||
comp->data.point.color
|
||||
);
|
||||
break;
|
||||
case GE_RENDER_COMP_TYPE_RECT:
|
||||
ctx->render->func_draw_rect(
|
||||
ctx->render,
|
||||
&(ge_render_rect_t) {
|
||||
*pos,
|
||||
comp->data.rect.size,
|
||||
},
|
||||
comp->data.rect.color
|
||||
);
|
||||
break;
|
||||
case GE_RENDER_COMP_TYPE_TEXT:
|
||||
TODO();
|
||||
break;
|
||||
case GE_RENDER_COMP_TYPE_RECOURCE:
|
||||
TODO();
|
||||
break;
|
||||
default:
|
||||
LOG_WARN("render component not set Avaliable type %d at [%d,%d]",
|
||||
comp->type, pos->x, pos->y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
ge_render_system_draw_all(ge_render_system_t* ctx) {
|
||||
Assert(ctx != NULL);
|
||||
@@ -35,33 +72,22 @@ ge_render_system_draw_all(ge_render_system_t* ctx) {
|
||||
ge_render_component_t* comp = &entity->renderable;
|
||||
Assert(comp != NULL);
|
||||
|
||||
switch (comp->type) {
|
||||
case GE_RENDER_COMPONENT_TYPE_POINT:
|
||||
ctx->render->func_draw_point(
|
||||
ctx->render,
|
||||
&pos,
|
||||
comp->data.point.color
|
||||
);
|
||||
break;
|
||||
case GE_RENDER_COMPONENT_TYPE_RECT:
|
||||
ctx->render->func_draw_rect(
|
||||
ctx->render,
|
||||
&(ge_render_rect_t) {
|
||||
pos,
|
||||
comp->data.rect.size,
|
||||
},
|
||||
comp->data.rect.color
|
||||
);
|
||||
break;
|
||||
case GE_RENDER_COMPONENT_TYPE_TEXT:
|
||||
TODO();
|
||||
break;
|
||||
case GE_RENDER_COMPONENT_TYPE_RECOURCE:
|
||||
TODO();
|
||||
break;
|
||||
default:
|
||||
LOG_WARN("render component not set Avaliable type %d, id %d", comp->type, i);
|
||||
break;
|
||||
if (comp->type != GE_RENDER_COMP_TYPE_TILEMAP) {
|
||||
ge_render_system_draw_basic(ctx, comp, &pos);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int y = 0; y < comp->data.tilemap.map_size.y; y++) {
|
||||
for (int x = 0; x < comp->data.tilemap.map_size.x; x++, pos.x += comp->data.tilemap.tile_size) {
|
||||
ge_render_component_t* tile = (comp->data.tilemap.components)
|
||||
[y * comp->data.tilemap.map_size.x + x];
|
||||
if (tile == NULL || tile->type == GE_RENDER_COMP_TYPE_NONE) {
|
||||
continue;
|
||||
}
|
||||
ge_render_system_draw_basic(ctx, tile, &pos);
|
||||
}
|
||||
pos.x -= comp->data.tilemap.map_size.x * comp->data.tilemap.tile_size;
|
||||
pos.y += comp->data.tilemap.tile_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user