Skip to content

Instantly share code, notes, and snippets.

@aprius
Last active February 8, 2023 16:16
Show Gist options
  • Save aprius/d4de9e6dc44db6c79e85cf5045f57d48 to your computer and use it in GitHub Desktop.
Save aprius/d4de9e6dc44db6c79e85cf5045f57d48 to your computer and use it in GitHub Desktop.
class Renderable : IRenderable
{
public void render()
{
}
}
class Moveable : IMoveable
{
public void move(float time)
{
}
}
class Spaceship
{
public IRenderable renderData;
public IMoveable moveData;
}
public void createSpaceship()
{
var spaceship = new Spaceship();
...
renderProcess.addItem( spaceship.renderData );
moveProcess.addItem( spaceship.moveData );
...
return spaceship;
}
public void createSpaceship()
{
var spaceship = new SpaceShipEntity();
var position = new PositionComponent();
position.x = Screen.width / 2;
position.y = Screen.height / 2;
var rotation = new RotationComponent();
rotation.x = 0;
rotation.y = 0;
spaceship.add( position );
spaceship.add( rotation );
var display = new DisplayComponent();
display.view = new SpaceshipImage();
spaceship.add( display );
engine.add( spaceship );
}
public class Engine
{
private List<Entity> entities;
private List<ISystem> systems;
public void addEntity(Entity entity )
{
entities.add( entity );
}
public void removeEntity(Entity entity )
{
entities.remove( entity );
}
public void addSystem(ISystem system,int priority )
{
systems.add( system, priority );
system.start();
}
public void removeSystem(ISystem system )
{
system.end();
systems.remove( system );
}
public T getComponent( type ):
{
// TODO
}
public void update( float time )
{
foreach( var system in systemes )
{
system.update( time );
}
}
}
interface IMoveable
{
void move(float time);
}
class MoveProcess : IProcess
{
private List<IMoveable> targets;
public bool start()
{
return true;
}
public void update(float time)
{
foreach(var target in targets)
{
target.move(time);
}
}
public void end()
{
}
}
class Moveable : IMoveable
{
public Vector2 position;
public Vector2 rotation;
public Vector2 velocity;
public Vector2 angularVelocity;
public void move(float time)
{
position += velocity * time;
rotation += angularVelocity * time;
}
}
class Spaceship : Moveable
{
}
interface IMoveable
{
void move(float time);
}
class Moveable : IMoveable
{
public PositionComponent position;
public RotationComponent rotation;
public VelocityComponent velocity;
public void move(float time)
{
position.x += velocity.velocityX * time;
position.y += velocity.velocityY * time;
position.rotation.x += velocity.angularVelocity.x * time;
position.rotation.y += velocity.angularVelocity.y * time;
}
}
class MoveProcess : IProcess
{
private List<IMoveable> targets;
public void move(float time)
{
foreach( var target in targets )
{
target.move(time);
}
}
}
class InvisibleMoveable : IMoveable
{
public Vector2 position;
public Vector2 rotation;
public Vector2 velocity;
public Vector2 angularVelocity;
public void move(float time ):void
{
position += velocity * time;
rotation += angularVelocity * time;
}
}
interface IProcess
{
bool start();
void update(float time );
void end();
}
interface IRenderable
{
void render();
}
interface IRenderable
{
void render();
}
class Renderable : IRenderable
{
public DisplayComponent display;
public PositionComponent position;
public function render():void
{
display.view.position = position;
display.view.rotation = position.rotation;
}
}
class RenderProcess : IProcess
{
private List<IRenderable> targets;
public void update(float time )
{
foreach( var target in targets )
{
target.render();
}
}
}
class Moveable : Renderable, IMoveable
{
public Vector2 velocity;
public Vector2 angularVelocity;
public function move(float time):void
{
position += velocity.x * time;
rotation += angularVelocity * time;
}
}
class Spaceship : Moveable
{
}
class MoveData
{
public PositionComponent position;
public RotationComponent rotation;
public VelocityComponent velocity;
}
class MoveProcess : IProcess
{
private List<MoveData> targets;
public void move(float time)
{
foreach( var target in targets )
{
target.position.x += target.velocity.velocityX * time;
target.position.y += target.velocity.velocityY * time;
target.position.rotation.x += target.velocity.angularVelocity.x * time;
}
}
}
void update(float time)
{
game.update(time);
spaceship.updateInputs(time);
foreach(var flyingSaucer in flyingSaucers)
{
flyingSaucer.updateAI(time);
}
spaceship.update(time);
foreach(var flyingSaucer in flyingSaucers)
{
flyingSaucer.update( time );
}
foreach(var asteroid in asteroids)
{
asteroid.update( time );
}
foreach(var bullet in bullets)
{
bullet.update( time );
}
collisionManager.update(time);
spaceship.render();
foreach(var flyingSaucer in flyingSaucers)
{
flyingSaucer.render();
}
foreach(var asteroid in asteroids)
{
asteroid.render();
}
foreach(var bullet in bullets)
{
bullet.render();
}
}
interface IRenderable
{
void render();
}
class RenderProcess : IProcess
{
private List<IRenderable> targets;
public void update(float time)
{
foreach(var target in targets)
{
target.render();
}
}
}
interface IMoveable
{
void move();
}
class MoveProcess : IProcess
{
private List<IMoveable> targets;
public void update(float time)
{
foreach(var target in targets)
{
target.move(time);
}
}
}
class PositionComponent
{
public float x;
public float y;
public float z;
}
class RotationComponent
{
public float x;
public float y;
public float z;
}
class VelocityComponent
{
public float velocityX;
public float velocityY;
public float velocityZ;
}
class AngularVelocityomponent
{
public float angularVelocityX;
public float angularVelocityY;
public float angularVelocityZ;
}
class DisplayComponent
{
public DisplayObject view;
}
class Renderable : IRenderable
{
public DisplayComponent display;
public PositionComponent position;
public RotationComponent rotation;
public void render()
{
display.view.position = position.position;
display.view.rotation = position.rotation;
}
}
class Moveable : IMoveable
{
public PositionComponent position;
public RotationComponent rotation;
public VelocityComponent velocity;
public AngularVelocityomponent angularVelocity;
public void move(float time )
{
position.x += velocity.x * time;
position.y += velocity.y * time;
rotation.x += angularVelocity.x * time;
rotation.y += angularVelocity.y * time;
}
}
class ProcessManager
{
private PrioritisedList processes;
public bool addProcess( IProcess process, int priority )
{
if( process.start() )
{
processes.add(process, priority);
return true;
}
return false;
}
public void update(float time )
{
foreach(IProcess proces in processes)
{
process.update(time);
}
}
public void removeProcess(IProcess proces)
{
process.end();
processes.remove( process );
}
}
class Renderable : IRenderable
{
public DisplayObject view;
public Vector2 position;
public Vector2 rotation;
public void render()
{
view.position = position;
view.rotation = rotation;
}
}
class Spaceship : Renderable
{
}
class Asteroid : Renderable
{
}
class Bullet : Renderable
{
}
class RenderData
{
public DisplayComponent display;
public PositionComponent position;
public RotationComponent rotation;
}
class RenderProcess : IProcess
{
private List<RenderData> targets;
public void update(float time)
{
foreach(var target in targets )
{
target.display.view.position = target.position;
target.display.view.rotation = target.rotation;
}
}
}
class RenderProcess : IProcess
{
public bool start()
{
// Initializing the render system
return true;
}
public void update( float time )
{
spaceship.render();
foreach( var flyingSaucer in flyingSaucers )
{
flyingSaucer.render();
}
foreach( var asteroid in asteroids )
{
asteroid.render();
}
foreach( var bullet in bullets )
{
bullet.render();
}
}
public void end()
{
// Cleaning up the render system
}
}
class RenderProcess : IProcess
{
private List<IRenderable> targets;
public function start() : Boolean
{
// init render system
return true;
}
public void update(float time)
{
foreach( var target in targets)
{
target.render();
}
}
public void end()
{
// Cleaning up the render system
}
}
class Spaceship
{
public function Spaceship()
{
moveData = new Moveable();
renderData = new Renderable();
moveData.position = new PositionComponent();
moveData.Rotation = new RotationComponent();
moveData.velocity = new VelocityComponent();
renderData.position = moveData.position;
renderData.rotation = moveData.rotation;
renderData.display = new DisplayComponent();
}
}
class Spaceship
{
public MoveData moveData;
public RenderData renderData;
}
class Spaceship
{
public PositionComponent position;
public RotationComponent rotation;
public VelocityComponent velocity;
public DisplayComponent display;
}
class MoveData
{
public PositionComponent position;
public RotationComponent rotation;
public VelocityComponent velocity;
public AngularVelocityComponent angularVelocity;
}
class RenderData
{
public DisplayComponent display;
public PositionComponent position;
public RotationComponent rotation;
}
class PositionComponent
{
public float x;
public float y;
}
class RotationComponent
{
public float x;
public float y;
}
class VelocityComponent
{
public float velocityX;
public float velocityY;
}
class AngularVelocityComponent
{
public float angularVelocityX;
public float angularVelocityY;
}
class DisplayComponent
{
public DisplayObject view;
}
class SpaceShipEntity
{
private Dictionary components;
public void add(Object component)
{
...
}
public void remove(key)
{
...
}
public T get(key)
{
...
}
}
class MoveProcess : IProcess
{
private List<MoveData> targets;
public void move(float time )
{
foreach( var target in targets )
{
target.position.x += target.velocity.velocityX * time;
target.position.y += target.velocity.velocityY * time;
target.position.rotation.x += target.velocity.angularVelocityX * time;
target.position.rotation.y += target.velocity.angularVelocityY * time;
}
}
}
class RenderProcess : IProcess
{
private List<RenderData> targets;
public void update(float time )
{
foreach( var target in targets )
{
target.display.view.position = target.position;
target.display.view.rotation = target.rotation;
}
}
}
class MoveSystem : ISystem
{
private List<MoveData> targets;
public void update(float time)
{
//TO_DO
}
}
class RenderSystem : ISystem
{
private List<RenderData> targets;
public void update(float time)
{
// TO_DO
}
}
interface ISystem
{
void update(float time);
}
class SystemManager
{
private PrioritisedList systems;
public void addSystem(ISystem system, int priority)
{
systems.add( system, priority );
system.start();
}
public void update(float time )
{
for each( var system in systemes )
{
system.update( time );
}
}
public function removeSystem(ISystem system )
{
system.end();
systems.remove( system );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment