搜尋套件、儲存庫與 APP 分類

GitHub 儲存庫d3xvn/illume-archive

illume

基於 Widget 的 Flutter 遊戲引擎

illume 專案封面
星標
24
分支
3
最近推送(UTC)
2022年4月23日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

illume

A Widget-based Game Engine for Flutter

Illume is a simple Flutter game engine which uses widgets to create game objects instead of sprites in normal game engines. This allows the app and game part to be quite integrated and use a lot of common components without needing graphics work to create sprites and backgrounds (which was honestly my main motivation, since I don't know anything about graphic design). It's also quite easy to create and manage the game state as shown in the features ahead. A lot of functionality still needs to be implemented including physics - only normal box-based collision is currently implemented.

Some parts were inspired by other game engines, primarily Flame.

DISCLAIMER: Since widgets are heavier than sprites drawn on a canvas, this engine is going to be less performant than others. It is in a very early stage and I plan to add a lot of features but this is primarily due to my interest in having widget-based game engines -- any serious game development should still be carried out with more mature engines like Flame. This is just meant as an experiment to satisfy my curiosity. I quite like - and still heavily use the main Flutter game engines whose development teams I respect a lot.

Features

Use Widgets directly to build your game objects
class FlappyWidget extends GameObject {

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.blue,
      child: const Text('Demo'),
    );
  }

  @override
  void init() {}

  @override
  void onCollision(List<Collision> collisions) { }

  @override
  void onScreenSizeChange(Vector2 size) {}

  @override
  void update(Duration delta) {}

  //...
}
Easy game development without large separation between widgets and games

You can add a game to your app simply by adding an Illume widget and an IllumeController. (More info given in usage section)

class _MyHomePageState extends State<MyHomePage> {
  IllumeController gameController = IllumeController();

  FlappyWidget flappyWidget = FlappyWidget();

  @override
  void initState() {
    super.initState();
    gameController.startGame();
    gameController.gameObjects.add(flappyWidget);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Illume(
        illumeController: gameController,
      ),
    );
  }
}

// Definition of game object given later
IllumeController allows easy manipulation of game state
  IllumeController gameController = IllumeController();

  gameController.startGame();
  gameController.gameObjects.add(DemoObject());
  gameController.stopGame();
  // etc

The controller is also available for use in all game objects so no need for an abundance of callbacks.

Collision detection

Collision detection is enabled by default for all objects which can be turned off. Every object is notified of collisions as well as given the Rect of intersection so collisions can be better understood. This is a very early prototype so no complex physics (Box2d-ish) exist but I hope to add this in the future.

class FlappyWidget extends GameObject {

  //...
  
  @override
  void onCollision(List<Collision> collisions) { 
    // This gives a list of objects which are colliding with this one 
    // as well as the rect of intersection.
  }

  //...
}
Gesture Detection

This is technically NOT a feature of illume since we can use the default Flutter gesture detecting widgets like the GestureDetector to power our apps. Check the example provided in the repo for more but here is a short demo:

@override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        flappyWidget.jump();
      },
      child: Scaffold(
        appBar: AppBar(
          title: Text('Illume Demo'),
        ),
        body: Illume(
          illumeController: gameController,
        ),
      ),
    );
  }

Usage

Step 1

Add the dependency first:

dependencies:
  illume: ^0.1.0
Step 2

Add the Illume widget and associated IllumeController wherever you need to create a game:

IllumeController gameController = IllumeController();

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Illume Demo'),
      ),
      body: Illume(
        illumeController: gameController,
      ),
    );
  }
Step 3

Define your GameObject by extending the class:

class FlappyWidget extends GameObject {
  var velocity = 0.0;
  var acceleration = 0.2;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.blue,
      child: const Text('Demo'),
    );
  }

  @override
  void init() {
    size = Vector2.all(50);
    alignment = GameObjectAlignment.center;
    position = (gameSize / 2);
  }

  @override
  void onCollision(List<Collision> collisions) {
    illumeController.stopGame();
  }

  @override
  void onScreenSizeChange(Vector2 size) {
    // This is a quick demo but you really should shift your positions in a
    // real world app or at least lock orientation.
  }

  @override
  void update(Duration delta) {
    position += Vector2(0, velocity);
    velocity = velocity + acceleration;
  }

  void jump() {
    velocity = -5;
  }
}
Note: In the object there are various properties -
  • gameSize gives the max size for the game.
  • alignment allows you to align the center to the center of the widget or the top left corner of the widget.
  • position is the position of the widget.
  • size is the size of the widget.
  • illumeController is the game controller for the game.
Step 4

Add the object to the game and start the game:

  FlappyWidget flappyWidget = FlappyWidget();

  @override
  void initState() {
    super.initState();
    gameController.startGame();
    gameController.gameObjects.add(flappyWidget);
  }

Check out the full example for the demo flappy bird game (This is a very basic demo for now, I'll add a far better one later).

Deven Joshi GitHub avatar
GitHub 作者

Deven Joshi ↗

Developer Relations Lead @GetStream 🥑 | Google Developer Expert, Flutter 💙

getstream.ioAmsterdam, The Netherlands
語言DartHTMLSwiftKotlinObjective-C

分類

使用的依賴

依賴清單 4 項

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗