Exemple #1
0
void add_yoshi( std::vector<std::shared_ptr<Object> > &objects, int x, int y)
{
    DrawablePtr yoshi (new Drawable());
    yoshi->SetTexture(1);
    yoshi->SetWidth(64.0);
    yoshi->SetHeight(64.0);
    yoshi->SetMaxFrame(8);
    yoshi->SetFrameRate(4);
    yoshi->SetLayer(Render::LayerBg);

    std::shared_ptr<RenderComponent> render_comp (new RenderComponent());
    render_comp->AddDrawable(yoshi);
    render->AddComponent(render_comp);

    std::shared_ptr<AIComponent> ai_comp(new AIComponent());
    ai_comp->SetMaxSpeed(3.5);
    ai_world->AddComponent(ai_comp);

    std::shared_ptr<PhysicsComponent> phy_comp(new PhysicsComponent());

    std::shared_ptr<Object> yoshi_obj(new Object());
    yoshi_obj->SetPosition(Vector(x, y));
    yoshi_obj->SetComponent(AIComponentId, ai_comp);
    yoshi_obj->SetComponent(RenderComponentId, render_comp);
    yoshi_obj->SetComponent(PhysicsComponentId, phy_comp);

    objects.emplace_back(yoshi_obj);
}