패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소d3xvn/illume-archive

illume

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 개

  • flutter{"sdk":"flutter"}
  • vector_math^2.1.0
  • flutter_test개발 의존성{"sdk":"flutter"}
  • flutter_lints개발 의존성^1.0.0

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

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

GitHub Docs — About repositories ↗