Created
May 2, 2019 14:40
-
-
Save SanderMertens/da3fc96c193ff91e21f23d930aa33c69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(int argc, char *argv[]) { | |
ecs_world_t *world = ecs_init_w_args(argc, argv); | |
ECS_IMPORT(world, FlecsComponentsTransform, ECS_2D); | |
ECS_IMPORT(world, FlecsComponentsGeometry, ECS_2D); | |
ECS_IMPORT(world, FlecsComponentsGraphics, ECS_2D); | |
ECS_IMPORT(world, FlecsComponentsInput, ECS_2D); | |
ECS_IMPORT(world, FlecsSystemsSdl2, ECS_2D); | |
ECS_ENTITY(world, WheelPrefab, EcsPrefab, EcsCircle, EcsColor); | |
ecs_set(world, WheelPrefab, EcsCircle, {.radius = 12}); | |
ecs_set(world, WheelPrefab, EcsColor, {100, 100, 100, 255}); | |
ECS_ENTITY(world, CarPrefab, EcsPrefab); | |
ECS_ENTITY(world, Chassis, EcsPrefab, EcsPosition2D); | |
ecs_set(world, Chassis, EcsPrefab, {.parent = CarPrefab}); | |
ecs_set(world, Chassis, EcsPosition2D, {0, 0}); | |
ecs_set(world, Chassis, EcsRectangle, {.width = 100, .height = 25}); | |
ECS_ENTITY(world, ChassisTop, EcsPrefab, EcsPosition2D); | |
ecs_set(world, ChassisTop, EcsPrefab, {.parent = CarPrefab}); | |
ecs_set(world, ChassisTop, EcsPosition2D, {-5, -15}); | |
ecs_set(world, ChassisTop, EcsRectangle, {.width = 70, .height = 25}); | |
ECS_ENTITY(world, WheelFront, EcsPrefab, WheelPrefab, EcsPosition2D); | |
ecs_set(world, WheelFront, EcsPrefab, {.parent = CarPrefab}); | |
ecs_set(world, WheelFront, EcsPosition2D, {30, 15}); | |
ECS_ENTITY(world, WheelBack, EcsPrefab, WheelPrefab, EcsPosition2D); | |
ecs_set(world, WheelBack, EcsPrefab, {.parent = CarPrefab}); | |
ecs_set(world, WheelBack, EcsPosition2D, {-30, 15}); | |
ecs_entity_t e = ecs_new(world, CarPrefab); | |
ecs_set(world, e, EcsPosition2D, {-150, 0}); | |
e = ecs_new(world, CarPrefab); | |
ecs_set(world, e, EcsPosition2D, {0, 0}); | |
e = ecs_new(world, CarPrefab); | |
ecs_set(world, e, EcsPosition2D, {150, 0}); | |
/* Initialize canvas */ | |
ecs_set(world, 0, EcsCanvas2D, { | |
.window = { .width = 800, .height = 600 }, .title = "Hello ecs_prefab_graphics!" | |
}); | |
/* Enter main loop */ | |
ecs_set_target_fps(world, 60); | |
while ( ecs_progress(world, 0)); | |
/* Cleanup */ | |
return ecs_fini(world); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment