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 :)
		
			
				
	
	
		
			67 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flame/components.dart';
 | |
| import 'package:flame/events.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flame/input.dart';
 | |
| import 'package:flame/parallax.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| 
 | |
| void main() {
 | |
|   runApp(GameWidget(game: SpaceShooterGame()));
 | |
| }
 | |
| 
 | |
| class SpaceShooterGame extends FlameGame with PanDetector {
 | |
|   late Player player;
 | |
| 
 | |
|   @override
 | |
|   Future<void> onLoad() async {
 | |
|     final parallax = await loadParallaxComponent(
 | |
|       [
 | |
|         ParallaxImageData('stars_0.png'),
 | |
|         ParallaxImageData('stars_1.png'),
 | |
|         ParallaxImageData('stars_2.png'),
 | |
|       ],
 | |
|       baseVelocity: Vector2(0, -5),
 | |
|       repeat: ImageRepeat.repeat,
 | |
|       velocityMultiplierDelta: Vector2(0, 5),
 | |
|     );
 | |
|     add(parallax);
 | |
| 
 | |
|     player = Player();
 | |
|     add(player);
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void onPanUpdate(DragUpdateInfo info) {
 | |
|     player.move(info.delta.global);
 | |
|   }
 | |
| }
 | |
| 
 | |
| class Player extends SpriteAnimationComponent
 | |
|     with HasGameReference<SpaceShooterGame> {
 | |
|   Player()
 | |
|       : super(
 | |
|           size: Vector2(100, 150),
 | |
|           anchor: Anchor.center,
 | |
|         );
 | |
| 
 | |
|   @override
 | |
|   Future<void> onLoad() async {
 | |
|     await super.onLoad();
 | |
| 
 | |
|     animation = await game.loadSpriteAnimation(
 | |
|       'player.png',
 | |
|       SpriteAnimationData.sequenced(
 | |
|         amount: 4,
 | |
|         stepTime: 0.2,
 | |
|         textureSize: Vector2(32, 48),
 | |
|       ),
 | |
|     );
 | |
| 
 | |
|     position = game.size / 2;
 | |
|   }
 | |
| 
 | |
|   void move(Vector2 delta) {
 | |
|     position.add(delta);
 | |
|   }
 | |
| }
 |