A Widget-based Game Engine For Flutter

Overview

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).

You might also like...

Mason templates for the Flame Engine

Flame Bricks 🔥 🧱 Flame Bricks is a collection of Mason's templates to help people bootstrap classes for the Flame engine. How to use To learn more a

Oct 9, 2022

uses Firebase's ML Engine to recognize murals in San Diego's Chicano park.

ABOUT Flutter-based app that uses Firebase's ML Engine to recognize murals in San Diego's Chicano park. App can be run on iOS and android and the trai

Jan 3, 2022

Game characters ui - A redesign of a game characters app using flutter

Game characters ui - A redesign of a game characters app using flutter

Oct 23, 2022

Flutter Switch Game: Get Fun With Play This Game

Flutter Switch Game: Get Fun With Play This Game

switch_game A new Flutter project. Getting Started Try Swap red circle to green

Jun 17, 2022

A simple dice game built using Flutter, that allows users to engage in a dice game

A simple dice game built using Flutter, that allows users to engage in a dice game. Each player rolls the dice and the highest value number that you can make WINS!

Sep 1, 2022

Game Flutter Using Flame.It was for the Game Jam 2022

binarymemory Memory Binary Flame Flutter Game Jam Getting Started This project is a starting point for a Flutter application. A few resources to get y

Sep 7, 2022

A starter game in Flutter with all the bells and whistles of a mobile (iOS & Android) game

A starter game in Flutter with all the bells and whistles of a mobile (iOS & Android) game including the following features: sound music main menu scr

Dec 22, 2022

Chess-game - Some simple lines of coding and made this awesome looking full functional chess board game

Chess-game - Some simple lines of coding and made this awesome looking full functional chess board game

flutter simple chess game It's a flutter chess game application with fast code.

Jun 17, 2022

Wordle-flutter - A Wordle Game Made With Flutter

Wordle-flutter - A Wordle Game Made With Flutter

wordle with flutter A small wordle made with flutter Getting Started Just a 4 ho

Dec 11, 2022
Owner
Deven Joshi
Google Developer Expert, Flutter | Technical Writer | Speaker
Deven Joshi
A minimalist Flutter game engine

A minimalistic Flutter game engine. English | 简体中文 | Polski | Русский About 1.0.0 Our goal is to release v1 soon. We are periodically launching RCs (r

Flame Engine 7.3k Jan 8, 2023
A simple 2D multiplayer online game built using Flutter and Flame engine

Club Penguin Introduction ?? Club Penguin A multiplayer game involving penguins and anonymous chat in a virtual 2D world Before we start, you can take

Sanjeev Madhav 67 Dec 24, 2022
A Flutter RPG Game Engine.

DevilF 游戏引擎 A Flutter RPG Game Engine. 一款使用Flutter开发的RPG游戏引擎。 引擎介绍 (Devil Fighter) 自从有了Flutter,轻松实现了三端跨平台,并且不增加包体积,就能拥有一套Native游戏引擎,为APP游戏化提供了更多可能性。 开

zhaoqipeng 72 Dec 21, 2022
A minimalist Flutter game engine

A minimalistic Flutter game engine. English | 简体中文 | Polski | Русский | Español About 1.0.0 Our goal is to release v1 soon. We are periodically launch

Flame Engine 7.3k Dec 31, 2022
🦖 🦖 🦖 Flutter 2D runner game using Flame engine.

t_rex_flame T-rex is the 2D game where you play as a cute little t-rex using Flame engine. All you need do it avoid being hit by enemies too many time

HuongPT 9 Dec 13, 2022
Dungeon Fantasy - A simple RPG game built with Bonfire and Flame engine

dungeon_fantasy A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Nguyen Minh Dung 1 Dec 28, 2021
A graphics engine for creating 2D games. Creating objects based on composition and painting on canvas.

A graphics engine for creating 2D games. Creating objects based on composition and painting on canvas.

Stanislav 10 Oct 26, 2022
An application cum Game-based App built using Flutter that compose a mind-tricked word game, Just for fun.

destini_challenge A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you st

dev_allauddin 3 Feb 3, 2022
M.U.D. Role-playing text-based game. A multiple-choice multiplayer interactive game developed on Flutter (Android, iOS, Windows, Web)

Teia M.U.D. Role-playing text-based game. A multiple-choice multiplayer interactive game developed on Flutter (Android, iOS, Windows, Web). The main f

Pedro Gonçalves 3 Feb 17, 2022
Snake-Game - A flutter based classic snake game with nothing just and just a feel to have play

snake_game This is a simple snake Game under development made with the help of y

Shubham Kumar 2 Mar 22, 2022