mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
.
This commit is contained in:
@ -1,8 +1,18 @@
|
||||
import 'package:flame/components/component.dart';
|
||||
import 'package:flame/flame.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/components/isometric_tile_map_component.dart';
|
||||
import 'package:flame/gestures.dart';
|
||||
import 'package:flame/position.dart';
|
||||
import 'package:flame/sprite.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const x = 500.0;
|
||||
const y = 500.0;
|
||||
const s = 64;
|
||||
final topLeft = Position(x, y);
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
final Size size = await Flame.util.initialDimensions();
|
||||
@ -10,7 +20,30 @@ void main() async {
|
||||
runApp(game.widget);
|
||||
}
|
||||
|
||||
class MyGame extends BaseGame {
|
||||
class Selector extends SpriteComponent {
|
||||
bool show = false;
|
||||
|
||||
Selector(double s)
|
||||
: super.fromSprite(
|
||||
s,
|
||||
s,
|
||||
Sprite('tiles.png', x: 64, y: 0, width: 32, height: 32),
|
||||
);
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
if (!show) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.render(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
class MyGame extends BaseGame with MouseMovementDetector {
|
||||
IsometricTileMapComponent base;
|
||||
Selector selector;
|
||||
|
||||
MyGame(Size size) {
|
||||
init();
|
||||
}
|
||||
@ -28,22 +61,43 @@ class MyGame extends BaseGame {
|
||||
[-1, 0, 0, 1, -1, -1],
|
||||
[-1, 0, -1, 1, -1, -1],
|
||||
[-1, -1, 0, 1, -1, -1],
|
||||
[-1, 0, 0, 1, -1, -1],
|
||||
[-1, 0, 0, 1, -1, 2],
|
||||
[0, 0, 0, 1, -1, -1],
|
||||
[0, -1, -1, -1, -1, -1],
|
||||
];
|
||||
const x = 500.0;
|
||||
const y = 500.0;
|
||||
const s = 64;
|
||||
final layer2 = [
|
||||
[-1, -1, -1, -1, -1, -1],
|
||||
[-1, -1, -1, -1, -1, -1],
|
||||
[-1, -1, 1, -1, -1, -1],
|
||||
[-1, -1, -1, -1, -1, -1],
|
||||
[-1, -1, 1, -1, -1, -1],
|
||||
[-1, -1, -1, -1, -1, -1],
|
||||
];
|
||||
add(
|
||||
IsometricTileMapComponent(tileset, layer0, destTileSize: s)
|
||||
base = IsometricTileMapComponent(tileset, layer0, destTileSize: s)
|
||||
..x = x
|
||||
..y = y,
|
||||
);
|
||||
add(
|
||||
IsometricTileMapComponent(tileset, layer1, destTileSize: s)
|
||||
..x = x
|
||||
..y = y - s / 2,
|
||||
);
|
||||
// add(
|
||||
// IsometricTileMapComponent(tileset, layer1, destTileSize: s)
|
||||
// ..x = x
|
||||
// ..y = y - s / 2,
|
||||
// );
|
||||
// add(
|
||||
// IsometricTileMapComponent(tileset, layer2, destTileSize: s)
|
||||
// ..x = x
|
||||
// ..y = y - 2 * s / 2,
|
||||
// );
|
||||
add(selector = Selector(s.toDouble()));
|
||||
}
|
||||
|
||||
@override
|
||||
void onMouseMove(PointerHoverEvent event) {
|
||||
final screenPosition = Position.fromOffset(event.position);
|
||||
final blockCoords = base.getBlock(screenPosition);
|
||||
final blockPosition =
|
||||
base.cartToIso(Position.fromInts(blockCoords.x * s, blockCoords.y * s));
|
||||
selector.setByPosition(blockPosition.add(topLeft));
|
||||
selector.show = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user