60 lines
1.3 KiB
Dart
60 lines
1.3 KiB
Dart
|
|
import 'dart:async';
|
||
|
|
|
||
|
|
import 'package:flame/collisions.dart';
|
||
|
|
import 'package:flame/components.dart';
|
||
|
|
import 'package:flame/events.dart';
|
||
|
|
import 'package:flame/extensions.dart';
|
||
|
|
import 'package:funny_letters/gen/assets.gen.dart';
|
||
|
|
import 'package:funny_letters/runner/game_manager.dart';
|
||
|
|
|
||
|
|
import '../main.dart';
|
||
|
|
|
||
|
|
class Player extends SpriteComponent with CollisionCallbacks, HasGameRef<GameManager> {
|
||
|
|
int health = 10;
|
||
|
|
|
||
|
|
Player(Vector2 size) {
|
||
|
|
super.size = size;
|
||
|
|
super.anchor = Anchor.center;
|
||
|
|
}
|
||
|
|
|
||
|
|
void hit() {
|
||
|
|
if (health > 0) {
|
||
|
|
if (difficulty == Difficulty.hard) {
|
||
|
|
health--;
|
||
|
|
}
|
||
|
|
health--;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void heal() {
|
||
|
|
if (health < 10) {
|
||
|
|
health++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
FutureOr<void> onLoad() async {
|
||
|
|
sprite = await gameRef.loadSprite(Assets.images.platform.path);
|
||
|
|
add(
|
||
|
|
RectangleHitbox(
|
||
|
|
size: this.size * 0.9,
|
||
|
|
position: size / 2,
|
||
|
|
anchor: Anchor.center,
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {
|
||
|
|
super.onCollision(intersectionPoints, other);
|
||
|
|
print(position);
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
void onCollisionStart(
|
||
|
|
Set<Vector2> intersectionPoints, PositionComponent other) {
|
||
|
|
super.onCollisionStart(intersectionPoints, other);
|
||
|
|
print(other);
|
||
|
|
}
|
||
|
|
}
|