<|start_filename|>lib/components/core/gameobject.dart<|end_filename|>
import 'dart:ui';
import 'package:flutters/flutters-game.dart';

class GameObject {
  final FluttersGame game;
  List<GameObject> children = List<GameObject>();
  GameObject(this.game);

  void render(Canvas c) {
    children.forEach((child) => child.render(c));
  }

  void update(double t) {
    children.forEach((child) => child.update(t));
  }

  void addChild(GameObject child) {
    children.add(child);
  }

  void removeChild(GameObject child) {
    for (GameObject obj in children) {
      if (obj == child) {
        children.remove(obj);
      }
    }
  }
}


<|start_filename|>lib/components/floor.dart<|end_filename|>
import 'dart:ui';

import 'package:flutters/components/core/gameobject.dart';
import 'package:flutters/flutters-game.dart';

class Floor extends GameObject {
  Rect rect;
  Paint paint;

  int colorCode;

  Floor(FluttersGame game, double x, double y, double width, double height,
      int colorCode)
      : super(game) {
    this.colorCode = colorCode;
    rect = Rect.fromLTWH(x, y, width, height);
    paint = Paint();
    paint.color = Color(colorCode);
  }

  @override
  void render(Canvas c) {
    c.drawRect(rect, paint);
  }

  @override
  void update(double t) {
    // TODO: implement update
  }
}


<|start_filename|>lib/components/background.dart<|end_filename|>
import 'dart:ui';

import 'package:flutter/rendering.dart';
import 'package:flutters/components/cloud.dart';
import 'package:flutters/components/core/gameobject.dart';
import 'package:flutters/flutters-game.dart';

class Background extends GameObject {
  final Gradient gradient = new LinearGradient(
    begin: Alignment.topCenter,
    colors: <Color>[
      Color(0xff0165b1),
      Color(0xffFFFFFF),
    ],
    stops: [
      0.0,
      1.0,
    ],
    end: Alignment(0, 0.9),
  );
  Rect rect;
  Paint paint;
  Background(FluttersGame game, double x, double y, double width, double height)
      : super(game) {
    paint = Paint();
    paint.color = Color(0xff77b5e1);

    rect = Rect.fromLTWH(x, y, width, height);
    paint = new Paint()..shader = gradient.createShader(rect);
    this.addChild(new Cloud(this.game, 0, game.tileSize * 1.7));
    this.addChild(new Cloud(this.game, 0, game.tileSize * 4.4));
  }

  @override
  void render(Canvas c) {
    c.drawRect(rect, paint);
    super.render(c);
  }

  @override
  void update(double t) {
    super.update(t);
  }
}


<|start_filename|>lib/components/cloud.dart<|end_filename|>
import 'dart:math';
import 'dart:ui';

import 'package:flame/sprite.dart';
import 'package:flutters/components/core/gameobject.dart';
import 'package:flutters/flutters-game.dart';

class Cloud extends GameObject {
  final Random rng = new Random();
  final List<Sprite> cloudSprites = [
    Sprite('cloud-1.png'),
    Sprite('cloud-2.png'),
    Sprite('cloud-3.png')
  ];

  Rect rect;
  Paint paint;

  double x;
  double y;
  double width = 100;
  double height = 100;

  int direction;
  int cloudType;
  double speedRng;
  double movementSpeed;

  Cloud(FluttersGame game, this.x, this.y) : super(game) {
    x = rng.nextDouble() * game.viewport.width;
    movementSpeed = rng.nextDouble() * game.viewport.width / 4;
    cloudType = rng.nextInt(2);
    direction = rng.nextBool() == true ? 1 : -1;
  }

  @override
  void render(Canvas c) {
    paint = Paint();
    // Transparent bounding box
    paint.color = Color(0x00000000);
    width = game.tileSize / 5 * (533 / 100);
    height = game.tileSize / 5 * (185 / 100);
    rect = Rect.fromLTWH(x, y, width, height);
    c.drawRect(rect, paint);
    cloudSprites[cloudType].renderRect(c, rect.inflate(0));
  }

  @override
  void update(double t) {
    checkCollision();
    x += direction * movementSpeed * t;
  }

  void checkCollision() {
    if (x >= game.viewport.width - width) {
      direction = -1;
    } else if (x <= 0) {
      direction = 1;
    }
  }
}


<|start_filename|>lib/components/obstacle.dart<|end_filename|>
import 'dart:math';
import 'dart:ui';

import 'package:flutters/components/core/gameobject.dart';
import 'package:flutters/flutters-game.dart';

class Obstacle extends GameObject {
  final Random rng = new Random();

  Rect rect;
  Paint paint;

  double x;
  double y;
  double width;
  double height;

  bool isMoving;
  int direction;
  double movementSpeed;

  Obstacle(
      FluttersGame game, this.x, this.y, this.width, this.height, this.isMoving)
      : super(game) {
    movementSpeed = game.viewport.width / 4;
    direction = rng.nextBool() == true ? 1 : -1;
    paint = Paint();
    paint.color = Color(0xff3D4852);
  }

  @override
  void render(Canvas c) {
    rect = Rect.fromLTWH(x, y, width, height);
    c.drawRect(rect, paint);
  }

  @override
  void update(double t) {
    if (isMoving) {
      checkCollision();
      x += direction * movementSpeed * t;
    }
  }

  void checkCollision() {
    if (x >= game.viewport.width - width) {
      direction = -1;
    } else if (x <= 0) {
      direction = 1;
    }
  }

  void markHit() {
    paint.color = Color(0xffEF5753);
  }

  Rect toRect() {
    return Rect.fromLTWH(x, y, width, height);
  }
}
