Created
January 7, 2016 13:11
-
-
Save RichardB01/c89de7a5b884009d8bb7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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; | |
| } | |
| } | |
| } |
This file contains hidden or 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
| 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() { } | |
| } | |
| } |
This file contains hidden or 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
| // 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