Skip to content

Instantly share code, notes, and snippets.

@RichardB01
Created January 7, 2016 13:11
Show Gist options
  • Save RichardB01/c89de7a5b884009d8bb7 to your computer and use it in GitHub Desktop.
Save RichardB01/c89de7a5b884009d8bb7 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
namespace FallingSpheres.Components
{
public class Component
{
public override string ToString()
{
return this.GetType().Name;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FallingSpheres.Components;
using OpenTK;
namespace FallingSpheres.Entities
{
class Entity
{
protected List<Component> Components = new List<Component>();
public void AddComponent(Component inComponent)
{
Components.Add(inComponent);
}
public void RemoveComponent(Component inComponent)
{
Components.Remove(inComponent);
}
public Component GetComponent(string inTypeName)
{
return Components.FirstOrDefault(comp => comp.ToString() == inTypeName);
}
public virtual void Load() { }
public virtual void Update(FrameEventArgs e) { }
public virtual void Render() { }
public virtual void Unload() { }
}
}
// LOADING //
// setup a sphere entity.
_sphereEnt = new Sphere();
// setup a model component for it.
Model model = new Model();
model.FromScene(AssetLoader.FromFile("couch1.obj"));
// setup a transform component for it.
Transform trans = new Transform();
_sphereEnt.AddComponent(model);
_sphereEnt.AddComponent(trans);
// UPDATING //
Transform referencedTrans = (Transform)_sphereEnt.GetComponent("Transform");
referencedTrans.Position += new Vector3(1, 0, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment