oxygen 0.1.0 copy "oxygen: ^0.1.0" to clipboard
oxygen: ^0.1.0 copied to clipboard

outdated

A lightweight Entity Component System framework written in Dart

example/lib/main.dart

import 'dart:io';

import 'package:oxygen/oxygen.dart';

import 'systems/move_system.dart';
import 'systems/render_system.dart';
import 'components/position_component.dart';
import 'components/render_component.dart';

const TARGET_FPS = 2;
const FRAME_TIME = 1000 ~/ TARGET_FPS;

void main(List<String> arguments) {
  if (!stdout.supportsAnsiEscapes) {
    throw Exception(
      'Sorry only terminals that support ANSI escapes are supported',
    );
  }

  final world = World();

  world.registerSystem(MoveSystem());
  world.registerSystem(RenderSystem());
  world.registerComponent(() => PositionComponent());
  world.registerComponent(() => RenderComponent());

  var offset = 0;
  for (var y = .0; y < stdout.terminalLines; y++) {
    for (var x = .0; x < 3; x++) {
      world.createEntity()
        ..add<RenderComponent, String>('x')
        ..add<PositionComponent, Position>(Position(x + offset, y));
    }
    offset++;
  }

  world.init();

  var watch = Stopwatch()..start();
  var last = watch.elapsedMilliseconds;

  void run() {
    final time = watch.elapsedMilliseconds;
    final delta = time - last;
    world.execute(delta / FRAME_TIME);
    last = time;

    sleep(Duration(milliseconds: FRAME_TIME));
    run();
  }

  run();
}
20
likes
0
pub points
76%
popularity

Publisher

verified publisherflame-engine.org

A lightweight Entity Component System framework written in Dart

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

meta

More

Packages that depend on oxygen