feat(game_core): 重构游戏引擎并添加新功能
- 重构了游戏引擎的核心逻辑和架构 - 添加了新的实体组件系统(ECS) - 实现了简单的碰撞检测和响应 - 新增了地图和子弹功能 - 优化了输入处理和渲染逻辑 - 调整了游戏控制方式
This commit is contained in:
32
game_core/entities/player.c
Normal file
32
game_core/entities/player.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "entities.h"
|
||||
|
||||
void init_player(ge_ecs_t* ecs, ge_entity_t **_player) {
|
||||
Assert(ecs != NULL && _player != NULL);
|
||||
ge_ecs_add_entity(ecs, _player);
|
||||
ge_entity_t* player = *_player;
|
||||
Assert(player != NULL);
|
||||
|
||||
player->user_type = PLAYER;
|
||||
player->component_mask = GE_COMPONENT_ACVIVE | GE_RENDERABLE_MASK | GE_PHYSICS_MASK | GE_COLLIDER_MASK;
|
||||
player->position = (ge_vector2i_t){ TILEMAP_SIZE * 8, TILEMAP_SIZE * 8 };
|
||||
player->renderable = (ge_render_component_t) {
|
||||
.type = GE_RENDER_COMP_TYPE_RECT,
|
||||
.data.rect = {
|
||||
.size = {TILEMAP_SIZE, TILEMAP_SIZE},
|
||||
.color = GE_COLOR_BLUE,
|
||||
}
|
||||
};
|
||||
player->physics_body = (ge_physics_component_t) {
|
||||
.type = GE_PHYSICS_COMP_TYPE_VELOCITY,
|
||||
.velocity = {0, 0},
|
||||
};
|
||||
player->collision = (ge_collision_component_t) {
|
||||
.type = GE_COLLISION_COMP_TYPE_BOX,
|
||||
.layers = LAYER_PLAYER_HITBOX,
|
||||
.mask = LAYER_WALL,
|
||||
.collider.box = {
|
||||
.relative_pos = {0, 0},
|
||||
.size = {TILEMAP_SIZE, TILEMAP_SIZE},
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user