mardi 31 octobre 2017

How can I convert this Ruby code to C++?

I want to write some code for Game Development with C++ but I can't figure out how to do it, I can only write it in Ruby, this is the code prototype:

class Component
    # ...
end

class Transform < Component
    # ...
end

class Renderer < Component
    # ...
end

class GameObject
    def initialize
        @components = {}
    end

    def update
        @components.each do |component|
            component.update
        end
    end

    def render
        @components.each do |component|
            component.render
        end
    end

    def add_component(component_class)
        component = component_class.new
        @components[component_class] = component
    end

    def rem_component(component_class)
        component = @components.delete(component_class)
        component.destroy if component
    end

    def get_component(component_class)
        return @components[component_class]
    end
end

I don't know how to create the functions GameObject#rem_component and GameObject#get_component. Please, give me some ideas

Aucun commentaire:

Enregistrer un commentaire