mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	 fabbf928d0
			
		
	
	fabbf928d0
	
	
	
		
			
			Enable DCM rule double-literal-format. More details [here](https://dcm.dev/docs/rules/common/double-literal-format/). This both forbids trailing zeroes and mandates leading zeroes. If we would prefer a different style (e.g. prefer no leading zero instead), just lmk :)
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flame/collisions.dart';
 | |
| import 'package:flame/components.dart';
 | |
| import 'package:flame/effects.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| 
 | |
| import '../ember_quest.dart';
 | |
| 
 | |
| class Star extends SpriteComponent with HasGameReference<EmberQuestGame> {
 | |
|   final Vector2 gridPosition;
 | |
|   double xOffset;
 | |
| 
 | |
|   final Vector2 velocity = Vector2.zero();
 | |
| 
 | |
|   Star({
 | |
|     required this.gridPosition,
 | |
|     required this.xOffset,
 | |
|   }) : super(size: Vector2.all(64), anchor: Anchor.center);
 | |
| 
 | |
|   @override
 | |
|   Future<void> onLoad() async {
 | |
|     final starImage = game.images.fromCache('star.png');
 | |
|     sprite = Sprite(starImage);
 | |
|     position = Vector2(
 | |
|       (gridPosition.x * size.x) + xOffset + (size.x / 2),
 | |
|       game.size.y - (gridPosition.y * size.y) - (size.y / 2),
 | |
|     );
 | |
|     add(RectangleHitbox(collisionType: CollisionType.passive));
 | |
|     add(
 | |
|       SizeEffect.by(
 | |
|         Vector2.all(-24),
 | |
|         EffectController(
 | |
|           duration: 0.75,
 | |
|           reverseDuration: 0.5,
 | |
|           infinite: true,
 | |
|           curve: Curves.easeOut,
 | |
|         ),
 | |
|       ),
 | |
|     );
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void update(double dt) {
 | |
|     velocity.x = game.objectSpeed;
 | |
|     position += velocity * dt;
 | |
|     if (position.x < -size.x || game.health <= 0) {
 | |
|       removeFromParent();
 | |
|     }
 | |
|     super.update(dt);
 | |
|   }
 | |
| }
 |