ziggurat 0.44.1 copy "ziggurat: ^0.44.1" to clipboard
ziggurat: ^0.44.1 copied to clipboard

retractedoutdated

A library for making fully-featured audio games using Dart and SDL.

example/ziggurat_example.dart

/// A quick example.
import 'package:dart_sdl/dart_sdl.dart';
import 'package:ziggurat/levels.dart';
import 'package:ziggurat/menus.dart';
import 'package:ziggurat/ziggurat.dart';

final quitCommandTrigger = CommandTrigger.basic(
  name: 'quit',
  description: 'Quit the game',
  scanCode: ScanCode.q,
  button: GameControllerButton.leftshoulder,
);
final leftCommandTrigger = CommandTrigger.basic(
  name: 'left',
  description: 'Decrease the coordinate',
  scanCode: ScanCode.left,
  button: GameControllerButton.dpadLeft,
);
const rightCommandTrigger = CommandTrigger(
  name: 'right',
  description: 'Increase the coordinate',
  keyboardKey: CommandKeyboardKey(ScanCode.right),
  button: GameControllerButton.dpadRight,
);
const upCommandTrigger = CommandTrigger(
  name: 'up',
  description: 'Move up in the menu',
  keyboardKey: CommandKeyboardKey(ScanCode.up),
  button: GameControllerButton.dpadUp,
);
const downCommandTrigger = CommandTrigger(
  name: 'down',
  description: 'Move down in a menu',
  keyboardKey: CommandKeyboardKey(ScanCode.down),
  button: GameControllerButton.dpadDown,
);

/// A level with some commands registered.
class ExcitingLevel extends Level {
  /// Create the level.
  ExcitingLevel(final Game game)
      : coordinate = 0,
        super(game: game) {
    registerCommand(
      quitCommandTrigger.name,
      Command(
        onStart: () => game.replaceLevel(MainMenu(game)),
      ),
    );
    registerCommand(
      leftCommandTrigger.name,
      Command(
        onStart: () {
          coordinate--;
          game.outputText('Left: $coordinate');
        },
        interval: 500,
      ),
    );
    registerCommand(
      rightCommandTrigger.name,
      Command(
        onStart: () {
          coordinate++;
          game.outputText('Right: $coordinate');
        },
        interval: 500,
      ),
    );
  }

  /// The x/y coordinate.
  int coordinate;
}

/// The main menu.
class MainMenu extends Menu {
  /// Create the menu.
  MainMenu(final Game game)
      : super(
          game: game,
          title: const Message(text: 'Main Menu'),
          items: [
            MenuItem(
              const Message(text: 'Play'),
              Button(() => game.replaceLevel(ExcitingLevel(game))),
            ),
            MenuItem(
              const Message(text: 'Quit'),
              Button(game.stop),
            )
          ],
          onCancel: () => game.outputText('You cannot exit from this menu.'),
        );
}

Future<void> main() async {
  final sdl = Sdl()..init();
  final game = Game(
    'Ziggurat Example',
    triggerMap: TriggerMap([
      quitCommandTrigger,
      CommandTrigger.basic(
        name: quitCommandTrigger.name,
        description: 'Quit the game',
        scanCode: ScanCode.escape,
      ),
      leftCommandTrigger,
      rightCommandTrigger,
      upCommandTrigger,
      downCommandTrigger,
    ]),
  );
  final level = MainMenu(game);
  await game.run(
    sdl,
    onStart: () => game.pushLevel(level),
  );
}
1
likes
0
pub points
0%
popularity

Publisher

verified publisherbackstreets.site

A library for making fully-featured audio games using Dart and SDL.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dart_sdl, encrypt, json_annotation, meta, path

More

Packages that depend on ziggurat