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

outdated

A library for making audio games. This package started out as a way to create 2d maps for use in games, but has since grown to include tools and methods for making audio games with and without maps.

example/ziggurat_example.dart

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

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

/// A level with some commands registered.
class ExcitingLevel extends Level {
  /// Create the level.
  ExcitingLevel(Game game)
      : coordinate = 0,
        super(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(Game game)
      : super(
            game: game,
            title: Message(text: 'Main Menu'),
            items: [
              MenuItem(Message(text: 'Play'),
                  Button(() => game.replaceLevel(ExcitingLevel(game)))),
              MenuItem(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.SCANCODE_ESCAPE),
        leftCommandTrigger,
        rightCommandTrigger,
        upCommandTrigger,
        downCommandTrigger,
      ]));
  final level = MainMenu(game);
  game.pushLevel(level);
  await game.run(sdl);
}
1
likes
0
pub points
0%
popularity

Publisher

verified publisherbackstreets.site

A library for making audio games. This package started out as a way to create 2d maps for use in games, but has since grown to include tools and methods for making audio games with and without maps.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dart_sdl, encrypt, json_annotation, meta

More

Packages that depend on ziggurat